diff --git a/.changeset/violet-rockets-relax.md b/.changeset/violet-rockets-relax.md
new file mode 100644
index 00000000..ef5231ea
--- /dev/null
+++ b/.changeset/violet-rockets-relax.md
@@ -0,0 +1,5 @@
+---
+"svelte-eslint-parser": patch
+---
+
+fix: wrong token when using `lang=ts`
diff --git a/src/context/script-let.ts b/src/context/script-let.ts
index 26244285..ad638218 100644
--- a/src/context/script-let.ts
+++ b/src/context/script-let.ts
@@ -178,6 +178,10 @@ export class ScriptLetContext {
callback(node as E, result);
}
+ tokens.shift(); // (
+ tokens.pop(); // )
+ tokens.pop(); // ;
+
if (isTS) {
for (const scope of extractTypeNodeScopes(
tsAs!.typeAnnotation,
@@ -201,10 +205,6 @@ export class ScriptLetContext {
(node as any).parent = parent;
- tokens.shift(); // (
- tokens.pop(); // )
- tokens.pop(); // ;
-
// Disconnect the tree structure.
exprSt.expression = null as never;
},
diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/11-1-$inspect-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/11-1-$inspect-ts-output.json
index 7db62744..6a64490e 100644
--- a/tests/fixtures/parser/ast/svelte5/docs/runes/11-1-$inspect-ts-output.json
+++ b/tests/fixtures/parser/ast/svelte5/docs/runes/11-1-$inspect-ts-output.json
@@ -1656,87 +1656,15 @@
},
{
"type": "Identifier",
- "value": "c",
+ "value": "count",
"range": [
194,
- 195
- ],
- "loc": {
- "start": {
- "line": 8,
- "column": 24
- },
- "end": {
- "line": 8,
- "column": 25
- }
- }
- },
- {
- "type": "Identifier",
- "value": "o",
- "range": [
- 195,
- 196
- ],
- "loc": {
- "start": {
- "line": 8,
- "column": 25
- },
- "end": {
- "line": 8,
- "column": 26
- }
- }
- },
- {
- "type": "Identifier",
- "value": "u",
- "range": [
- 196,
- 197
- ],
- "loc": {
- "start": {
- "line": 8,
- "column": 26
- },
- "end": {
- "line": 8,
- "column": 27
- }
- }
- },
- {
- "type": "Identifier",
- "value": "n",
- "range": [
- 197,
- 198
- ],
- "loc": {
- "start": {
- "line": 8,
- "column": 27
- },
- "end": {
- "line": 8,
- "column": 28
- }
- }
- },
- {
- "type": "Identifier",
- "value": "t",
- "range": [
- 198,
199
],
"loc": {
"start": {
"line": 8,
- "column": 28
+ "column": 24
},
"end": {
"line": 8,
@@ -1746,33 +1674,15 @@
},
{
"type": "Punctuator",
- "value": "+",
+ "value": "++",
"range": [
199,
- 200
- ],
- "loc": {
- "start": {
- "line": 8,
- "column": 29
- },
- "end": {
- "line": 8,
- "column": 30
- }
- }
- },
- {
- "type": "Punctuator",
- "value": "+",
- "range": [
- 200,
201
],
"loc": {
"start": {
"line": 8,
- "column": 30
+ "column": 29
},
"end": {
"line": 8,
diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/11-2-$inspect-ts-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/11-2-$inspect-ts-output.json
index 0a711bb8..0b52ca4c 100644
--- a/tests/fixtures/parser/ast/svelte5/docs/runes/11-2-$inspect-ts-output.json
+++ b/tests/fixtures/parser/ast/svelte5/docs/runes/11-2-$inspect-ts-output.json
@@ -1837,87 +1837,15 @@
},
{
"type": "Identifier",
- "value": "c",
+ "value": "count",
"range": [
223,
- 224
- ],
- "loc": {
- "start": {
- "line": 11,
- "column": 24
- },
- "end": {
- "line": 11,
- "column": 25
- }
- }
- },
- {
- "type": "Identifier",
- "value": "o",
- "range": [
- 224,
- 225
- ],
- "loc": {
- "start": {
- "line": 11,
- "column": 25
- },
- "end": {
- "line": 11,
- "column": 26
- }
- }
- },
- {
- "type": "Identifier",
- "value": "u",
- "range": [
- 225,
- 226
- ],
- "loc": {
- "start": {
- "line": 11,
- "column": 26
- },
- "end": {
- "line": 11,
- "column": 27
- }
- }
- },
- {
- "type": "Identifier",
- "value": "n",
- "range": [
- 226,
- 227
- ],
- "loc": {
- "start": {
- "line": 11,
- "column": 27
- },
- "end": {
- "line": 11,
- "column": 28
- }
- }
- },
- {
- "type": "Identifier",
- "value": "t",
- "range": [
- 227,
228
],
"loc": {
"start": {
"line": 11,
- "column": 28
+ "column": 24
},
"end": {
"line": 11,
@@ -1927,33 +1855,15 @@
},
{
"type": "Punctuator",
- "value": "+",
+ "value": "++",
"range": [
228,
- 229
- ],
- "loc": {
- "start": {
- "line": 11,
- "column": 29
- },
- "end": {
- "line": 11,
- "column": 30
- }
- }
- },
- {
- "type": "Punctuator",
- "value": "+",
- "range": [
- 229,
230
],
"loc": {
"start": {
"line": 11,
- "column": 30
+ "column": 29
},
"end": {
"line": 11,
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json
index 941ab0a4..fd06e36e 100644
--- a/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json
+++ b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json
@@ -2745,7 +2745,7 @@
}
},
{
- "type": "Identifier",
+ "type": "Numeric",
"value": "1",
"range": [
241,
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$derived01-output.json b/tests/fixtures/parser/ast/svelte5/ts-$derived01-output.json
index 3ae6df96..f1c4eb09 100644
--- a/tests/fixtures/parser/ast/svelte5/ts-$derived01-output.json
+++ b/tests/fixtures/parser/ast/svelte5/ts-$derived01-output.json
@@ -1613,87 +1613,15 @@
},
{
"type": "Identifier",
- "value": "c",
+ "value": "count",
"range": [
119,
- 120
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 25
- },
- "end": {
- "line": 6,
- "column": 26
- }
- }
- },
- {
- "type": "Identifier",
- "value": "o",
- "range": [
- 120,
- 121
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 26
- },
- "end": {
- "line": 6,
- "column": 27
- }
- }
- },
- {
- "type": "Identifier",
- "value": "u",
- "range": [
- 121,
- 122
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 27
- },
- "end": {
- "line": 6,
- "column": 28
- }
- }
- },
- {
- "type": "Identifier",
- "value": "n",
- "range": [
- 122,
- 123
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 28
- },
- "end": {
- "line": 6,
- "column": 29
- }
- }
- },
- {
- "type": "Identifier",
- "value": "t",
- "range": [
- 123,
124
],
"loc": {
"start": {
"line": 6,
- "column": 29
+ "column": 25
},
"end": {
"line": 6,
@@ -1703,33 +1631,15 @@
},
{
"type": "Punctuator",
- "value": "+",
+ "value": "++",
"range": [
124,
- 125
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 30
- },
- "end": {
- "line": 6,
- "column": 31
- }
- }
- },
- {
- "type": "Punctuator",
- "value": "+",
- "range": [
- 125,
126
],
"loc": {
"start": {
"line": 6,
- "column": 31
+ "column": 30
},
"end": {
"line": 6,
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$effect01-output.json b/tests/fixtures/parser/ast/svelte5/ts-$effect01-output.json
index 1dc5c511..cc41b8ab 100644
--- a/tests/fixtures/parser/ast/svelte5/ts-$effect01-output.json
+++ b/tests/fixtures/parser/ast/svelte5/ts-$effect01-output.json
@@ -2824,87 +2824,15 @@
},
{
"type": "Identifier",
- "value": "c",
+ "value": "count",
"range": [
514,
- 515
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 25
- },
- "end": {
- "line": 20,
- "column": 26
- }
- }
- },
- {
- "type": "Identifier",
- "value": "o",
- "range": [
- 515,
- 516
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 26
- },
- "end": {
- "line": 20,
- "column": 27
- }
- }
- },
- {
- "type": "Identifier",
- "value": "u",
- "range": [
- 516,
- 517
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 27
- },
- "end": {
- "line": 20,
- "column": 28
- }
- }
- },
- {
- "type": "Identifier",
- "value": "n",
- "range": [
- 517,
- 518
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 28
- },
- "end": {
- "line": 20,
- "column": 29
- }
- }
- },
- {
- "type": "Identifier",
- "value": "t",
- "range": [
- 518,
519
],
"loc": {
"start": {
"line": 20,
- "column": 29
+ "column": 25
},
"end": {
"line": 20,
@@ -2914,33 +2842,15 @@
},
{
"type": "Punctuator",
- "value": "+",
+ "value": "++",
"range": [
519,
- 520
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 30
- },
- "end": {
- "line": 20,
- "column": 31
- }
- }
- },
- {
- "type": "Punctuator",
- "value": "+",
- "range": [
- 520,
521
],
"loc": {
"start": {
"line": 20,
- "column": 31
+ "column": 30
},
"end": {
"line": 20,
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$effectpre01-output.json b/tests/fixtures/parser/ast/svelte5/ts-$effectpre01-output.json
index 10db2b28..b9b4385a 100644
--- a/tests/fixtures/parser/ast/svelte5/ts-$effectpre01-output.json
+++ b/tests/fixtures/parser/ast/svelte5/ts-$effectpre01-output.json
@@ -2824,87 +2824,15 @@
},
{
"type": "Identifier",
- "value": "c",
+ "value": "count",
"range": [
516,
- 517
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 25
- },
- "end": {
- "line": 20,
- "column": 26
- }
- }
- },
- {
- "type": "Identifier",
- "value": "o",
- "range": [
- 517,
- 518
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 26
- },
- "end": {
- "line": 20,
- "column": 27
- }
- }
- },
- {
- "type": "Identifier",
- "value": "u",
- "range": [
- 518,
- 519
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 27
- },
- "end": {
- "line": 20,
- "column": 28
- }
- }
- },
- {
- "type": "Identifier",
- "value": "n",
- "range": [
- 519,
- 520
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 28
- },
- "end": {
- "line": 20,
- "column": 29
- }
- }
- },
- {
- "type": "Identifier",
- "value": "t",
- "range": [
- 520,
521
],
"loc": {
"start": {
"line": 20,
- "column": 29
+ "column": 25
},
"end": {
"line": 20,
@@ -2914,33 +2842,15 @@
},
{
"type": "Punctuator",
- "value": "+",
+ "value": "++",
"range": [
521,
- 522
- ],
- "loc": {
- "start": {
- "line": 20,
- "column": 30
- },
- "end": {
- "line": 20,
- "column": 31
- }
- }
- },
- {
- "type": "Punctuator",
- "value": "+",
- "range": [
- 522,
523
],
"loc": {
"start": {
"line": 20,
- "column": 31
+ "column": 30
},
"end": {
"line": 20,
diff --git a/tests/fixtures/parser/ast/svelte5/ts-$state01-output.json b/tests/fixtures/parser/ast/svelte5/ts-$state01-output.json
index 82240390..21a01cbd 100644
--- a/tests/fixtures/parser/ast/svelte5/ts-$state01-output.json
+++ b/tests/fixtures/parser/ast/svelte5/ts-$state01-output.json
@@ -1321,87 +1321,15 @@
},
{
"type": "Identifier",
- "value": "c",
+ "value": "count",
"range": [
103,
- 104
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 25
- },
- "end": {
- "line": 6,
- "column": 26
- }
- }
- },
- {
- "type": "Identifier",
- "value": "o",
- "range": [
- 104,
- 105
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 26
- },
- "end": {
- "line": 6,
- "column": 27
- }
- }
- },
- {
- "type": "Identifier",
- "value": "u",
- "range": [
- 105,
- 106
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 27
- },
- "end": {
- "line": 6,
- "column": 28
- }
- }
- },
- {
- "type": "Identifier",
- "value": "n",
- "range": [
- 106,
- 107
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 28
- },
- "end": {
- "line": 6,
- "column": 29
- }
- }
- },
- {
- "type": "Identifier",
- "value": "t",
- "range": [
- 107,
108
],
"loc": {
"start": {
"line": 6,
- "column": 29
+ "column": 25
},
"end": {
"line": 6,
@@ -1411,33 +1339,15 @@
},
{
"type": "Punctuator",
- "value": "+",
+ "value": "++",
"range": [
108,
- 109
- ],
- "loc": {
- "start": {
- "line": 6,
- "column": 30
- },
- "end": {
- "line": 6,
- "column": 31
- }
- }
- },
- {
- "type": "Punctuator",
- "value": "+",
- "range": [
- 109,
110
],
"loc": {
"start": {
"line": 6,
- "column": 31
+ "column": 30
},
"end": {
"line": 6,
diff --git a/tests/fixtures/parser/ast/ts-tokens-bug-input.svelte b/tests/fixtures/parser/ast/ts-tokens-bug-input.svelte
new file mode 100644
index 00000000..a36ea69a
--- /dev/null
+++ b/tests/fixtures/parser/ast/ts-tokens-bug-input.svelte
@@ -0,0 +1,7 @@
+
+
+
diff --git a/tests/fixtures/parser/ast/ts-tokens-bug-no-undef-result.json b/tests/fixtures/parser/ast/ts-tokens-bug-no-undef-result.json
new file mode 100644
index 00000000..6de3b2ba
--- /dev/null
+++ b/tests/fixtures/parser/ast/ts-tokens-bug-no-undef-result.json
@@ -0,0 +1,26 @@
+[
+ {
+ "ruleId": "no-undef",
+ "code": "$store",
+ "line": 5,
+ "column": 17
+ },
+ {
+ "ruleId": "no-undef",
+ "code": "index",
+ "line": 5,
+ "column": 35
+ },
+ {
+ "ruleId": "no-undef",
+ "code": "index",
+ "line": 6,
+ "column": 6
+ },
+ {
+ "ruleId": "no-undef",
+ "code": "tab",
+ "line": 6,
+ "column": 14
+ }
+]
\ No newline at end of file
diff --git a/tests/fixtures/parser/ast/ts-tokens-bug-output.json b/tests/fixtures/parser/ast/ts-tokens-bug-output.json
new file mode 100644
index 00000000..f61d2323
--- /dev/null
+++ b/tests/fixtures/parser/ast/ts-tokens-bug-output.json
@@ -0,0 +1,1439 @@
+{
+ "type": "Program",
+ "body": [
+ {
+ "type": "SvelteHTMLComment",
+ "value": " Copied from https://github.com/sveltejs/svelte-eslint-parser/issues/502 ",
+ "range": [
+ 0,
+ 80
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 80
+ }
+ }
+ },
+ {
+ "type": "SvelteText",
+ "value": "\n",
+ "range": [
+ 80,
+ 81
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 80
+ },
+ "end": {
+ "line": 2,
+ "column": 0
+ }
+ }
+ },
+ {
+ "type": "SvelteScriptElement",
+ "name": {
+ "type": "SvelteName",
+ "name": "script",
+ "range": [
+ 82,
+ 88
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 1
+ },
+ "end": {
+ "line": 2,
+ "column": 7
+ }
+ }
+ },
+ "startTag": {
+ "type": "SvelteStartTag",
+ "attributes": [
+ {
+ "type": "SvelteAttribute",
+ "key": {
+ "type": "SvelteName",
+ "name": "lang",
+ "range": [
+ 89,
+ 93
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 8
+ },
+ "end": {
+ "line": 2,
+ "column": 12
+ }
+ }
+ },
+ "boolean": false,
+ "value": [
+ {
+ "type": "SvelteLiteral",
+ "value": "ts",
+ "range": [
+ 95,
+ 97
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 14
+ },
+ "end": {
+ "line": 2,
+ "column": 16
+ }
+ }
+ }
+ ],
+ "range": [
+ 89,
+ 98
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 8
+ },
+ "end": {
+ "line": 2,
+ "column": 17
+ }
+ }
+ }
+ ],
+ "selfClosing": false,
+ "range": [
+ 81,
+ 99
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 0
+ },
+ "end": {
+ "line": 2,
+ "column": 18
+ }
+ }
+ },
+ "body": [
+ {
+ "type": "ImportDeclaration",
+ "importKind": "value",
+ "source": {
+ "type": "Literal",
+ "raw": "\"$lib/Button.svelte\"",
+ "value": "$lib/Button.svelte",
+ "range": [
+ 123,
+ 143
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 23
+ },
+ "end": {
+ "line": 3,
+ "column": 43
+ }
+ }
+ },
+ "specifiers": [
+ {
+ "type": "ImportDefaultSpecifier",
+ "local": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ },
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ }
+ ],
+ "range": [
+ 104,
+ 144
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 4
+ },
+ "end": {
+ "line": 3,
+ "column": 44
+ }
+ }
+ }
+ ],
+ "endTag": {
+ "type": "SvelteEndTag",
+ "range": [
+ 145,
+ 154
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 0
+ },
+ "end": {
+ "line": 4,
+ "column": 9
+ }
+ }
+ },
+ "range": [
+ 81,
+ 154
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 0
+ },
+ "end": {
+ "line": 4,
+ "column": 9
+ }
+ }
+ },
+ {
+ "type": "SvelteText",
+ "value": "\n",
+ "range": [
+ 154,
+ 155
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 9
+ },
+ "end": {
+ "line": 5,
+ "column": 0
+ }
+ }
+ },
+ {
+ "type": "SvelteElement",
+ "kind": "component",
+ "name": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 156,
+ 162
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 1
+ },
+ "end": {
+ "line": 5,
+ "column": 7
+ }
+ }
+ },
+ "startTag": {
+ "type": "SvelteStartTag",
+ "attributes": [
+ {
+ "type": "SvelteAttribute",
+ "key": {
+ "type": "SvelteName",
+ "name": "active",
+ "range": [
+ 163,
+ 169
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 8
+ },
+ "end": {
+ "line": 5,
+ "column": 14
+ }
+ }
+ },
+ "boolean": false,
+ "value": [
+ {
+ "type": "SvelteMustacheTag",
+ "kind": "text",
+ "expression": {
+ "type": "BinaryExpression",
+ "left": {
+ "type": "MemberExpression",
+ "computed": false,
+ "object": {
+ "type": "Identifier",
+ "name": "$store",
+ "range": [
+ 171,
+ 177
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 22
+ }
+ }
+ },
+ "optional": false,
+ "property": {
+ "type": "Identifier",
+ "name": "number",
+ "range": [
+ 178,
+ 184
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 23
+ },
+ "end": {
+ "line": 5,
+ "column": 29
+ }
+ }
+ },
+ "range": [
+ 171,
+ 184
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 29
+ }
+ }
+ },
+ "operator": "===",
+ "right": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 189,
+ 194
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 34
+ },
+ "end": {
+ "line": 5,
+ "column": 39
+ }
+ }
+ },
+ "range": [
+ 171,
+ 194
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 39
+ }
+ }
+ },
+ "range": [
+ 170,
+ 195
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 15
+ },
+ "end": {
+ "line": 5,
+ "column": 40
+ }
+ }
+ }
+ ],
+ "range": [
+ 163,
+ 195
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 8
+ },
+ "end": {
+ "line": 5,
+ "column": 40
+ }
+ }
+ }
+ ],
+ "selfClosing": false,
+ "range": [
+ 155,
+ 196
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 0
+ },
+ "end": {
+ "line": 5,
+ "column": 41
+ }
+ }
+ },
+ "children": [
+ {
+ "type": "SvelteText",
+ "value": "\n ",
+ "range": [
+ 196,
+ 201
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 41
+ },
+ "end": {
+ "line": 6,
+ "column": 4
+ }
+ }
+ },
+ {
+ "type": "SvelteMustacheTag",
+ "kind": "text",
+ "expression": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 202,
+ 207
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 5
+ },
+ "end": {
+ "line": 6,
+ "column": 10
+ }
+ }
+ },
+ "range": [
+ 201,
+ 208
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 4
+ },
+ "end": {
+ "line": 6,
+ "column": 11
+ }
+ }
+ },
+ {
+ "type": "SvelteText",
+ "value": " ",
+ "range": [
+ 208,
+ 209
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 11
+ },
+ "end": {
+ "line": 6,
+ "column": 12
+ }
+ }
+ },
+ {
+ "type": "SvelteMustacheTag",
+ "kind": "text",
+ "expression": {
+ "type": "Identifier",
+ "name": "tab",
+ "range": [
+ 210,
+ 213
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 13
+ },
+ "end": {
+ "line": 6,
+ "column": 16
+ }
+ }
+ },
+ "range": [
+ 209,
+ 214
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 12
+ },
+ "end": {
+ "line": 6,
+ "column": 17
+ }
+ }
+ },
+ {
+ "type": "SvelteText",
+ "value": "\n",
+ "range": [
+ 214,
+ 215
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 17
+ },
+ "end": {
+ "line": 7,
+ "column": 0
+ }
+ }
+ }
+ ],
+ "endTag": {
+ "type": "SvelteEndTag",
+ "range": [
+ 215,
+ 224
+ ],
+ "loc": {
+ "start": {
+ "line": 7,
+ "column": 0
+ },
+ "end": {
+ "line": 7,
+ "column": 9
+ }
+ }
+ },
+ "range": [
+ 155,
+ 224
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 0
+ },
+ "end": {
+ "line": 7,
+ "column": 9
+ }
+ }
+ }
+ ],
+ "sourceType": "module",
+ "comments": [],
+ "tokens": [
+ {
+ "type": "HTMLComment",
+ "value": "",
+ "range": [
+ 0,
+ 80
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 80
+ }
+ }
+ },
+ {
+ "type": "HTMLText",
+ "value": "\n",
+ "range": [
+ 80,
+ 81
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 80
+ },
+ "end": {
+ "line": 2,
+ "column": 0
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "<",
+ "range": [
+ 81,
+ 82
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 0
+ },
+ "end": {
+ "line": 2,
+ "column": 1
+ }
+ }
+ },
+ {
+ "type": "HTMLIdentifier",
+ "value": "script",
+ "range": [
+ 82,
+ 88
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 1
+ },
+ "end": {
+ "line": 2,
+ "column": 7
+ }
+ }
+ },
+ {
+ "type": "HTMLIdentifier",
+ "value": "lang",
+ "range": [
+ 89,
+ 93
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 8
+ },
+ "end": {
+ "line": 2,
+ "column": 12
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "=",
+ "range": [
+ 93,
+ 94
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 12
+ },
+ "end": {
+ "line": 2,
+ "column": 13
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "\"",
+ "range": [
+ 94,
+ 95
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 13
+ },
+ "end": {
+ "line": 2,
+ "column": 14
+ }
+ }
+ },
+ {
+ "type": "HTMLText",
+ "value": "ts",
+ "range": [
+ 95,
+ 97
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 14
+ },
+ "end": {
+ "line": 2,
+ "column": 16
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "\"",
+ "range": [
+ 97,
+ 98
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 16
+ },
+ "end": {
+ "line": 2,
+ "column": 17
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": ">",
+ "range": [
+ 98,
+ 99
+ ],
+ "loc": {
+ "start": {
+ "line": 2,
+ "column": 17
+ },
+ "end": {
+ "line": 2,
+ "column": 18
+ }
+ }
+ },
+ {
+ "type": "Keyword",
+ "value": "import",
+ "range": [
+ 104,
+ 110
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 4
+ },
+ "end": {
+ "line": 3,
+ "column": 10
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "from",
+ "range": [
+ 118,
+ 122
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 18
+ },
+ "end": {
+ "line": 3,
+ "column": 22
+ }
+ }
+ },
+ {
+ "type": "String",
+ "value": "\"$lib/Button.svelte\"",
+ "range": [
+ 123,
+ 143
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 23
+ },
+ "end": {
+ "line": 3,
+ "column": 43
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": ";",
+ "range": [
+ 143,
+ 144
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 43
+ },
+ "end": {
+ "line": 3,
+ "column": 44
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "<",
+ "range": [
+ 145,
+ 146
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 0
+ },
+ "end": {
+ "line": 4,
+ "column": 1
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "/",
+ "range": [
+ 146,
+ 147
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 1
+ },
+ "end": {
+ "line": 4,
+ "column": 2
+ }
+ }
+ },
+ {
+ "type": "HTMLIdentifier",
+ "value": "script",
+ "range": [
+ 147,
+ 153
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 2
+ },
+ "end": {
+ "line": 4,
+ "column": 8
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": ">",
+ "range": [
+ 153,
+ 154
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 8
+ },
+ "end": {
+ "line": 4,
+ "column": 9
+ }
+ }
+ },
+ {
+ "type": "HTMLText",
+ "value": "\n",
+ "range": [
+ 154,
+ 155
+ ],
+ "loc": {
+ "start": {
+ "line": 4,
+ "column": 9
+ },
+ "end": {
+ "line": 5,
+ "column": 0
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "<",
+ "range": [
+ 155,
+ 156
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 0
+ },
+ "end": {
+ "line": 5,
+ "column": 1
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "Button",
+ "range": [
+ 156,
+ 162
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 1
+ },
+ "end": {
+ "line": 5,
+ "column": 7
+ }
+ }
+ },
+ {
+ "type": "HTMLIdentifier",
+ "value": "active",
+ "range": [
+ 163,
+ 169
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 8
+ },
+ "end": {
+ "line": 5,
+ "column": 14
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "=",
+ "range": [
+ 169,
+ 170
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 14
+ },
+ "end": {
+ "line": 5,
+ "column": 15
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "{",
+ "range": [
+ 170,
+ 171
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 15
+ },
+ "end": {
+ "line": 5,
+ "column": 16
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "$store",
+ "range": [
+ 171,
+ 177
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 22
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": ".",
+ "range": [
+ 177,
+ 178
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 22
+ },
+ "end": {
+ "line": 5,
+ "column": 23
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "number",
+ "range": [
+ 178,
+ 184
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 23
+ },
+ "end": {
+ "line": 5,
+ "column": 29
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "===",
+ "range": [
+ 185,
+ 188
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 30
+ },
+ "end": {
+ "line": 5,
+ "column": 33
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "index",
+ "range": [
+ 189,
+ 194
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 34
+ },
+ "end": {
+ "line": 5,
+ "column": 39
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "}",
+ "range": [
+ 194,
+ 195
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 39
+ },
+ "end": {
+ "line": 5,
+ "column": 40
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": ">",
+ "range": [
+ 195,
+ 196
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 40
+ },
+ "end": {
+ "line": 5,
+ "column": 41
+ }
+ }
+ },
+ {
+ "type": "HTMLText",
+ "value": "\n ",
+ "range": [
+ 196,
+ 201
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 41
+ },
+ "end": {
+ "line": 6,
+ "column": 4
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "{",
+ "range": [
+ 201,
+ 202
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 4
+ },
+ "end": {
+ "line": 6,
+ "column": 5
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "index",
+ "range": [
+ 202,
+ 207
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 5
+ },
+ "end": {
+ "line": 6,
+ "column": 10
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "}",
+ "range": [
+ 207,
+ 208
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 10
+ },
+ "end": {
+ "line": 6,
+ "column": 11
+ }
+ }
+ },
+ {
+ "type": "HTMLText",
+ "value": " ",
+ "range": [
+ 208,
+ 209
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 11
+ },
+ "end": {
+ "line": 6,
+ "column": 12
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "{",
+ "range": [
+ 209,
+ 210
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 12
+ },
+ "end": {
+ "line": 6,
+ "column": 13
+ }
+ }
+ },
+ {
+ "type": "Identifier",
+ "value": "tab",
+ "range": [
+ 210,
+ 213
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 13
+ },
+ "end": {
+ "line": 6,
+ "column": 16
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "}",
+ "range": [
+ 213,
+ 214
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 16
+ },
+ "end": {
+ "line": 6,
+ "column": 17
+ }
+ }
+ },
+ {
+ "type": "HTMLText",
+ "value": "\n",
+ "range": [
+ 214,
+ 215
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 17
+ },
+ "end": {
+ "line": 7,
+ "column": 0
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "<",
+ "range": [
+ 215,
+ 216
+ ],
+ "loc": {
+ "start": {
+ "line": 7,
+ "column": 0
+ },
+ "end": {
+ "line": 7,
+ "column": 1
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": "/",
+ "range": [
+ 216,
+ 217
+ ],
+ "loc": {
+ "start": {
+ "line": 7,
+ "column": 1
+ },
+ "end": {
+ "line": 7,
+ "column": 2
+ }
+ }
+ },
+ {
+ "type": "HTMLIdentifier",
+ "value": "Button",
+ "range": [
+ 217,
+ 223
+ ],
+ "loc": {
+ "start": {
+ "line": 7,
+ "column": 2
+ },
+ "end": {
+ "line": 7,
+ "column": 8
+ }
+ }
+ },
+ {
+ "type": "Punctuator",
+ "value": ">",
+ "range": [
+ 223,
+ 224
+ ],
+ "loc": {
+ "start": {
+ "line": 7,
+ "column": 8
+ },
+ "end": {
+ "line": 7,
+ "column": 9
+ }
+ }
+ }
+ ],
+ "range": [
+ 0,
+ 225
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 8,
+ "column": 0
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/fixtures/parser/ast/ts-tokens-bug-scope-output.json b/tests/fixtures/parser/ast/ts-tokens-bug-scope-output.json
new file mode 100644
index 00000000..589c6f54
--- /dev/null
+++ b/tests/fixtures/parser/ast/ts-tokens-bug-scope-output.json
@@ -0,0 +1,477 @@
+{
+ "type": "global",
+ "variables": [
+ {
+ "name": "$$slots",
+ "identifiers": [],
+ "defs": [],
+ "references": []
+ },
+ {
+ "name": "$$props",
+ "identifiers": [],
+ "defs": [],
+ "references": []
+ },
+ {
+ "name": "$$restProps",
+ "identifiers": [],
+ "defs": [],
+ "references": []
+ }
+ ],
+ "references": [],
+ "childScopes": [
+ {
+ "type": "module",
+ "variables": [
+ {
+ "name": "Button",
+ "identifiers": [
+ {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ }
+ ],
+ "defs": [
+ {
+ "type": "ImportBinding",
+ "name": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ },
+ "node": {
+ "type": "ImportDefaultSpecifier",
+ "local": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ },
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ }
+ }
+ ],
+ "references": [
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 156,
+ 162
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 1
+ },
+ "end": {
+ "line": 5,
+ "column": 7
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ }
+ }
+ ]
+ }
+ ],
+ "references": [
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "$store",
+ "range": [
+ 171,
+ 177
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 22
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 189,
+ 194
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 34
+ },
+ "end": {
+ "line": 5,
+ "column": 39
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 202,
+ 207
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 5
+ },
+ "end": {
+ "line": 6,
+ "column": 10
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "tab",
+ "range": [
+ 210,
+ 213
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 13
+ },
+ "end": {
+ "line": 6,
+ "column": 16
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 156,
+ 162
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 1
+ },
+ "end": {
+ "line": 5,
+ "column": 7
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": {
+ "type": "Identifier",
+ "name": "Button",
+ "range": [
+ 111,
+ 117
+ ],
+ "loc": {
+ "start": {
+ "line": 3,
+ "column": 11
+ },
+ "end": {
+ "line": 3,
+ "column": 17
+ }
+ }
+ }
+ }
+ ],
+ "childScopes": [],
+ "through": [
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "$store",
+ "range": [
+ 171,
+ 177
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 22
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 189,
+ 194
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 34
+ },
+ "end": {
+ "line": 5,
+ "column": 39
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 202,
+ 207
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 5
+ },
+ "end": {
+ "line": 6,
+ "column": 10
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "tab",
+ "range": [
+ 210,
+ 213
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 13
+ },
+ "end": {
+ "line": 6,
+ "column": 16
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ }
+ ]
+ }
+ ],
+ "through": [
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "$store",
+ "range": [
+ 171,
+ 177
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 16
+ },
+ "end": {
+ "line": 5,
+ "column": 22
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 189,
+ 194
+ ],
+ "loc": {
+ "start": {
+ "line": 5,
+ "column": 34
+ },
+ "end": {
+ "line": 5,
+ "column": 39
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "index",
+ "range": [
+ 202,
+ 207
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 5
+ },
+ "end": {
+ "line": 6,
+ "column": 10
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ },
+ {
+ "identifier": {
+ "type": "Identifier",
+ "name": "tab",
+ "range": [
+ 210,
+ 213
+ ],
+ "loc": {
+ "start": {
+ "line": 6,
+ "column": 13
+ },
+ "end": {
+ "line": 6,
+ "column": 16
+ }
+ }
+ },
+ "from": "module",
+ "init": null,
+ "resolved": null
+ }
+ ]
+}
\ No newline at end of file
diff --git a/tests/src/parser/typescript/index.ts b/tests/src/parser/typescript/index.ts
index 053c4200..6bfd733f 100644
--- a/tests/src/parser/typescript/index.ts
+++ b/tests/src/parser/typescript/index.ts
@@ -14,7 +14,7 @@ describe("Check for typescript analyze result.", () => {
meetRequirements,
} of listupFixtures()) {
if (!meetRequirements("parse")) {
- return;
+ continue;
}
if (!input.includes('lang="ts"')) {
continue;