Skip to content

Commit 5309d7b

Browse files
fehnomenalbluwy
authored andcommitted
fix: use script lang regex from svelte compiler (#1028)
1 parent d2183bf commit 5309d7b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/swift-dolphins-cheat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
Allow script tags to span multiple lines

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

+3-3
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)