This is a plugin for Acorn - a tiny, fast JavaScript parser, written completely in JavaScript.
It was created as an experimental alternative, faster TypeScript parser. It will help you to parse
TypeScript using Acorn.
Usage
To get started, import the plugin and use Acorn's extension mechanism to register it. You have to enable options.locations while using @sveltejs/acorn-typescript.
import { Parser } from 'acorn';import { tsPlugin } from '@sveltejs/acorn-typescript';const node = Parser.extend(tsPlugin()).parse( `const a = 1type A = numberexport { a, type A as B}`, { sourceType: 'module', ecmaVersion: 'latest', locations: true });
If you want to enable parsing within a TypeScript ambient context, where certain syntax have different rules (like .d.ts files and inside declare module blocks):
import { Parser } from 'acorn';import { tsPlugin } from '@sveltejs/acorn-typescript';const node = Parser.extend(tsPlugin({ dts: true })).parse( `const a = 1type A = numberexport { a, type A as B}`, { sourceType: 'module', ecmaVersion: 'latest', locations: true });