Skip to content

Commit ad56417

Browse files
authored
fix: remove pure comments only for Svelte 3 (#673)
1 parent ffbe8d3 commit ad56417

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

.changeset/long-dodos-report.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
fix: remove pure comments only for Svelte 3

packages/vite-plugin-svelte/src/utils/compile.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ export const _createCompileSvelte = (makeHot) => {
125125
const endStat = stats?.start(filename);
126126
const compiled = compile(finalCode, finalCompileOptions);
127127

128-
// prevent dangling pure comments
129-
// see https://github.com/sveltejs/kit/issues/9492#issuecomment-1487704985
130-
// uses regex replace with whitespace to keep sourcemap/character count unmodified
131-
compiled.js.code = compiled.js.code.replace(
132-
/\/\* [@#]__PURE__ \*\/(\s*)$/gm,
133-
' $1'
134-
);
128+
if (isSvelte3) {
129+
// prevent dangling pure comments
130+
// see https://github.com/sveltejs/kit/issues/9492#issuecomment-1487704985
131+
// uses regex replace with whitespace to keep sourcemap/character count unmodified
132+
compiled.js.code = compiled.js.code.replace(
133+
/\/\* [@#]__PURE__ \*\/(\s*)$/gm,
134+
' $1'
135+
);
136+
}
135137
if (endStat) {
136138
endStat();
137139
}

0 commit comments

Comments
 (0)