From a1d6b79ffcf4415ded930614baf0ee54eb8be6c5 Mon Sep 17 00:00:00 2001 From: lukasmoellerch Date: Sun, 28 Jun 2020 13:22:10 +0200 Subject: [PATCH] add support for self-closing style tags --- src/compiler/preprocess/index.ts | 4 ++-- .../preprocess/samples/style-self-closing/_config.js | 12 ++++++++++++ .../samples/style-self-closing/input.svelte | 3 +++ .../samples/style-self-closing/output.svelte | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/preprocess/samples/style-self-closing/_config.js create mode 100644 test/preprocess/samples/style-self-closing/input.svelte create mode 100644 test/preprocess/samples/style-self-closing/output.svelte diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 1a13b869e7..4ff3b13942 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -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/style-self-closing/_config.js b/test/preprocess/samples/style-self-closing/_config.js new file mode 100644 index 0000000000..0a05cd3d64 --- /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 0000000000..07176c87e5 --- /dev/null +++ b/test/preprocess/samples/style-self-closing/input.svelte @@ -0,0 +1,3 @@ +
$brand
+ + \ No newline at end of file