Package Exports
- buntis
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (buntis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Buntis
A 100% compliant, self-hosted Typescript parser that emits an ESTree-compatible abstract syntax tree
WORK IN PROGRESS!!
Features
- Conforms to the standard ECMAScript® 2020 (ECMA-262 10th Edition) language specification
- Conforms to the latest Typescript language specification
- Support TC39 proposals via option (wip)
- Support for additional ECMAScript features for Web Browsers
- JSX / TSX support via option
- Optionally track syntactic node locations (wip)
- Emits an ESTree-compatible abstract syntax tree
- No backtracking
- Low memory usage
- Very well tested (~14 000 unit tests with full code coverage)
- Lightweight - ~80 KB minified
Installation
npm install buntis --save-dev
API
Buntis generates AST
according to ESTree AST format, and can be used to perform syntactic analysis (parsing) of a Javascript or Typescript program, and with ES2015
and later a JavaScript program can be either a script or a module.
The parse
methods exposed by Buntis takes an optional options
object which allows you to specify whether to parse in script
mode (the default) or in module
mode.
Similiar parse
methods exist for Typescript - parseTSModule
and parseTSScript
.
This is the available options:
{
// The flag to enable stage 3 support (ESNext)
next: false;
// Disable web compability
disableWebCompat: false;
// The flag to enable line/column location information to each node
loc: false;
// The flag to attach raw property to each literal and identifier node
raw: false;
// Enabled directives
directives: false;
// The flag to allow return in the global scope
globalReturn: false;
// The flag to enable implied strict mode
impliedStrict: false;
// Enable comment extraction. Accepts **only** a function
onComment: function() {}
// Adds a source attribute in every node’s loc object when the locations option is `true`
source: false;
// Enable React JSX parsing
jsx: false
// Enable Typescript parsing
ts: false
// Allow edge cases that deviate from the spec
specDeviation: false
}
Example usage:
import { parseTSScript } from './buntis';
parseTSScript('const f = function<T>(x?: T): T {}', { ts: true });
This will return when serialized in json:
{
"type": "Program",
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"kind": "const",
"declarations": [
{
"type": "VariableDeclarator",
"init": {
"type": "FunctionExpression",
"params": [
{
"type": "Identifier",
"name": "x",
"optional": true,
"typeAnnotation": {
"type": "TypeAnnotation",
"typeAnnotation": {
"type": "TypeReference",
"typeName": {
"type": "Identifier",
"name": "T"
},
"typeParameters": []
}
}
}
],
"body": {
"type": "BlockStatement",
"body": []
},
"async": false,
"generator": false,
"id": null,
"typeParameters": {
"type": "TypeParameterDeclaration",
"params": [
{
"type": "TypeParameter",
"name": {
"type": "Identifier",
"name": "T",
"optional": 0,
"typeAnnotation": []
},
"constraint": null,
"default": null
}
]
},
"returnType": {
"type": "TypeAnnotation",
"typeAnnotation": {
"type": "TypeReference",
"typeName": {
"type": "Identifier",
"name": "T",
"optional": false,
"typeAnnotation": []
},
"typeParameters": []
}
},
"declare": false
},
"id": {
"type": "Identifier",
"name": "f",
"optional": false,
"typeAnnotation": []
},
"definite": false
}
]
}
]
}