diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 1a13b869e7af..d90d4814d787 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -94,8 +94,8 @@ export default async function preprocess( for (const fn of script) { source = await replace_async( source, - /|([^]*?)<\/script>/gi, - async (match, attributes = '', content) => { + /|([^]*?)<\/script>|\/>)/gi, + async (match, attributes = '', content = '') => { if (!attributes && !content) { return match; } @@ -114,8 +114,8 @@ export default async function preprocess( for (const fn of style) { source = await replace_async( source, - /|([^]*?)<\/style>/gi, - async (match, attributes = '', content) => { + /|([^]*?)<\/style>|\/>)/gi, + async (match, attributes = '', content = '') => { if (!attributes && !content) { return match; } diff --git a/test/preprocess/samples/script-self-closing/_config.js b/test/preprocess/samples/script-self-closing/_config.js new file mode 100644 index 000000000000..4baab9730e12 --- /dev/null +++ b/test/preprocess/samples/script-self-closing/_config.js @@ -0,0 +1,12 @@ +import * as assert from "assert"; + +export default { + preprocess: { + script: ({ content, attributes }) => { + assert.equal(content, ""); + return { + code: `console.log("${attributes["the-answer"]}");` + }; + } + } +}; diff --git a/test/preprocess/samples/script-self-closing/input.svelte b/test/preprocess/samples/script-self-closing/input.svelte new file mode 100644 index 000000000000..c5816cb3baee --- /dev/null +++ b/test/preprocess/samples/script-self-closing/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/preprocess/samples/style-self-closing/_config.js b/test/preprocess/samples/style-self-closing/_config.js new file mode 100644 index 000000000000..0a05cd3d641e --- /dev/null +++ b/test/preprocess/samples/style-self-closing/_config.js @@ -0,0 +1,12 @@ +import * as assert from "assert"; + +export default { + preprocess: { + style: ({ content, attributes: { color } }) => { + assert.equal(content, ""); + return { + code: `div { color: ${color}; }` + }; + } + } +}; diff --git a/test/preprocess/samples/style-self-closing/input.svelte b/test/preprocess/samples/style-self-closing/input.svelte new file mode 100644 index 000000000000..07176c87e5b2 --- /dev/null +++ b/test/preprocess/samples/style-self-closing/input.svelte @@ -0,0 +1,3 @@ +
$brand
+ + \ No newline at end of file