acorn-hammerhead
Advanced tools
Comparing version 0.6.1 to 0.6.2
"use strict"; | ||
var _path = require("path"); | ||
var _fs = require("fs"); | ||
var acorn = _interopRequireWildcard(require("acorn")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
let inputFilePaths = [], | ||
forceFileName = false, | ||
fileMode = false, | ||
silent = false, | ||
compact = false, | ||
tokenize = false; | ||
forceFileName = false, | ||
fileMode = false, | ||
silent = false, | ||
compact = false, | ||
tokenize = false; | ||
const options = {}; | ||
function help(status) { | ||
@@ -27,3 +21,2 @@ const print = status === 0 ? console.log : console.error; | ||
} | ||
for (let i = 2; i < process.argv.length; ++i) { | ||
@@ -40,11 +33,8 @@ const arg = process.argv[i]; | ||
} | ||
function run(codeList) { | ||
let result = [], | ||
fileIdx = 0; | ||
fileIdx = 0; | ||
try { | ||
codeList.forEach((code, idx) => { | ||
fileIdx = idx; | ||
if (!tokenize) { | ||
@@ -55,4 +45,3 @@ result = acorn.parse(code, options); | ||
let tokenizer = acorn.tokenizer(code, options), | ||
token; | ||
token; | ||
do { | ||
@@ -68,6 +57,4 @@ token = tokenizer.getToken(); | ||
} | ||
if (!silent) console.log(JSON.stringify(result, null, compact ? null : 2)); | ||
} | ||
if (fileMode = inputFilePaths.length && (forceFileName || !inputFilePaths.includes("-") || inputFilePaths.length !== 1)) { | ||
@@ -74,0 +61,0 @@ run(inputFilePaths.map(path => (0, _fs.readFileSync)(path, "utf8"))); |
"use strict"; | ||
var _tokentype = require("./tokentype.js"); | ||
var _tokencontext = require("./tokencontext.js"); | ||
var _state = require("./state.js"); | ||
var _parseutil = require("./parseutil.js"); | ||
var _whitespace = require("./whitespace.js"); | ||
var _scopeflags = require("./scopeflags.js"); | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } // A recursive descent parser operates by defining functions for all | ||
// syntactic elements, and recursively calling those, each function | ||
// advancing the input stream and returning an AST node. Precedence | ||
// of constructs (for example, the fact that `!x[1]` means `!(x[1])` | ||
// instead of `(!x)[1]` is handled by the fact that the parser | ||
// function that parses unary prefix operators is called first, and | ||
// in turn calls the function that parses `[]` subscripts — that | ||
// way, it'll receive the node for `x[1]` already parsed, and wraps | ||
// *that* in the unary operator node. | ||
// | ||
// Acorn uses an [operator precedence parser][opp] to handle binary | ||
// operator precedence, because it is much more compact than using | ||
// the technique outlined above, which uses different, nesting | ||
// functions to specify precedence, for all of the ten binary | ||
// precedence levels that JavaScript defines. | ||
// | ||
// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser | ||
const pp = _state.Parser.prototype; | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
const pp = _state.Parser.prototype; // Check if property name clashes with already added. | ||
// Check if property name clashes with already added. | ||
// Object/class getters and setters are not allowed to clash — | ||
@@ -30,4 +39,3 @@ // either with each other or with an init property — and in | ||
let key = prop.key, | ||
name; | ||
name; | ||
switch (key.type) { | ||
@@ -37,13 +45,9 @@ case "Identifier": | ||
break; | ||
case "Literal": | ||
name = String(key.value); | ||
break; | ||
default: | ||
return; | ||
} | ||
let kind = prop.kind; | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -60,15 +64,10 @@ if (name === "__proto__" && kind === "init") { | ||
} | ||
propHash.proto = true; | ||
} | ||
return; | ||
} | ||
name = "$" + name; | ||
let other = propHash[name]; | ||
if (other) { | ||
let redefinition; | ||
if (kind === "init") { | ||
@@ -79,3 +78,2 @@ redefinition = this.strict && other.init || other.get || other.set; | ||
} | ||
if (redefinition) this.raiseRecoverable(key.start, "Redefinition of property"); | ||
@@ -89,5 +87,7 @@ } else { | ||
} | ||
other[kind] = true; | ||
}; | ||
other[kind] = true; | ||
}; // ### Expression parsing | ||
// ### Expression parsing | ||
// These nest, from the most general expression type at the top to | ||
@@ -98,2 +98,3 @@ // 'atomic', nondivisible expression types at the bottom. Most of | ||
// the AST node that the inner parser gave them in another node. | ||
// Parse a full expression. The optional arguments are used to | ||
@@ -106,34 +107,29 @@ // forbid the `in` operator (in for loops initalization expressions) | ||
pp.parseExpression = function (forInit, refDestructuringErrors) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
startLoc = this.startLoc; | ||
let expr = this.parseMaybeAssign(forInit, refDestructuringErrors); | ||
if (this.type === _tokentype.types.comma) { | ||
let node = this.startNodeAt(startPos, startLoc); | ||
node.expressions = [expr]; | ||
while (this.eat(_tokentype.types.comma)) node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors)); | ||
return this.finishNode(node, "SequenceExpression"); | ||
} | ||
return expr; | ||
}; | ||
return expr; | ||
}; // Parse an assignment expression. This includes applications of | ||
// Parse an assignment expression. This includes applications of | ||
// operators like `+=`. | ||
pp.parseMaybeAssign = function (forInit, refDestructuringErrors, afterLeftParse) { | ||
if (this.isContextual("yield")) { | ||
if (this.inGenerator) return this.parseYield(forInit); // The tokenizer will assume an expression is allowed after | ||
if (this.inGenerator) return this.parseYield(forInit); | ||
// The tokenizer will assume an expression is allowed after | ||
// `yield`, but this isn't that kind of yield | ||
else this.exprAllowed = false; | ||
} | ||
let ownDestructuringErrors = false, | ||
oldParenAssign = -1, | ||
oldTrailingComma = -1, | ||
oldDoubleProto = -1; | ||
oldParenAssign = -1, | ||
oldTrailingComma = -1, | ||
oldDoubleProto = -1; | ||
if (refDestructuringErrors) { | ||
@@ -148,6 +144,4 @@ oldParenAssign = refDestructuringErrors.parenthesizedAssign; | ||
} | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
startLoc = this.startLoc; | ||
if (this.type === _tokentype.types.parenL || this.type === _tokentype.types.name) { | ||
@@ -157,6 +151,4 @@ this.potentialArrowAt = this.start; | ||
} | ||
let left = this.parseMaybeConditional(forInit, refDestructuringErrors); | ||
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc); | ||
if (this.type.isAssign) { | ||
@@ -166,9 +158,6 @@ let node = this.startNodeAt(startPos, startLoc); | ||
if (this.type === _tokentype.types.eq) left = this.toAssignable(left, false, refDestructuringErrors); | ||
if (!ownDestructuringErrors) { | ||
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1; | ||
} | ||
if (refDestructuringErrors.shorthandAssign >= left.start) refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly | ||
if (this.type === _tokentype.types.eq) this.checkLValPattern(left);else this.checkLValSimple(left); | ||
@@ -183,15 +172,14 @@ node.left = left; | ||
} | ||
if (oldParenAssign > -1) refDestructuringErrors.parenthesizedAssign = oldParenAssign; | ||
if (oldTrailingComma > -1) refDestructuringErrors.trailingComma = oldTrailingComma; | ||
return left; | ||
}; // Parse a ternary conditional (`?:`) operator. | ||
}; | ||
// Parse a ternary conditional (`?:`) operator. | ||
pp.parseMaybeConditional = function (forInit, refDestructuringErrors) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
startLoc = this.startLoc; | ||
let expr = this.parseExprOps(forInit, refDestructuringErrors); | ||
if (this.checkExpressionErrors(refDestructuringErrors)) return expr; | ||
if (this.eat(_tokentype.types.question)) { | ||
@@ -205,14 +193,16 @@ let node = this.startNodeAt(startPos, startLoc); | ||
} | ||
return expr; | ||
}; // Start the precedence parser. | ||
}; | ||
// Start the precedence parser. | ||
pp.parseExprOps = function (forInit, refDestructuringErrors) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
startLoc = this.startLoc; | ||
let expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit); | ||
if (this.checkExpressionErrors(refDestructuringErrors)) return expr; | ||
return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit); | ||
}; // Parse binary operators with the operator precedence parsing | ||
}; | ||
// Parse binary operators with the operator precedence parsing | ||
// algorithm. `left` is the left-hand side of the operator. | ||
@@ -223,6 +213,4 @@ // `minPrec` provides context that allows the function to stop and | ||
pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, forInit) { | ||
let prec = this.type.binop; | ||
if (prec != null && (!forInit || this.type !== _tokentype.types._in)) { | ||
@@ -232,3 +220,2 @@ if (prec > minPrec) { | ||
let coalesce = this.type === _tokentype.types.coalesce; | ||
if (coalesce) { | ||
@@ -239,21 +226,16 @@ // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions. | ||
} | ||
let op = this.value; | ||
this.next(); | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
startLoc = this.startLoc; | ||
let right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit); | ||
let node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce); | ||
if (logical && this.type === _tokentype.types.coalesce || coalesce && (this.type === _tokentype.types.logicalOR || this.type === _tokentype.types.logicalAND)) { | ||
this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"); | ||
} | ||
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit); | ||
} | ||
} | ||
return left; | ||
}; | ||
pp.buildBinary = function (startPos, startLoc, left, right, op, logical) { | ||
@@ -266,10 +248,10 @@ if (right.type === "PrivateIdentifier") this.raise(right.start, "Private identifier can only be left side of binary expression"); | ||
return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression"); | ||
}; // Parse unary operators, both prefix and postfix. | ||
}; | ||
// Parse unary operators, both prefix and postfix. | ||
pp.parseMaybeUnary = function (refDestructuringErrors, sawUnary, incDec, forInit) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc, | ||
expr; | ||
startLoc = this.startLoc, | ||
expr; | ||
if (this.isContextual("await") && this.canAwait) { | ||
@@ -280,3 +262,3 @@ expr = this.parseAwait(forInit); | ||
let node = this.startNode(), | ||
update = this.type === _tokentype.types.incDec; | ||
update = this.type === _tokentype.types.incDec; | ||
node.operator = this.value; | ||
@@ -291,4 +273,4 @@ node.prefix = true; | ||
if (forInit || this.privateNameStack.length === 0) this.unexpected(); | ||
expr = this.parsePrivateIdent(); // only could be private fields in 'in', such as #x in obj | ||
expr = this.parsePrivateIdent(); | ||
// only could be private fields in 'in', such as #x in obj | ||
if (this.type !== _tokentype.types._in) this.unexpected(); | ||
@@ -298,3 +280,2 @@ } else { | ||
if (this.checkExpressionErrors(refDestructuringErrors)) return expr; | ||
while (this.type.postfix && !this.canInsertSemicolon()) { | ||
@@ -310,3 +291,2 @@ let node = this.startNodeAt(startPos, startLoc); | ||
} | ||
if (!incDec && this.eat(_tokentype.types.starstar)) { | ||
@@ -318,15 +298,14 @@ if (sawUnary) this.unexpected(this.lastTokStart);else return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false); | ||
}; | ||
function isPrivateFieldAccess(node) { | ||
return node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" || node.type === "ChainExpression" && isPrivateFieldAccess(node.expression); | ||
} // Parse call, dot, and `[]`-subscript expressions. | ||
} | ||
// Parse call, dot, and `[]`-subscript expressions. | ||
pp.parseExprSubscripts = function (refDestructuringErrors, forInit) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
startLoc = this.startLoc; | ||
let expr = this.parseExprAtom(refDestructuringErrors, forInit); | ||
if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")") return expr; | ||
let result = this.parseSubscripts(expr, startPos, startLoc, false, forInit); | ||
if (refDestructuringErrors && result.type === "MemberExpression") { | ||
@@ -337,14 +316,10 @@ if (refDestructuringErrors.parenthesizedAssign >= result.start) refDestructuringErrors.parenthesizedAssign = -1; | ||
} | ||
return result; | ||
}; | ||
pp.parseSubscripts = function (base, startPos, startLoc, noCalls, forInit) { | ||
let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.potentialArrowAt === base.start; | ||
let optionalChained = false; | ||
while (true) { | ||
let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit); | ||
if (element.optional) optionalChained = true; | ||
if (element === base || element.type === "ArrowFunctionExpression") { | ||
@@ -356,10 +331,7 @@ if (optionalChained) { | ||
} | ||
return element; | ||
} | ||
base = element; | ||
} | ||
}; | ||
pp.parseSubscript = function (base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) { | ||
@@ -370,7 +342,5 @@ let optionalSupported = this.options.ecmaVersion >= 11; | ||
let computed = this.eat(_tokentype.types.bracketL); | ||
if (computed || optional && this.type !== _tokentype.types.parenL && this.type !== _tokentype.types.backQuote || this.eat(_tokentype.types.dot)) { | ||
let node = this.startNodeAt(startPos, startLoc); | ||
node.object = base; | ||
if (computed) { | ||
@@ -384,15 +354,12 @@ node.property = this.parseExpression(); | ||
} | ||
node.computed = !!computed; | ||
if (optionalSupported) { | ||
node.optional = optional; | ||
node.optional = optional || node.object.optional; | ||
} | ||
base = this.finishNode(node, "MemberExpression"); | ||
} else if (!noCalls && this.eat(_tokentype.types.parenL)) { | ||
let refDestructuringErrors = new _parseutil.DestructuringErrors(), | ||
oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
this.yieldPos = 0; | ||
@@ -402,3 +369,2 @@ this.awaitPos = 0; | ||
let exprList = this.parseExprList(_tokentype.types.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors); | ||
if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) { | ||
@@ -413,3 +379,2 @@ this.checkPatternErrors(refDestructuringErrors, false); | ||
} | ||
this.checkExpressionErrors(refDestructuringErrors, true); | ||
@@ -422,7 +387,5 @@ this.yieldPos = oldYieldPos || this.yieldPos; | ||
node.arguments = exprList; | ||
if (optionalSupported) { | ||
node.optional = optional; | ||
} | ||
base = this.finishNode(node, "CallExpression"); | ||
@@ -433,3 +396,2 @@ } else if (this.type === _tokentype.types.backQuote) { | ||
} | ||
let node = this.startNodeAt(startPos, startLoc); | ||
@@ -442,5 +404,6 @@ node.tag = base; | ||
} | ||
return base; | ||
}; | ||
return base; | ||
}; // Parse an atomic expression — either a single token that is an | ||
// Parse an atomic expression — either a single token that is an | ||
// expression, an expression started by a keyword like `function` or | ||
@@ -450,3 +413,2 @@ // `new`, or an expression wrapped in punctuation like `()`, `[]`, | ||
pp.parseExprAtom = function (refDestructuringErrors, forInit) { | ||
@@ -457,4 +419,3 @@ // If a division operator appears in an expression position, the | ||
let node, | ||
canBeArrow = this.potentialArrowAt === this.start; | ||
canBeArrow = this.potentialArrowAt === this.start; | ||
switch (this.type) { | ||
@@ -465,3 +426,4 @@ case _tokentype.types._super: | ||
this.next(); | ||
if (this.type === _tokentype.types.parenL && !this.allowDirectSuper) this.raise(node.start, "super() call outside constructor of a subclass"); // The `super` keyword can appear at below: | ||
if (this.type === _tokentype.types.parenL && !this.allowDirectSuper) this.raise(node.start, "super() call outside constructor of a subclass"); | ||
// The `super` keyword can appear at below: | ||
// SuperProperty: | ||
@@ -472,6 +434,4 @@ // super [ Expression ] | ||
// super ( Arguments ) | ||
if (this.type !== _tokentype.types.dot && this.type !== _tokentype.types.bracketL && this.type !== _tokentype.types.parenL) this.unexpected(); | ||
return this.finishNode(node, "Super"); | ||
case _tokentype.types._this: | ||
@@ -481,9 +441,7 @@ node = this.startNode(); | ||
return this.finishNode(node, "ThisExpression"); | ||
case _tokentype.types.name: | ||
let startPos = this.start, | ||
startLoc = this.startLoc, | ||
containsEsc = this.containsEsc; | ||
startLoc = this.startLoc, | ||
containsEsc = this.containsEsc; | ||
let id = this.parseIdent(false); | ||
if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(_tokentype.types._function)) { | ||
@@ -493,6 +451,4 @@ this.overrideContext(_tokencontext.types.f_expr); | ||
} | ||
if (canBeArrow && !this.canInsertSemicolon()) { | ||
if (this.eat(_tokentype.types.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit); | ||
if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === _tokentype.types.name && !containsEsc && (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) { | ||
@@ -504,5 +460,3 @@ id = this.parseIdent(false); | ||
} | ||
return id; | ||
case _tokentype.types.regexp: | ||
@@ -516,7 +470,5 @@ let value = this.value; | ||
return node; | ||
case _tokentype.types.num: | ||
case _tokentype.types.string: | ||
return this.parseLiteral(this.value); | ||
case _tokentype.types._null: | ||
@@ -530,7 +482,5 @@ case _tokentype.types._true: | ||
return this.finishNode(node, "Literal"); | ||
case _tokentype.types.parenL: | ||
let start = this.start, | ||
expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit); | ||
expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit); | ||
if (refDestructuringErrors) { | ||
@@ -540,5 +490,3 @@ if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr)) refDestructuringErrors.parenthesizedAssign = start; | ||
} | ||
return expr; | ||
case _tokentype.types.bracketL: | ||
@@ -549,7 +497,5 @@ node = this.startNode(); | ||
return this.finishNode(node, "ArrayExpression"); | ||
case _tokentype.types.braceL: | ||
this.overrideContext(_tokencontext.types.b_expr); | ||
return this.parseObj(false, refDestructuringErrors); | ||
case _tokentype.types._function: | ||
@@ -559,12 +505,8 @@ node = this.startNode(); | ||
return this.parseFunction(node, 0); | ||
case _tokentype.types._class: | ||
return this.parseClass(this.startNode(), false); | ||
case _tokentype.types._new: | ||
return this.parseNew(); | ||
case _tokentype.types.backQuote: | ||
return this.parseTemplate(); | ||
case _tokentype.types._import: | ||
@@ -576,3 +518,2 @@ if (this.options.ecmaVersion >= 11) { | ||
} | ||
default: | ||
@@ -582,18 +523,15 @@ this.unexpected(); | ||
}; | ||
pp.parseExprImport = function () { | ||
const node = this.startNode(); | ||
pp.parseExprImport = function () { | ||
const node = this.startNode(); // Consume `import` as an identifier for `import.meta`. | ||
// Consume `import` as an identifier for `import.meta`. | ||
// Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`. | ||
if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword import"); | ||
const meta = this.parseIdent(true); | ||
switch (this.type) { | ||
case _tokentype.types.parenL: | ||
return this.parseDynamicImport(node); | ||
case _tokentype.types.dot: | ||
node.meta = meta; | ||
return this.parseImportMeta(node); | ||
default: | ||
@@ -603,12 +541,11 @@ this.unexpected(); | ||
}; | ||
pp.parseDynamicImport = function (node) { | ||
this.next(); // skip `(` | ||
// Parse node.source. | ||
node.source = this.parseMaybeAssign(); | ||
node.source = this.parseMaybeAssign(); // Verify ending. | ||
// Verify ending. | ||
if (!this.eat(_tokentype.types.parenR)) { | ||
const errorPos = this.start; | ||
if (this.eat(_tokentype.types.comma) && this.eat(_tokentype.types.parenR)) { | ||
@@ -620,6 +557,4 @@ this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()"); | ||
} | ||
return this.finishNode(node, "ImportExpression"); | ||
}; | ||
pp.parseImportMeta = function (node) { | ||
@@ -635,3 +570,2 @@ this.next(); // skip `.` | ||
}; | ||
pp.parseLiteral = function (value) { | ||
@@ -645,3 +579,2 @@ let node = this.startNode(); | ||
}; | ||
pp.parseParenExpression = function () { | ||
@@ -653,26 +586,23 @@ this.expect(_tokentype.types.parenL); | ||
}; | ||
pp.parseParenAndDistinguishExpression = function (canBeArrow, forInit) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc, | ||
val, | ||
allowTrailingComma = this.options.ecmaVersion >= 8; | ||
startLoc = this.startLoc, | ||
val, | ||
allowTrailingComma = this.options.ecmaVersion >= 8; | ||
if (this.options.ecmaVersion >= 6) { | ||
this.next(); | ||
let innerStartPos = this.start, | ||
innerStartLoc = this.startLoc; | ||
innerStartLoc = this.startLoc; | ||
let exprList = [], | ||
first = true, | ||
lastIsComma = false; | ||
first = true, | ||
lastIsComma = false; | ||
let refDestructuringErrors = new _parseutil.DestructuringErrors(), | ||
oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
spreadStart; | ||
oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
spreadStart; | ||
this.yieldPos = 0; | ||
this.awaitPos = 0; // Do not save awaitIdentPos to allow checking awaits nested in parameters | ||
this.awaitPos = 0; | ||
// Do not save awaitIdentPos to allow checking awaits nested in parameters | ||
while (this.type !== _tokentype.types.parenR) { | ||
first ? first = false : this.expect(_tokentype.types.comma); | ||
if (allowTrailingComma && this.afterTrailingComma(_tokentype.types.parenR, true)) { | ||
@@ -690,7 +620,5 @@ lastIsComma = true; | ||
} | ||
let innerEndPos = this.lastTokEnd, | ||
innerEndLoc = this.lastTokEndLoc; | ||
innerEndLoc = this.lastTokEndLoc; | ||
this.expect(_tokentype.types.parenR); | ||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) { | ||
@@ -703,3 +631,2 @@ this.checkPatternErrors(refDestructuringErrors, false); | ||
} | ||
if (!exprList.length || lastIsComma) this.unexpected(this.lastTokStart); | ||
@@ -710,3 +637,2 @@ if (spreadStart) this.unexpected(spreadStart); | ||
this.awaitPos = oldAwaitPos || this.awaitPos; | ||
if (exprList.length > 1) { | ||
@@ -722,3 +648,2 @@ val = this.startNodeAt(innerStartPos, innerStartLoc); | ||
} | ||
if (this.options.preserveParens) { | ||
@@ -732,10 +657,10 @@ let par = this.startNodeAt(startPos, startLoc); | ||
}; | ||
pp.parseParenItem = function (item) { | ||
return item; | ||
}; | ||
pp.parseParenArrowList = function (startPos, startLoc, exprList, forInit) { | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false, forInit); | ||
}; // New's precedence is slightly tricky. It must allow its argument to | ||
}; | ||
// New's precedence is slightly tricky. It must allow its argument to | ||
// be a `[]` or dot subscript expression, but not a call — at least, | ||
@@ -746,5 +671,3 @@ // not without wrapping it in parentheses. Thus, it uses the noCalls | ||
const empty = []; | ||
pp.parseNew = function () { | ||
@@ -754,3 +677,2 @@ if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword new"); | ||
let meta = this.parseIdent(true); | ||
if (this.options.ecmaVersion >= 6 && this.eat(_tokentype.types.dot)) { | ||
@@ -765,16 +687,14 @@ node.meta = meta; | ||
} | ||
let startPos = this.start, | ||
startLoc = this.startLoc, | ||
isImport = this.type === _tokentype.types._import; | ||
startLoc = this.startLoc, | ||
isImport = this.type === _tokentype.types._import; | ||
node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true, false); | ||
if (isImport && node.callee.type === "ImportExpression") { | ||
this.raise(startPos, "Cannot use new with import()"); | ||
} | ||
if (this.eat(_tokentype.types.parenL)) node.arguments = this.parseExprList(_tokentype.types.parenR, this.options.ecmaVersion >= 8, false);else node.arguments = empty; | ||
return this.finishNode(node, "NewExpression"); | ||
}; // Parse template expression. | ||
}; | ||
// Parse template expression. | ||
@@ -785,3 +705,2 @@ pp.parseTemplateElement = function ({ | ||
let elem = this.startNode(); | ||
if (this.type === _tokentype.types.invalidTemplate) { | ||
@@ -791,3 +710,2 @@ if (!isTagged) { | ||
} | ||
elem.value = { | ||
@@ -803,3 +721,2 @@ raw: this.value, | ||
} | ||
this.next(); | ||
@@ -809,3 +726,2 @@ elem.tail = this.type === _tokentype.types.backQuote; | ||
}; | ||
pp.parseTemplate = function ({ | ||
@@ -821,3 +737,2 @@ isTagged = false | ||
node.quasis = [curElt]; | ||
while (!curElt.tail) { | ||
@@ -832,19 +747,17 @@ if (this.type === _tokentype.types.eof) this.raise(this.pos, "Unterminated template literal"); | ||
} | ||
this.next(); | ||
return this.finishNode(node, "TemplateLiteral"); | ||
}; | ||
pp.isAsyncProp = function (prop) { | ||
return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" && (this.type === _tokentype.types.name || this.type === _tokentype.types.num || this.type === _tokentype.types.string || this.type === _tokentype.types.bracketL || this.type.keyword || this.options.ecmaVersion >= 9 && this.type === _tokentype.types.star) && !_whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); | ||
}; // Parse an object literal or binding pattern. | ||
}; | ||
// Parse an object literal or binding pattern. | ||
pp.parseObj = function (isPattern, refDestructuringErrors) { | ||
let node = this.startNode(), | ||
first = true, | ||
propHash = {}; | ||
first = true, | ||
propHash = {}; | ||
node.properties = []; | ||
this.next(); | ||
while (!this.eat(_tokentype.types.braceR)) { | ||
@@ -855,3 +768,2 @@ if (!first) { | ||
} else first = false; | ||
const prop = this.parseProperty(isPattern, refDestructuringErrors); | ||
@@ -861,25 +773,19 @@ if (!isPattern) this.checkPropClash(prop, propHash, refDestructuringErrors); | ||
} | ||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); | ||
}; | ||
pp.parseProperty = function (isPattern, refDestructuringErrors) { | ||
let prop = this.startNode(), | ||
isGenerator, | ||
isAsync, | ||
startPos, | ||
startLoc; | ||
isGenerator, | ||
isAsync, | ||
startPos, | ||
startLoc; | ||
if (this.options.ecmaVersion >= 9 && this.eat(_tokentype.types.ellipsis)) { | ||
if (isPattern) { | ||
prop.argument = this.parseIdent(false); | ||
if (this.type === _tokentype.types.comma) { | ||
this.raise(this.start, "Comma is not permitted after the rest element"); | ||
} | ||
return this.finishNode(prop, "RestElement"); | ||
} // To disallow parenthesized identifier via `this.toAssignable()`. | ||
} | ||
// To disallow parenthesized identifier via `this.toAssignable()`. | ||
if (this.type === _tokentype.types.parenL && refDestructuringErrors) { | ||
@@ -889,23 +795,18 @@ if (refDestructuringErrors.parenthesizedAssign < 0) { | ||
} | ||
if (refDestructuringErrors.parenthesizedBind < 0) { | ||
refDestructuringErrors.parenthesizedBind = this.start; | ||
} | ||
} // Parse argument. | ||
prop.argument = this.parseMaybeAssign(false, refDestructuringErrors); // To disallow trailing comma via `this.toAssignable()`. | ||
} | ||
// Parse argument. | ||
prop.argument = this.parseMaybeAssign(false, refDestructuringErrors); | ||
// To disallow trailing comma via `this.toAssignable()`. | ||
if (this.type === _tokentype.types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) { | ||
refDestructuringErrors.trailingComma = this.start; | ||
} // Finish | ||
} | ||
// Finish | ||
return this.finishNode(prop, "SpreadElement"); | ||
} | ||
if (this.options.ecmaVersion >= 6) { | ||
prop.method = false; | ||
prop.shorthand = false; | ||
if (isPattern || refDestructuringErrors) { | ||
@@ -915,9 +816,6 @@ startPos = this.start; | ||
} | ||
if (!isPattern) isGenerator = this.eat(_tokentype.types.star); | ||
} | ||
let containsEsc = this.containsEsc; | ||
this.parsePropertyName(prop); | ||
if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) { | ||
@@ -930,10 +828,7 @@ isAsync = true; | ||
} | ||
this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc); | ||
return this.finishNode(prop, "Property"); | ||
}; | ||
pp.parsePropertyValue = function (prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { | ||
if ((isGenerator || isAsync) && this.type === _tokentype.types.colon) this.unexpected(); | ||
if (this.eat(_tokentype.types.colon)) { | ||
@@ -953,3 +848,2 @@ prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors); | ||
let paramCount = prop.kind === "get" ? 0 : 1; | ||
if (prop.value.params.length !== paramCount) { | ||
@@ -966,3 +860,2 @@ let start = prop.value.start; | ||
prop.kind = "init"; | ||
if (isPattern) { | ||
@@ -976,7 +869,5 @@ prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key)); | ||
} | ||
prop.shorthand = true; | ||
} else this.unexpected(); | ||
}; | ||
pp.parsePropertyName = function (prop) { | ||
@@ -993,6 +884,6 @@ if (this.options.ecmaVersion >= 6) { | ||
} | ||
return prop.key = this.type === _tokentype.types.num || this.type === _tokentype.types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never"); | ||
}; // Initialize empty function node. | ||
}; | ||
// Initialize empty function node. | ||
@@ -1003,10 +894,11 @@ pp.initFunction = function (node) { | ||
if (this.options.ecmaVersion >= 8) node.async = false; | ||
}; // Parse object or class method. | ||
}; | ||
// Parse object or class method. | ||
pp.parseMethod = function (isGenerator, isAsync, allowDirectSuper) { | ||
let node = this.startNode(), | ||
oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
this.initFunction(node); | ||
@@ -1027,9 +919,10 @@ if (this.options.ecmaVersion >= 6) node.generator = isGenerator; | ||
return this.finishNode(node, "FunctionExpression"); | ||
}; // Parse arrow function expression with given parameters. | ||
}; | ||
// Parse arrow function expression with given parameters. | ||
pp.parseArrowExpression = function (node, params, isAsync, forInit) { | ||
let oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
this.enterScope((0, _scopeflags.functionFlags)(isAsync, false) | _scopeflags.SCOPE_ARROW); | ||
@@ -1047,4 +940,5 @@ this.initFunction(node); | ||
return this.finishNode(node, "ArrowFunctionExpression"); | ||
}; // Parse function body and check parameters. | ||
}; | ||
// Parse function body and check parameters. | ||
@@ -1054,4 +948,3 @@ pp.parseFunctionBody = function (node, isArrowFunction, isMethod, forInit) { | ||
let oldStrict = this.strict, | ||
useStrict = false; | ||
useStrict = false; | ||
if (isExpression) { | ||
@@ -1063,20 +956,19 @@ node.body = this.parseMaybeAssign(forInit); | ||
let nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params); | ||
if (!oldStrict || nonSimple) { | ||
useStrict = this.strictDirective(this.end); // If this is a strict mode function, verify that argument names | ||
useStrict = this.strictDirective(this.end); | ||
// If this is a strict mode function, verify that argument names | ||
// are not repeated, and it does not try to bind the words `eval` | ||
// or `arguments`. | ||
if (useStrict && nonSimple) this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); | ||
} // Start a new scope with regard to labels and the `inFunction` | ||
} | ||
// Start a new scope with regard to labels and the `inFunction` | ||
// flag (restore them to their old value afterwards). | ||
let oldLabels = this.labels; | ||
this.labels = []; | ||
if (useStrict) this.strict = true; // Add the params to varDeclaredNames to ensure that an error is thrown | ||
if (useStrict) this.strict = true; | ||
// Add the params to varDeclaredNames to ensure that an error is thrown | ||
// if a let/const declaration in the function clashes with one of the params. | ||
this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params)); // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval' | ||
this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params)); | ||
// Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval' | ||
if (this.strict && node.id) this.checkLValSimple(node.id, _scopeflags.BIND_OUTSIDE); | ||
@@ -1088,6 +980,4 @@ node.body = this.parseBlock(false, undefined, useStrict && !oldStrict); | ||
} | ||
this.exitScope(); | ||
}; | ||
pp.isSimpleParamList = function (params) { | ||
@@ -1098,11 +988,10 @@ for (var _iterator = _createForOfIteratorHelperLoose(params), _step; !(_step = _iterator()).done;) { | ||
} | ||
return true; | ||
}; | ||
return true; | ||
}; // Checks function params for various disallowed patterns such as using "eval" | ||
// Checks function params for various disallowed patterns such as using "eval" | ||
// or "arguments" and duplicate parameters. | ||
pp.checkParams = function (node, allowDuplicates) { | ||
let nameHash = Object.create(null); | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(node.params), _step2; !(_step2 = _iterator2()).done;) { | ||
@@ -1112,3 +1001,5 @@ let param = _step2.value; | ||
} | ||
}; // Parses a comma-separated list of expressions, and returns them as | ||
}; | ||
// Parses a comma-separated list of expressions, and returns them as | ||
// an array. `close` is the token type that ends the list, and | ||
@@ -1119,7 +1010,5 @@ // `allowEmpty` can be turned on to allow subsequent commas with | ||
pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refDestructuringErrors) { | ||
let elts = [], | ||
first = true; | ||
first = true; | ||
while (!this.eat(close)) { | ||
@@ -1130,3 +1019,2 @@ if (!first) { | ||
} else first = false; | ||
let elt; | ||
@@ -1141,6 +1029,4 @@ if (allowEmpty && this.type === _tokentype.types.comma) elt = null;else if (this.type === _tokentype.types.ellipsis) { | ||
} | ||
return elts; | ||
}; | ||
pp.checkUnreserved = function ({ | ||
@@ -1158,3 +1044,2 @@ start, | ||
const re = this.strict ? this.reservedWordsStrict : this.reservedWords; | ||
if (re.test(name)) { | ||
@@ -1164,18 +1049,19 @@ if (!this.inAsync && name === "await") this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); | ||
} | ||
}; // Parse the next token as an identifier. If `liberal` is true (used | ||
}; | ||
// Parse the next token as an identifier. If `liberal` is true (used | ||
// when parsing properties), it will also convert keywords into | ||
// identifiers. | ||
pp.parseIdent = function (liberal, isBinding) { | ||
let node = this.startNode(); | ||
if (this.type === _tokentype.types.name) { | ||
node.name = this.value; | ||
} else if (this.type.keyword) { | ||
node.name = this.type.keyword; // To fix https://github.com/acornjs/acorn/issues/575 | ||
node.name = this.type.keyword; | ||
// To fix https://github.com/acornjs/acorn/issues/575 | ||
// `class` and `function` keywords push new context into this.context. | ||
// But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name. | ||
// If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword | ||
if ((node.name === "class" || node.name === "function") && (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) { | ||
@@ -1187,6 +1073,4 @@ this.context.pop(); | ||
} | ||
this.next(!!liberal); | ||
this.finishNode(node, "Identifier"); | ||
if (!liberal) { | ||
@@ -1196,9 +1080,6 @@ this.checkUnreserved(node); | ||
} | ||
return node; | ||
}; | ||
pp.parsePrivateIdent = function () { | ||
const node = this.startNode(); | ||
if (this.type === _tokentype.types.privateId) { | ||
@@ -1209,6 +1090,6 @@ node.name = this.value; | ||
} | ||
this.next(); | ||
this.finishNode(node, "PrivateIdentifier"); // For validating existence | ||
this.finishNode(node, "PrivateIdentifier"); | ||
// For validating existence | ||
if (this.privateNameStack.length === 0) { | ||
@@ -1219,6 +1100,6 @@ this.raise(node.start, `Private field '#${node.name}' must be declared in an enclosing class`); | ||
} | ||
return node; | ||
}; // Parses yield expression inside generator. | ||
}; | ||
// Parses yield expression inside generator. | ||
@@ -1229,3 +1110,2 @@ pp.parseYield = function (forInit) { | ||
this.next(); | ||
if (this.type === _tokentype.types.semi || this.canInsertSemicolon() || this.type !== _tokentype.types.star && !this.type.startsExpr) { | ||
@@ -1238,6 +1118,4 @@ node.delegate = false; | ||
} | ||
return this.finishNode(node, "YieldExpression"); | ||
}; | ||
pp.parseAwait = function (forInit) { | ||
@@ -1244,0 +1122,0 @@ if (!this.awaitPos) this.awaitPos = this.start; |
@@ -8,2 +8,3 @@ "use strict"; | ||
// Reserved word lists for various dialects of the language | ||
const reservedWords = { | ||
@@ -15,4 +16,5 @@ 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile", | ||
strictBind: "eval arguments" | ||
}; // And the keywords | ||
}; | ||
// And the keywords | ||
exports.reservedWords = reservedWords; | ||
@@ -26,3 +28,6 @@ const ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this"; | ||
exports.keywords = keywords; | ||
const keywordRelationalOperator = /^in(stanceof)?$/; // ## Character categories | ||
const keywordRelationalOperator = /^in(stanceof)?$/; | ||
// ## Character categories | ||
// Big ugly regular expressions that match characters in the | ||
@@ -33,3 +38,2 @@ // whitespace, identifier, and identifier-start categories. These | ||
// Generated by `bin/generate-identifier-regex.js`. | ||
exports.keywordRelationalOperator = keywordRelationalOperator; | ||
@@ -40,3 +44,5 @@ let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; | ||
const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); | ||
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; // These are a run-length and offset encoded representation of the | ||
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; | ||
// These are a run-length and offset encoded representation of the | ||
// >0xffff code points that are a valid part of identifiers. The | ||
@@ -46,13 +52,14 @@ // offset starts at 0x10000, and each pair of numbers represents an | ||
// generated by bin/generate-identifier-regex.js | ||
// eslint-disable-next-line comma-spacing | ||
const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 190, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1070, 4050, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 46, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 482, 44, 11, 6, 17, 0, 322, 29, 19, 43, 1269, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4152, 8, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938]; | ||
const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 190, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1070, 4050, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 46, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 482, 44, 11, 6, 17, 0, 322, 29, 19, 43, 1269, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4152, 8, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938]; // eslint-disable-next-line comma-spacing | ||
// eslint-disable-next-line comma-spacing | ||
const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 357, 0, 62, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239]; | ||
const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 357, 0, 62, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239]; // This has a complexity linear to the value of the code. The | ||
// This has a complexity linear to the value of the code. The | ||
// assumption is that looking up astral identifier characters is | ||
// rare. | ||
function isInAstralSet(code, set) { | ||
let pos = 0x10000; | ||
for (let i = 0; i < set.length; i += 2) { | ||
@@ -64,4 +71,5 @@ pos += set[i]; | ||
} | ||
} // Test whether a given character code starts an identifier. | ||
} | ||
// Test whether a given character code starts an identifier. | ||
@@ -76,4 +84,5 @@ function isIdentifierStart(code, astral) { | ||
return isInAstralSet(code, astralIdentifierStartCodes); | ||
} // Test whether a given character is part of an identifier. | ||
} | ||
// Test whether a given character is part of an identifier. | ||
@@ -80,0 +89,0 @@ function isIdentifierChar(code, astral) { |
@@ -8,55 +8,31 @@ "use strict"; | ||
exports.version = void 0; | ||
var _state = require("./state.js"); | ||
exports.Parser = _state.Parser; | ||
require("./parseutil.js"); | ||
require("./statement.js"); | ||
require("./lval.js"); | ||
require("./expression.js"); | ||
require("./location.js"); | ||
require("./scope.js"); | ||
var _options = require("./options.js"); | ||
exports.defaultOptions = _options.defaultOptions; | ||
var _locutil = require("./locutil.js"); | ||
exports.Position = _locutil.Position; | ||
exports.SourceLocation = _locutil.SourceLocation; | ||
exports.getLineInfo = _locutil.getLineInfo; | ||
var _node = require("./node.js"); | ||
exports.Node = _node.Node; | ||
var _tokentype = require("./tokentype.js"); | ||
exports.TokenType = _tokentype.TokenType; | ||
exports.tokTypes = _tokentype.types; | ||
exports.keywordTypes = _tokentype.keywords; | ||
var _tokencontext = require("./tokencontext.js"); | ||
exports.TokContext = _tokencontext.TokContext; | ||
exports.tokContexts = _tokencontext.types; | ||
var _identifier = require("./identifier.js"); | ||
exports.isIdentifierChar = _identifier.isIdentifierChar; | ||
exports.isIdentifierStart = _identifier.isIdentifierStart; | ||
var _tokenize = require("./tokenize.js"); | ||
exports.Token = _tokenize.Token; | ||
var _whitespace = require("./whitespace.js"); | ||
exports.isNewLine = _whitespace.isNewLine; | ||
@@ -66,9 +42,5 @@ exports.lineBreak = _whitespace.lineBreak; | ||
exports.nonASCIIwhitespace = _whitespace.nonASCIIwhitespace; | ||
var utils = _interopRequireWildcard(require("./util")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
// Acorn is a tiny, fast JavaScript parser written in JavaScript. | ||
@@ -89,2 +61,3 @@ // | ||
// [walk]: util/walk.js | ||
const version = "8.7.0"; | ||
@@ -112,3 +85,5 @@ exports.version = version; | ||
nonASCIIwhitespace: _whitespace.nonASCIIwhitespace | ||
}; // The main exported interface (under `self.acorn` when in the | ||
}; | ||
// The main exported interface (under `self.acorn` when in the | ||
// browser) is a `parse` function that takes a code string and | ||
@@ -122,17 +97,21 @@ // returns an abstract syntax tree as specified by [Mozilla parser | ||
return _state.Parser.parse(input, options); | ||
} // This function tries to parse a single expression at a given | ||
} | ||
// This function tries to parse a single expression at a given | ||
// offset in a string. Useful for parsing mixed-language formats | ||
// that embed JavaScript expressions. | ||
function parseExpressionAt(input, pos, options) { | ||
return _state.Parser.parseExpressionAt(input, pos, options); | ||
} // Acorn is organized as a tokenizer and a recursive-descent parser. | ||
} | ||
// Acorn is organized as a tokenizer and a recursive-descent parser. | ||
// The `tokenizer` export provides an interface to the tokenizer. | ||
function tokenizer(input, options) { | ||
return _state.Parser.tokenizer(input, options); | ||
} // ============================================================================= | ||
} | ||
// ============================================================================= | ||
// ============================================================================= | ||
// ===================== TestCafe performance patch ============================ | ||
@@ -142,10 +121,10 @@ // =====================||||||||||||||||||||||||||||============================ | ||
const storedWordsRegexp = utils.wordsRegexp; | ||
const wordsRegexpCache = {}; | ||
utils.wordsRegexp = function (words) { | ||
if (!wordsRegexpCache[words]) wordsRegexpCache[words] = storedWordsRegexp(words); | ||
return wordsRegexpCache[words]; | ||
}; // =====================^^^^^^^^^^^^^^^^^^^^^^^^^^^^============================ | ||
}; | ||
// =====================^^^^^^^^^^^^^^^^^^^^^^^^^^^^============================ | ||
// =====================||||||||||||||||||||||||||||============================ | ||
@@ -152,0 +131,0 @@ // ===================== TestCafe performance patch ============================ |
"use strict"; | ||
var _state = require("./state.js"); | ||
var _locutil = require("./locutil.js"); | ||
const pp = _state.Parser.prototype; | ||
const pp = _state.Parser.prototype; // This function is used to raise exceptions on parse errors. It | ||
// This function is used to raise exceptions on parse errors. It | ||
// takes an offset integer (into the current `input`) to indicate | ||
@@ -22,5 +22,3 @@ // the location of the error, attaches the position to the end | ||
}; | ||
pp.raiseRecoverable = pp.raise; | ||
pp.curPosition = function () { | ||
@@ -27,0 +25,0 @@ if (this.options.locations) { |
@@ -6,7 +6,6 @@ "use strict"; | ||
exports.getLineInfo = getLineInfo; | ||
var _whitespace = require("./whitespace.js"); | ||
// These are used when `options.locations` is on, for the | ||
// `startLoc` and `endLoc` properties. | ||
class Position { | ||
@@ -17,11 +16,7 @@ constructor(line, col) { | ||
} | ||
offset(n) { | ||
return new Position(this.line, this.column + n); | ||
} | ||
} | ||
exports.Position = Position; | ||
class SourceLocation { | ||
@@ -33,4 +28,5 @@ constructor(p, start, end) { | ||
} | ||
} | ||
} // The `getLineInfo` function is mostly useful when the | ||
// The `getLineInfo` function is mostly useful when the | ||
// `locations` option is off (for performance reasons) and you | ||
@@ -40,6 +36,3 @@ // want to find the line/column position for a given character | ||
// into. | ||
exports.SourceLocation = SourceLocation; | ||
function getLineInfo(input, offset) { | ||
@@ -46,0 +39,0 @@ for (let line = 1, cur = 0;;) { |
"use strict"; | ||
var _tokentype = require("./tokentype.js"); | ||
var _state = require("./state.js"); | ||
var _util = require("./util.js"); | ||
var _scopeflags = require("./scopeflags.js"); | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
const pp = _state.Parser.prototype; | ||
const pp = _state.Parser.prototype; // Convert existing expression atom to assignable pattern | ||
// Convert existing expression atom to assignable pattern | ||
// if possible. | ||
@@ -26,3 +21,2 @@ | ||
break; | ||
case "ObjectPattern": | ||
@@ -33,10 +27,9 @@ case "ArrayPattern": | ||
break; | ||
case "ObjectExpression": | ||
node.type = "ObjectPattern"; | ||
if (refDestructuringErrors) this.checkPatternErrors(refDestructuringErrors, true); | ||
for (var _iterator = _createForOfIteratorHelperLoose(node.properties), _step; !(_step = _iterator()).done;) { | ||
let prop = _step.value; | ||
this.toAssignable(prop, isBinding); // Early error: | ||
this.toAssignable(prop, isBinding); | ||
// Early error: | ||
// AssignmentRestProperty[Yield, Await] : | ||
@@ -46,3 +39,2 @@ // `...` DestructuringAssignmentTarget[Yield, Await] | ||
// It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|. | ||
if (prop.type === "RestElement" && (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")) { | ||
@@ -52,5 +44,3 @@ this.raise(prop.argument.start, "Unexpected token"); | ||
} | ||
break; | ||
case "Property": | ||
@@ -61,3 +51,2 @@ // AssignmentProperty has type === "Property" | ||
break; | ||
case "ArrayExpression": | ||
@@ -68,3 +57,2 @@ node.type = "ArrayPattern"; | ||
break; | ||
case "SpreadElement": | ||
@@ -75,3 +63,2 @@ node.type = "RestElement"; | ||
break; | ||
case "AssignmentExpression": | ||
@@ -83,14 +70,10 @@ if (node.operator !== "=") this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); | ||
break; | ||
case "ParenthesizedExpression": | ||
this.toAssignable(node.expression, isBinding, refDestructuringErrors); | ||
break; | ||
case "ChainExpression": | ||
this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side"); | ||
break; | ||
case "MemberExpression": | ||
if (!isBinding) break; | ||
default: | ||
@@ -100,10 +83,9 @@ this.raise(node.start, "Assigning to rvalue"); | ||
} else if (refDestructuringErrors) this.checkPatternErrors(refDestructuringErrors, true); | ||
return node; | ||
}; // Convert list of expression atoms to binding list. | ||
}; | ||
// Convert list of expression atoms to binding list. | ||
pp.toAssignableList = function (exprList, isBinding) { | ||
let end = exprList.length; | ||
for (let i = 0; i < end; i++) { | ||
@@ -113,3 +95,2 @@ let elt = exprList[i]; | ||
} | ||
if (end) { | ||
@@ -119,6 +100,6 @@ let last = exprList[end - 1]; | ||
} | ||
return exprList; | ||
}; // Parses spread element. | ||
}; | ||
// Parses spread element. | ||
@@ -131,12 +112,13 @@ pp.parseSpread = function (refDestructuringErrors) { | ||
}; | ||
pp.parseRestBinding = function () { | ||
let node = this.startNode(); | ||
this.next(); // RestElement inside of a function parameter must be an identifier | ||
this.next(); | ||
// RestElement inside of a function parameter must be an identifier | ||
if (this.options.ecmaVersion === 6 && this.type !== _tokentype.types.name) this.unexpected(); | ||
node.argument = this.parseBindingAtom(); | ||
return this.finishNode(node, "RestElement"); | ||
}; // Parses lvalue (assignable) atom. | ||
}; | ||
// Parses lvalue (assignable) atom. | ||
@@ -151,3 +133,2 @@ pp.parseBindingAtom = function () { | ||
return this.finishNode(node, "ArrayPattern"); | ||
case _tokentype.types.braceL: | ||
@@ -157,13 +138,9 @@ return this.parseObj(true); | ||
} | ||
return this.parseIdent(); | ||
}; | ||
pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) { | ||
let elts = [], | ||
first = true; | ||
first = true; | ||
while (!this.eat(close)) { | ||
if (first) first = false;else this.expect(_tokentype.types.comma); | ||
if (allowEmpty && this.type === _tokentype.types.comma) { | ||
@@ -186,10 +163,9 @@ elts.push(null); | ||
} | ||
return elts; | ||
}; | ||
pp.parseBindingListItem = function (param) { | ||
return param; | ||
}; // Parses assignment pattern around given atom if possible. | ||
}; | ||
// Parses assignment pattern around given atom if possible. | ||
@@ -203,3 +179,5 @@ pp.parseMaybeDefault = function (startPos, startLoc, left) { | ||
return this.finishNode(node, "AssignmentPattern"); | ||
}; // The following three functions all verify that a node is an lvalue — | ||
}; | ||
// The following three functions all verify that a node is an lvalue — | ||
// something that can be bound, or assigned to. In order to do so, they perform | ||
@@ -268,13 +246,9 @@ // a variety of checks: | ||
pp.checkLValSimple = function (expr, bindingType = _scopeflags.BIND_NONE, checkClashes) { | ||
const isBind = bindingType !== _scopeflags.BIND_NONE; | ||
switch (expr.type) { | ||
case "Identifier": | ||
if (this.strict && this.reservedWordsStrictBind.test(expr.name)) this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); | ||
if (isBind) { | ||
if (bindingType === _scopeflags.BIND_LEXICAL && expr.name === "let") this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); | ||
if (checkClashes) { | ||
@@ -284,20 +258,14 @@ if ((0, _util.hasOwn)(checkClashes, expr.name)) this.raiseRecoverable(expr.start, "Argument name clash"); | ||
} | ||
if (bindingType !== _scopeflags.BIND_OUTSIDE) this.declareName(expr.name, bindingType, expr.start); | ||
} | ||
break; | ||
case "ChainExpression": | ||
this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side"); | ||
break; | ||
case "MemberExpression": | ||
if (isBind) this.raiseRecoverable(expr.start, "Binding member expression"); | ||
break; | ||
case "ParenthesizedExpression": | ||
if (isBind) this.raiseRecoverable(expr.start, "Binding parenthesized expression"); | ||
return this.checkLValSimple(expr.expression, bindingType, checkClashes); | ||
default: | ||
@@ -307,3 +275,2 @@ this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue"); | ||
}; | ||
pp.checkLValPattern = function (expr, bindingType = _scopeflags.BIND_NONE, checkClashes) { | ||
@@ -316,5 +283,3 @@ switch (expr.type) { | ||
} | ||
break; | ||
case "ArrayPattern": | ||
@@ -325,5 +290,3 @@ for (var _iterator3 = _createForOfIteratorHelperLoose(expr.elements), _step3; !(_step3 = _iterator3()).done;) { | ||
} | ||
break; | ||
default: | ||
@@ -333,3 +296,2 @@ this.checkLValSimple(expr, bindingType, checkClashes); | ||
}; | ||
pp.checkLValInnerPattern = function (expr, bindingType = _scopeflags.BIND_NONE, checkClashes) { | ||
@@ -341,11 +303,8 @@ switch (expr.type) { | ||
break; | ||
case "AssignmentPattern": | ||
this.checkLValPattern(expr.left, bindingType, checkClashes); | ||
break; | ||
case "RestElement": | ||
this.checkLValPattern(expr.argument, bindingType, checkClashes); | ||
break; | ||
default: | ||
@@ -352,0 +311,0 @@ this.checkLValPattern(expr, bindingType, checkClashes); |
@@ -5,7 +5,4 @@ "use strict"; | ||
exports.Node = void 0; | ||
var _state = require("./state.js"); | ||
var _locutil = require("./locutil.js"); | ||
class Node { | ||
@@ -20,17 +17,15 @@ constructor(parser, pos, loc) { | ||
} | ||
} | ||
} // Start an AST node, attaching a start offset. | ||
// Start an AST node, attaching a start offset. | ||
exports.Node = Node; | ||
const pp = _state.Parser.prototype; | ||
pp.startNode = function () { | ||
return new Node(this, this.start, this.startLoc); | ||
}; | ||
pp.startNodeAt = function (pos, loc) { | ||
return new Node(this, pos, loc); | ||
}; // Finish an AST node, adding `type` and `end` properties. | ||
}; | ||
// Finish an AST node, adding `type` and `end` properties. | ||
@@ -44,7 +39,7 @@ function finishNodeAt(node, type, pos, loc) { | ||
} | ||
pp.finishNode = function (node, type) { | ||
return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc); | ||
}; // Finish node at given position | ||
}; | ||
// Finish node at given position | ||
@@ -54,9 +49,6 @@ pp.finishNodeAt = function (node, type, pos, loc) { | ||
}; | ||
pp.copyNode = function (node) { | ||
let newNode = new Node(this, node.start, this.startLoc); | ||
for (let prop in node) newNode[prop] = node[prop]; | ||
return newNode; | ||
}; |
@@ -6,9 +6,7 @@ "use strict"; | ||
exports.getOptions = getOptions; | ||
var _util = require("./util.js"); | ||
var _locutil = require("./locutil.js"); | ||
// A second argument must be given to configure the parser process. | ||
// These options are recognized (only `ecmaVersion` is required): | ||
const defaultOptions = { | ||
@@ -103,12 +101,10 @@ // `ecmaVersion` indicates the ECMAScript version to parse. Must be | ||
preserveParens: false | ||
}; // Interpret and default an options object | ||
}; | ||
// Interpret and default an options object | ||
exports.defaultOptions = defaultOptions; | ||
let warnedAboutEcmaVersion = false; | ||
function getOptions(opts) { | ||
let options = {}; | ||
for (let opt in defaultOptions) options[opt] = opts && (0, _util.hasOwn)(opts, opt) ? opts[opt] : defaultOptions[opt]; | ||
if (options.ecmaVersion === "latest") { | ||
@@ -121,3 +117,2 @@ options.ecmaVersion = 1e8; | ||
} | ||
options.ecmaVersion = 11; | ||
@@ -127,15 +122,10 @@ } else if (options.ecmaVersion >= 2015) { | ||
} | ||
if (options.allowReserved == null) options.allowReserved = options.ecmaVersion < 5; | ||
if ((0, _util.isArray)(options.onToken)) { | ||
let tokens = options.onToken; | ||
options.onToken = token => tokens.push(token); | ||
} | ||
if ((0, _util.isArray)(options.onComment)) options.onComment = pushComment(options, options.onComment); | ||
return options; | ||
} | ||
function pushComment(options, array) { | ||
@@ -142,0 +132,0 @@ return function (block, text, start, end, startLoc, endLoc) { |
@@ -5,13 +5,10 @@ "use strict"; | ||
exports.DestructuringErrors = DestructuringErrors; | ||
var _tokentype = require("./tokentype.js"); | ||
var _state = require("./state.js"); | ||
var _whitespace = require("./whitespace.js"); | ||
const pp = _state.Parser.prototype; | ||
const pp = _state.Parser.prototype; // ## Parser utilities | ||
// ## Parser utilities | ||
const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/; | ||
pp.strictDirective = function (start) { | ||
@@ -25,4 +22,5 @@ for (;;) { | ||
if ((match[1] || match[2]) === "use strict") return false; | ||
start += match[0].length; // Skip semicolon, if any. | ||
start += match[0].length; | ||
// Skip semicolon, if any. | ||
_whitespace.skipWhiteSpace.lastIndex = start; | ||
@@ -32,6 +30,7 @@ start += _whitespace.skipWhiteSpace.exec(this.input)[0].length; | ||
} | ||
}; // Predicate that tests whether the next token is of the given | ||
}; | ||
// Predicate that tests whether the next token is of the given | ||
// type, and if yes, consumes it as a side effect. | ||
pp.eat = function (type) { | ||
@@ -44,9 +43,11 @@ if (this.type === type) { | ||
} | ||
}; // Tests whether parsed token is a contextual keyword. | ||
}; | ||
// Tests whether parsed token is a contextual keyword. | ||
pp.isContextual = function (name) { | ||
return this.type === _tokentype.types.name && this.value === name && !this.containsEsc; | ||
}; // Consumes contextual keyword if possible. | ||
}; | ||
// Consumes contextual keyword if possible. | ||
@@ -57,9 +58,11 @@ pp.eatContextual = function (name) { | ||
return true; | ||
}; // Asserts that following token is given contextual keyword. | ||
}; | ||
// Asserts that following token is given contextual keyword. | ||
pp.expectContextual = function (name) { | ||
if (!this.eatContextual(name)) this.unexpected(); | ||
}; // Test whether a semicolon can be inserted at the current position. | ||
}; | ||
// Test whether a semicolon can be inserted at the current position. | ||
@@ -69,3 +72,2 @@ pp.canInsertSemicolon = function () { | ||
}; | ||
pp.insertSemicolon = function () { | ||
@@ -76,10 +78,10 @@ if (this.canInsertSemicolon()) { | ||
} | ||
}; // Consume a semicolon, or, failing that, see if we are allowed to | ||
}; | ||
// Consume a semicolon, or, failing that, see if we are allowed to | ||
// pretend that there is a semicolon at this position. | ||
pp.semicolon = function () { | ||
if (!this.eat(_tokentype.types.semi) && !this.insertSemicolon()) this.unexpected(); | ||
}; | ||
pp.afterTrailingComma = function (tokType, notNext) { | ||
@@ -91,10 +93,12 @@ if (this.type === tokType) { | ||
} | ||
}; // Expect a token of a given type. If found, consume it, otherwise, | ||
}; | ||
// Expect a token of a given type. If found, consume it, otherwise, | ||
// raise an unexpected token error. | ||
pp.expect = function (type) { | ||
this.eat(type) || this.unexpected(); | ||
}; // Raise an unexpected token error. | ||
}; | ||
// Raise an unexpected token error. | ||
@@ -104,7 +108,5 @@ pp.unexpected = function (pos) { | ||
}; | ||
function DestructuringErrors() { | ||
this.shorthandAssign = this.trailingComma = this.parenthesizedAssign = this.parenthesizedBind = this.doubleProto = -1; | ||
} | ||
pp.checkPatternErrors = function (refDestructuringErrors, isAssign) { | ||
@@ -116,7 +118,6 @@ if (!refDestructuringErrors) return; | ||
}; | ||
pp.checkExpressionErrors = function (refDestructuringErrors, andThrow) { | ||
if (!refDestructuringErrors) return false; | ||
let shorthandAssign = refDestructuringErrors.shorthandAssign, | ||
doubleProto = refDestructuringErrors.doubleProto; | ||
doubleProto = refDestructuringErrors.doubleProto; | ||
if (!andThrow) return shorthandAssign >= 0 || doubleProto >= 0; | ||
@@ -126,3 +127,2 @@ if (shorthandAssign >= 0) this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); | ||
}; | ||
pp.checkYieldAwaitInDefaultParams = function () { | ||
@@ -132,3 +132,2 @@ if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos)) this.raise(this.yieldPos, "Yield expression cannot be a default value"); | ||
}; | ||
pp.isSimpleAssignTarget = function (expr) { | ||
@@ -135,0 +134,0 @@ if (expr.type === "ParenthesizedExpression") return this.isSimpleAssignTarget(expr.expression); |
@@ -5,21 +5,11 @@ "use strict"; | ||
exports.RegExpValidationState = void 0; | ||
var _identifier = require("./identifier.js"); | ||
var _state = require("./state.js"); | ||
var _unicodePropertyData = _interopRequireDefault(require("./unicode-property-data.js")); | ||
var _util = require("./util.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
const pp = _state.Parser.prototype; | ||
class RegExpValidationState { | ||
@@ -44,3 +34,2 @@ constructor(parser) { | ||
} | ||
reset(start, pattern, flags) { | ||
@@ -54,57 +43,43 @@ const unicode = flags.indexOf("u") !== -1; | ||
} | ||
raise(message) { | ||
this.parser.raiseRecoverable(this.start, `Invalid regular expression: /${this.source}/: ${message}`); | ||
} // If u flag is given, this returns the code point at the index (it combines a surrogate pair). | ||
} | ||
// If u flag is given, this returns the code point at the index (it combines a surrogate pair). | ||
// Otherwise, this returns the code unit of the index (can be a part of a surrogate pair). | ||
at(i, forceU = false) { | ||
const s = this.source; | ||
const l = s.length; | ||
if (i >= l) { | ||
return -1; | ||
} | ||
const c = s.charCodeAt(i); | ||
if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { | ||
return c; | ||
} | ||
const next = s.charCodeAt(i + 1); | ||
return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c; | ||
} | ||
nextIndex(i, forceU = false) { | ||
const s = this.source; | ||
const l = s.length; | ||
if (i >= l) { | ||
return l; | ||
} | ||
let c = s.charCodeAt(i), | ||
next; | ||
next; | ||
if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l || (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) { | ||
return i + 1; | ||
} | ||
return i + 2; | ||
} | ||
current(forceU = false) { | ||
return this.at(this.pos, forceU); | ||
} | ||
lookahead(forceU = false) { | ||
return this.at(this.nextIndex(this.pos, forceU), forceU); | ||
} | ||
advance(forceU = false) { | ||
this.pos = this.nextIndex(this.pos, forceU); | ||
} | ||
eat(ch, forceU = false) { | ||
@@ -115,10 +90,6 @@ if (this.current(forceU) === ch) { | ||
} | ||
return false; | ||
} | ||
} | ||
exports.RegExpValidationState = RegExpValidationState; | ||
function codePointToString(ch) { | ||
@@ -129,2 +100,3 @@ if (ch <= 0xFFFF) return String.fromCharCode(ch); | ||
} | ||
/** | ||
@@ -136,15 +108,10 @@ * Validate the flags part of a given RegExpLiteral. | ||
*/ | ||
pp.validateRegExpFlags = function (state) { | ||
const validFlags = state.validFlags; | ||
const flags = state.flags; | ||
for (let i = 0; i < flags.length; i++) { | ||
const flag = flags.charAt(i); | ||
if (validFlags.indexOf(flag) === -1) { | ||
this.raise(state.start, "Invalid regular expression flag"); | ||
} | ||
if (flags.indexOf(flag, i + 1) > -1) { | ||
@@ -155,2 +122,3 @@ this.raise(state.start, "Duplicate regular expression flag"); | ||
}; | ||
/** | ||
@@ -162,6 +130,6 @@ * Validate the pattern part of a given RegExpLiteral. | ||
*/ | ||
pp.validateRegExpPattern = function (state) { | ||
this.regexp_pattern(state); | ||
pp.validateRegExpPattern = function (state) { | ||
this.regexp_pattern(state); // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of | ||
// The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of | ||
// parsing contains a |GroupName|, reparse with the goal symbol | ||
@@ -171,3 +139,2 @@ // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError* | ||
// were not matched by the parse, or if any Early Error conditions exist. | ||
if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) { | ||
@@ -177,5 +144,5 @@ state.switchN = true; | ||
} | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern | ||
pp.regexp_pattern = function (state) { | ||
@@ -191,27 +158,16 @@ state.pos = 0; | ||
this.regexp_disjunction(state); | ||
if (state.pos !== state.source.length) { | ||
// Make the same messages as V8. | ||
if (state.eat(0x29 | ||
/* ) */ | ||
)) { | ||
if (state.eat(0x29 /* ) */)) { | ||
state.raise("Unmatched ')'"); | ||
} | ||
if (state.eat(0x5D | ||
/* ] */ | ||
) || state.eat(0x7D | ||
/* } */ | ||
)) { | ||
if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) { | ||
state.raise("Lone quantifier brackets"); | ||
} | ||
} | ||
if (state.maxBackReference > state.numCapturingParens) { | ||
state.raise("Invalid escape"); | ||
} | ||
for (var _iterator = _createForOfIteratorHelperLoose(state.backReferenceNames), _step; !(_step = _iterator()).done;) { | ||
const name = _step.value; | ||
if (state.groupNames.indexOf(name) === -1) { | ||
@@ -221,32 +177,26 @@ state.raise("Invalid named capture referenced"); | ||
} | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction | ||
pp.regexp_disjunction = function (state) { | ||
this.regexp_alternative(state); | ||
while (state.eat(0x7C | ||
/* | */ | ||
)) { | ||
while (state.eat(0x7C /* | */)) { | ||
this.regexp_alternative(state); | ||
} // Make the same message as V8. | ||
} | ||
// Make the same message as V8. | ||
if (this.regexp_eatQuantifier(state, true)) { | ||
state.raise("Nothing to repeat"); | ||
} | ||
if (state.eat(0x7B | ||
/* { */ | ||
)) { | ||
if (state.eat(0x7B /* { */)) { | ||
state.raise("Lone quantifier brackets"); | ||
} | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative | ||
pp.regexp_alternative = function (state) { | ||
while (state.pos < state.source.length && this.regexp_eatTerm(state)); | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term | ||
pp.regexp_eatTerm = function (state) { | ||
@@ -263,6 +213,4 @@ if (this.regexp_eatAssertion(state)) { | ||
} | ||
return true; | ||
} | ||
if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) { | ||
@@ -272,61 +220,35 @@ this.regexp_eatQuantifier(state); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion | ||
pp.regexp_eatAssertion = function (state) { | ||
const start = state.pos; | ||
state.lastAssertionIsQuantifiable = false; // ^, $ | ||
state.lastAssertionIsQuantifiable = false; | ||
if (state.eat(0x5E | ||
/* ^ */ | ||
) || state.eat(0x24 | ||
/* $ */ | ||
)) { | ||
// ^, $ | ||
if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) { | ||
return true; | ||
} // \b \B | ||
} | ||
if (state.eat(0x5C | ||
/* \ */ | ||
)) { | ||
if (state.eat(0x42 | ||
/* B */ | ||
) || state.eat(0x62 | ||
/* b */ | ||
)) { | ||
// \b \B | ||
if (state.eat(0x5C /* \ */)) { | ||
if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) { | ||
return true; | ||
} | ||
state.pos = start; | ||
} // Lookahead / Lookbehind | ||
} | ||
if (state.eat(0x28 | ||
/* ( */ | ||
) && state.eat(0x3F | ||
/* ? */ | ||
)) { | ||
// Lookahead / Lookbehind | ||
if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) { | ||
let lookbehind = false; | ||
if (this.options.ecmaVersion >= 9) { | ||
lookbehind = state.eat(0x3C | ||
/* < */ | ||
); | ||
lookbehind = state.eat(0x3C /* < */); | ||
} | ||
if (state.eat(0x3D | ||
/* = */ | ||
) || state.eat(0x21 | ||
/* ! */ | ||
)) { | ||
if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) { | ||
this.regexp_disjunction(state); | ||
if (!state.eat(0x29 | ||
/* ) */ | ||
)) { | ||
if (!state.eat(0x29 /* ) */)) { | ||
state.raise("Unterminated group"); | ||
} | ||
state.lastAssertionIsQuantifiable = !lookbehind; | ||
@@ -336,51 +258,30 @@ return true; | ||
} | ||
state.pos = start; | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier | ||
pp.regexp_eatQuantifier = function (state, noError = false) { | ||
if (this.regexp_eatQuantifierPrefix(state, noError)) { | ||
state.eat(0x3F | ||
/* ? */ | ||
); | ||
state.eat(0x3F /* ? */); | ||
return true; | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix | ||
pp.regexp_eatQuantifierPrefix = function (state, noError) { | ||
return state.eat(0x2A | ||
/* * */ | ||
) || state.eat(0x2B | ||
/* + */ | ||
) || state.eat(0x3F | ||
/* ? */ | ||
) || this.regexp_eatBracedQuantifier(state, noError); | ||
return state.eat(0x2A /* * */) || state.eat(0x2B /* + */) || state.eat(0x3F /* ? */) || this.regexp_eatBracedQuantifier(state, noError); | ||
}; | ||
pp.regexp_eatBracedQuantifier = function (state, noError) { | ||
const start = state.pos; | ||
if (state.eat(0x7B | ||
/* { */ | ||
)) { | ||
if (state.eat(0x7B /* { */)) { | ||
let min = 0, | ||
max = -1; | ||
max = -1; | ||
if (this.regexp_eatDecimalDigits(state)) { | ||
min = state.lastIntValue; | ||
if (state.eat(0x2C | ||
/* , */ | ||
) && this.regexp_eatDecimalDigits(state)) { | ||
if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) { | ||
max = state.lastIntValue; | ||
} | ||
if (state.eat(0x7D | ||
/* } */ | ||
)) { | ||
if (state.eat(0x7D /* } */)) { | ||
// SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term | ||
@@ -390,103 +291,64 @@ if (max !== -1 && max < min && !noError) { | ||
} | ||
return true; | ||
} | ||
} | ||
if (state.switchU && !noError) { | ||
state.raise("Incomplete quantifier"); | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Atom | ||
pp.regexp_eatAtom = function (state) { | ||
return this.regexp_eatPatternCharacters(state) || state.eat(0x2E | ||
/* . */ | ||
) || this.regexp_eatReverseSolidusAtomEscape(state) || this.regexp_eatCharacterClass(state) || this.regexp_eatUncapturingGroup(state) || this.regexp_eatCapturingGroup(state); | ||
return this.regexp_eatPatternCharacters(state) || state.eat(0x2E /* . */) || this.regexp_eatReverseSolidusAtomEscape(state) || this.regexp_eatCharacterClass(state) || this.regexp_eatUncapturingGroup(state) || this.regexp_eatCapturingGroup(state); | ||
}; | ||
pp.regexp_eatReverseSolidusAtomEscape = function (state) { | ||
const start = state.pos; | ||
if (state.eat(0x5C | ||
/* \ */ | ||
)) { | ||
if (state.eat(0x5C /* \ */)) { | ||
if (this.regexp_eatAtomEscape(state)) { | ||
return true; | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; | ||
pp.regexp_eatUncapturingGroup = function (state) { | ||
const start = state.pos; | ||
if (state.eat(0x28 | ||
/* ( */ | ||
)) { | ||
if (state.eat(0x3F | ||
/* ? */ | ||
) && state.eat(0x3A | ||
/* : */ | ||
)) { | ||
if (state.eat(0x28 /* ( */)) { | ||
if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) { | ||
this.regexp_disjunction(state); | ||
if (state.eat(0x29 | ||
/* ) */ | ||
)) { | ||
if (state.eat(0x29 /* ) */)) { | ||
return true; | ||
} | ||
state.raise("Unterminated group"); | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; | ||
pp.regexp_eatCapturingGroup = function (state) { | ||
if (state.eat(0x28 | ||
/* ( */ | ||
)) { | ||
if (state.eat(0x28 /* ( */)) { | ||
if (this.options.ecmaVersion >= 9) { | ||
this.regexp_groupSpecifier(state); | ||
} else if (state.current() === 0x3F | ||
/* ? */ | ||
) { | ||
} else if (state.current() === 0x3F /* ? */) { | ||
state.raise("Invalid group"); | ||
} | ||
this.regexp_disjunction(state); | ||
if (state.eat(0x29 | ||
/* ) */ | ||
)) { | ||
if (state.eat(0x29 /* ) */)) { | ||
state.numCapturingParens += 1; | ||
return true; | ||
} | ||
state.raise("Unterminated group"); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom | ||
pp.regexp_eatExtendedAtom = function (state) { | ||
return state.eat(0x2E | ||
/* . */ | ||
) || this.regexp_eatReverseSolidusAtomEscape(state) || this.regexp_eatCharacterClass(state) || this.regexp_eatUncapturingGroup(state) || this.regexp_eatCapturingGroup(state) || this.regexp_eatInvalidBracedQuantifier(state) || this.regexp_eatExtendedPatternCharacter(state); | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier | ||
return state.eat(0x2E /* . */) || this.regexp_eatReverseSolidusAtomEscape(state) || this.regexp_eatCharacterClass(state) || this.regexp_eatUncapturingGroup(state) || this.regexp_eatCapturingGroup(state) || this.regexp_eatInvalidBracedQuantifier(state) || this.regexp_eatExtendedPatternCharacter(state); | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier | ||
pp.regexp_eatInvalidBracedQuantifier = function (state) { | ||
@@ -496,10 +358,8 @@ if (this.regexp_eatBracedQuantifier(state, true)) { | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter | ||
pp.regexp_eatSyntaxCharacter = function (state) { | ||
const ch = state.current(); | ||
if (isSyntaxCharacter(ch)) { | ||
@@ -510,76 +370,34 @@ state.lastIntValue = ch; | ||
} | ||
return false; | ||
}; | ||
function isSyntaxCharacter(ch) { | ||
return ch === 0x24 /* $ */ || ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ || ch === 0x2E /* . */ || ch === 0x3F /* ? */ || ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ || ch >= 0x7B /* { */ && ch <= 0x7D /* } */; | ||
} | ||
function isSyntaxCharacter(ch) { | ||
return ch === 0x24 | ||
/* $ */ | ||
|| ch >= 0x28 | ||
/* ( */ | ||
&& ch <= 0x2B | ||
/* + */ | ||
|| ch === 0x2E | ||
/* . */ | ||
|| ch === 0x3F | ||
/* ? */ | ||
|| ch >= 0x5B | ||
/* [ */ | ||
&& ch <= 0x5E | ||
/* ^ */ | ||
|| ch >= 0x7B | ||
/* { */ | ||
&& ch <= 0x7D | ||
/* } */ | ||
; | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter | ||
// But eat eager. | ||
pp.regexp_eatPatternCharacters = function (state) { | ||
const start = state.pos; | ||
let ch = 0; | ||
while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) { | ||
state.advance(); | ||
} | ||
return state.pos !== start; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter | ||
pp.regexp_eatExtendedPatternCharacter = function (state) { | ||
const ch = state.current(); | ||
if (ch !== -1 && ch !== 0x24 | ||
/* $ */ | ||
&& !(ch >= 0x28 | ||
/* ( */ | ||
&& ch <= 0x2B | ||
/* + */ | ||
) && ch !== 0x2E | ||
/* . */ | ||
&& ch !== 0x3F | ||
/* ? */ | ||
&& ch !== 0x5B | ||
/* [ */ | ||
&& ch !== 0x5E | ||
/* ^ */ | ||
&& ch !== 0x7C | ||
/* | */ | ||
) { | ||
if (ch !== -1 && ch !== 0x24 /* $ */ && !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) && ch !== 0x2E /* . */ && ch !== 0x3F /* ? */ && ch !== 0x5B /* [ */ && ch !== 0x5E /* ^ */ && ch !== 0x7C /* | */) { | ||
state.advance(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; // GroupSpecifier :: | ||
// GroupSpecifier :: | ||
// [empty] | ||
// `?` GroupName | ||
pp.regexp_groupSpecifier = function (state) { | ||
if (state.eat(0x3F | ||
/* ? */ | ||
)) { | ||
if (state.eat(0x3F /* ? */)) { | ||
if (this.regexp_eatGroupName(state)) { | ||
@@ -589,51 +407,40 @@ if (state.groupNames.indexOf(state.lastStringValue) !== -1) { | ||
} | ||
state.groupNames.push(state.lastStringValue); | ||
return; | ||
} | ||
state.raise("Invalid group"); | ||
} | ||
}; // GroupName :: | ||
}; | ||
// GroupName :: | ||
// `<` RegExpIdentifierName `>` | ||
// Note: this updates `state.lastStringValue` property with the eaten name. | ||
pp.regexp_eatGroupName = function (state) { | ||
state.lastStringValue = ""; | ||
if (state.eat(0x3C | ||
/* < */ | ||
)) { | ||
if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E | ||
/* > */ | ||
)) { | ||
if (state.eat(0x3C /* < */)) { | ||
if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) { | ||
return true; | ||
} | ||
state.raise("Invalid capture group name"); | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; // RegExpIdentifierName :: | ||
// RegExpIdentifierName :: | ||
// RegExpIdentifierStart | ||
// RegExpIdentifierName RegExpIdentifierPart | ||
// Note: this updates `state.lastStringValue` property with the eaten name. | ||
pp.regexp_eatRegExpIdentifierName = function (state) { | ||
state.lastStringValue = ""; | ||
if (this.regexp_eatRegExpIdentifierStart(state)) { | ||
state.lastStringValue += codePointToString(state.lastIntValue); | ||
while (this.regexp_eatRegExpIdentifierPart(state)) { | ||
state.lastStringValue += codePointToString(state.lastIntValue); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; // RegExpIdentifierStart :: | ||
// RegExpIdentifierStart :: | ||
// UnicodeIDStart | ||
@@ -643,4 +450,2 @@ // `$` | ||
// `\` RegExpUnicodeEscapeSequence[+U] | ||
pp.regexp_eatRegExpIdentifierStart = function (state) { | ||
@@ -651,9 +456,5 @@ const start = state.pos; | ||
state.advance(forceU); | ||
if (ch === 0x5C | ||
/* \ */ | ||
&& this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
ch = state.lastIntValue; | ||
} | ||
if (isRegExpIdentifierStart(ch)) { | ||
@@ -663,13 +464,10 @@ state.lastIntValue = ch; | ||
} | ||
state.pos = start; | ||
return false; | ||
}; | ||
function isRegExpIdentifierStart(ch) { | ||
return (0, _identifier.isIdentifierStart)(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F; /* _ */ | ||
} | ||
function isRegExpIdentifierStart(ch) { | ||
return (0, _identifier.isIdentifierStart)(ch, true) || ch === 0x24 | ||
/* $ */ | ||
|| ch === 0x5F; | ||
/* _ */ | ||
} // RegExpIdentifierPart :: | ||
// RegExpIdentifierPart :: | ||
// UnicodeIDContinue | ||
@@ -681,4 +479,2 @@ // `$` | ||
// <ZWJ> | ||
pp.regexp_eatRegExpIdentifierPart = function (state) { | ||
@@ -689,9 +485,5 @@ const start = state.pos; | ||
state.advance(forceU); | ||
if (ch === 0x5C | ||
/* \ */ | ||
&& this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
ch = state.lastIntValue; | ||
} | ||
if (isRegExpIdentifierPart(ch)) { | ||
@@ -701,19 +493,10 @@ state.lastIntValue = ch; | ||
} | ||
state.pos = start; | ||
return false; | ||
}; | ||
function isRegExpIdentifierPart(ch) { | ||
return (0, _identifier.isIdentifierChar)(ch, true) || ch === 0x24 | ||
/* $ */ | ||
|| ch === 0x5F | ||
/* _ */ | ||
|| ch === 0x200C | ||
/* <ZWNJ> */ | ||
|| ch === 0x200D; | ||
/* <ZWJ> */ | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape | ||
return (0, _identifier.isIdentifierChar)(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D; /* <ZWJ> */ | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape | ||
pp.regexp_eatAtomEscape = function (state) { | ||
@@ -723,23 +506,15 @@ if (this.regexp_eatBackReference(state) || this.regexp_eatCharacterClassEscape(state) || this.regexp_eatCharacterEscape(state) || state.switchN && this.regexp_eatKGroupName(state)) { | ||
} | ||
if (state.switchU) { | ||
// Make the same message as V8. | ||
if (state.current() === 0x63 | ||
/* c */ | ||
) { | ||
if (state.current() === 0x63 /* c */) { | ||
state.raise("Invalid unicode escape"); | ||
} | ||
state.raise("Invalid escape"); | ||
} | ||
return false; | ||
}; | ||
pp.regexp_eatBackReference = function (state) { | ||
const start = state.pos; | ||
if (this.regexp_eatDecimalEscape(state)) { | ||
const n = state.lastIntValue; | ||
if (state.switchU) { | ||
@@ -750,20 +525,13 @@ // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape | ||
} | ||
return true; | ||
} | ||
if (n <= state.numCapturingParens) { | ||
return true; | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; | ||
pp.regexp_eatKGroupName = function (state) { | ||
if (state.eat(0x6B | ||
/* k */ | ||
)) { | ||
if (state.eat(0x6B /* k */)) { | ||
if (this.regexp_eatGroupName(state)) { | ||
@@ -773,34 +541,23 @@ state.backReferenceNames.push(state.lastStringValue); | ||
} | ||
state.raise("Invalid named reference"); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape | ||
pp.regexp_eatCharacterEscape = function (state) { | ||
return this.regexp_eatControlEscape(state) || this.regexp_eatCControlLetter(state) || this.regexp_eatZero(state) || this.regexp_eatHexEscapeSequence(state) || this.regexp_eatRegExpUnicodeEscapeSequence(state, false) || !state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state) || this.regexp_eatIdentityEscape(state); | ||
}; | ||
pp.regexp_eatCControlLetter = function (state) { | ||
const start = state.pos; | ||
if (state.eat(0x63 | ||
/* c */ | ||
)) { | ||
if (state.eat(0x63 /* c */)) { | ||
if (this.regexp_eatControlLetter(state)) { | ||
return true; | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; | ||
pp.regexp_eatZero = function (state) { | ||
if (state.current() === 0x30 | ||
/* 0 */ | ||
&& !isDecimalDigit(state.lookahead())) { | ||
if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) { | ||
state.lastIntValue = 0; | ||
@@ -810,67 +567,39 @@ state.advance(); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape | ||
pp.regexp_eatControlEscape = function (state) { | ||
const ch = state.current(); | ||
if (ch === 0x74 | ||
/* t */ | ||
) { | ||
state.lastIntValue = 0x09; | ||
/* \t */ | ||
if (ch === 0x74 /* t */) { | ||
state.lastIntValue = 0x09; /* \t */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x6E | ||
/* n */ | ||
) { | ||
state.lastIntValue = 0x0A; | ||
/* \n */ | ||
if (ch === 0x6E /* n */) { | ||
state.lastIntValue = 0x0A; /* \n */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x76 | ||
/* v */ | ||
) { | ||
state.lastIntValue = 0x0B; | ||
/* \v */ | ||
if (ch === 0x76 /* v */) { | ||
state.lastIntValue = 0x0B; /* \v */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x66 | ||
/* f */ | ||
) { | ||
state.lastIntValue = 0x0C; | ||
/* \f */ | ||
if (ch === 0x66 /* f */) { | ||
state.lastIntValue = 0x0C; /* \f */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x72 | ||
/* r */ | ||
) { | ||
state.lastIntValue = 0x0D; | ||
/* \r */ | ||
if (ch === 0x72 /* r */) { | ||
state.lastIntValue = 0x0D; /* \r */ | ||
state.advance(); | ||
return true; | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter | ||
pp.regexp_eatControlLetter = function (state) { | ||
const ch = state.current(); | ||
if (isControlLetter(ch)) { | ||
@@ -881,39 +610,19 @@ state.lastIntValue = ch % 0x20; | ||
} | ||
return false; | ||
}; | ||
function isControlLetter(ch) { | ||
return ch >= 0x41 | ||
/* A */ | ||
&& ch <= 0x5A | ||
/* Z */ | ||
|| ch >= 0x61 | ||
/* a */ | ||
&& ch <= 0x7A | ||
/* z */ | ||
; | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence | ||
return ch >= 0x41 /* A */ && ch <= 0x5A /* Z */ || ch >= 0x61 /* a */ && ch <= 0x7A /* z */; | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence | ||
pp.regexp_eatRegExpUnicodeEscapeSequence = function (state, forceU = false) { | ||
const start = state.pos; | ||
const switchU = forceU || state.switchU; | ||
if (state.eat(0x75 | ||
/* u */ | ||
)) { | ||
if (state.eat(0x75 /* u */)) { | ||
if (this.regexp_eatFixedHexDigits(state, 4)) { | ||
const lead = state.lastIntValue; | ||
if (switchU && lead >= 0xD800 && lead <= 0xDBFF) { | ||
const leadSurrogateEnd = state.pos; | ||
if (state.eat(0x5C | ||
/* \ */ | ||
) && state.eat(0x75 | ||
/* u */ | ||
) && this.regexp_eatFixedHexDigits(state, 4)) { | ||
if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) { | ||
const trail = state.lastIntValue; | ||
if (trail >= 0xDC00 && trail <= 0xDFFF) { | ||
@@ -924,33 +633,22 @@ state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000; | ||
} | ||
state.pos = leadSurrogateEnd; | ||
state.lastIntValue = lead; | ||
} | ||
return true; | ||
} | ||
if (switchU && state.eat(0x7B | ||
/* { */ | ||
) && this.regexp_eatHexDigits(state) && state.eat(0x7D | ||
/* } */ | ||
) && isValidUnicode(state.lastIntValue)) { | ||
if (switchU && state.eat(0x7B /* { */) && this.regexp_eatHexDigits(state) && state.eat(0x7D /* } */) && isValidUnicode(state.lastIntValue)) { | ||
return true; | ||
} | ||
if (switchU) { | ||
state.raise("Invalid unicode escape"); | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; | ||
function isValidUnicode(ch) { | ||
return ch >= 0 && ch <= 0x10FFFF; | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape | ||
pp.regexp_eatIdentityEscape = function (state) { | ||
@@ -961,22 +659,10 @@ if (state.switchU) { | ||
} | ||
if (state.eat(0x2F | ||
/* / */ | ||
)) { | ||
state.lastIntValue = 0x2F; | ||
/* / */ | ||
if (state.eat(0x2F /* / */)) { | ||
state.lastIntValue = 0x2F; /* / */ | ||
return true; | ||
} | ||
return false; | ||
} | ||
const ch = state.current(); | ||
if (ch !== 0x63 | ||
/* c */ | ||
&& (!state.switchN || ch !== 0x6B | ||
/* k */ | ||
)) { | ||
if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) { | ||
state.lastIntValue = ch; | ||
@@ -986,37 +672,22 @@ state.advance(); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape | ||
pp.regexp_eatDecimalEscape = function (state) { | ||
state.lastIntValue = 0; | ||
let ch = state.current(); | ||
if (ch >= 0x31 | ||
/* 1 */ | ||
&& ch <= 0x39 | ||
/* 9 */ | ||
) { | ||
if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) { | ||
do { | ||
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 | ||
/* 0 */ | ||
); | ||
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */); | ||
state.advance(); | ||
} while ((ch = state.current()) >= 0x30 | ||
/* 0 */ | ||
&& ch <= 0x39 | ||
/* 9 */ | ||
); | ||
} while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */); | ||
return true; | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape | ||
pp.regexp_eatCharacterClassEscape = function (state) { | ||
const ch = state.current(); | ||
if (isCharacterClassEscape(ch)) { | ||
@@ -1027,52 +698,25 @@ state.lastIntValue = -1; | ||
} | ||
if (state.switchU && this.options.ecmaVersion >= 9 && (ch === 0x50 | ||
/* P */ | ||
|| ch === 0x70 | ||
/* p */ | ||
)) { | ||
if (state.switchU && this.options.ecmaVersion >= 9 && (ch === 0x50 /* P */ || ch === 0x70 /* p */)) { | ||
state.lastIntValue = -1; | ||
state.advance(); | ||
if (state.eat(0x7B | ||
/* { */ | ||
) && this.regexp_eatUnicodePropertyValueExpression(state) && state.eat(0x7D | ||
/* } */ | ||
)) { | ||
if (state.eat(0x7B /* { */) && this.regexp_eatUnicodePropertyValueExpression(state) && state.eat(0x7D /* } */)) { | ||
return true; | ||
} | ||
state.raise("Invalid property name"); | ||
} | ||
return false; | ||
}; | ||
function isCharacterClassEscape(ch) { | ||
return ch === 0x64 /* d */ || ch === 0x44 /* D */ || ch === 0x73 /* s */ || ch === 0x53 /* S */ || ch === 0x77 /* w */ || ch === 0x57 /* W */; | ||
} | ||
function isCharacterClassEscape(ch) { | ||
return ch === 0x64 | ||
/* d */ | ||
|| ch === 0x44 | ||
/* D */ | ||
|| ch === 0x73 | ||
/* s */ | ||
|| ch === 0x53 | ||
/* S */ | ||
|| ch === 0x77 | ||
/* w */ | ||
|| ch === 0x57 | ||
/* W */ | ||
; | ||
} // UnicodePropertyValueExpression :: | ||
// UnicodePropertyValueExpression :: | ||
// UnicodePropertyName `=` UnicodePropertyValue | ||
// LoneUnicodePropertyNameOrValue | ||
pp.regexp_eatUnicodePropertyValueExpression = function (state) { | ||
const start = state.pos; // UnicodePropertyName `=` UnicodePropertyValue | ||
const start = state.pos; | ||
if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D | ||
/* = */ | ||
)) { | ||
// UnicodePropertyName `=` UnicodePropertyValue | ||
if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) { | ||
const name = state.lastStringValue; | ||
if (this.regexp_eatUnicodePropertyValue(state)) { | ||
@@ -1084,5 +728,5 @@ const value = state.lastStringValue; | ||
} | ||
state.pos = start; | ||
state.pos = start; // LoneUnicodePropertyNameOrValue | ||
// LoneUnicodePropertyNameOrValue | ||
if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) { | ||
@@ -1093,6 +737,4 @@ const nameOrValue = state.lastStringValue; | ||
} | ||
return false; | ||
}; | ||
pp.regexp_validateUnicodePropertyNameAndValue = function (state, name, value) { | ||
@@ -1102,13 +744,11 @@ if (!(0, _util.hasOwn)(state.unicodeProperties.nonBinary, name)) state.raise("Invalid property name"); | ||
}; | ||
pp.regexp_validateUnicodePropertyNameOrValue = function (state, nameOrValue) { | ||
if (!state.unicodeProperties.binary.test(nameOrValue)) state.raise("Invalid property name"); | ||
}; // UnicodePropertyName :: | ||
}; | ||
// UnicodePropertyName :: | ||
// UnicodePropertyNameCharacters | ||
pp.regexp_eatUnicodePropertyName = function (state) { | ||
let ch = 0; | ||
state.lastStringValue = ""; | ||
while (isUnicodePropertyNameCharacter(ch = state.current())) { | ||
@@ -1118,17 +758,13 @@ state.lastStringValue += codePointToString(ch); | ||
} | ||
return state.lastStringValue !== ""; | ||
}; | ||
function isUnicodePropertyNameCharacter(ch) { | ||
return isControlLetter(ch) || ch === 0x5F; /* _ */ | ||
} | ||
function isUnicodePropertyNameCharacter(ch) { | ||
return isControlLetter(ch) || ch === 0x5F; | ||
/* _ */ | ||
} // UnicodePropertyValue :: | ||
// UnicodePropertyValue :: | ||
// UnicodePropertyValueCharacters | ||
pp.regexp_eatUnicodePropertyValue = function (state) { | ||
let ch = 0; | ||
state.lastStringValue = ""; | ||
while (isUnicodePropertyValueCharacter(ch = state.current())) { | ||
@@ -1138,55 +774,39 @@ state.lastStringValue += codePointToString(ch); | ||
} | ||
return state.lastStringValue !== ""; | ||
}; | ||
function isUnicodePropertyValueCharacter(ch) { | ||
return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch); | ||
} // LoneUnicodePropertyNameOrValue :: | ||
} | ||
// LoneUnicodePropertyNameOrValue :: | ||
// UnicodePropertyValueCharacters | ||
pp.regexp_eatLoneUnicodePropertyNameOrValue = function (state) { | ||
return this.regexp_eatUnicodePropertyValue(state); | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass | ||
pp.regexp_eatCharacterClass = function (state) { | ||
if (state.eat(0x5B | ||
/* [ */ | ||
)) { | ||
state.eat(0x5E | ||
/* ^ */ | ||
); | ||
if (state.eat(0x5B /* [ */)) { | ||
state.eat(0x5E /* ^ */); | ||
this.regexp_classRanges(state); | ||
if (state.eat(0x5D | ||
/* ] */ | ||
)) { | ||
if (state.eat(0x5D /* ] */)) { | ||
return true; | ||
} // Unreachable since it threw "unterminated regular expression" error before. | ||
} | ||
// Unreachable since it threw "unterminated regular expression" error before. | ||
state.raise("Unterminated character class"); | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash | ||
pp.regexp_classRanges = function (state) { | ||
while (this.regexp_eatClassAtom(state)) { | ||
const left = state.lastIntValue; | ||
if (state.eat(0x2D | ||
/* - */ | ||
) && this.regexp_eatClassAtom(state)) { | ||
if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) { | ||
const right = state.lastIntValue; | ||
if (state.switchU && (left === -1 || right === -1)) { | ||
state.raise("Invalid character class"); | ||
} | ||
if (left !== -1 && right !== -1 && left > right) { | ||
@@ -1197,37 +817,24 @@ state.raise("Range out of order in character class"); | ||
} | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash | ||
pp.regexp_eatClassAtom = function (state) { | ||
const start = state.pos; | ||
if (state.eat(0x5C | ||
/* \ */ | ||
)) { | ||
if (state.eat(0x5C /* \ */)) { | ||
if (this.regexp_eatClassEscape(state)) { | ||
return true; | ||
} | ||
if (state.switchU) { | ||
// Make the same message as V8. | ||
const ch = state.current(); | ||
if (ch === 0x63 | ||
/* c */ | ||
|| isOctalDigit(ch)) { | ||
if (ch === 0x63 /* c */ || isOctalDigit(ch)) { | ||
state.raise("Invalid class escape"); | ||
} | ||
state.raise("Invalid escape"); | ||
} | ||
state.pos = start; | ||
} | ||
const ch = state.current(); | ||
if (ch !== 0x5D | ||
/* ] */ | ||
) { | ||
if (ch !== 0x5D /* ] */) { | ||
state.lastIntValue = ch; | ||
@@ -1237,48 +844,29 @@ state.advance(); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape | ||
pp.regexp_eatClassEscape = function (state) { | ||
const start = state.pos; | ||
if (state.eat(0x62 | ||
/* b */ | ||
)) { | ||
state.lastIntValue = 0x08; | ||
/* <BS> */ | ||
if (state.eat(0x62 /* b */)) { | ||
state.lastIntValue = 0x08; /* <BS> */ | ||
return true; | ||
} | ||
if (state.switchU && state.eat(0x2D | ||
/* - */ | ||
)) { | ||
state.lastIntValue = 0x2D; | ||
/* - */ | ||
if (state.switchU && state.eat(0x2D /* - */)) { | ||
state.lastIntValue = 0x2D; /* - */ | ||
return true; | ||
} | ||
if (!state.switchU && state.eat(0x63 | ||
/* c */ | ||
)) { | ||
if (!state.switchU && state.eat(0x63 /* c */)) { | ||
if (this.regexp_eatClassControlLetter(state)) { | ||
return true; | ||
} | ||
state.pos = start; | ||
} | ||
return this.regexp_eatCharacterClassEscape(state) || this.regexp_eatCharacterEscape(state); | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter | ||
pp.regexp_eatClassControlLetter = function (state) { | ||
const ch = state.current(); | ||
if (isDecimalDigit(ch) || ch === 0x5F | ||
/* _ */ | ||
) { | ||
if (isDecimalDigit(ch) || ch === 0x5F /* _ */) { | ||
state.lastIntValue = ch % 0x20; | ||
@@ -1288,28 +876,21 @@ state.advance(); | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence | ||
pp.regexp_eatHexEscapeSequence = function (state) { | ||
const start = state.pos; | ||
if (state.eat(0x78 | ||
/* x */ | ||
)) { | ||
if (state.eat(0x78 /* x */)) { | ||
if (this.regexp_eatFixedHexDigits(state, 2)) { | ||
return true; | ||
} | ||
if (state.switchU) { | ||
state.raise("Invalid escape"); | ||
} | ||
state.pos = start; | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits | ||
pp.regexp_eatDecimalDigits = function (state) { | ||
@@ -1319,21 +900,13 @@ const start = state.pos; | ||
state.lastIntValue = 0; | ||
while (isDecimalDigit(ch = state.current())) { | ||
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 | ||
/* 0 */ | ||
); | ||
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */); | ||
state.advance(); | ||
} | ||
return state.pos !== start; | ||
}; | ||
function isDecimalDigit(ch) { | ||
return ch >= 0x30 | ||
/* 0 */ | ||
&& ch <= 0x39; | ||
/* 9 */ | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits | ||
return ch >= 0x30 /* 0 */ && ch <= 0x39; /* 9 */ | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits | ||
pp.regexp_eatHexDigits = function (state) { | ||
@@ -1343,3 +916,2 @@ const start = state.pos; | ||
state.lastIntValue = 0; | ||
while (isHexDigit(ch = state.current())) { | ||
@@ -1349,56 +921,27 @@ state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); | ||
} | ||
return state.pos !== start; | ||
}; | ||
function isHexDigit(ch) { | ||
return ch >= 0x30 | ||
/* 0 */ | ||
&& ch <= 0x39 | ||
/* 9 */ | ||
|| ch >= 0x41 | ||
/* A */ | ||
&& ch <= 0x46 | ||
/* F */ | ||
|| ch >= 0x61 | ||
/* a */ | ||
&& ch <= 0x66 | ||
/* f */ | ||
; | ||
return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */ || ch >= 0x41 /* A */ && ch <= 0x46 /* F */ || ch >= 0x61 /* a */ && ch <= 0x66 /* f */; | ||
} | ||
function hexToInt(ch) { | ||
if (ch >= 0x41 | ||
/* A */ | ||
&& ch <= 0x46 | ||
/* F */ | ||
) { | ||
return 10 + (ch - 0x41 | ||
/* A */ | ||
); | ||
if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) { | ||
return 10 + (ch - 0x41 /* A */); | ||
} | ||
if (ch >= 0x61 | ||
/* a */ | ||
&& ch <= 0x66 | ||
/* f */ | ||
) { | ||
return 10 + (ch - 0x61 | ||
/* a */ | ||
); | ||
if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) { | ||
return 10 + (ch - 0x61 /* a */); | ||
} | ||
return ch - 0x30; | ||
/* 0 */ | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence | ||
return ch - 0x30; /* 0 */ | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence | ||
// Allows only 0-377(octal) i.e. 0-255(decimal). | ||
pp.regexp_eatLegacyOctalEscapeSequence = function (state) { | ||
if (this.regexp_eatOctalDigit(state)) { | ||
const n1 = state.lastIntValue; | ||
if (this.regexp_eatOctalDigit(state)) { | ||
const n2 = state.lastIntValue; | ||
if (n1 <= 3 && this.regexp_eatOctalDigit(state)) { | ||
@@ -1412,42 +955,30 @@ state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue; | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit | ||
}; | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit | ||
pp.regexp_eatOctalDigit = function (state) { | ||
const ch = state.current(); | ||
if (isOctalDigit(ch)) { | ||
state.lastIntValue = ch - 0x30; | ||
/* 0 */ | ||
state.lastIntValue = ch - 0x30; /* 0 */ | ||
state.advance(); | ||
return true; | ||
} | ||
state.lastIntValue = 0; | ||
return false; | ||
}; | ||
function isOctalDigit(ch) { | ||
return ch >= 0x30 /* 0 */ && ch <= 0x37; /* 7 */ | ||
} | ||
function isOctalDigit(ch) { | ||
return ch >= 0x30 | ||
/* 0 */ | ||
&& ch <= 0x37; | ||
/* 7 */ | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit | ||
// And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence | ||
pp.regexp_eatFixedHexDigits = function (state, length) { | ||
const start = state.pos; | ||
state.lastIntValue = 0; | ||
for (let i = 0; i < length; ++i) { | ||
const ch = state.current(); | ||
if (!isHexDigit(ch)) { | ||
@@ -1457,8 +988,6 @@ state.pos = start; | ||
} | ||
state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); | ||
state.advance(); | ||
} | ||
return true; | ||
}; |
"use strict"; | ||
var _state = require("./state.js"); | ||
var _scopeflags = require("./scopeflags.js"); | ||
const pp = _state.Parser.prototype; | ||
class Scope { | ||
constructor(flags) { | ||
this.flags = flags; // A list of var-declared names in the current lexical scope | ||
this.var = []; // A list of lexically-declared names in the current lexical scope | ||
this.lexical = []; // A list of lexically-declared FunctionDeclaration names in the current lexical scope | ||
this.functions = []; // A switch to disallow the identifier reference 'arguments' | ||
this.flags = flags; | ||
// A list of var-declared names in the current lexical scope | ||
this.var = []; | ||
// A list of lexically-declared names in the current lexical scope | ||
this.lexical = []; | ||
// A list of lexically-declared FunctionDeclaration names in the current lexical scope | ||
this.functions = []; | ||
// A switch to disallow the identifier reference 'arguments' | ||
this.inClassFieldInit = false; | ||
} | ||
} | ||
} // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names. | ||
// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names. | ||
pp.enterScope = function (flags) { | ||
this.scopeStack.push(new Scope(flags)); | ||
}; | ||
pp.exitScope = function () { | ||
this.scopeStack.pop(); | ||
}; // The spec says: | ||
}; | ||
// The spec says: | ||
// > At the top level of a function, or script, function declarations are | ||
// > treated like var declarations rather than like lexical declarations. | ||
pp.treatFunctionsAsVarInScope = function (scope) { | ||
return scope.flags & _scopeflags.SCOPE_FUNCTION || !this.inModule && scope.flags & _scopeflags.SCOPE_TOP; | ||
}; | ||
pp.declareName = function (name, bindingType, pos) { | ||
let redeclared = false; | ||
if (bindingType === _scopeflags.BIND_LEXICAL) { | ||
@@ -58,3 +52,2 @@ const scope = this.currentScope(); | ||
const scope = this.scopeStack[i]; | ||
if (scope.lexical.indexOf(name) > -1 && !(scope.flags & _scopeflags.SCOPE_SIMPLE_CATCH && scope.lexical[0] === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.indexOf(name) > -1) { | ||
@@ -64,3 +57,2 @@ redeclared = true; | ||
} | ||
scope.var.push(name); | ||
@@ -71,6 +63,4 @@ if (this.inModule && scope.flags & _scopeflags.SCOPE_TOP) delete this.undefinedExports[name]; | ||
} | ||
if (redeclared) this.raiseRecoverable(pos, `Identifier '${name}' has already been declared`); | ||
}; | ||
pp.checkLocalExport = function (id) { | ||
@@ -82,7 +72,5 @@ // scope.functions must be empty as Module code is always strict. | ||
}; | ||
pp.currentScope = function () { | ||
return this.scopeStack[this.scopeStack.length - 1]; | ||
}; | ||
pp.currentVarScope = function () { | ||
@@ -93,5 +81,5 @@ for (let i = this.scopeStack.length - 1;; i--) { | ||
} | ||
}; // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`. | ||
}; | ||
// Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`. | ||
pp.currentThisScope = function () { | ||
@@ -98,0 +86,0 @@ for (let i = this.scopeStack.length - 1;; i--) { |
@@ -8,11 +8,11 @@ "use strict"; | ||
const SCOPE_TOP = 1, | ||
SCOPE_FUNCTION = 2, | ||
SCOPE_ASYNC = 4, | ||
SCOPE_GENERATOR = 8, | ||
SCOPE_ARROW = 16, | ||
SCOPE_SIMPLE_CATCH = 32, | ||
SCOPE_SUPER = 64, | ||
SCOPE_DIRECT_SUPER = 128, | ||
SCOPE_CLASS_STATIC_BLOCK = 256, | ||
SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK; | ||
SCOPE_FUNCTION = 2, | ||
SCOPE_ASYNC = 4, | ||
SCOPE_GENERATOR = 8, | ||
SCOPE_ARROW = 16, | ||
SCOPE_SIMPLE_CATCH = 32, | ||
SCOPE_SUPER = 64, | ||
SCOPE_DIRECT_SUPER = 128, | ||
SCOPE_CLASS_STATIC_BLOCK = 256, | ||
SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK; | ||
exports.SCOPE_VAR = SCOPE_VAR; | ||
@@ -28,20 +28,18 @@ exports.SCOPE_CLASS_STATIC_BLOCK = SCOPE_CLASS_STATIC_BLOCK; | ||
exports.SCOPE_TOP = SCOPE_TOP; | ||
function functionFlags(async, generator) { | ||
return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0); | ||
} // Used in checkLVal* and declareName to determine the type of a binding | ||
} | ||
// Used in checkLVal* and declareName to determine the type of a binding | ||
const BIND_NONE = 0, | ||
// Not a binding | ||
BIND_VAR = 1, | ||
// Var-style binding | ||
BIND_LEXICAL = 2, | ||
// Let- or const-style binding | ||
BIND_FUNCTION = 3, | ||
// Function declaration | ||
BIND_SIMPLE_CATCH = 4, | ||
// Simple (identifier pattern) catch binding | ||
BIND_OUTSIDE = 5; // Special case for function names as bound inside the function | ||
// Not a binding | ||
BIND_VAR = 1, | ||
// Var-style binding | ||
BIND_LEXICAL = 2, | ||
// Let- or const-style binding | ||
BIND_FUNCTION = 3, | ||
// Function declaration | ||
BIND_SIMPLE_CATCH = 4, | ||
// Simple (identifier pattern) catch binding | ||
BIND_OUTSIDE = 5; // Special case for function names as bound inside the function | ||
exports.BIND_OUTSIDE = BIND_OUTSIDE; | ||
@@ -48,0 +46,0 @@ exports.BIND_SIMPLE_CATCH = BIND_SIMPLE_CATCH; |
104
lib/state.js
@@ -5,15 +5,8 @@ "use strict"; | ||
exports.Parser = void 0; | ||
var _identifier = require("./identifier.js"); | ||
var _tokentype = require("./tokentype.js"); | ||
var _whitespace = require("./whitespace.js"); | ||
var _options = require("./options.js"); | ||
var _util = require("./util.js"); | ||
var _scopeflags = require("./scopeflags.js"); | ||
class Parser { | ||
@@ -25,3 +18,2 @@ constructor(options, input, startPos) { | ||
let reserved = ""; | ||
if (options.allowReserved !== true) { | ||
@@ -31,3 +23,2 @@ reserved = _identifier.reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3]; | ||
} | ||
this.reservedWords = (0, _util.wordsRegexp)(reserved); | ||
@@ -37,9 +28,12 @@ let reservedStrict = (reserved ? reserved + " " : "") + _identifier.reservedWords.strict; | ||
this.reservedWordsStrictBind = (0, _util.wordsRegexp)(reservedStrict + " " + _identifier.reservedWords.strictBind); | ||
this.input = String(input); // Used to signal to callers of `readWord1` whether the word | ||
this.input = String(input); | ||
// Used to signal to callers of `readWord1` whether the word | ||
// contained any escape sequences. This is needed because words with | ||
// escape sequences must not be interpreted as keywords. | ||
this.containsEsc = false; | ||
this.containsEsc = false; // Set up token state | ||
// Set up token state | ||
// The current position of the tokenizer in the input. | ||
if (startPos) { | ||
@@ -52,47 +46,55 @@ this.pos = startPos; | ||
this.curLine = 1; | ||
} // Properties of the current token: | ||
} | ||
// Properties of the current token: | ||
// Its type | ||
this.type = _tokentype.types.eof; // For tokens that include more information than their type, the value | ||
this.value = null; // Its start and end offset | ||
this.start = this.end = this.pos; // And, if locations are used, the {line, column} object | ||
this.type = _tokentype.types.eof; | ||
// For tokens that include more information than their type, the value | ||
this.value = null; | ||
// Its start and end offset | ||
this.start = this.end = this.pos; | ||
// And, if locations are used, the {line, column} object | ||
// corresponding to those offsets | ||
this.startLoc = this.endLoc = this.curPosition(); | ||
this.startLoc = this.endLoc = this.curPosition(); // Position information for the previous token | ||
// Position information for the previous token | ||
this.lastTokEndLoc = this.lastTokStartLoc = null; | ||
this.lastTokStart = this.lastTokEnd = this.pos; | ||
this.lastTokEndLoc = this.lastTokStartLoc = null; | ||
this.lastTokStart = this.lastTokEnd = this.pos; // The context stack is used to superficially track syntactic | ||
// The context stack is used to superficially track syntactic | ||
// context to predict whether a regular expression is allowed in a | ||
// given position. | ||
this.context = this.initialContext(); | ||
this.exprAllowed = true; // Figure out if it's a module code. | ||
this.exprAllowed = true; | ||
// Figure out if it's a module code. | ||
this.inModule = options.sourceType === "module"; | ||
this.strict = this.inModule || this.strictDirective(this.pos); // Used to signify the start of a potential arrow function | ||
this.strict = this.inModule || this.strictDirective(this.pos); | ||
// Used to signify the start of a potential arrow function | ||
this.potentialArrowAt = -1; | ||
this.potentialArrowInForAwait = false; // Positions to delayed-check that yield/await does not exist in default parameters. | ||
this.potentialArrowInForAwait = false; | ||
this.yieldPos = this.awaitPos = this.awaitIdentPos = 0; // Labels in scope. | ||
// Positions to delayed-check that yield/await does not exist in default parameters. | ||
this.yieldPos = this.awaitPos = this.awaitIdentPos = 0; | ||
// Labels in scope. | ||
this.labels = []; | ||
// Thus-far undefined exports. | ||
this.undefinedExports = Object.create(null); | ||
this.labels = []; // Thus-far undefined exports. | ||
// If enabled, skip leading hashbang line. | ||
if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2); | ||
this.undefinedExports = Object.create(null); // If enabled, skip leading hashbang line. | ||
// Scope tracking for duplicate variable names (see scope.js) | ||
this.scopeStack = []; | ||
this.enterScope(_scopeflags.SCOPE_TOP); | ||
if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2); // Scope tracking for duplicate variable names (see scope.js) | ||
// For RegExp validation | ||
this.regexpState = null; | ||
this.scopeStack = []; | ||
this.enterScope(_scopeflags.SCOPE_TOP); // For RegExp validation | ||
this.regexpState = null; // The stack of private names. | ||
// The stack of private names. | ||
// Each element has two properties: 'declared' and 'used'. | ||
// When it exited from the outermost class definition, all used private names must be declared. | ||
this.privateNameStack = []; | ||
} | ||
parse() { | ||
@@ -103,15 +105,11 @@ let node = this.options.program || this.startNode(); | ||
} | ||
get inFunction() { | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_FUNCTION) > 0; | ||
} | ||
get inGenerator() { | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit; | ||
} | ||
get inAsync() { | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit; | ||
} | ||
get canAwait() { | ||
@@ -123,46 +121,33 @@ for (let i = this.scopeStack.length - 1; i >= 0; i--) { | ||
} | ||
return this.inModule && this.options.ecmaVersion >= 13 || this.options.allowAwaitOutsideFunction; | ||
} | ||
get allowSuper() { | ||
const _this$currentThisScop = this.currentThisScope(), | ||
flags = _this$currentThisScop.flags, | ||
inClassFieldInit = _this$currentThisScop.inClassFieldInit; | ||
flags = _this$currentThisScop.flags, | ||
inClassFieldInit = _this$currentThisScop.inClassFieldInit; | ||
return (flags & _scopeflags.SCOPE_SUPER) > 0 || inClassFieldInit || this.options.allowSuperOutsideMethod; | ||
} | ||
get allowDirectSuper() { | ||
return (this.currentThisScope().flags & _scopeflags.SCOPE_DIRECT_SUPER) > 0; | ||
} | ||
get treatFunctionsAsVar() { | ||
return this.treatFunctionsAsVarInScope(this.currentScope()); | ||
} | ||
get allowNewDotTarget() { | ||
const _this$currentThisScop2 = this.currentThisScope(), | ||
flags = _this$currentThisScop2.flags, | ||
inClassFieldInit = _this$currentThisScop2.inClassFieldInit; | ||
flags = _this$currentThisScop2.flags, | ||
inClassFieldInit = _this$currentThisScop2.inClassFieldInit; | ||
return (flags & (_scopeflags.SCOPE_FUNCTION | _scopeflags.SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit; | ||
} | ||
get inClassStaticBlock() { | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_CLASS_STATIC_BLOCK) > 0; | ||
} | ||
static extend(...plugins) { | ||
let cls = this; | ||
for (let i = 0; i < plugins.length; i++) cls = plugins[i](cls); | ||
return cls; | ||
} | ||
static parse(input, options) { | ||
return new this(options, input).parse(); | ||
} | ||
static parseExpressionAt(input, pos, options) { | ||
@@ -173,9 +158,6 @@ let parser = new this(options, input, pos); | ||
} | ||
static tokenizer(input, options) { | ||
return new this(options, input); | ||
} | ||
} | ||
exports.Parser = Parser; |
"use strict"; | ||
var _tokentype = require("./tokentype.js"); | ||
var _state = require("./state.js"); | ||
var _whitespace = require("./whitespace.js"); | ||
var _identifier = require("./identifier.js"); | ||
var _util = require("./util.js"); | ||
var _parseutil = require("./parseutil.js"); | ||
var _scopeflags = require("./scopeflags.js"); | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
const pp = _state.Parser.prototype; | ||
const pp = _state.Parser.prototype; // ### Statement parsing | ||
// ### Statement parsing | ||
// Parse a program. Initializes the parser, reads any number of | ||
@@ -32,3 +25,2 @@ // statements, and wraps them in a Program node. Optionally takes a | ||
if (!node.body) node.body = []; | ||
while (this.type !== _tokentype.types.eof) { | ||
@@ -38,3 +30,2 @@ let stmt = this.parseStatement(null, true, exports); | ||
} | ||
if (this.inModule) for (var _i = 0, _Object$keys = Object.keys(this.undefinedExports); _i < _Object$keys.length; _i++) { | ||
@@ -49,32 +40,24 @@ let name = _Object$keys[_i]; | ||
}; | ||
const loopLabel = { | ||
kind: "loop" | ||
}, | ||
switchLabel = { | ||
kind: "switch" | ||
}; | ||
kind: "loop" | ||
}, | ||
switchLabel = { | ||
kind: "switch" | ||
}; | ||
pp.isLet = function (context) { | ||
if (this.options.ecmaVersion < 6 || !this.isContextual("let")) return false; | ||
_whitespace.skipWhiteSpace.lastIndex = this.pos; | ||
let skip = _whitespace.skipWhiteSpace.exec(this.input); | ||
let next = this.pos + skip[0].length, | ||
nextCh = this.input.charCodeAt(next); // For ambiguous cases, determine if a LexicalDeclaration (or only a | ||
nextCh = this.input.charCodeAt(next); | ||
// For ambiguous cases, determine if a LexicalDeclaration (or only a | ||
// Statement) is allowed here. If context is not empty then only a Statement | ||
// is allowed. However, `let [` is an explicit negative lookahead for | ||
// ExpressionStatement, so special-case it first. | ||
if (nextCh === 91 || nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true; // '[', '/', astral | ||
if (context) return false; | ||
if (nextCh === 123) return true; // '{' | ||
if ((0, _identifier.isIdentifierStart)(nextCh, true)) { | ||
let pos = next + 1; | ||
while ((0, _identifier.isIdentifierChar)(nextCh = this.input.charCodeAt(pos), true)) ++pos; | ||
if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true; | ||
@@ -84,19 +67,18 @@ let ident = this.input.slice(next, pos); | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; // check 'async [no LineTerminator here] function' | ||
// check 'async [no LineTerminator here] function' | ||
// - 'async /*foo*/ function' is OK. | ||
// - 'async /*\n*/ function' is invalid. | ||
pp.isAsyncFunction = function () { | ||
if (this.options.ecmaVersion < 8 || !this.isContextual("async")) return false; | ||
_whitespace.skipWhiteSpace.lastIndex = this.pos; | ||
let skip = _whitespace.skipWhiteSpace.exec(this.input); | ||
let next = this.pos + skip[0].length, | ||
after; | ||
after; | ||
return !_whitespace.lineBreak.test(this.input.slice(this.pos, next)) && this.input.slice(next, next + 8) === "function" && (next + 8 === this.input.length || !((0, _identifier.isIdentifierChar)(after = this.input.charCodeAt(next + 8)) || after > 0xd7ff && after < 0xdc00)); | ||
}; // Parse a single statement. | ||
}; | ||
// Parse a single statement. | ||
// | ||
@@ -108,16 +90,15 @@ // If expecting a statement and finding a slash operator, parse a | ||
pp.parseStatement = function (context, topLevel, exports) { | ||
let starttype = this.type, | ||
node = this.startNode(), | ||
kind; | ||
node = this.startNode(), | ||
kind; | ||
if (this.isLet(context)) { | ||
starttype = _tokentype.types._var; | ||
kind = "let"; | ||
} // Most types of statements are recognized by the keyword they | ||
} | ||
// Most types of statements are recognized by the keyword they | ||
// start with. Many are trivial to parse, some require a bit of | ||
// complexity. | ||
switch (starttype) { | ||
@@ -127,12 +108,8 @@ case _tokentype.types._break: | ||
return this.parseBreakContinueStatement(node, starttype.keyword); | ||
case _tokentype.types._debugger: | ||
return this.parseDebuggerStatement(node); | ||
case _tokentype.types._do: | ||
return this.parseDoStatement(node); | ||
case _tokentype.types._for: | ||
return this.parseForStatement(node); | ||
case _tokentype.types._function: | ||
@@ -144,22 +121,15 @@ // Function as sole body of either an if statement or a labeled statement | ||
return this.parseFunctionStatement(node, false, !context); | ||
case _tokentype.types._class: | ||
if (context) this.unexpected(); | ||
return this.parseClass(node, true); | ||
case _tokentype.types._if: | ||
return this.parseIfStatement(node); | ||
case _tokentype.types._return: | ||
return this.parseReturnStatement(node); | ||
case _tokentype.types._switch: | ||
return this.parseSwitchStatement(node); | ||
case _tokentype.types._throw: | ||
return this.parseThrowStatement(node); | ||
case _tokentype.types._try: | ||
return this.parseTryStatement(node); | ||
case _tokentype.types._const: | ||
@@ -170,15 +140,10 @@ case _tokentype.types._var: | ||
return this.parseVarStatement(node, kind); | ||
case _tokentype.types._while: | ||
return this.parseWhileStatement(node); | ||
case _tokentype.types._with: | ||
return this.parseWithStatement(node); | ||
case _tokentype.types.braceL: | ||
return this.parseBlock(true, node); | ||
case _tokentype.types.semi: | ||
return this.parseEmptyStatement(node); | ||
case _tokentype.types._export: | ||
@@ -188,11 +153,9 @@ case _tokentype.types._import: | ||
_whitespace.skipWhiteSpace.lastIndex = this.pos; | ||
let skip = _whitespace.skipWhiteSpace.exec(this.input); | ||
let next = this.pos + skip[0].length, | ||
nextCh = this.input.charCodeAt(next); | ||
if (nextCh === 40 || nextCh === 46) // '(' or '.' | ||
nextCh = this.input.charCodeAt(next); | ||
if (nextCh === 40 || nextCh === 46) | ||
// '(' or '.' | ||
return this.parseExpressionStatement(node, this.parseExpression()); | ||
} | ||
if (!this.options.allowImportExportEverywhere) { | ||
@@ -202,4 +165,4 @@ if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level"); | ||
} | ||
return starttype === _tokentype.types._import ? this.parseImport(node) : this.parseExport(node, exports); | ||
return starttype === _tokentype.types._import ? this.parseImport(node) : this.parseExport(node, exports); | ||
// If the statement does not start with a statement keyword or a | ||
@@ -210,3 +173,2 @@ // brace, it's an ExpressionStatement or LabeledStatement. We | ||
// Identifier node, we switch to interpreting it as a label. | ||
default: | ||
@@ -218,9 +180,7 @@ if (this.isAsyncFunction()) { | ||
} | ||
let maybeName = this.value, | ||
expr = this.parseExpression(); | ||
expr = this.parseExpression(); | ||
if (starttype === _tokentype.types.name && expr.type === "Identifier" && this.eat(_tokentype.types.colon)) return this.parseLabeledStatement(node, maybeName, expr, context);else return this.parseExpressionStatement(node, expr); | ||
} | ||
}; | ||
pp.parseBreakContinueStatement = function (node, keyword) { | ||
@@ -232,10 +192,9 @@ let isBreak = keyword === "break"; | ||
this.semicolon(); | ||
} // Verify that there is an actual destination to break or | ||
} | ||
// Verify that there is an actual destination to break or | ||
// continue to. | ||
let i = 0; | ||
for (; i < this.labels.length; ++i) { | ||
let lab = this.labels[i]; | ||
if (node.label == null || lab.name === node.label.name) { | ||
@@ -246,7 +205,5 @@ if (lab.kind != null && (isBreak || lab.kind === "loop")) break; | ||
} | ||
if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword); | ||
return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); | ||
}; | ||
pp.parseDebuggerStatement = function (node) { | ||
@@ -257,3 +214,2 @@ this.next(); | ||
}; | ||
pp.parseDoStatement = function (node) { | ||
@@ -268,3 +224,5 @@ this.next(); | ||
return this.finishNode(node, "DoWhileStatement"); | ||
}; // Disambiguating between a `for` and a `for`/`in` or `for`/`of` | ||
}; | ||
// Disambiguating between a `for` and a `for`/`in` or `for`/`of` | ||
// loop is non-trivial. Basically, we have to parse the init `var` | ||
@@ -277,3 +235,2 @@ // statement or expression, disallowing the `in` operator (see | ||
pp.parseForStatement = function (node) { | ||
@@ -285,3 +242,2 @@ this.next(); | ||
this.expect(_tokentype.types.parenL); | ||
if (this.type === _tokentype.types.semi) { | ||
@@ -291,12 +247,9 @@ if (awaitAt > -1) this.unexpected(awaitAt); | ||
} | ||
let isLet = this.isLet(); | ||
if (this.type === _tokentype.types._var || this.type === _tokentype.types._const || isLet) { | ||
let init = this.startNode(), | ||
kind = isLet ? "let" : this.value; | ||
kind = isLet ? "let" : this.value; | ||
this.next(); | ||
this.parseVar(init, true, kind); | ||
this.finishNode(init, "VariableDeclaration"); | ||
if ((this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && init.declarations.length === 1) { | ||
@@ -308,15 +261,11 @@ if (this.options.ecmaVersion >= 9) { | ||
} | ||
return this.parseForIn(node, init); | ||
} | ||
if (awaitAt > -1) this.unexpected(awaitAt); | ||
return this.parseFor(node, init); | ||
} | ||
let startsWithLet = this.isContextual("let"), | ||
isForOf = false; | ||
isForOf = false; | ||
let refDestructuringErrors = new _parseutil.DestructuringErrors(); | ||
let init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors); | ||
if (this.type === _tokentype.types._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) { | ||
@@ -328,3 +277,2 @@ if (this.options.ecmaVersion >= 9) { | ||
} | ||
if (startsWithLet && isForOf) this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); | ||
@@ -337,7 +285,5 @@ this.toAssignable(init, false, refDestructuringErrors); | ||
} | ||
if (awaitAt > -1) this.unexpected(awaitAt); | ||
return this.parseFor(node, init); | ||
}; | ||
pp.parseFunctionStatement = function (node, isAsync, declarationPosition) { | ||
@@ -347,7 +293,6 @@ this.next(); | ||
}; | ||
pp.parseIfStatement = function (node) { | ||
this.next(); | ||
node.test = this.parseParenExpression(); // allow function declarations in branches, but only in non-strict mode | ||
node.test = this.parseParenExpression(); | ||
// allow function declarations in branches, but only in non-strict mode | ||
node.consequent = this.parseStatement("if"); | ||
@@ -357,6 +302,7 @@ node.alternate = this.eat(_tokentype.types._else) ? this.parseStatement("if") : null; | ||
}; | ||
pp.parseReturnStatement = function (node) { | ||
if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function"); | ||
this.next(); // In `return` (and `break`/`continue`), the keywords with | ||
this.next(); | ||
// In `return` (and `break`/`continue`), the keywords with | ||
// optional arguments, we eagerly look for a semicolon or the | ||
@@ -371,3 +317,2 @@ // possibility to insert one. | ||
}; | ||
pp.parseSwitchStatement = function (node) { | ||
@@ -379,3 +324,5 @@ this.next(); | ||
this.labels.push(switchLabel); | ||
this.enterScope(0); // Statements under must be grouped (by label) in SwitchCase | ||
this.enterScope(0); | ||
// Statements under must be grouped (by label) in SwitchCase | ||
// nodes. `cur` is used to keep the node that we are currently | ||
@@ -385,3 +332,2 @@ // adding statements to. | ||
let cur; | ||
for (let sawDefault = false; this.type !== _tokentype.types.braceR;) { | ||
@@ -394,3 +340,2 @@ if (this.type === _tokentype.types._case || this.type === _tokentype.types._default) { | ||
this.next(); | ||
if (isCase) { | ||
@@ -403,3 +348,2 @@ cur.test = this.parseExpression(); | ||
} | ||
this.expect(_tokentype.types.colon); | ||
@@ -411,11 +355,8 @@ } else { | ||
} | ||
this.exitScope(); | ||
if (cur) this.finishNode(cur, "SwitchCase"); | ||
this.next(); // Closing brace | ||
this.labels.pop(); | ||
return this.finishNode(node, "SwitchStatement"); | ||
}; | ||
pp.parseThrowStatement = function (node) { | ||
@@ -427,7 +368,7 @@ this.next(); | ||
return this.finishNode(node, "ThrowStatement"); | ||
}; // Reused empty array added for node fields that are always empty. | ||
}; | ||
// Reused empty array added for node fields that are always empty. | ||
const empty = []; | ||
pp.parseTryStatement = function (node) { | ||
@@ -437,7 +378,5 @@ this.next(); | ||
node.handler = null; | ||
if (this.type === _tokentype.types._catch) { | ||
let clause = this.startNode(); | ||
this.next(); | ||
if (this.eat(_tokentype.types.parenL)) { | ||
@@ -454,3 +393,2 @@ clause.param = this.parseBindingAtom(); | ||
} | ||
clause.body = this.parseBlock(false); | ||
@@ -460,3 +398,2 @@ this.exitScope(); | ||
} | ||
node.finalizer = this.eat(_tokentype.types._finally) ? this.parseBlock() : null; | ||
@@ -466,3 +403,2 @@ if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause"); | ||
}; | ||
pp.parseVarStatement = function (node, kind) { | ||
@@ -474,3 +410,2 @@ this.next(); | ||
}; | ||
pp.parseWhileStatement = function (node) { | ||
@@ -484,3 +419,2 @@ this.next(); | ||
}; | ||
pp.parseWithStatement = function (node) { | ||
@@ -493,3 +427,2 @@ if (this.strict) this.raise(this.start, "'with' in strict mode"); | ||
}; | ||
pp.parseEmptyStatement = function (node) { | ||
@@ -499,3 +432,2 @@ this.next(); | ||
}; | ||
pp.parseLabeledStatement = function (node, maybeName, expr, context) { | ||
@@ -506,8 +438,5 @@ for (var _iterator = _createForOfIteratorHelperLoose(this.labels), _step; !(_step = _iterator()).done;) { | ||
} | ||
let kind = this.type.isLoop ? "loop" : this.type === _tokentype.types._switch ? "switch" : null; | ||
for (let i = this.labels.length - 1; i >= 0; i--) { | ||
let label = this.labels[i]; | ||
if (label.statementStart === node.start) { | ||
@@ -519,3 +448,2 @@ // Update information about previous labels on this node | ||
} | ||
this.labels.push({ | ||
@@ -531,3 +459,2 @@ name: maybeName, | ||
}; | ||
pp.parseExpressionStatement = function (node, expr) { | ||
@@ -537,7 +464,8 @@ node.expression = expr; | ||
return this.finishNode(node, "ExpressionStatement"); | ||
}; // Parse a semicolon-enclosed block of statements, handling `"use | ||
}; | ||
// Parse a semicolon-enclosed block of statements, handling `"use | ||
// strict"` declarations when `allowStrict` is true (used for | ||
// function bodies). | ||
pp.parseBlock = function (createNewLexicalScope = true, node = this.startNode(), exitStrict) { | ||
@@ -547,3 +475,2 @@ node.body = []; | ||
if (createNewLexicalScope) this.enterScope(0); | ||
while (this.type !== _tokentype.types.braceR) { | ||
@@ -553,3 +480,2 @@ let stmt = this.parseStatement(null); | ||
} | ||
if (exitStrict) this.strict = false; | ||
@@ -559,7 +485,8 @@ this.next(); | ||
return this.finishNode(node, "BlockStatement"); | ||
}; // Parse a regular `for` loop. The disambiguation code in | ||
}; | ||
// Parse a regular `for` loop. The disambiguation code in | ||
// `parseStatement` will already have parsed the init statement or | ||
// expression. | ||
pp.parseFor = function (node, init) { | ||
@@ -576,14 +503,13 @@ node.init = init; | ||
return this.finishNode(node, "ForStatement"); | ||
}; // Parse a `for`/`in` and `for`/`of` loop, which are almost | ||
}; | ||
// Parse a `for`/`in` and `for`/`of` loop, which are almost | ||
// same from parser's perspective. | ||
pp.parseForIn = function (node, init) { | ||
const isForIn = this.type === _tokentype.types._in; | ||
this.next(); | ||
if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.options.ecmaVersion < 8 || this.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) { | ||
this.raise(init.start, `${isForIn ? "for-in" : "for-of"} loop variable declaration may not have an initializer`); | ||
} | ||
node.left = init; | ||
@@ -596,4 +522,5 @@ node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign(); | ||
return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement"); | ||
}; // Parse a list of variable declarations. | ||
}; | ||
// Parse a list of variable declarations. | ||
@@ -603,7 +530,5 @@ pp.parseVar = function (node, isFor, kind) { | ||
node.kind = kind; | ||
for (;;) { | ||
let decl = this.startNode(); | ||
this.parseVarId(decl, kind); | ||
if (this.eat(_tokentype.types.eq)) { | ||
@@ -618,10 +543,7 @@ decl.init = this.parseMaybeAssign(isFor); | ||
} | ||
node.declarations.push(this.finishNode(decl, "VariableDeclarator")); | ||
if (!this.eat(_tokentype.types.comma)) break; | ||
} | ||
return node; | ||
}; | ||
pp.parseVarId = function (decl, kind) { | ||
@@ -631,12 +553,12 @@ decl.id = this.parseBindingAtom(); | ||
}; | ||
const FUNC_STATEMENT = 1, | ||
FUNC_HANGING_STATEMENT = 2, | ||
FUNC_NULLABLE_ID = 4; | ||
const FUNC_STATEMENT = 1, | ||
FUNC_HANGING_STATEMENT = 2, | ||
FUNC_NULLABLE_ID = 4; // Parse a function declaration or literal (depending on the | ||
// Parse a function declaration or literal (depending on the | ||
// `statement & FUNC_STATEMENT`). | ||
// Remove `allowExpressionBody` for 7.0.0, as it is only called with false | ||
pp.parseFunction = function (node, statement, allowExpressionBody, isAsync, forInit) { | ||
this.initFunction(node); | ||
if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) { | ||
@@ -646,8 +568,7 @@ if (this.type === _tokentype.types.star && statement & FUNC_HANGING_STATEMENT) this.unexpected(); | ||
} | ||
if (this.options.ecmaVersion >= 8) node.async = !!isAsync; | ||
if (statement & FUNC_STATEMENT) { | ||
node.id = statement & FUNC_NULLABLE_ID && this.type !== _tokentype.types.name ? null : this.parseIdent(); | ||
if (node.id && !(statement & FUNC_HANGING_STATEMENT)) // If it is a regular function declaration in sloppy mode, then it is | ||
if (node.id && !(statement & FUNC_HANGING_STATEMENT)) | ||
// If it is a regular function declaration in sloppy mode, then it is | ||
// subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding | ||
@@ -658,6 +579,5 @@ // mode depends on properties of the current scope (see | ||
} | ||
let oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
this.yieldPos = 0; | ||
@@ -675,3 +595,2 @@ this.awaitPos = 0; | ||
}; | ||
pp.parseFunctionParams = function (node) { | ||
@@ -681,10 +600,12 @@ this.expect(_tokentype.types.parenL); | ||
this.checkYieldAwaitInDefaultParams(); | ||
}; // Parse a class declaration or literal (depending on the | ||
}; | ||
// Parse a class declaration or literal (depending on the | ||
// `isStatement` parameter). | ||
pp.parseClass = function (node, isStatement) { | ||
this.next(); | ||
pp.parseClass = function (node, isStatement) { | ||
this.next(); // ecma-262 14.6 Class Definitions | ||
// ecma-262 14.6 Class Definitions | ||
// A class definition is always strict mode code. | ||
const oldStrict = this.strict; | ||
@@ -699,9 +620,6 @@ this.strict = true; | ||
this.expect(_tokentype.types.braceL); | ||
while (this.type !== _tokentype.types.braceR) { | ||
const element = this.parseClassElement(node.superClass !== null); | ||
if (element) { | ||
classBody.body.push(element); | ||
if (element.type === "MethodDefinition" && element.kind === "constructor") { | ||
@@ -715,3 +633,2 @@ if (hadConstructor) this.raise(element.start, "Duplicate constructor in the same class"); | ||
} | ||
this.strict = oldStrict; | ||
@@ -723,3 +640,2 @@ this.next(); | ||
}; | ||
pp.parseClassElement = function (constructorAllowsSuper) { | ||
@@ -734,3 +650,2 @@ if (this.eat(_tokentype.types.semi)) return null; | ||
let isStatic = false; | ||
if (this.eatContextual("static")) { | ||
@@ -742,3 +657,2 @@ // Parse static init block | ||
} | ||
if (this.isClassElementNameStart() || this.type === _tokentype.types.star) { | ||
@@ -750,5 +664,3 @@ isStatic = true; | ||
} | ||
node.static = isStatic; | ||
if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) { | ||
@@ -761,10 +673,7 @@ if ((this.isClassElementNameStart() || this.type === _tokentype.types.star) && !this.canInsertSemicolon()) { | ||
} | ||
if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(_tokentype.types.star)) { | ||
isGenerator = true; | ||
} | ||
if (!keyName && !isAsync && !isGenerator) { | ||
const lastValue = this.value; | ||
if (this.eatContextual("get") || this.eatContextual("set")) { | ||
@@ -777,5 +686,5 @@ if (this.isClassElementNameStart()) { | ||
} | ||
} // Parse element name | ||
} | ||
// Parse element name | ||
if (keyName) { | ||
@@ -790,9 +699,9 @@ // 'async', 'get', 'set', or 'static' were not a keyword contextually. | ||
this.parseClassElementName(node); | ||
} // Parse element value | ||
} | ||
// Parse element value | ||
if (ecmaVersion < 13 || this.type === _tokentype.types.parenL || kind !== "method" || isGenerator || isAsync) { | ||
const isConstructor = !node.static && checkKeyName(node, "constructor"); | ||
const allowsDirectSuper = isConstructor && constructorAllowsSuper; // Couldn't move this check into the 'parseClassMethod' method for backward compatibility. | ||
const allowsDirectSuper = isConstructor && constructorAllowsSuper; | ||
// Couldn't move this check into the 'parseClassMethod' method for backward compatibility. | ||
if (isConstructor && kind !== "method") this.raise(node.key.start, "Constructor can't have get/set modifier"); | ||
@@ -804,10 +713,7 @@ node.kind = isConstructor ? "constructor" : kind; | ||
} | ||
return node; | ||
}; | ||
pp.isClassElementNameStart = function () { | ||
return this.type === _tokentype.types.name || this.type === _tokentype.types.privateId || this.type === _tokentype.types.num || this.type === _tokentype.types.string || this.type === _tokentype.types.bracketL || this.type.keyword; | ||
}; | ||
pp.parseClassElementName = function (element) { | ||
@@ -818,3 +724,2 @@ if (this.type === _tokentype.types.privateId) { | ||
} | ||
element.computed = false; | ||
@@ -826,7 +731,5 @@ element.key = this.parsePrivateIdent(); | ||
}; | ||
pp.parseClassMethod = function (method, isGenerator, isAsync, allowsDirectSuper) { | ||
// Check key and flags | ||
const key = method.key; | ||
if (method.kind === "constructor") { | ||
@@ -837,7 +740,8 @@ if (isGenerator) this.raise(key.start, "Constructor can't be a generator"); | ||
this.raise(key.start, "Classes may not have a static property named prototype"); | ||
} // Parse value | ||
} | ||
// Parse value | ||
const value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper); | ||
const value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper); // Check value | ||
// Check value | ||
if (method.kind === "get" && value.params.length !== 0) this.raiseRecoverable(value.start, "getter should have no params"); | ||
@@ -848,3 +752,2 @@ if (method.kind === "set" && value.params.length !== 1) this.raiseRecoverable(value.start, "setter should have exactly one param"); | ||
}; | ||
pp.parseClassField = function (field) { | ||
@@ -856,3 +759,2 @@ if (checkKeyName(field, "constructor")) { | ||
} | ||
if (this.eat(_tokentype.types.eq)) { | ||
@@ -868,7 +770,5 @@ // To raise SyntaxError if 'arguments' exists in the initializer. | ||
} | ||
this.semicolon(); | ||
return this.finishNode(field, "PropertyDefinition"); | ||
}; | ||
pp.parseClassStaticBlock = function (node) { | ||
@@ -879,3 +779,2 @@ node.body = []; | ||
this.enterScope(_scopeflags.SCOPE_CLASS_STATIC_BLOCK | _scopeflags.SCOPE_SUPER); | ||
while (this.type !== _tokentype.types.braceR) { | ||
@@ -885,3 +784,2 @@ let stmt = this.parseStatement(null); | ||
} | ||
this.next(); | ||
@@ -892,3 +790,2 @@ this.exitScope(); | ||
}; | ||
pp.parseClassId = function (node, isStatement) { | ||
@@ -903,7 +800,5 @@ if (this.type === _tokentype.types.name) { | ||
}; | ||
pp.parseClassSuper = function (node) { | ||
node.superClass = this.eat(_tokentype.types._extends) ? this.parseExprSubscripts(false) : null; | ||
}; | ||
pp.enterClassBody = function () { | ||
@@ -917,14 +812,10 @@ const element = { | ||
}; | ||
pp.exitClassBody = function () { | ||
const _this$privateNameStac = this.privateNameStack.pop(), | ||
declared = _this$privateNameStac.declared, | ||
used = _this$privateNameStac.used; | ||
declared = _this$privateNameStac.declared, | ||
used = _this$privateNameStac.used; | ||
const len = this.privateNameStack.length; | ||
const parent = len === 0 ? null : this.privateNameStack[len - 1]; | ||
for (let i = 0; i < used.length; ++i) { | ||
const id = used[i]; | ||
if (!(0, _util.hasOwn)(declared, id.name)) { | ||
@@ -939,3 +830,2 @@ if (parent) { | ||
}; | ||
function isPrivateNameConflicted(privateNameMap, element) { | ||
@@ -945,8 +835,7 @@ const name = element.key.name; | ||
let next = "true"; | ||
if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) { | ||
next = (element.static ? "s" : "i") + element.kind; | ||
} // `class { get #a(){}; static set #a(_){} }` is also conflict. | ||
} | ||
// `class { get #a(){}; static set #a(_){} }` is also conflict. | ||
if (curr === "iget" && next === "iset" || curr === "iset" && next === "iget" || curr === "sget" && next === "sset" || curr === "sset" && next === "sget") { | ||
@@ -962,13 +851,13 @@ privateNameMap[name] = "true"; | ||
} | ||
function checkKeyName(node, name) { | ||
const computed = node.computed, | ||
key = node.key; | ||
key = node.key; | ||
return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name); | ||
} // Parses module export declaration. | ||
} | ||
// Parses module export declaration. | ||
pp.parseExport = function (node, exports) { | ||
this.next(); // export * from '...' | ||
this.next(); | ||
// export * from '...' | ||
if (this.eat(_tokentype.types.star)) { | ||
@@ -983,3 +872,2 @@ if (this.options.ecmaVersion >= 11) { | ||
} | ||
this.expectContextual("from"); | ||
@@ -991,3 +879,2 @@ if (this.type !== _tokentype.types.string) this.unexpected(); | ||
} | ||
if (this.eat(_tokentype.types._default)) { | ||
@@ -997,3 +884,2 @@ // export default ... | ||
let isAsync; | ||
if (this.type === _tokentype.types._function || (isAsync = this.isAsyncFunction())) { | ||
@@ -1011,7 +897,5 @@ let fNode = this.startNode(); | ||
} | ||
return this.finishNode(node, "ExportDefaultDeclaration"); | ||
} // export var|const|let|function|class ... | ||
} | ||
// export var|const|let|function|class ... | ||
if (this.shouldParseExportStatement()) { | ||
@@ -1026,3 +910,2 @@ node.declaration = this.parseStatement(null); | ||
node.specifiers = this.parseExportSpecifiers(exports); | ||
if (this.eatContextual("from")) { | ||
@@ -1035,6 +918,5 @@ if (this.type !== _tokentype.types.string) this.unexpected(); | ||
// check for keywords used as local names | ||
this.checkUnreserved(spec.local); // check if export is defined | ||
this.checkUnreserved(spec.local); | ||
// check if export is defined | ||
this.checkLocalExport(spec.local); | ||
if (spec.local.type === "Literal") { | ||
@@ -1044,12 +926,8 @@ this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`."); | ||
} | ||
node.source = null; | ||
} | ||
this.semicolon(); | ||
} | ||
return this.finishNode(node, "ExportNamedDeclaration"); | ||
}; | ||
pp.checkExport = function (exports, name, pos) { | ||
@@ -1060,3 +938,2 @@ if (!exports) return; | ||
}; | ||
pp.checkPatternExport = function (exports, pat) { | ||
@@ -1076,6 +953,4 @@ let type = pat.type; | ||
}; | ||
pp.checkVariableExport = function (exports, decls) { | ||
if (!exports) return; | ||
for (var _iterator5 = _createForOfIteratorHelperLoose(decls), _step5; !(_step5 = _iterator5()).done;) { | ||
@@ -1086,14 +961,13 @@ let decl = _step5.value; | ||
}; | ||
pp.shouldParseExportStatement = function () { | ||
return this.type.keyword === "var" || this.type.keyword === "const" || this.type.keyword === "class" || this.type.keyword === "function" || this.isLet() || this.isAsyncFunction(); | ||
}; // Parses a comma-separated list of module exports. | ||
}; | ||
// Parses a comma-separated list of module exports. | ||
pp.parseExportSpecifiers = function (exports) { | ||
let nodes = [], | ||
first = true; // export { x, y as z } [from '...'] | ||
first = true; | ||
// export { x, y as z } [from '...'] | ||
this.expect(_tokentype.types.braceL); | ||
while (!this.eat(_tokentype.types.braceR)) { | ||
@@ -1104,3 +978,2 @@ if (!first) { | ||
} else first = false; | ||
let node = this.startNode(); | ||
@@ -1112,10 +985,10 @@ node.local = this.parseModuleExportName(); | ||
} | ||
return nodes; | ||
}; // Parses import declaration. | ||
}; | ||
// Parses import declaration. | ||
pp.parseImport = function (node) { | ||
this.next(); // import '...' | ||
this.next(); | ||
// import '...' | ||
if (this.type === _tokentype.types.string) { | ||
@@ -1129,12 +1002,11 @@ node.specifiers = empty; | ||
} | ||
this.semicolon(); | ||
return this.finishNode(node, "ImportDeclaration"); | ||
}; // Parses a comma-separated list of module imports. | ||
}; | ||
// Parses a comma-separated list of module imports. | ||
pp.parseImportSpecifiers = function () { | ||
let nodes = [], | ||
first = true; | ||
first = true; | ||
if (this.type === _tokentype.types.name) { | ||
@@ -1148,3 +1020,2 @@ // import defaultObj, { x, y as z } from '...' | ||
} | ||
if (this.type === _tokentype.types.star) { | ||
@@ -1159,5 +1030,3 @@ let node = this.startNode(); | ||
} | ||
this.expect(_tokentype.types.braceL); | ||
while (!this.eat(_tokentype.types.braceR)) { | ||
@@ -1168,6 +1037,4 @@ if (!first) { | ||
} else first = false; | ||
let node = this.startNode(); | ||
node.imported = this.parseModuleExportName(); | ||
if (this.eatContextual("as")) { | ||
@@ -1179,25 +1046,19 @@ node.local = this.parseIdent(); | ||
} | ||
this.checkLValSimple(node.local, _scopeflags.BIND_LEXICAL); | ||
nodes.push(this.finishNode(node, "ImportSpecifier")); | ||
} | ||
return nodes; | ||
}; | ||
pp.parseModuleExportName = function () { | ||
if (this.options.ecmaVersion >= 13 && this.type === _tokentype.types.string) { | ||
const stringLiteral = this.parseLiteral(this.value); | ||
if (_util.loneSurrogate.test(stringLiteral.value)) { | ||
this.raise(stringLiteral.start, "An export name cannot include a lone surrogate."); | ||
} | ||
return stringLiteral; | ||
} | ||
return this.parseIdent(true); | ||
}; // Set `ExpressionStatement#directive` property for directive prologues. | ||
}; | ||
// Set `ExpressionStatement#directive` property for directive prologues. | ||
pp.adaptDirectivePrologue = function (statements) { | ||
@@ -1208,6 +1069,6 @@ for (let i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) { | ||
}; | ||
pp.isDirectiveCandidate = function (statement) { | ||
return statement.type === "ExpressionStatement" && statement.expression.type === "Literal" && typeof statement.expression.value === "string" && ( // Reject parenthesized strings. | ||
return statement.type === "ExpressionStatement" && statement.expression.type === "Literal" && typeof statement.expression.value === "string" && ( | ||
// Reject parenthesized strings. | ||
this.input[statement.start] === "\"" || this.input[statement.start] === "'"); | ||
}; |
@@ -5,12 +5,9 @@ "use strict"; | ||
exports.types = exports.TokContext = void 0; | ||
var _state = require("./state.js"); | ||
var _tokentype = require("./tokentype.js"); | ||
var _whitespace = require("./whitespace.js"); | ||
// The algorithm used to determine whether a regexp can appear at a | ||
// given point in the program is loosely based on sweet.js' approach. | ||
// See https://github.com/mozilla/sweet.js/wiki/design | ||
class TokContext { | ||
@@ -24,5 +21,3 @@ constructor(token, isExpr, preserveSpace, override, generator) { | ||
} | ||
} | ||
exports.TokContext = TokContext; | ||
@@ -43,18 +38,16 @@ const types = { | ||
const pp = _state.Parser.prototype; | ||
pp.initialContext = function () { | ||
return [types.b_stat]; | ||
}; | ||
pp.curContext = function () { | ||
return this.context[this.context.length - 1]; | ||
}; | ||
pp.braceIsBlock = function (prevType) { | ||
let parent = this.curContext(); | ||
if (parent === types.f_expr || parent === types.f_stat) return true; | ||
if (prevType === _tokentype.types.colon && (parent === types.b_stat || parent === types.b_expr)) return !parent.isExpr; // The check for `tt.name && exprAllowed` detects whether we are | ||
if (prevType === _tokentype.types.colon && (parent === types.b_stat || parent === types.b_expr)) return !parent.isExpr; | ||
// The check for `tt.name && exprAllowed` detects whether we are | ||
// after a `yield` or `of` construct. See the `updateContext` for | ||
// `tt.name`. | ||
if (prevType === _tokentype.types._return || prevType === _tokentype.types.name && this.exprAllowed) return _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); | ||
@@ -66,3 +59,2 @@ if (prevType === _tokentype.types._else || prevType === _tokentype.types.semi || prevType === _tokentype.types.eof || prevType === _tokentype.types.parenR || prevType === _tokentype.types.arrow) return true; | ||
}; | ||
pp.inGeneratorContext = function () { | ||
@@ -73,13 +65,11 @@ for (let i = this.context.length - 1; i >= 1; i--) { | ||
} | ||
return false; | ||
}; | ||
pp.updateContext = function (prevType) { | ||
let update, | ||
type = this.type; | ||
type = this.type; | ||
if (type.keyword && prevType === _tokentype.types.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr; | ||
}; // Used to handle egde case when token context could not be inferred correctly in tokenize phase | ||
}; | ||
// Used to handle egde case when token context could not be inferred correctly in tokenize phase | ||
pp.overrideContext = function (tokenCtx) { | ||
@@ -89,4 +79,5 @@ if (this.curContext() !== tokenCtx) { | ||
} | ||
}; // Token-specific context update code | ||
}; | ||
// Token-specific context update code | ||
@@ -98,12 +89,8 @@ _tokentype.types.parenR.updateContext = _tokentype.types.braceR.updateContext = function () { | ||
} | ||
let out = this.context.pop(); | ||
if (out === types.b_stat && this.curContext().token === "function") { | ||
out = this.context.pop(); | ||
} | ||
this.exprAllowed = !out.isExpr; | ||
}; | ||
_tokentype.types.braceL.updateContext = function (prevType) { | ||
@@ -113,3 +100,2 @@ this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr); | ||
}; | ||
_tokentype.types.dollarBraceL.updateContext = function () { | ||
@@ -119,3 +105,2 @@ this.context.push(types.b_tmpl); | ||
}; | ||
_tokentype.types.parenL.updateContext = function (prevType) { | ||
@@ -126,6 +111,5 @@ let statementParens = prevType === _tokentype.types._if || prevType === _tokentype.types._for || prevType === _tokentype.types._with || prevType === _tokentype.types._while; | ||
}; | ||
_tokentype.types.incDec.updateContext = function () {// tokExprAllowed stays unchanged | ||
_tokentype.types.incDec.updateContext = function () { | ||
// tokExprAllowed stays unchanged | ||
}; | ||
_tokentype.types._function.updateContext = _tokentype.types._class.updateContext = function (prevType) { | ||
@@ -135,3 +119,2 @@ if (prevType.beforeExpr && prevType !== _tokentype.types._else && !(prevType === _tokentype.types.semi && this.curContext() !== types.p_stat) && !(prevType === _tokentype.types._return && _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) && !((prevType === _tokentype.types.colon || prevType === _tokentype.types.braceL) && this.curContext() === types.b_stat)) this.context.push(types.f_expr);else this.context.push(types.f_stat); | ||
}; | ||
_tokentype.types.backQuote.updateContext = function () { | ||
@@ -141,3 +124,2 @@ if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl); | ||
}; | ||
_tokentype.types.star.updateContext = function (prevType) { | ||
@@ -148,14 +130,10 @@ if (prevType === _tokentype.types._function) { | ||
} | ||
this.exprAllowed = true; | ||
}; | ||
_tokentype.types.name.updateContext = function (prevType) { | ||
let allowed = false; | ||
if (this.options.ecmaVersion >= 6 && prevType !== _tokentype.types.dot) { | ||
if (this.value === "of" && !this.exprAllowed || this.value === "yield" && this.inGeneratorContext()) allowed = true; | ||
} | ||
this.exprAllowed = allowed; | ||
}; |
@@ -5,18 +5,12 @@ "use strict"; | ||
exports.Token = void 0; | ||
var _identifier = require("./identifier.js"); | ||
var _tokentype = require("./tokentype.js"); | ||
var _state = require("./state.js"); | ||
var _locutil = require("./locutil.js"); | ||
var _regexp = require("./regexp.js"); | ||
var _whitespace = require("./whitespace.js"); | ||
// Object type used to represent tokens. Note that normally, tokens | ||
// simply exist as properties on the parser object. This is only | ||
// used for the onToken callback and the external tokenizer. | ||
class Token { | ||
@@ -31,9 +25,10 @@ constructor(p) { | ||
} | ||
} | ||
} // ## Tokenizer | ||
// ## Tokenizer | ||
exports.Token = Token; | ||
const pp = _state.Parser.prototype; | ||
// Move to the next token | ||
exports.Token = Token; | ||
const pp = _state.Parser.prototype; // Move to the next token | ||
pp.next = function (ignoreEscapeSequenceInKeyword) { | ||
@@ -48,9 +43,8 @@ if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); | ||
}; | ||
pp.getToken = function () { | ||
this.next(); | ||
return new Token(this); | ||
}; // If we're in an ES6 environment, make parsers iterable | ||
}; | ||
// If we're in an ES6 environment, make parsers iterable | ||
if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () { | ||
@@ -66,4 +60,7 @@ return { | ||
}; | ||
}; // Toggle strict mode. Re-reads the next number or string to please | ||
}; | ||
// Toggle strict mode. Re-reads the next number or string to please | ||
// pedantic tests (`"use strict"; 010;` should fail). | ||
// Read a single token, updating the parser object's token-related | ||
@@ -80,12 +77,8 @@ // properties. | ||
}; | ||
pp.readToken = function (code) { | ||
// Identifier or keyword. '\uXXXX' sequences are allowed in | ||
// identifiers, so '\' also dispatches to that. | ||
if ((0, _identifier.isIdentifierStart)(code, this.options.ecmaVersion >= 6) || code === 92 | ||
/* '\' */ | ||
) return this.readWord(); | ||
if ((0, _identifier.isIdentifierStart)(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord(); | ||
return this.getTokenFromCode(code); | ||
}; | ||
pp.fullCharCodeAtPos = function () { | ||
@@ -97,10 +90,8 @@ let code = this.input.charCodeAt(this.pos); | ||
}; | ||
pp.skipBlockComment = function () { | ||
let startLoc = this.options.onComment && this.curPosition(); | ||
let start = this.pos, | ||
end = this.input.indexOf("*/", this.pos += 2); | ||
end = this.input.indexOf("*/", this.pos += 2); | ||
if (end === -1) this.raise(this.pos - 2, "Unterminated comment"); | ||
this.pos = end + 2; | ||
if (this.options.locations) { | ||
@@ -112,6 +103,4 @@ for (let nextBreak, pos = start; (nextBreak = (0, _whitespace.nextLineBreak)(this.input, pos, this.pos)) > -1;) { | ||
} | ||
if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition()); | ||
}; | ||
pp.skipLineComment = function (startSkip) { | ||
@@ -121,16 +110,14 @@ let start = this.pos; | ||
let ch = this.input.charCodeAt(this.pos += startSkip); | ||
while (this.pos < this.input.length && !(0, _whitespace.isNewLine)(ch)) { | ||
ch = this.input.charCodeAt(++this.pos); | ||
} | ||
if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition()); | ||
}; | ||
if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition()); | ||
}; // Called at the start of the parse and after every token. Skips | ||
// Called at the start of the parse and after every token. Skips | ||
// whitespace and comments, and. | ||
pp.skipSpace = function () { | ||
loop: while (this.pos < this.input.length) { | ||
let ch = this.input.charCodeAt(this.pos); | ||
switch (ch) { | ||
@@ -142,3 +129,2 @@ case 32: | ||
break; | ||
case 13: | ||
@@ -148,3 +134,2 @@ if (this.input.charCodeAt(this.pos + 1) === 10) { | ||
} | ||
case 10: | ||
@@ -154,3 +139,2 @@ case 8232: | ||
++this.pos; | ||
if (this.options.locations) { | ||
@@ -160,5 +144,3 @@ ++this.curLine; | ||
} | ||
break; | ||
case 47: | ||
@@ -171,13 +153,9 @@ // '/' | ||
break; | ||
case 47: | ||
this.skipLineComment(2); | ||
break; | ||
default: | ||
break loop; | ||
} | ||
break; | ||
default: | ||
@@ -189,6 +167,7 @@ if (ch > 8 && ch < 14 || ch >= 5760 && _whitespace.nonASCIIwhitespace.test(String.fromCharCode(ch))) { | ||
} | ||
} | ||
} | ||
}; // Called at the end of every token. Sets `end`, `val`, and | ||
}; | ||
// Called at the end of every token. Sets `end`, `val`, and | ||
// maintains `context` and `exprAllowed`, and skips the space after | ||
@@ -198,3 +177,2 @@ // the token, so that the next one's `start` will point at the | ||
pp.finishToken = function (type, val) { | ||
@@ -207,3 +185,6 @@ this.end = this.pos; | ||
this.updateContext(prevType); | ||
}; // ### Token reading | ||
}; | ||
// ### Token reading | ||
// This is the function that is called to fetch the next token. It | ||
@@ -216,4 +197,2 @@ // is somewhat obscure, because it works in character codes rather | ||
// | ||
pp.readToken_dot = function () { | ||
@@ -223,3 +202,2 @@ let next = this.input.charCodeAt(this.pos + 1); | ||
let next2 = this.input.charCodeAt(this.pos + 2); | ||
if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { | ||
@@ -234,7 +212,5 @@ // 46 = dot '.' | ||
}; | ||
pp.readToken_slash = function () { | ||
// '/' | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (this.exprAllowed) { | ||
@@ -244,7 +220,5 @@ ++this.pos; | ||
} | ||
if (next === 61) return this.finishOp(_tokentype.types.assign, 2); | ||
return this.finishOp(_tokentype.types.slash, 1); | ||
}; | ||
pp.readToken_mult_modulo_exp = function (code) { | ||
@@ -254,4 +228,5 @@ // '%*' | ||
let size = 1; | ||
let tokentype = code === 42 ? _tokentype.types.star : _tokentype.types.modulo; // exponentiation operator ** and **= | ||
let tokentype = code === 42 ? _tokentype.types.star : _tokentype.types.modulo; | ||
// exponentiation operator ** and **= | ||
if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) { | ||
@@ -262,11 +237,8 @@ ++size; | ||
} | ||
if (next === 61) return this.finishOp(_tokentype.types.assign, size + 1); | ||
return this.finishOp(tokentype, size); | ||
}; | ||
pp.readToken_pipe_amp = function (code) { | ||
// '|&' | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (next === code) { | ||
@@ -277,10 +249,7 @@ if (this.options.ecmaVersion >= 12) { | ||
} | ||
return this.finishOp(code === 124 ? _tokentype.types.logicalOR : _tokentype.types.logicalAND, 2); | ||
} | ||
if (next === 61) return this.finishOp(_tokentype.types.assign, 2); | ||
return this.finishOp(code === 124 ? _tokentype.types.bitwiseOR : _tokentype.types.bitwiseAND, 1); | ||
}; | ||
pp.readToken_caret = function () { | ||
@@ -292,7 +261,5 @@ // '^' | ||
}; | ||
pp.readToken_plus_min = function (code) { | ||
// '+-' | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (next === code) { | ||
@@ -305,10 +272,7 @@ if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 && (this.lastTokEnd === 0 || _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) { | ||
} | ||
return this.finishOp(_tokentype.types.incDec, 2); | ||
} | ||
if (next === 61) return this.finishOp(_tokentype.types.assign, 2); | ||
return this.finishOp(_tokentype.types.plusMin, 1); | ||
}; | ||
pp.readToken_lt_gt = function (code) { | ||
@@ -318,3 +282,2 @@ // '<>' | ||
let size = 1; | ||
if (next === code) { | ||
@@ -325,3 +288,2 @@ size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2; | ||
} | ||
if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 && this.input.charCodeAt(this.pos + 3) === 45) { | ||
@@ -333,7 +295,5 @@ // `<!--`, an XML-style comment that should be interpreted as a line comment | ||
} | ||
if (next === 61) size = 2; | ||
return this.finishOp(_tokentype.types.relational, size); | ||
}; | ||
pp.readToken_eq_excl = function (code) { | ||
@@ -343,3 +303,2 @@ // '=!' | ||
if (next === 61) return this.finishOp(_tokentype.types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2); | ||
if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { | ||
@@ -350,13 +309,9 @@ // '=>' | ||
} | ||
return this.finishOp(code === 61 ? _tokentype.types.eq : _tokentype.types.prefix, 1); | ||
}; | ||
pp.readToken_question = function () { | ||
// '?' | ||
const ecmaVersion = this.options.ecmaVersion; | ||
if (ecmaVersion >= 11) { | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (next === 46) { | ||
@@ -366,3 +321,2 @@ let next2 = this.input.charCodeAt(this.pos + 2); | ||
} | ||
if (next === 63) { | ||
@@ -373,10 +327,7 @@ if (ecmaVersion >= 12) { | ||
} | ||
return this.finishOp(_tokentype.types.coalesce, 2); | ||
} | ||
} | ||
return this.finishOp(_tokentype.types.question, 1); | ||
}; | ||
pp.readToken_numberSign = function () { | ||
@@ -386,17 +337,11 @@ // '#' | ||
let code = 35; // '#' | ||
if (ecmaVersion >= 13) { | ||
++this.pos; | ||
code = this.fullCharCodeAtPos(); | ||
if ((0, _identifier.isIdentifierStart)(code, true) || code === 92 | ||
/* '\' */ | ||
) { | ||
if ((0, _identifier.isIdentifierStart)(code, true) || code === 92 /* '\' */) { | ||
return this.finishToken(_tokentype.types.privateId, this.readWord1()); | ||
} | ||
} | ||
this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'"); | ||
}; | ||
pp.getTokenFromCode = function (code) { | ||
@@ -409,40 +354,31 @@ switch (code) { | ||
return this.readToken_dot(); | ||
// Punctuation tokens. | ||
case 40: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.parenL); | ||
case 41: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.parenR); | ||
case 59: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.semi); | ||
case 44: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.comma); | ||
case 91: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.bracketL); | ||
case 93: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.bracketR); | ||
case 123: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.braceL); | ||
case 125: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.braceR); | ||
case 58: | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.colon); | ||
case 96: | ||
@@ -453,3 +389,2 @@ // '`' | ||
return this.finishToken(_tokentype.types.backQuote); | ||
case 48: | ||
@@ -459,6 +394,4 @@ // '0' | ||
if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number | ||
if (this.options.ecmaVersion >= 6) { | ||
if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number | ||
if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number | ||
@@ -469,3 +402,2 @@ } | ||
// number, or float. | ||
case 49: | ||
@@ -482,4 +414,4 @@ case 50: | ||
return this.readNumber(false); | ||
// Quotes produce strings. | ||
case 34: | ||
@@ -489,2 +421,3 @@ case 39: | ||
return this.readString(code); | ||
// Operators are parsed inline in tiny state machines. '=' (61) is | ||
@@ -494,7 +427,5 @@ // often referred to. `finishOp` simply skips the amount of | ||
// of the type given by its first argument. | ||
case 47: | ||
// '/' | ||
return this.readToken_slash(); | ||
case 37: | ||
@@ -504,3 +435,2 @@ case 42: | ||
return this.readToken_mult_modulo_exp(code); | ||
case 124: | ||
@@ -510,7 +440,5 @@ case 38: | ||
return this.readToken_pipe_amp(code); | ||
case 94: | ||
// '^' | ||
return this.readToken_caret(); | ||
case 43: | ||
@@ -520,3 +448,2 @@ case 45: | ||
return this.readToken_plus_min(code); | ||
case 60: | ||
@@ -526,3 +453,2 @@ case 62: | ||
return this.readToken_lt_gt(code); | ||
case 61: | ||
@@ -532,11 +458,8 @@ case 33: | ||
return this.readToken_eq_excl(code); | ||
case 63: | ||
// '?' | ||
return this.readToken_question(); | ||
case 126: | ||
// '~' | ||
return this.finishOp(_tokentype.types.prefix, 1); | ||
case 35: | ||
@@ -546,6 +469,4 @@ // '#' | ||
} | ||
this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'"); | ||
}; | ||
pp.finishOp = function (type, size) { | ||
@@ -556,8 +477,6 @@ let str = this.input.slice(this.pos, this.pos + size); | ||
}; | ||
pp.readRegexp = function () { | ||
let escaped, | ||
inClass, | ||
start = this.pos; | ||
inClass, | ||
start = this.pos; | ||
for (;;) { | ||
@@ -567,3 +486,2 @@ if (this.pos >= this.input.length) this.raise(start, "Unterminated regular expression"); | ||
if (_whitespace.lineBreak.test(ch)) this.raise(start, "Unterminated regular expression"); | ||
if (!escaped) { | ||
@@ -573,6 +491,4 @@ if (ch === "[") inClass = true;else if (ch === "]" && inClass) inClass = false;else if (ch === "/" && !inClass) break; | ||
} else escaped = false; | ||
++this.pos; | ||
} | ||
let pattern = this.input.slice(start, this.pos); | ||
@@ -582,17 +498,18 @@ ++this.pos; | ||
let flags = this.readWord1(); | ||
if (this.containsEsc) this.unexpected(flagsStart); // Validate pattern | ||
if (this.containsEsc) this.unexpected(flagsStart); | ||
// Validate pattern | ||
const state = this.regexpState || (this.regexpState = new _regexp.RegExpValidationState(this)); | ||
state.reset(start, pattern, flags); | ||
this.validateRegExpFlags(state); | ||
this.validateRegExpPattern(state); // Create Literal#value property value. | ||
this.validateRegExpPattern(state); | ||
// Create Literal#value property value. | ||
let value = null; | ||
try { | ||
value = new RegExp(pattern, flags); | ||
} catch (e) {// ESTree requires null if it failed to instantiate RegExp object. | ||
} catch (e) { | ||
// ESTree requires null if it failed to instantiate RegExp object. | ||
// https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral | ||
} | ||
return this.finishToken(_tokentype.types.regexp, { | ||
@@ -603,22 +520,22 @@ pattern, | ||
}); | ||
}; // Read an integer in the given radix. Return null if zero digits | ||
}; | ||
// Read an integer in the given radix. Return null if zero digits | ||
// were read, the integer value otherwise. When `len` is given, this | ||
// will return `null` unless the integer has exactly `len` digits. | ||
pp.readInt = function (radix, len, maybeLegacyOctalNumericLiteral) { | ||
// `len` is used for character escape sequences. In that case, disallow separators. | ||
const allowSeparators = this.options.ecmaVersion >= 12 && len === undefined; // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b) | ||
const allowSeparators = this.options.ecmaVersion >= 12 && len === undefined; | ||
// `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b) | ||
// and isn't fraction part nor exponent part. In that case, if the first digit | ||
// is zero then disallow separators. | ||
const isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48; | ||
let start = this.pos, | ||
total = 0, | ||
lastCode = 0; | ||
total = 0, | ||
lastCode = 0; | ||
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) { | ||
let code = this.input.charCodeAt(this.pos), | ||
val; | ||
val; | ||
if (allowSeparators && code === 95) { | ||
@@ -631,3 +548,2 @@ if (isLegacyOctalNumericLiteral) this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); | ||
} | ||
if (code >= 97) val = code - 97 + 10; // a | ||
@@ -641,3 +557,2 @@ else if (code >= 65) val = code - 65 + 10; // A | ||
} | ||
if (allowSeparators && lastCode === 95) this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); | ||
@@ -647,28 +562,23 @@ if (this.pos === start || len != null && this.pos - start !== len) return null; | ||
}; | ||
function stringToNumber(str, isLegacyOctalNumericLiteral) { | ||
if (isLegacyOctalNumericLiteral) { | ||
return parseInt(str, 8); | ||
} // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value. | ||
} | ||
// `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value. | ||
return parseFloat(str.replace(/_/g, "")); | ||
} | ||
function stringToBigInt(str) { | ||
if (typeof BigInt !== "function") { | ||
return null; | ||
} // `BigInt(value)` throws syntax error if the string contains numeric separators. | ||
} | ||
// `BigInt(value)` throws syntax error if the string contains numeric separators. | ||
return BigInt(str.replace(/_/g, "")); | ||
} | ||
pp.readRadixNumber = function (radix) { | ||
let start = this.pos; | ||
this.pos += 2; // 0x | ||
let val = this.readInt(radix); | ||
if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix); | ||
if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) { | ||
@@ -678,6 +588,6 @@ val = stringToBigInt(this.input.slice(start, this.pos)); | ||
} else if ((0, _identifier.isIdentifierStart)(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number"); | ||
return this.finishToken(_tokentype.types.num, val); | ||
}; // Read an integer, octal integer, or floating-point number. | ||
}; | ||
// Read an integer, octal integer, or floating-point number. | ||
@@ -690,3 +600,2 @@ pp.readNumber = function (startsWithDot) { | ||
let next = this.input.charCodeAt(this.pos); | ||
if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) { | ||
@@ -698,5 +607,3 @@ let val = stringToBigInt(this.input.slice(start, this.pos)); | ||
} | ||
if (octal && /[89]/.test(this.input.slice(start, this.pos))) octal = false; | ||
if (next === 46 && !octal) { | ||
@@ -708,3 +615,2 @@ // '.' | ||
} | ||
if ((next === 69 || next === 101) && !octal) { | ||
@@ -714,16 +620,14 @@ // 'eE' | ||
if (next === 43 || next === 45) ++this.pos; // '+-' | ||
if (this.readInt(10) === null) this.raise(start, "Invalid number"); | ||
} | ||
if ((0, _identifier.isIdentifierStart)(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number"); | ||
let val = stringToNumber(this.input.slice(start, this.pos), octal); | ||
return this.finishToken(_tokentype.types.num, val); | ||
}; // Read a string value, interpreting backslash-escapes. | ||
}; | ||
// Read a string value, interpreting backslash-escapes. | ||
pp.readCodePoint = function () { | ||
let ch = this.input.charCodeAt(this.pos), | ||
code; | ||
code; | ||
if (ch === 123) { | ||
@@ -739,6 +643,4 @@ // '{' | ||
} | ||
return code; | ||
}; | ||
function codePointToString(code) { | ||
@@ -750,7 +652,5 @@ // UTF-16 Decoding | ||
} | ||
pp.readString = function (quote) { | ||
let out = "", | ||
chunkStart = ++this.pos; | ||
chunkStart = ++this.pos; | ||
for (;;) { | ||
@@ -760,3 +660,2 @@ if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant"); | ||
if (ch === quote) break; | ||
if (ch === 92) { | ||
@@ -770,3 +669,2 @@ // '\' | ||
++this.pos; | ||
if (this.options.locations) { | ||
@@ -781,13 +679,11 @@ this.curLine++; | ||
} | ||
out += this.input.slice(chunkStart, this.pos++); | ||
return this.finishToken(_tokentype.types.string, out); | ||
}; // Reads template string tokens. | ||
}; | ||
// Reads template string tokens. | ||
const INVALID_TEMPLATE_ESCAPE_ERROR = {}; | ||
pp.tryReadTemplateToken = function () { | ||
this.inTemplateElement = true; | ||
try { | ||
@@ -802,6 +698,4 @@ this.readTmplToken(); | ||
} | ||
this.inTemplateElement = false; | ||
}; | ||
pp.invalidStringToken = function (position, message) { | ||
@@ -814,11 +708,8 @@ if (this.inTemplateElement && this.options.ecmaVersion >= 9) { | ||
}; | ||
pp.readTmplToken = function () { | ||
let out = "", | ||
chunkStart = this.pos; | ||
chunkStart = this.pos; | ||
for (;;) { | ||
if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template"); | ||
let ch = this.input.charCodeAt(this.pos); | ||
if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { | ||
@@ -835,7 +726,5 @@ // '`', '${' | ||
} | ||
out += this.input.slice(chunkStart, this.pos); | ||
return this.finishToken(_tokentype.types.template, out); | ||
} | ||
if (ch === 92) { | ||
@@ -849,11 +738,8 @@ // '\' | ||
++this.pos; | ||
switch (ch) { | ||
case 13: | ||
if (this.input.charCodeAt(this.pos) === 10) ++this.pos; | ||
case 10: | ||
out += "\n"; | ||
break; | ||
default: | ||
@@ -863,3 +749,2 @@ out += String.fromCharCode(ch); | ||
} | ||
if (this.options.locations) { | ||
@@ -869,3 +754,2 @@ ++this.curLine; | ||
} | ||
chunkStart = this.pos; | ||
@@ -876,5 +760,5 @@ } else { | ||
} | ||
}; // Reads a template token to search for the end, without validating any escape sequences | ||
}; | ||
// Reads a template token to search for the end, without validating any escape sequences | ||
pp.readInvalidTemplateToken = function () { | ||
@@ -886,3 +770,2 @@ for (; this.pos < this.input.length; this.pos++) { | ||
break; | ||
case "$": | ||
@@ -894,5 +777,5 @@ if (this.input[this.pos + 1] !== "{") { | ||
// falls through | ||
case "`": | ||
return this.finishToken(_tokentype.types.invalidTemplate, this.input.slice(this.start, this.pos)); | ||
// no default | ||
@@ -903,4 +786,5 @@ } | ||
this.raise(this.start, "Unterminated template"); | ||
}; // Used to read escaped characters | ||
}; | ||
// Used to read escaped characters | ||
@@ -910,3 +794,2 @@ pp.readEscapedChar = function (inTemplate) { | ||
++this.pos; | ||
switch (ch) { | ||
@@ -916,35 +799,26 @@ case 110: | ||
// 'n' -> '\n' | ||
case 114: | ||
return "\r"; | ||
// 'r' -> '\r' | ||
case 120: | ||
return String.fromCharCode(this.readHexChar(2)); | ||
// 'x' | ||
case 117: | ||
return codePointToString(this.readCodePoint()); | ||
// 'u' | ||
case 116: | ||
return "\t"; | ||
// 't' -> '\t' | ||
case 98: | ||
return "\b"; | ||
// 'b' -> '\b' | ||
case 118: | ||
return "\u000b"; | ||
// 'v' -> '\u000b' | ||
case 102: | ||
return "\f"; | ||
// 'f' -> '\f' | ||
case 13: | ||
if (this.input.charCodeAt(this.pos) === 10) ++this.pos; | ||
// '\r\n' | ||
case 10: | ||
@@ -956,5 +830,3 @@ // ' \n' | ||
} | ||
return ""; | ||
case 56: | ||
@@ -965,3 +837,2 @@ case 57: | ||
} | ||
if (inTemplate) { | ||
@@ -972,3 +843,2 @@ const codePos = this.pos - 1; | ||
} | ||
default: | ||
@@ -978,3 +848,2 @@ if (ch >= 48 && ch <= 55) { | ||
let octal = parseInt(octalStr, 8); | ||
if (octal > 255) { | ||
@@ -984,13 +853,9 @@ octalStr = octalStr.slice(0, -1); | ||
} | ||
this.pos += octalStr.length - 1; | ||
ch = this.input.charCodeAt(this.pos); | ||
if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) { | ||
this.invalidStringToken(this.pos - 1 - octalStr.length, inTemplate ? "Octal literal in template string" : "Octal literal in strict mode"); | ||
} | ||
return String.fromCharCode(octal); | ||
} | ||
if ((0, _whitespace.isNewLine)(ch)) { | ||
@@ -1001,7 +866,7 @@ // Unicode new line characters after \ get removed from output in both | ||
} | ||
return String.fromCharCode(ch); | ||
} | ||
}; // Used to read character escape sequences ('\x', '\u', '\U'). | ||
}; | ||
// Used to read character escape sequences ('\x', '\u', '\U'). | ||
@@ -1013,3 +878,5 @@ pp.readHexChar = function (len) { | ||
return n; | ||
}; // Read an identifier, and return it as a string. Sets `this.containsEsc` | ||
}; | ||
// Read an identifier, and return it as a string. Sets `this.containsEsc` | ||
// to whether the word contained a '\u' escape. | ||
@@ -1020,13 +887,10 @@ // | ||
pp.readWord1 = function () { | ||
this.containsEsc = false; | ||
let word = "", | ||
first = true, | ||
chunkStart = this.pos; | ||
first = true, | ||
chunkStart = this.pos; | ||
let astral = this.options.ecmaVersion >= 6; | ||
while (this.pos < this.input.length) { | ||
let ch = this.fullCharCodeAtPos(); | ||
if ((0, _identifier.isIdentifierChar)(ch, astral)) { | ||
@@ -1039,3 +903,4 @@ this.pos += ch <= 0xffff ? 1 : 2; | ||
let escStart = this.pos; | ||
if (this.input.charCodeAt(++this.pos) !== 117) // "u" | ||
if (this.input.charCodeAt(++this.pos) !== 117) | ||
// "u" | ||
this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); | ||
@@ -1050,20 +915,17 @@ ++this.pos; | ||
} | ||
first = false; | ||
} | ||
return word + this.input.slice(chunkStart, this.pos); | ||
}; | ||
return word + this.input.slice(chunkStart, this.pos); | ||
}; // Read an identifier or keyword token. Will check for reserved | ||
// Read an identifier or keyword token. Will check for reserved | ||
// words when necessary. | ||
pp.readWord = function () { | ||
let word = this.readWord1(); | ||
let type = _tokentype.types.name; | ||
if (this.keywords.test(word)) { | ||
type = _tokentype.keywords[word]; | ||
} | ||
return this.finishToken(type, word); | ||
}; |
@@ -5,9 +5,11 @@ "use strict"; | ||
exports.types = exports.keywords = exports.TokenType = void 0; | ||
// ## Token types | ||
// ## Token types | ||
// The assignment of fine-grained, information-carrying type objects | ||
// allows the tokenizer to store the information it has about a | ||
// token in a way that is very cheap for the parser to look up. | ||
// All token type variables start with an underscore, to make them | ||
// easy to recognize. | ||
// The `beforeExpr` property is used to disambiguate between regular | ||
@@ -26,2 +28,3 @@ // expressions and divisions. It is set on all token types that can | ||
// continue jumps to that label. | ||
class TokenType { | ||
@@ -40,7 +43,4 @@ constructor(label, conf = {}) { | ||
} | ||
} | ||
exports.TokenType = TokenType; | ||
function binop(name, prec) { | ||
@@ -52,14 +52,15 @@ return new TokenType(name, { | ||
} | ||
const beforeExpr = { | ||
beforeExpr: true | ||
}, | ||
startsExpr = { | ||
startsExpr: true | ||
}; // Map keyword names to token types. | ||
beforeExpr: true | ||
}, | ||
startsExpr = { | ||
startsExpr: true | ||
}; | ||
const keywords = {}; // Succinct definitions of keyword token types | ||
// Map keyword names to token types. | ||
const keywords = {}; | ||
// Succinct definitions of keyword token types | ||
exports.keywords = keywords; | ||
function kw(name, options = {}) { | ||
@@ -69,3 +70,2 @@ options.keyword = name; | ||
} | ||
const types = { | ||
@@ -122,2 +122,3 @@ num: new TokenType("num", startsExpr), | ||
// in AssignmentExpression nodes. | ||
eq: new TokenType("=", { | ||
@@ -124,0 +125,0 @@ beforeExpr: true, |
@@ -5,5 +5,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _util = require("./util.js"); | ||
// This file contains Unicode properties extracted from the ECMAScript | ||
@@ -24,6 +22,8 @@ // specification. The lists are extracted like so: | ||
13: ecma13BinaryProperties | ||
}; // #table-unicode-general-category-values | ||
}; | ||
const unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu"; // #table-unicode-script-values | ||
// #table-unicode-general-category-values | ||
const unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu"; | ||
// #table-unicode-script-values | ||
const ecma9ScriptValues = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb"; | ||
@@ -42,3 +42,2 @@ const ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd"; | ||
const data = {}; | ||
function buildUnicodeData(ecmaVersion) { | ||
@@ -57,3 +56,2 @@ const d = data[ecmaVersion] = { | ||
} | ||
for (var _i = 0, _arr = [9, 10, 11, 12, 13]; _i < _arr.length; _i++) { | ||
@@ -63,5 +61,4 @@ const ecmaVersion = _arr[_i]; | ||
} | ||
var _default = data; | ||
exports.default = _default; | ||
module.exports = exports["default"]; |
@@ -7,18 +7,12 @@ "use strict"; | ||
const _Object$prototype = Object.prototype, | ||
hasOwnProperty = _Object$prototype.hasOwnProperty, | ||
toString = _Object$prototype.toString; | ||
hasOwnProperty = _Object$prototype.hasOwnProperty, | ||
toString = _Object$prototype.toString; | ||
const hasOwn = Object.hasOwn || ((obj, propName) => hasOwnProperty.call(obj, propName)); | ||
exports.hasOwn = hasOwn; | ||
const isArray = Array.isArray || (obj => toString.call(obj) === "[object Array]"); | ||
exports.isArray = isArray; | ||
function wordsRegexp(words) { | ||
return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"); | ||
} | ||
const loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/; | ||
exports.loneSurrogate = loneSurrogate; |
@@ -10,2 +10,3 @@ "use strict"; | ||
// line break). Used to count lines. | ||
const lineBreak = /\r\n?|\n|\u2028|\u2029/; | ||
@@ -15,7 +16,5 @@ exports.lineBreak = lineBreak; | ||
exports.lineBreakG = lineBreakG; | ||
function isNewLine(code) { | ||
return code === 10 || code === 13 || code === 0x2028 || code === 0x2029; | ||
} | ||
function nextLineBreak(code, from, end = code.length) { | ||
@@ -26,6 +25,4 @@ for (let i = from; i < end; i++) { | ||
} | ||
return -1; | ||
} | ||
const nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/; | ||
@@ -32,0 +29,0 @@ exports.nonASCIIwhitespace = nonASCIIwhitespace; |
{ | ||
"name": "acorn-hammerhead", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "acorn.js parser adapted to TestCafe Hammerhead", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232673
5251
1