preprocess self-closing script and style tags (#5082)

pull/5130/head
Lukas Möller 4 years ago committed by GitHub
parent 4910f5797f
commit f36b414d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;
}
@ -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;
}

@ -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"]}");`
};
}
}
};

@ -0,0 +1 @@
<script the-answer="42">console.log("42");</script>

@ -0,0 +1,12 @@
import * as assert from "assert";
export default {
preprocess: {
style: ({ content, attributes: { color } }) => {
assert.equal(content, "");
return {
code: `div { color: ${color}; }`
};
}
}
};

@ -0,0 +1,3 @@
<div class='brand-color'>$brand</div>
<style color="red"/>

@ -0,0 +1,3 @@
<div class='brand-color'>$brand</div>
<style color="red">div { color: red; }</style>
Loading…
Cancel
Save