Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocess self closing style #5082

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/preprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export default async function preprocess(
for (const fn of script) {
source = await replace_async(
source,
/<!--[^]*?-->|<script(\s[^]*?)?>([^]*?)<\/script>/gi,
async (match, attributes = '', content) => {
/<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi,
async (match, attributes = '', content = '') => {
if (!attributes && !content) {
return match;
}
Expand All @@ -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/script-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: {
script: ({ content, attributes }) => {
assert.equal(content, "");
return {
code: `console.log("${attributes["the-answer"]}");`
};
}
}
};
1 change: 1 addition & 0 deletions test/preprocess/samples/script-self-closing/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script the-answer="42"/>
1 change: 1 addition & 0 deletions test/preprocess/samples/script-self-closing/output.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script the-answer="42">console.log("42");</script>
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>