Merge pull request #3894 from tanhauhau/tanhauhau/skip-comment-for-preprocessors

skip comments for preprocessors
pull/3928/head
Rich Harris 5 years ago committed by GitHub
commit d67b44861a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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