Skip to content

Commit b31eab6

Browse files
committed
fix: update regexes to correctly account for unquoted attribute values, see sveltejs/svelte#9552
1 parent a58ecfc commit b31eab6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { isSvelte5 } from './svelte-version.js';
1616
// which is closer to the other regexes in at least not falling into commented script
1717
// but ideally would be shared exactly with svelte and other tools that use it
1818
const scriptLangRE =
19-
/<!--[^]*?-->|<script (?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s])\s+)*)lang=["']?([^"' >]+)["']?[^>]*>/;
19+
/<!--[^]*?-->|<script (?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=["']?([^"' >]+)["']?[^>]*>/;
2020

2121
/**
2222
* @param {Function} [makeHot]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ export function enhanceCompileError(err, originalCode, preprocessors) {
114114

115115
// Handle incorrect TypeScript usage
116116
if (err.code === 'parse-error') {
117-
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/e0271f0fc7b3191ba3d5fc7982ec09d7cb0d0ac9/packages/svelte/src/compiler/preprocess/index.js#L258
117+
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/9926347ad9dbdd0f3324d5538e25dcb7f5e442f8/packages/svelte/src/compiler/preprocess/index.js#L259
118118
const scriptRe =
119-
/<!--[^]*?-->|<script((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
119+
/<!--[^]*?-->|<script((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
120120
const errIndex = err.pos ?? -1;
121121

122122
let m;
@@ -143,9 +143,9 @@ export function enhanceCompileError(err, originalCode, preprocessors) {
143143

144144
// Handle incorrect CSS preprocessor usage
145145
if (err.code === 'css-syntax-error') {
146-
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/e0271f0fc7b3191ba3d5fc7982ec09d7cb0d0ac9/packages/svelte/src/compiler/preprocess/index.js#L256
146+
// Reference from Svelte:https://github.com/sveltejs/svelte/blob/9926347ad9dbdd0f3324d5538e25dcb7f5e442f8/packages/svelte/src/compiler/preprocess/index.js#L257
147147
const styleRe =
148-
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
148+
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
149149

150150
let m;
151151
while ((m = styleRe.exec(originalCode))) {

0 commit comments

Comments
 (0)