react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / src / index.js
80551 views// Acorn is a tiny, fast JavaScript parser written in JavaScript.1//2// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and3// various contributors and released under an MIT license.4//5// Git repositories for Acorn are available at6//7// http://marijnhaverbeke.nl/git/acorn8// https://github.com/marijnh/acorn.git9//10// Please use the [github bug tracker][ghbt] to report issues.11//12// [ghbt]: https://github.com/marijnh/acorn/issues13//14// This file defines the main parser interface. The library also comes15// with a [error-tolerant parser][dammit] and an16// [abstract syntax tree walker][walk], defined in other files.17//18// [dammit]: acorn_loose.js19// [walk]: util/walk.js2021import {Parser} from "./state"22import {getOptions} from "./options"23import "./parseutil"24import "./statement"25import "./lval"26import "./expression"2728export {Parser, plugins} from "./state"29export {defaultOptions} from "./options"30export {SourceLocation} from "./location"31export {getLineInfo} from "./location"32export {Node} from "./node"33export {TokenType, types as tokTypes} from "./tokentype"34export {TokContext, types as tokContexts} from "./tokencontext"35export {isIdentifierChar, isIdentifierStart} from "./identifier"36export {Token} from "./tokenize"37export {isNewLine, lineBreak, lineBreakG} from "./whitespace"3839export const version = "1.2.2"4041// The main exported interface (under `self.acorn` when in the42// browser) is a `parse` function that takes a code string and43// returns an abstract syntax tree as specified by [Mozilla parser44// API][api].45//46// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API4748export function parse(input, options) {49let p = parser(options, input)50let startPos = p.pos, startLoc = p.options.locations && p.curPosition()51p.nextToken()52return p.parseTopLevel(p.options.program || p.startNodeAt(startPos, startLoc))53}5455// This function tries to parse a single expression at a given56// offset in a string. Useful for parsing mixed-language formats57// that embed JavaScript expressions.5859export function parseExpressionAt(input, pos, options) {60let p = parser(options, input, pos)61p.nextToken()62return p.parseExpression()63}6465// Acorn is organized as a tokenizer and a recursive-descent parser.66// The `tokenize` export provides an interface to the tokenizer.6768export function tokenizer(input, options) {69return parser(options, input)70}7172function parser(options, input) {73return new Parser(getOptions(options), String(input))74}757677