Skip to content

Commit a92bc2d

Browse files
committed
work around acorn-typescript quirks
1 parent c3535d2 commit a92bc2d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as acorn from 'acorn';
22
import { walk } from 'zimmerframe';
33
import { tsPlugin } from 'acorn-typescript';
4+
import { locator } from '../../state.js';
45

56
const ParserWithTS = acorn.Parser.extend(tsPlugin({ allowSatisfies: true }));
67

@@ -127,6 +128,16 @@ function amend(source, node) {
127128
// @ts-expect-error
128129
delete node.loc.end.index;
129130

131+
if (typeof node.loc?.end === 'number') {
132+
const loc = locator(node.loc.end);
133+
if (loc) {
134+
node.loc.end = {
135+
line: loc.line,
136+
column: loc.column
137+
};
138+
}
139+
}
140+
130141
if (/** @type {any} */ (node).typeAnnotation && node.end === undefined) {
131142
// i think there might be a bug in acorn-typescript that prevents
132143
// `end` from being assigned when there's a type annotation

packages/svelte/tests/parser-modern/samples/snippets/output.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
},
3737
"end": {
3838
"line": 3,
39-
"column": 25,
40-
"character": 54
39+
"column": 25
4140
}
4241
},
4342
"end": 46,

packages/svelte/tests/parser-modern/samples/typescript-in-event-handler/output.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
"line": 6,
5555
"column": 12
5656
},
57-
"end": 87
57+
"end": {
58+
"line": 6,
59+
"column": 25
60+
}
5861
},
5962
"name": "e",
6063
"typeAnnotation": {

0 commit comments

Comments
 (0)