Skip to content

Commit

Permalink
add support for self-closing style tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmoellerch committed Jun 28, 2020
1 parent db0b3b3 commit a1d6b79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compiler/preprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default async function preprocess(
for (const fn of style) {
source = await replace_async(
source,
/<!--[^]*?-->|<style(\s[^]*?)?>([^]*?)<\/style>/gi,
async (match, attributes = '', content) => {
/<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi,
async (match, attributes = '', content = '') => {
if (!attributes && !content) {
return match;
}
Expand Down
12 changes: 12 additions & 0 deletions test/preprocess/samples/style-self-closing/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as assert from "assert";

export default {
preprocess: {
style: ({ content, attributes: { color } }) => {
assert.equal(content, "");
return {
code: `div { color: ${color}; }`
};
}
}
};
3 changes: 3 additions & 0 deletions test/preprocess/samples/style-self-closing/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class='brand-color'>$brand</div>

<style color="red"/>
3 changes: 3 additions & 0 deletions test/preprocess/samples/style-self-closing/output.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class='brand-color'>$brand</div>

<style color="red">div { color: red; }</style>

0 comments on commit a1d6b79

Please sign in to comment.