skip comments for preprocessors

pull/3894/head
Tan Li Hau 5 years ago
parent ad2aac509d
commit 3fb9626eb4

@ -94,8 +94,12 @@ export default async function preprocess(
for (const fn of script) {
source = await replace_async(
source,
/<script(\s[^]*?)?>([^]*?)<\/script>/gi,
/<!--[^]*?-->|<script(\s[^]*?)?>([^]*?)<\/script>/gi,
async (match, attributes = '', content) => {
if (!attributes && !content) {
return match;
}
attributes = attributes || '';
const processed = await fn({
content,
attributes: parse_attributes(attributes),
@ -110,8 +114,11 @@ export default async function preprocess(
for (const fn of style) {
source = await replace_async(
source,
/<style(\s[^]*?)?>([^]*?)<\/style>/gi,
/<!--[^]*?-->|<style(\s[^]*?)?>([^]*?)<\/style>/gi,
async (match, attributes = '', content) => {
if (!attributes && !content) {
return match;
}
const processed: Processed = await fn({
content,
attributes: parse_attributes(attributes),

@ -0,0 +1,8 @@
export default {
preprocess: [
{
script: ({ content }) => ({ code: content.replace(/one/g, 'two') }),
style: ({ content }) => ({ code: content.replace(/one/g, 'three') }),
},
],
};

@ -0,0 +1,25 @@
<style>
one
</style>
<script>
one
</script>
<!-- <style>
one
</style> -->
<!-- <script>
one
</script> -->
<style>
<!-- one -->
</style>
<script>
<!-- one -->
</script>

@ -0,0 +1,25 @@
<style>
three
</style>
<script>
two
</script>
<!-- <style>
one
</style> -->
<!-- <script>
one
</script> -->
<style>
<!-- three -->
</style>
<script>
<!-- two -->
</script>
Loading…
Cancel
Save