0.2.1 • Published 4 years ago

buntis v0.2.1

Weekly downloads
10,851
License
ISC
Repository
github
Last release
4 years ago

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 (~16 000 unit tests with full code coverage)
  • Lightweight - ~85 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 same methods are used when parsing in Typescript mode - parseTSModule and parseTSScript.

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 or Typescript mode.

This is the available options:

{

  // Enabled directives
  directives: false;

  // Disable web compability
  disableWebCompat: false;

  // Enable React JSX parsing when set to `true`
  jsx: false

  // The flag to enable stage 3 support (ESNext)
  next: 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;

  // 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() {}

  // Enable Typescript parsing
  ts: false

  // Adds a source attribute in every node’s loc object when the locations option is `true`
  source: false;
}

Example usage:

import { parseTSScript } from './buntis';

parseTSScript('const f = function<T>(x?: T): T {}');

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
                }
            ]
        }
    ]
}
0.2.1

4 years ago

0.2.0

4 years ago

0.1.60

4 years ago

0.1.55

4 years ago

0.1.54

4 years ago

0.1.53

4 years ago

0.1.52

4 years ago

0.1.51

4 years ago

0.1.50

4 years ago

0.1.49

4 years ago

0.1.48

5 years ago

0.1.47

5 years ago

0.1.46

5 years ago

0.1.45

5 years ago

0.1.44

5 years ago

0.1.43

5 years ago

0.1.42

5 years ago

0.1.41

5 years ago

0.1.40

5 years ago

0.1.39

5 years ago

0.1.38

5 years ago

0.1.37

5 years ago

0.1.36

5 years ago

0.1.35

5 years ago

0.1.34

5 years ago

0.1.33

5 years ago

0.1.32

5 years ago

0.1.31

5 years ago

0.1.30

5 years ago

0.1.29

5 years ago

0.1.28

5 years ago

0.1.27

5 years ago

0.1.26

5 years ago

0.1.25

5 years ago

0.1.24

5 years ago

0.1.23

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago