Skip to content

Commit 44c1704

Browse files
authored
fix: wrong token when using lang=ts (#504)
1 parent b9f00bc commit 44c1704

14 files changed

+1984
-570
lines changed

.changeset/violet-rockets-relax.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: wrong token when using `lang=ts`

src/context/script-let.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export class ScriptLetContext {
178178
callback(node as E, result);
179179
}
180180

181+
tokens.shift(); // (
182+
tokens.pop(); // )
183+
tokens.pop(); // ;
184+
181185
if (isTS) {
182186
for (const scope of extractTypeNodeScopes(
183187
tsAs!.typeAnnotation,
@@ -201,10 +205,6 @@ export class ScriptLetContext {
201205

202206
(node as any).parent = parent;
203207

204-
tokens.shift(); // (
205-
tokens.pop(); // )
206-
tokens.pop(); // ;
207-
208208
// Disconnect the tree structure.
209209
exprSt.expression = null as never;
210210
},

tests/fixtures/parser/ast/svelte5/docs/runes/11-1-$inspect-ts-output.json

+4-94
Original file line numberDiff line numberDiff line change
@@ -1656,87 +1656,15 @@
16561656
},
16571657
{
16581658
"type": "Identifier",
1659-
"value": "c",
1659+
"value": "count",
16601660
"range": [
16611661
194,
1662-
195
1663-
],
1664-
"loc": {
1665-
"start": {
1666-
"line": 8,
1667-
"column": 24
1668-
},
1669-
"end": {
1670-
"line": 8,
1671-
"column": 25
1672-
}
1673-
}
1674-
},
1675-
{
1676-
"type": "Identifier",
1677-
"value": "o",
1678-
"range": [
1679-
195,
1680-
196
1681-
],
1682-
"loc": {
1683-
"start": {
1684-
"line": 8,
1685-
"column": 25
1686-
},
1687-
"end": {
1688-
"line": 8,
1689-
"column": 26
1690-
}
1691-
}
1692-
},
1693-
{
1694-
"type": "Identifier",
1695-
"value": "u",
1696-
"range": [
1697-
196,
1698-
197
1699-
],
1700-
"loc": {
1701-
"start": {
1702-
"line": 8,
1703-
"column": 26
1704-
},
1705-
"end": {
1706-
"line": 8,
1707-
"column": 27
1708-
}
1709-
}
1710-
},
1711-
{
1712-
"type": "Identifier",
1713-
"value": "n",
1714-
"range": [
1715-
197,
1716-
198
1717-
],
1718-
"loc": {
1719-
"start": {
1720-
"line": 8,
1721-
"column": 27
1722-
},
1723-
"end": {
1724-
"line": 8,
1725-
"column": 28
1726-
}
1727-
}
1728-
},
1729-
{
1730-
"type": "Identifier",
1731-
"value": "t",
1732-
"range": [
1733-
198,
17341662
199
17351663
],
17361664
"loc": {
17371665
"start": {
17381666
"line": 8,
1739-
"column": 28
1667+
"column": 24
17401668
},
17411669
"end": {
17421670
"line": 8,
@@ -1746,33 +1674,15 @@
17461674
},
17471675
{
17481676
"type": "Punctuator",
1749-
"value": "+",
1677+
"value": "++",
17501678
"range": [
17511679
199,
1752-
200
1753-
],
1754-
"loc": {
1755-
"start": {
1756-
"line": 8,
1757-
"column": 29
1758-
},
1759-
"end": {
1760-
"line": 8,
1761-
"column": 30
1762-
}
1763-
}
1764-
},
1765-
{
1766-
"type": "Punctuator",
1767-
"value": "+",
1768-
"range": [
1769-
200,
17701680
201
17711681
],
17721682
"loc": {
17731683
"start": {
17741684
"line": 8,
1775-
"column": 30
1685+
"column": 29
17761686
},
17771687
"end": {
17781688
"line": 8,

tests/fixtures/parser/ast/svelte5/docs/runes/11-2-$inspect-ts-output.json

+4-94
Original file line numberDiff line numberDiff line change
@@ -1837,87 +1837,15 @@
18371837
},
18381838
{
18391839
"type": "Identifier",
1840-
"value": "c",
1840+
"value": "count",
18411841
"range": [
18421842
223,
1843-
224
1844-
],
1845-
"loc": {
1846-
"start": {
1847-
"line": 11,
1848-
"column": 24
1849-
},
1850-
"end": {
1851-
"line": 11,
1852-
"column": 25
1853-
}
1854-
}
1855-
},
1856-
{
1857-
"type": "Identifier",
1858-
"value": "o",
1859-
"range": [
1860-
224,
1861-
225
1862-
],
1863-
"loc": {
1864-
"start": {
1865-
"line": 11,
1866-
"column": 25
1867-
},
1868-
"end": {
1869-
"line": 11,
1870-
"column": 26
1871-
}
1872-
}
1873-
},
1874-
{
1875-
"type": "Identifier",
1876-
"value": "u",
1877-
"range": [
1878-
225,
1879-
226
1880-
],
1881-
"loc": {
1882-
"start": {
1883-
"line": 11,
1884-
"column": 26
1885-
},
1886-
"end": {
1887-
"line": 11,
1888-
"column": 27
1889-
}
1890-
}
1891-
},
1892-
{
1893-
"type": "Identifier",
1894-
"value": "n",
1895-
"range": [
1896-
226,
1897-
227
1898-
],
1899-
"loc": {
1900-
"start": {
1901-
"line": 11,
1902-
"column": 27
1903-
},
1904-
"end": {
1905-
"line": 11,
1906-
"column": 28
1907-
}
1908-
}
1909-
},
1910-
{
1911-
"type": "Identifier",
1912-
"value": "t",
1913-
"range": [
1914-
227,
19151843
228
19161844
],
19171845
"loc": {
19181846
"start": {
19191847
"line": 11,
1920-
"column": 28
1848+
"column": 24
19211849
},
19221850
"end": {
19231851
"line": 11,
@@ -1927,33 +1855,15 @@
19271855
},
19281856
{
19291857
"type": "Punctuator",
1930-
"value": "+",
1858+
"value": "++",
19311859
"range": [
19321860
228,
1933-
229
1934-
],
1935-
"loc": {
1936-
"start": {
1937-
"line": 11,
1938-
"column": 29
1939-
},
1940-
"end": {
1941-
"line": 11,
1942-
"column": 30
1943-
}
1944-
}
1945-
},
1946-
{
1947-
"type": "Punctuator",
1948-
"value": "+",
1949-
"range": [
1950-
229,
19511861
230
19521862
],
19531863
"loc": {
19541864
"start": {
19551865
"line": 11,
1956-
"column": 30
1866+
"column": 29
19571867
},
19581868
"end": {
19591869
"line": 11,

tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@
27452745
}
27462746
},
27472747
{
2748-
"type": "Identifier",
2748+
"type": "Numeric",
27492749
"value": "1",
27502750
"range": [
27512751
241,

0 commit comments

Comments
 (0)