Skip to content

Commit

Permalink
fix: use script lang regex from svelte compiler (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
fehnomenal authored Nov 21, 2024
1 parent e3344b4 commit 0db95a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-dolphins-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

Allow script tags to span multiple lines
6 changes: 3 additions & 3 deletions packages/vite-plugin-svelte/src/utils/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { enhanceCompileError } from './error.js';
// which is closer to the other regexes in at least not falling into commented script
// but ideally would be shared exactly with svelte and other tools that use it
const scriptLangRE =
/<!--[^]*?-->|<script (?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=["']?([^"' >]+)["']?[^>]*>/g;
/<!--[^]*?-->|<script\s+(?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=(["'])?([^"' >]+)\1[^>]*>/g;

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

let lang = 'js';
for (const match of code.matchAll(scriptLangRE)) {
if (match[1]) {
lang = match[1];
if (match[2]) {
lang = match[2];
break;
}
}
Expand Down

0 comments on commit 0db95a9

Please sign in to comment.