react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / src / state.js
80551 viewsimport {reservedWords, keywords} from "./identifier"1import {types as tt} from "./tokentype"2import {lineBreak} from "./whitespace"34export function Parser(options, input, startPos) {5this.options = options6this.sourceFile = this.options.sourceFile || null7this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5]8this.isReservedWord = reservedWords[this.options.ecmaVersion]9this.input = input1011// Load plugins12this.loadPlugins(this.options.plugins)1314// Set up token state1516// The current position of the tokenizer in the input.17if (startPos) {18this.pos = startPos19this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos))20this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length21} else {22this.pos = this.lineStart = 023this.curLine = 124}2526// Properties of the current token:27// Its type28this.type = tt.eof29// For tokens that include more information than their type, the value30this.value = null31// Its start and end offset32this.start = this.end = this.pos33// And, if locations are used, the {line, column} object34// corresponding to those offsets35this.startLoc = this.endLoc = null3637// Position information for the previous token38this.lastTokEndLoc = this.lastTokStartLoc = null39this.lastTokStart = this.lastTokEnd = this.pos4041// The context stack is used to superficially track syntactic42// context to predict whether a regular expression is allowed in a43// given position.44this.context = this.initialContext()45this.exprAllowed = true4647// Figure out if it's a module code.48this.strict = this.inModule = this.options.sourceType === "module"4950// Used to signify the start of a potential arrow function51this.potentialArrowAt = -15253// Flags to track whether we are in a function, a generator.54this.inFunction = this.inGenerator = false55// Labels in scope.56this.labels = []5758// If enabled, skip leading hashbang line.59if (this.pos === 0 && this.options.allowHashBang && this.input.slice(0, 2) === '#!')60this.skipLineComment(2)61}6263Parser.prototype.extend = function(name, f) {64this[name] = f(this[name])65}6667// Registered plugins6869export const plugins = {}7071Parser.prototype.loadPlugins = function(plugins) {72for (let name in plugins) {73let plugin = exports.plugins[name]74if (!plugin) throw new Error("Plugin '" + name + "' not found")75plugin(this, plugins[name])76}77}787980