Skip to content

Commit 5a47ef9

Browse files
committed
use script lang regex from svelte compiler
1 parent e262266 commit 5a47ef9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

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

1919
/**
2020
* @returns {import('../types/compile.d.ts').CompileSvelte}
@@ -172,8 +172,8 @@ export function createCompileSvelte() {
172172

173173
let lang = 'js';
174174
for (const match of code.matchAll(scriptLangRE)) {
175-
if (match[1]) {
176-
lang = match[1];
175+
if (match[2]) {
176+
lang = match[2];
177177
break;
178178
}
179179
}

0 commit comments

Comments
 (0)