Upgrade to https://github.com/acornjs/acorn.git commit 84eda6bf
[jst.git] / src / index.js
1 // Acorn is a tiny, fast JavaScript parser written in JavaScript.
2 //
3 // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
4 // various contributors and released under an MIT license.
5 //
6 // Git repositories for Acorn are available at
7 //
8 //     http://marijnhaverbeke.nl/git/acorn
9 //     https://github.com/acornjs/acorn.git
10 //
11 // Please use the [github bug tracker][ghbt] to report issues.
12 //
13 // [ghbt]: https://github.com/acornjs/acorn/issues
14 //
15 // [walk]: util/walk.js
16
17 import {Parser} from "./state.js"
18 import "./parseutil.js"
19 import "./statement.js"
20 import "./lval.js"
21 import "./expression.js"
22 import "./location.js"
23 import "./scope.js"
24
25 import {defaultOptions} from "./options.js"
26 import {Position, SourceLocation, getLineInfo} from "./locutil.js"
27 import {Node} from "./node.js"
28 import {TokenType, types as tokTypes, keywords as keywordTypes} from "./tokentype.js"
29 import {TokContext, types as tokContexts} from "./tokencontext.js"
30 import {isIdentifierChar, isIdentifierStart} from "./identifier.js"
31 import {Token} from "./tokenize.js"
32 import {isNewLine, lineBreak, lineBreakG, nonASCIIwhitespace} from "./whitespace.js"
33
34 export const version = "8.7.0"
35 export {
36   Parser,
37   defaultOptions,
38   Position,
39   SourceLocation,
40   getLineInfo,
41   Node,
42   TokenType,
43   tokTypes,
44   keywordTypes,
45   TokContext,
46   tokContexts,
47   isIdentifierChar,
48   isIdentifierStart,
49   Token,
50   isNewLine,
51   lineBreak,
52   lineBreakG,
53   nonASCIIwhitespace
54 }
55
56 Parser.acorn = {
57   Parser,
58   version,
59   defaultOptions,
60   Position,
61   SourceLocation,
62   getLineInfo,
63   Node,
64   TokenType,
65   tokTypes,
66   keywordTypes,
67   TokContext,
68   tokContexts,
69   isIdentifierChar,
70   isIdentifierStart,
71   Token,
72   isNewLine,
73   lineBreak,
74   lineBreakG,
75   nonASCIIwhitespace
76 }
77
78 // The main exported interface (under `self.acorn` when in the
79 // browser) is a `parse` function that takes a code string and
80 // returns an abstract syntax tree as specified by [Mozilla parser
81 // API][api].
82 //
83 // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
84
85 export function parse(input, options) {
86   return Parser.parse(input, options)
87 }
88
89 // This function tries to parse a single expression at a given
90 // offset in a string. Useful for parsing mixed-language formats
91 // that embed JavaScript expressions.
92
93 export function parseExpressionAt(input, pos, options) {
94   return Parser.parseExpressionAt(input, pos, options)
95 }
96
97 // Acorn is organized as a tokenizer and a recursive-descent parser.
98 // The `tokenizer` export provides an interface to the tokenizer.
99
100 export function tokenizer(input, options) {
101   return Parser.tokenizer(input, options)
102 }