react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / src / loose / index.js
80555 views// Acorn: Loose parser1//2// This module provides an alternative parser (`parse_dammit`) that3// exposes that same interface as `parse`, but will try to parse4// anything as JavaScript, repairing syntax error the best it can.5// There are circumstances in which it will raise an error and give6// up, but they are very rare. The resulting AST will be a mostly7// valid JavaScript AST (as per the [Mozilla parser API][api], except8// that:9//10// - Return outside functions is allowed11//12// - Label consistency (no conflicts, break only to existing labels)13// is not enforced.14//15// - Bogus Identifier nodes with a name of `"✖"` are inserted whenever16// the parser got too confused to return anything meaningful.17//18// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API19//20// The expected use for this is to *first* try `acorn.parse`, and only21// if that fails switch to `parse_dammit`. The loose parser might22// parse badly indented code incorrectly, so **don't** use it as23// your default parser.24//25// Quite a lot of acorn.js is duplicated here. The alternative was to26// add a *lot* of extra cruft to that file, making it less readable27// and slower. Copying and editing the code allowed me to make28// invasive changes and simplifications without creating a complicated29// tangle.3031import * as acorn from ".."32import {LooseParser} from "./state"33import "./tokenize"34import "./parseutil"35import "./statement"36import "./expression"3738export {LooseParser} from "./state"3940acorn.defaultOptions.tabSize = 44142export function parse_dammit(input, options) {43let p = new LooseParser(input, options)44p.next()45return p.parseTopLevel()46}4748acorn.parse_dammit = parse_dammit49acorn.LooseParser = LooseParser505152