Skip to content

Commit 3bcb337

Browse files
committed
faster
1 parent 21b64ed commit 3bcb337

File tree

1 file changed

+7
-8
lines changed
  • packages/svelte/src/compiler/phases/1-parse

1 file changed

+7
-8
lines changed

packages/svelte/src/compiler/phases/1-parse/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ export class Parser {
4949

5050
this.template = template.trimRight();
5151

52-
const lang_matches = this.template.matchAll(regex_lang_attribute);
52+
let match_lang;
5353

54-
for (const match of lang_matches) {
55-
if (match[0]?.[1] === 's') {
56-
// ensure it starts with '<s' to match script tags
57-
this.ts = match[2] === 'ts';
58-
break;
59-
}
60-
}
54+
do match_lang = regex_lang_attribute.exec(template);
55+
while (match_lang && match_lang[0][1] !== 's'); // ensure it starts with '<s' to match script tags
56+
57+
regex_lang_attribute.lastIndex = 0; // need to reset index to pass tests — otherwise do not use global regex
58+
59+
this.ts = match_lang?.[2] === 'ts';
6160

6261
this.root = {
6362
css: null,

0 commit comments

Comments
 (0)