acorn-typescript v1.4.13
acorn-typescript
This is 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 script into typeScript AST.
Usage
Requiring this module provides you with an Acorn plugin that you can use like this:
import * as acorn from 'acorn'
import tsPlugin from 'acorn-typescript'
/*
*
* */
const node = acorn.Parser.extend(tsPlugin()).parse(`
const a = 1
type A = number
export {
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 * as acorn from 'acorn'
import tsPlugin from 'acorn-typescript'
/*
*
* */
const node = acorn.Parser.extend(tsPlugin({ dts: true })).parse(`
const a = 1
type A = number
export {
a,
type A as B
}
`, {
sourceType: 'module',
ecmaVersion: 'latest',
locations: true
})
Notice
- You have to enable options.locations while using acorn-typescript
acorn.parse(input, {
sourceType: 'module',
ecmaVersion: 'latest',
// here
locations: true
})
SUPPORTED
- Typescript normal syntax
- Support to parse TypeScript Decorators
- Support to parse JSX & TSX
CHANGELOG
RoadMap
- support import-assertions
License
4 months ago
5 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
10 months ago
6 months ago
6 months ago
7 months ago
6 months ago
7 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
11 months ago
12 months ago
11 months ago
12 months ago
11 months ago
12 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago