From 0b07be410d496c3acb1a2ee962e48d33798a094b Mon Sep 17 00:00:00 2001 From: lukasmoellerch Date: Sun, 28 Jun 2020 13:30:51 +0200 Subject: [PATCH] add support for self-closing script tags --- src/compiler/preprocess/index.ts | 4 ++-- .../samples/script-self-closing/_config.js | 12 ++++++++++++ .../samples/script-self-closing/input.svelte | 1 + .../samples/script-self-closing/output.svelte | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/preprocess/samples/script-self-closing/_config.js create mode 100644 test/preprocess/samples/script-self-closing/input.svelte create mode 100644 test/preprocess/samples/script-self-closing/output.svelte diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 4ff3b1394275..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; } 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