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
100% compliant, self-hosted Typescript & Javascript parser with high focus on both performance and stability
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
- Support for additional ECMAScript features for Web Browsers
- JSX support via option
- Optionally track syntactic node locations
- Emits an ESTree-compatible abstract syntax tree.
- No backtracking
- Low memory usage
- Very well tested (~2 000 unit tests with full code coverage)
- Lightweight - ~30 KB minified
Installation
npm install buntis --save-devAPI
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 method 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.
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;
// Distinguish identifier from IdentifierPattern
identifierPattern: false;
// Enable React JSX parsing
jsx: false
// Enable Typescript parsing
jsx: false
// Allow edge cases that deviate from the spec
specDeviation: false
}Example usage:
import { parseScript } from './buntis';
parseScript('const f = function<T>(x?: T): T {}', { ts: true });
This will return when serialized in json:
{
body: [
{
declarations: [
{
id: {
name: 'f',
optional: false,
type: 'Identifier',
typeAnnotation: []
},
definite: false,
init: {
async: false,
body: {
body: [],
type: 'BlockStatement'
},
declare: false,
generator: false,
id: null,
params: [
{
name: 'x',
optional: true,
type: 'Identifier',
typeAnnotation: {
type: 'TSTypeAnnotation',
typeAnnotation: {
type: 'TSTypeReference',
typeName: {
name: 'T',
type: 'Identifier'
},
typeParameters: []
}
}
}
],
returnType: {
type: 'TSTypeAnnotation',
typeAnnotation: {
type: 'TSTypeReference',
typeName: {
name: 'T',
type: 'Identifier'
},
typeParameters: []
}
},
type: 'FunctionExpression',
typeParameters: {
params: [
{
constraint: null,
default: null,
name: {
name: 'T',
optional: 0,
type: 'Identifier',
typeAnnotation: []
},
type: 'TSTypeParameter'
}
],
type: 'TSTypeParameterDeclaration'
}
},
type: 'VariableDeclarator'
}
],
kind: 'const',
type: 'VariableDeclaration'
}
],
sourceType: 'script',
type: 'Program'
}Typescript
Buntis conforms to the latest language specification used in the newest version of Typescript, and are producing an ESTree-compatible AST.
Note: For Typescript parsing to work you need to set the ts option to true.