11/** @import { Comment, Program } from 'estree' */
2- /** @import { Node } from 'acorn' */
32import * as acorn from 'acorn' ;
43import { walk } from 'zimmerframe' ;
5- import { tsPlugin } from 'acorn-typescript' ;
6- import { locator } from '../../state.js' ;
4+ import { tsPlugin } from '@sveltejs/acorn-typescript' ;
75
8- const ParserWithTS = acorn . Parser . extend ( tsPlugin ( { allowSatisfies : true } ) ) ;
6+ const ParserWithTS = acorn . Parser . extend ( tsPlugin ( ) ) ;
97
108/**
119 * @param {string } source
@@ -48,7 +46,6 @@ export function parse(source, typescript, is_script) {
4846 }
4947 }
5048
51- if ( typescript ) amend ( source , ast ) ;
5249 add_comments ( ast ) ;
5350
5451 return /** @type {Program } */ ( ast ) ;
@@ -71,7 +68,6 @@ export function parse_expression_at(source, typescript, index) {
7168 locations : true
7269 } ) ;
7370
74- if ( typescript ) amend ( source , ast ) ;
7571 add_comments ( ast ) ;
7672
7773 return ast ;
@@ -173,42 +169,3 @@ function get_comment_handlers(source) {
173169 }
174170 } ;
175171}
176-
177- /**
178- * Tidy up some stuff left behind by acorn-typescript
179- * @param {string } source
180- * @param {Node } node
181- */
182- function amend ( source , node ) {
183- return walk ( node , null , {
184- _ ( node , context ) {
185- // @ts -expect-error
186- delete node . loc . start . index ;
187- // @ts -expect-error
188- delete node . loc . end . index ;
189-
190- if ( typeof node . loc ?. end === 'number' ) {
191- const loc = locator ( node . loc . end ) ;
192- if ( loc ) {
193- node . loc . end = {
194- line : loc . line ,
195- column : loc . column
196- } ;
197- }
198- }
199-
200- if (
201- /** @type {any } */ ( node ) . typeAnnotation &&
202- ( node . end === undefined || node . end < node . start )
203- ) {
204- // i think there might be a bug in acorn-typescript that prevents
205- // `end` from being assigned when there's a type annotation
206- let end = /** @type {any } */ ( node ) . typeAnnotation . start ;
207- while ( / \s / . test ( source [ end - 1 ] ) ) end -= 1 ;
208- node . end = end ;
209- }
210-
211- context . next ( ) ;
212- }
213- } ) ;
214- }
0 commit comments