acorn-hammerhead
Advanced tools
Comparing version
@@ -5,2 +5,4 @@ "use strict"; | ||
var _tokencontext = require("./tokencontext.js"); | ||
var _state = require("./state.js"); | ||
@@ -14,5 +16,9 @@ | ||
const pp = _state.Parser.prototype; | ||
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."); } | ||
// Check if property name clashes with already added. | ||
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; // Check if property name clashes with already added. | ||
// Object/class getters and setters are not allowed to clash — | ||
@@ -22,20 +28,2 @@ // either with each other or with an init property — and in | ||
// 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 | ||
pp.checkPropClash = function (prop, propHash, refDestructuringErrors) { | ||
@@ -46,10 +34,16 @@ if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement") return; | ||
name; | ||
switch (key.type) { | ||
case "Identifier": | ||
name = key.name;break; | ||
name = key.name; | ||
break; | ||
case "Literal": | ||
name = String(key.value);break; | ||
name = String(key.value); | ||
break; | ||
default: | ||
return; | ||
} | ||
let kind = prop.kind; | ||
@@ -61,14 +55,22 @@ | ||
if (refDestructuringErrors) { | ||
if (refDestructuringErrors.doubleProto < 0) refDestructuringErrors.doubleProto = key.start; | ||
// Backwards-compat kludge. Can be removed in version 6.0 | ||
} else this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); | ||
if (refDestructuringErrors.doubleProto < 0) { | ||
refDestructuringErrors.doubleProto = key.start; | ||
} | ||
} else { | ||
this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); | ||
} | ||
} | ||
propHash.proto = true; | ||
} | ||
return; | ||
} | ||
name = "$" + name; | ||
let other = propHash[name]; | ||
if (other) { | ||
let redefinition; | ||
if (kind === "init") { | ||
@@ -79,2 +81,3 @@ redefinition = this.strict && other.init || other.get || other.set; | ||
} | ||
if (redefinition) this.raiseRecoverable(key.start, "Redefinition of property"); | ||
@@ -88,7 +91,5 @@ } else { | ||
} | ||
other[kind] = true; | ||
}; | ||
// ### Expression parsing | ||
}; // ### Expression parsing | ||
// These nest, from the most general expression type at the top to | ||
@@ -99,3 +100,2 @@ // '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 | ||
@@ -108,22 +108,25 @@ // forbid the `in` operator (in for loops initalization expressions) | ||
pp.parseExpression = function (noIn, refDestructuringErrors) { | ||
pp.parseExpression = function (forInit, refDestructuringErrors) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
let expr = this.parseMaybeAssign(noIn, refDestructuringErrors); | ||
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(noIn, refDestructuringErrors)); | ||
while (this.eat(_tokentype.types.comma)) node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors)); | ||
return this.finishNode(node, "SequenceExpression"); | ||
} | ||
return expr; | ||
}; | ||
// Parse an assignment expression. This includes applications of | ||
}; // Parse an assignment expression. This includes applications of | ||
// operators like `+=`. | ||
pp.parseMaybeAssign = function (noIn, refDestructuringErrors, afterLeftParse) { | ||
pp.parseMaybeAssign = function (forInit, refDestructuringErrors, afterLeftParse) { | ||
if (this.isContextual("yield")) { | ||
if (this.inGenerator) return this.parseYield(noIn); | ||
// 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 | ||
@@ -135,6 +138,9 @@ else this.exprAllowed = false; | ||
oldParenAssign = -1, | ||
oldTrailingComma = -1; | ||
oldTrailingComma = -1, | ||
oldDoubleProto = -1; | ||
if (refDestructuringErrors) { | ||
oldParenAssign = refDestructuringErrors.parenthesizedAssign; | ||
oldTrailingComma = refDestructuringErrors.trailingComma; | ||
oldDoubleProto = refDestructuringErrors.doubleProto; | ||
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1; | ||
@@ -148,5 +154,11 @@ } else { | ||
startLoc = this.startLoc; | ||
if (this.type === _tokentype.types.parenL || this.type === _tokentype.types.name) this.potentialArrowAt = this.start; | ||
let left = this.parseMaybeConditional(noIn, refDestructuringErrors); | ||
if (this.type === _tokentype.types.parenL || this.type === _tokentype.types.name) { | ||
this.potentialArrowAt = this.start; | ||
this.potentialArrowInForAwait = forInit === "await"; | ||
} | ||
let left = this.parseMaybeConditional(forInit, refDestructuringErrors); | ||
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc); | ||
if (this.type.isAssign) { | ||
@@ -156,10 +168,14 @@ 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); | ||
node.left = left; | ||
this.next(); | ||
node.right = this.parseMaybeAssign(noIn); | ||
node.right = this.parseMaybeAssign(forInit); | ||
if (oldDoubleProto > -1) refDestructuringErrors.doubleProto = oldDoubleProto; | ||
return this.finishNode(node, "AssignmentExpression"); | ||
@@ -169,14 +185,15 @@ } else { | ||
} | ||
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 (noIn, refDestructuringErrors) { | ||
pp.parseMaybeConditional = function (forInit, refDestructuringErrors) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
let expr = this.parseExprOps(noIn, refDestructuringErrors); | ||
let expr = this.parseExprOps(forInit, refDestructuringErrors); | ||
if (this.checkExpressionErrors(refDestructuringErrors)) return expr; | ||
if (this.eat(_tokentype.types.question)) { | ||
@@ -187,19 +204,17 @@ let node = this.startNodeAt(startPos, startLoc); | ||
this.expect(_tokentype.types.colon); | ||
node.alternate = this.parseMaybeAssign(noIn); | ||
node.alternate = this.parseMaybeAssign(forInit); | ||
return this.finishNode(node, "ConditionalExpression"); | ||
} | ||
return expr; | ||
}; | ||
}; // Start the precedence parser. | ||
// Start the precedence parser. | ||
pp.parseExprOps = function (noIn, refDestructuringErrors) { | ||
pp.parseExprOps = function (forInit, refDestructuringErrors) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
let expr = this.parseMaybeUnary(refDestructuringErrors, false); | ||
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, noIn); | ||
}; | ||
// Parse binary operators with the operator precedence parsing | ||
return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit); | ||
}; // Parse binary operators with the operator precedence parsing | ||
// algorithm. `left` is the left-hand side of the operator. | ||
@@ -210,8 +225,11 @@ // `minPrec` provides context that allows the function to stop and | ||
pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) { | ||
pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, forInit) { | ||
let prec = this.type.binop; | ||
if (prec != null && (!noIn || this.type !== _tokentype.types._in)) { | ||
if (prec != null && (!forInit || this.type !== _tokentype.types._in)) { | ||
if (prec > minPrec) { | ||
let logical = this.type === _tokentype.types.logicalOR || this.type === _tokentype.types.logicalAND; | ||
let coalesce = this.type === _tokentype.types.coalesce; | ||
if (coalesce) { | ||
@@ -222,2 +240,3 @@ // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions. | ||
} | ||
let op = this.value; | ||
@@ -227,10 +246,13 @@ this.next(); | ||
startLoc = this.startLoc; | ||
let right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn); | ||
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, noIn); | ||
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit); | ||
} | ||
} | ||
return left; | ||
@@ -240,2 +262,3 @@ }; | ||
pp.buildBinary = function (startPos, startLoc, left, right, op, logical) { | ||
if (right.type === "PrivateIdentifier") this.raise(right.start, "Private identifier can only be left side of binary expression"); | ||
let node = this.startNodeAt(startPos, startLoc); | ||
@@ -246,12 +269,12 @@ node.left = left; | ||
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) { | ||
pp.parseMaybeUnary = function (refDestructuringErrors, sawUnary, incDec, forInit) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc, | ||
expr; | ||
if (this.isContextual("await") && (this.inAsync || !this.inFunction && this.options.allowAwaitOutsideFunction)) { | ||
expr = this.parseAwait(); | ||
if (this.isContextual("await") && this.canAwait) { | ||
expr = this.parseAwait(forInit); | ||
sawUnary = true; | ||
@@ -264,9 +287,15 @@ } else if (this.type.prefix) { | ||
this.next(); | ||
node.argument = this.parseMaybeUnary(null, true); | ||
node.argument = this.parseMaybeUnary(null, true, update, forInit); | ||
this.checkExpressionErrors(refDestructuringErrors, true); | ||
if (update) this.checkLValSimple(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raiseRecoverable(node.start, "Deleting local variable in strict mode");else sawUnary = true; | ||
if (update) this.checkLValSimple(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raiseRecoverable(node.start, "Deleting local variable in strict mode");else if (node.operator === "delete" && isPrivateFieldAccess(node.argument)) this.raiseRecoverable(node.start, "Private fields can not be deleted");else sawUnary = true; | ||
expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); | ||
} else if (!sawUnary && this.type === _tokentype.types.privateId) { | ||
if (forInit || this.privateNameStack.length === 0) this.unexpected(); | ||
expr = this.parsePrivateIdent(); // only could be private fields in 'in', such as #x in obj | ||
if (this.type !== _tokentype.types._in) this.unexpected(); | ||
} else { | ||
expr = this.parseExprSubscripts(refDestructuringErrors); | ||
expr = this.parseExprSubscripts(refDestructuringErrors, forInit); | ||
if (this.checkExpressionErrors(refDestructuringErrors)) return expr; | ||
while (this.type.postfix && !this.canInsertSemicolon()) { | ||
@@ -283,13 +312,21 @@ let node = this.startNodeAt(startPos, startLoc); | ||
if (!sawUnary && this.eat(_tokentype.types.starstar)) return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false);else return expr; | ||
if (!incDec && this.eat(_tokentype.types.starstar)) { | ||
if (sawUnary) this.unexpected(this.lastTokStart);else return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false); | ||
} else { | ||
return expr; | ||
} | ||
}; | ||
// Parse call, dot, and `[]`-subscript expressions. | ||
function isPrivateFieldAccess(node) { | ||
return node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" || node.type === "ChainExpression" && isPrivateFieldAccess(node.expression); | ||
} // Parse call, dot, and `[]`-subscript expressions. | ||
pp.parseExprSubscripts = function (refDestructuringErrors) { | ||
pp.parseExprSubscripts = function (refDestructuringErrors, forInit) { | ||
let startPos = this.start, | ||
startLoc = this.startLoc; | ||
let expr = this.parseExprAtom(refDestructuringErrors); | ||
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); | ||
let result = this.parseSubscripts(expr, startPos, startLoc, false, forInit); | ||
if (refDestructuringErrors && result.type === "MemberExpression") { | ||
@@ -300,6 +337,7 @@ if (refDestructuringErrors.parenthesizedAssign >= result.start) refDestructuringErrors.parenthesizedAssign = -1; | ||
} | ||
return result; | ||
}; | ||
pp.parseSubscripts = function (base, startPos, startLoc, noCalls) { | ||
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; | ||
@@ -309,5 +347,5 @@ let optionalChained = false; | ||
while (true) { | ||
let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained); | ||
let element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit); | ||
if (element.optional) optionalChained = true; | ||
if (element.optional) optionalChained = true; | ||
if (element === base || element.type === "ArrowFunctionExpression") { | ||
@@ -319,2 +357,3 @@ if (optionalChained) { | ||
} | ||
return element; | ||
@@ -327,17 +366,27 @@ } | ||
pp.parseSubscript = function (base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) { | ||
pp.parseSubscript = function (base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) { | ||
let optionalSupported = this.options.ecmaVersion >= 11; | ||
let optional = optionalSupported && this.eat(_tokentype.types.questionDot); | ||
if (noCalls && optional) this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); | ||
let computed = this.eat(_tokentype.types.bracketL); | ||
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; | ||
node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never"); | ||
if (computed) { | ||
node.property = this.parseExpression(); | ||
this.expect(_tokentype.types.bracketR); | ||
} else if (this.type === _tokentype.types.privateId && base.type !== "Super") { | ||
node.property = this.parsePrivateIdent(); | ||
} else { | ||
node.property = this.parseIdent(this.options.allowReserved !== "never"); | ||
} | ||
node.computed = !!computed; | ||
if (computed) this.expect(_tokentype.types.bracketR); | ||
if (optionalSupported) { | ||
node.optional = optional; | ||
} | ||
base = this.finishNode(node, "MemberExpression"); | ||
@@ -353,2 +402,3 @@ } else if (!noCalls && this.eat(_tokentype.types.parenL)) { | ||
let exprList = this.parseExprList(_tokentype.types.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors); | ||
if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) { | ||
@@ -361,4 +411,5 @@ this.checkPatternErrors(refDestructuringErrors, false); | ||
this.awaitIdentPos = oldAwaitIdentPos; | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true); | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true, forInit); | ||
} | ||
this.checkExpressionErrors(refDestructuringErrors, true); | ||
@@ -371,5 +422,7 @@ this.yieldPos = oldYieldPos || this.yieldPos; | ||
node.arguments = exprList; | ||
if (optionalSupported) { | ||
node.optional = optional; | ||
} | ||
base = this.finishNode(node, "CallExpression"); | ||
@@ -380,11 +433,13 @@ } else if (this.type === _tokentype.types.backQuote) { | ||
} | ||
let node = this.startNodeAt(startPos, startLoc); | ||
node.tag = base; | ||
node.quasi = this.parseTemplate({ isTagged: true }); | ||
node.quasi = this.parseTemplate({ | ||
isTagged: true | ||
}); | ||
base = this.finishNode(node, "TaggedTemplateExpression"); | ||
} | ||
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 | ||
@@ -394,9 +449,10 @@ // `new`, or an expression wrapped in punctuation like `()`, `[]`, | ||
pp.parseExprAtom = function (refDestructuringErrors) { | ||
pp.parseExprAtom = function (refDestructuringErrors, forInit) { | ||
// If a division operator appears in an expression position, the | ||
// tokenizer got confused, and we force it to read a regexp instead. | ||
if (this.type === _tokentype.types.slash) this.readRegexp(); | ||
let node, | ||
canBeArrow = this.potentialArrowAt === this.start; | ||
switch (this.type) { | ||
@@ -407,4 +463,3 @@ 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: | ||
@@ -415,2 +470,3 @@ // super [ Expression ] | ||
// super ( Arguments ) | ||
if (this.type !== _tokentype.types.dot && this.type !== _tokentype.types.bracketL && this.type !== _tokentype.types.parenL) this.unexpected(); | ||
@@ -429,11 +485,18 @@ return this.finishNode(node, "Super"); | ||
let id = this.parseIdent(false); | ||
if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(_tokentype.types._function)) return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true); | ||
if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(_tokentype.types._function)) { | ||
this.overrideContext(_tokencontext.types.f_expr); | ||
return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit); | ||
} | ||
if (canBeArrow && !this.canInsertSemicolon()) { | ||
if (this.eat(_tokentype.types.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false); | ||
if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === _tokentype.types.name && !containsEsc) { | ||
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)) { | ||
id = this.parseIdent(false); | ||
if (this.canInsertSemicolon() || !this.eat(_tokentype.types.arrow)) this.unexpected(); | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true); | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true, forInit); | ||
} | ||
} | ||
return id; | ||
@@ -444,9 +507,15 @@ | ||
node = this.parseLiteral(value.value); | ||
node.regex = { pattern: value.pattern, flags: value.flags }; | ||
node.regex = { | ||
pattern: value.pattern, | ||
flags: value.flags | ||
}; | ||
return node; | ||
case _tokentype.types.num:case _tokentype.types.string: | ||
case _tokentype.types.num: | ||
case _tokentype.types.string: | ||
return this.parseLiteral(this.value); | ||
case _tokentype.types._null:case _tokentype.types._true:case _tokentype.types._false: | ||
case _tokentype.types._null: | ||
case _tokentype.types._true: | ||
case _tokentype.types._false: | ||
node = this.startNode(); | ||
@@ -460,3 +529,4 @@ node.value = this.type === _tokentype.types._null ? null : this.type === _tokentype.types._true; | ||
let start = this.start, | ||
expr = this.parseParenAndDistinguishExpression(canBeArrow); | ||
expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit); | ||
if (refDestructuringErrors) { | ||
@@ -466,2 +536,3 @@ if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr)) refDestructuringErrors.parenthesizedAssign = start; | ||
} | ||
return expr; | ||
@@ -476,2 +547,3 @@ | ||
case _tokentype.types.braceL: | ||
this.overrideContext(_tokencontext.types.b_expr); | ||
return this.parseObj(false, refDestructuringErrors); | ||
@@ -506,6 +578,5 @@ | ||
pp.parseExprImport = function () { | ||
const node = this.startNode(); | ||
const node = this.startNode(); // Consume `import` as an identifier for `import.meta`. | ||
// Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`. | ||
// 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"); | ||
@@ -517,5 +588,7 @@ const meta = this.parseIdent(true); | ||
return this.parseDynamicImport(node); | ||
case _tokentype.types.dot: | ||
node.meta = meta; | ||
return this.parseImportMeta(node); | ||
default: | ||
@@ -528,9 +601,9 @@ this.unexpected(); | ||
this.next(); // skip `(` | ||
// Parse node.source. | ||
node.source = this.parseMaybeAssign(); | ||
// Verify ending. | ||
node.source = this.parseMaybeAssign(); // Verify ending. | ||
if (!this.eat(_tokentype.types.parenR)) { | ||
const errorPos = this.start; | ||
if (this.eat(_tokentype.types.comma) && this.eat(_tokentype.types.parenR)) { | ||
@@ -551,7 +624,5 @@ this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()"); | ||
node.property = this.parseIdent(true); | ||
if (node.property.name !== "meta") this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); | ||
if (containsEsc) this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); | ||
if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere) this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); | ||
return this.finishNode(node, "MetaProperty"); | ||
@@ -576,3 +647,3 @@ }; | ||
pp.parseParenAndDistinguishExpression = function (canBeArrow) { | ||
pp.parseParenAndDistinguishExpression = function (canBeArrow, forInit) { | ||
let startPos = this.start, | ||
@@ -582,5 +653,5 @@ startLoc = this.startLoc, | ||
allowTrailingComma = this.options.ecmaVersion >= 8; | ||
if (this.options.ecmaVersion >= 6) { | ||
this.next(); | ||
let innerStartPos = this.start, | ||
@@ -596,6 +667,7 @@ innerStartLoc = this.startLoc; | ||
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)) { | ||
@@ -613,4 +685,5 @@ lastIsComma = true; | ||
} | ||
let innerEndPos = this.start, | ||
innerEndLoc = this.startLoc; | ||
let innerEndPos = this.lastTokEnd, | ||
innerEndLoc = this.lastTokEndLoc; | ||
this.expect(_tokentype.types.parenR); | ||
@@ -623,3 +696,3 @@ | ||
this.awaitPos = oldAwaitPos; | ||
return this.parseParenArrowList(startPos, startLoc, exprList); | ||
return this.parseParenArrowList(startPos, startLoc, exprList, forInit); | ||
} | ||
@@ -657,7 +730,5 @@ | ||
pp.parseParenArrowList = function (startPos, startLoc, exprList) { | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList); | ||
}; | ||
// New's precedence is slightly tricky. It must allow its argument to | ||
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 | ||
// be a `[]` or dot subscript expression, but not a call — at least, | ||
@@ -668,2 +739,3 @@ // not without wrapping it in parentheses. Thus, it uses the noCalls | ||
const empty = []; | ||
@@ -675,2 +747,3 @@ | ||
let meta = this.parseIdent(true); | ||
if (this.options.ecmaVersion >= 6 && this.eat(_tokentype.types.dot)) { | ||
@@ -682,20 +755,25 @@ node.meta = meta; | ||
if (containsEsc) this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); | ||
if (!this.inNonArrowFunction) this.raiseRecoverable(node.start, "'new.target' can only be used in functions"); | ||
if (!this.allowNewDotTarget) this.raiseRecoverable(node.start, "'new.target' can only be used in functions and class static block"); | ||
return this.finishNode(node, "MetaProperty"); | ||
} | ||
let startPos = this.start, | ||
startLoc = this.startLoc, | ||
isImport = this.type === _tokentype.types._import; | ||
node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true); | ||
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. | ||
pp.parseTemplateElement = function ({ isTagged }) { | ||
pp.parseTemplateElement = function ({ | ||
isTagged | ||
}) { | ||
let elem = this.startNode(); | ||
if (this.type === _tokentype.types.invalidTemplate) { | ||
@@ -705,2 +783,3 @@ if (!isTagged) { | ||
} | ||
elem.value = { | ||
@@ -716,2 +795,3 @@ raw: this.value, | ||
} | ||
this.next(); | ||
@@ -722,8 +802,13 @@ elem.tail = this.type === _tokentype.types.backQuote; | ||
pp.parseTemplate = function ({ isTagged = false } = {}) { | ||
pp.parseTemplate = function ({ | ||
isTagged = false | ||
} = {}) { | ||
let node = this.startNode(); | ||
this.next(); | ||
node.expressions = []; | ||
let curElt = this.parseTemplateElement({ isTagged }); | ||
let curElt = this.parseTemplateElement({ | ||
isTagged | ||
}); | ||
node.quasis = [curElt]; | ||
while (!curElt.tail) { | ||
@@ -734,4 +819,7 @@ if (this.type === _tokentype.types.eof) this.raise(this.pos, "Unterminated template literal"); | ||
this.expect(_tokentype.types.braceR); | ||
node.quasis.push(curElt = this.parseTemplateElement({ isTagged })); | ||
node.quasis.push(curElt = this.parseTemplateElement({ | ||
isTagged | ||
})); | ||
} | ||
this.next(); | ||
@@ -743,5 +831,4 @@ return this.finishNode(node, "TemplateLiteral"); | ||
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. | ||
@@ -754,2 +841,3 @@ pp.parseObj = function (isPattern, refDestructuringErrors) { | ||
this.next(); | ||
while (!this.eat(_tokentype.types.braceR)) { | ||
@@ -765,2 +853,3 @@ if (!first) { | ||
} | ||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); | ||
@@ -775,11 +864,15 @@ }; | ||
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) { | ||
@@ -789,18 +882,23 @@ 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) { | ||
@@ -810,6 +908,9 @@ 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)) { | ||
@@ -822,2 +923,3 @@ isAsync = true; | ||
} | ||
this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc); | ||
@@ -844,2 +946,3 @@ return this.finishNode(prop, "Property"); | ||
let paramCount = prop.kind === "get" ? 0 : 1; | ||
if (prop.value.params.length !== paramCount) { | ||
@@ -856,2 +959,3 @@ let start = prop.value.start; | ||
prop.kind = "init"; | ||
if (isPattern) { | ||
@@ -865,2 +969,3 @@ prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key)); | ||
} | ||
prop.shorthand = true; | ||
@@ -881,6 +986,6 @@ } else this.unexpected(); | ||
} | ||
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. | ||
@@ -891,5 +996,4 @@ pp.initFunction = function (node) { | ||
if (this.options.ecmaVersion >= 8) node.async = false; | ||
}; | ||
}; // Parse object or class method. | ||
// Parse object or class method. | ||
@@ -901,7 +1005,5 @@ pp.parseMethod = function (isGenerator, isAsync, allowDirectSuper) { | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
this.initFunction(node); | ||
if (this.options.ecmaVersion >= 6) node.generator = isGenerator; | ||
if (this.options.ecmaVersion >= 8) node.async = !!isAsync; | ||
this.yieldPos = 0; | ||
@@ -911,8 +1013,6 @@ this.awaitPos = 0; | ||
this.enterScope((0, _scopeflags.functionFlags)(isAsync, node.generator) | _scopeflags.SCOPE_SUPER | (allowDirectSuper ? _scopeflags.SCOPE_DIRECT_SUPER : 0)); | ||
this.expect(_tokentype.types.parenL); | ||
node.params = this.parseBindingList(_tokentype.types.parenR, false, this.options.ecmaVersion >= 8); | ||
this.checkYieldAwaitInDefaultParams(); | ||
this.parseFunctionBody(node, false, true); | ||
this.parseFunctionBody(node, false, true, false); | ||
this.yieldPos = oldYieldPos; | ||
@@ -922,22 +1022,17 @@ this.awaitPos = oldAwaitPos; | ||
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) { | ||
pp.parseArrowExpression = function (node, params, isAsync, forInit) { | ||
let oldYieldPos = this.yieldPos, | ||
oldAwaitPos = this.awaitPos, | ||
oldAwaitIdentPos = this.awaitIdentPos; | ||
this.enterScope((0, _scopeflags.functionFlags)(isAsync, false) | _scopeflags.SCOPE_ARROW); | ||
this.initFunction(node); | ||
if (this.options.ecmaVersion >= 8) node.async = !!isAsync; | ||
this.yieldPos = 0; | ||
this.awaitPos = 0; | ||
this.awaitIdentPos = 0; | ||
node.params = this.toAssignableList(params, true); | ||
this.parseFunctionBody(node, true, false); | ||
this.parseFunctionBody(node, true, false, forInit); | ||
this.yieldPos = oldYieldPos; | ||
@@ -947,7 +1042,6 @@ this.awaitPos = oldAwaitPos; | ||
return this.finishNode(node, "ArrowFunctionExpression"); | ||
}; | ||
}; // Parse function body and check parameters. | ||
// Parse function body and check parameters. | ||
pp.parseFunctionBody = function (node, isArrowFunction, isMethod) { | ||
pp.parseFunctionBody = function (node, isArrowFunction, isMethod, forInit) { | ||
let isExpression = isArrowFunction && this.type !== _tokentype.types.braceL; | ||
@@ -958,3 +1052,3 @@ let oldStrict = this.strict, | ||
if (isExpression) { | ||
node.body = this.parseMaybeAssign(); | ||
node.body = this.parseMaybeAssign(forInit); | ||
node.expression = true; | ||
@@ -964,19 +1058,20 @@ this.checkParams(node, false); | ||
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; | ||
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. | ||
// 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); | ||
@@ -988,2 +1083,3 @@ node.body = this.parseBlock(false, undefined, useStrict && !oldStrict); | ||
} | ||
this.exitScope(); | ||
@@ -993,44 +1089,20 @@ }; | ||
pp.isSimpleParamList = function (params) { | ||
for (var _iterator = params, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
let param = _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(params), _step; !(_step = _iterator()).done;) { | ||
let param = _step.value; | ||
if (param.type !== "Identifier") return false; | ||
}return true; | ||
}; | ||
} | ||
// Checks function params for various disallowed patterns such as using "eval" | ||
return true; | ||
}; // 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 = node.params, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
let param = _ref2; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(node.params), _step2; !(_step2 = _iterator2()).done;) { | ||
let param = _step2.value; | ||
this.checkLValInnerPattern(param, _scopeflags.BIND_VAR, allowDuplicates ? null : nameHash); | ||
} | ||
}; | ||
// 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 | ||
@@ -1041,5 +1113,7 @@ // `allowEmpty` can be turned on to allow subsequent commas with | ||
pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refDestructuringErrors) { | ||
let elts = [], | ||
first = true; | ||
while (!this.eat(close)) { | ||
@@ -1060,11 +1134,19 @@ if (!first) { | ||
} | ||
return elts; | ||
}; | ||
pp.checkUnreserved = function ({ start, end, name }) { | ||
pp.checkUnreserved = function ({ | ||
start, | ||
end, | ||
name | ||
}) { | ||
if (this.inGenerator && name === "yield") this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); | ||
if (this.inAsync && name === "await") this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); | ||
if (this.currentThisScope().inClassFieldInit && name === "arguments") this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); | ||
if (this.inClassStaticBlock && (name === "arguments" || name === "await")) this.raise(start, `Cannot use ${name} in class static initialization block`); | ||
if (this.keywords.test(name)) this.raise(start, `Unexpected keyword '${name}'`); | ||
if (this.options.ecmaVersion < 6 && this.input.slice(start, end).indexOf("\\") !== -1) return; | ||
const re = this.strict ? this.reservedWordsStrict : this.reservedWords; | ||
if (re.test(name)) { | ||
@@ -1074,19 +1156,18 @@ 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)) { | ||
@@ -1098,4 +1179,6 @@ this.context.pop(); | ||
} | ||
this.next(!!liberal); | ||
this.finishNode(node, "Identifier"); | ||
if (!liberal) { | ||
@@ -1105,12 +1188,33 @@ this.checkUnreserved(node); | ||
} | ||
return node; | ||
}; | ||
// Parses yield expression inside generator. | ||
pp.parsePrivateIdent = function () { | ||
const node = this.startNode(); | ||
pp.parseYield = function (noIn) { | ||
if (this.type === _tokentype.types.privateId) { | ||
node.name = this.value; | ||
} else { | ||
this.unexpected(); | ||
} | ||
this.next(); | ||
this.finishNode(node, "PrivateIdentifier"); // For validating existence | ||
if (this.privateNameStack.length === 0) { | ||
this.raise(node.start, `Private field '#${node.name}' must be declared in an enclosing class`); | ||
} else { | ||
this.privateNameStack[this.privateNameStack.length - 1].used.push(node); | ||
} | ||
return node; | ||
}; // Parses yield expression inside generator. | ||
pp.parseYield = function (forInit) { | ||
if (!this.yieldPos) this.yieldPos = this.start; | ||
let node = this.startNode(); | ||
this.next(); | ||
if (this.type === _tokentype.types.semi || this.canInsertSemicolon() || this.type !== _tokentype.types.star && !this.type.startsExpr) { | ||
@@ -1121,14 +1225,14 @@ node.delegate = false; | ||
node.delegate = this.eat(_tokentype.types.star); | ||
node.argument = this.parseMaybeAssign(noIn); | ||
node.argument = this.parseMaybeAssign(forInit); | ||
} | ||
return this.finishNode(node, "YieldExpression"); | ||
}; | ||
pp.parseAwait = function () { | ||
pp.parseAwait = function (forInit) { | ||
if (!this.awaitPos) this.awaitPos = this.start; | ||
let node = this.startNode(); | ||
this.next(); | ||
node.argument = this.parseMaybeUnary(null, true); | ||
node.argument = this.parseMaybeUnary(null, true, false, forInit); | ||
return this.finishNode(node, "AwaitExpression"); | ||
}; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.isIdentifierChar = isIdentifierChar; | ||
exports.isIdentifierStart = isIdentifierStart; | ||
exports.isIdentifierChar = isIdentifierChar; | ||
exports.reservedWords = exports.keywords = exports.keywordRelationalOperator = void 0; | ||
// Reserved word lists for various dialects of the language | ||
const reservedWords = exports.reservedWords = { | ||
const reservedWords = { | ||
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", | ||
@@ -14,8 +14,7 @@ 5: "class enum extends super const export import", | ||
strictBind: "eval arguments" | ||
}; // And the keywords | ||
// And the keywords | ||
};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"; | ||
const keywords = exports.keywords = { | ||
exports.reservedWords = reservedWords; | ||
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"; | ||
const keywords = { | ||
5: ecma5AndLessKeywords, | ||
@@ -25,7 +24,4 @@ "5module": ecma5AndLessKeywords + " export import", | ||
}; | ||
const keywordRelationalOperator = exports.keywordRelationalOperator = /^in(stanceof)?$/; | ||
// ## Character categories | ||
exports.keywords = keywords; | ||
const keywordRelationalOperator = /^in(stanceof)?$/; // ## Character categories | ||
// Big ugly regular expressions that match characters in the | ||
@@ -36,11 +32,9 @@ // whitespace, identifier, and identifier-start categories. These | ||
// Generated by `bin/generate-identifier-regex.js`. | ||
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\u08a0-\u08b4\u08b6-\u08c7\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\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\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-\u170c\u170e-\u1711\u1720-\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-\u1b4b\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-\u2c2e\u2c30-\u2c5e\u2c60-\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-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\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"; | ||
let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; | ||
exports.keywordRelationalOperator = keywordRelationalOperator; | ||
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"; | ||
let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; | ||
const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); | ||
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 | ||
@@ -50,14 +44,13 @@ // 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, 157, 310, 10, 21, 11, 7, 153, 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, 107, 20, 28, 22, 13, 52, 76, 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, 230, 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, 35, 56, 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, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 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, 8952, 286, 50, 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, 2357, 44, 11, 6, 17, 0, 370, 43, 1301, 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, 42717, 35, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938]; | ||
// 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, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 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, 135, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 5319, 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, 419, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239]; | ||
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 | ||
// This has a complexity linear to the value of the code. The | ||
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 | ||
// 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) { | ||
@@ -69,5 +62,4 @@ pos += set[i]; | ||
} | ||
} | ||
} // Test whether a given character code starts an identifier. | ||
// Test whether a given character code starts an identifier. | ||
@@ -82,5 +74,4 @@ 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. | ||
@@ -87,0 +78,0 @@ function isIdentifierChar(code, astral) { |
"use strict"; | ||
exports.__esModule = true; | ||
exports.nonASCIIwhitespace = exports.lineBreakG = exports.lineBreak = exports.isNewLine = exports.Token = exports.isIdentifierStart = exports.isIdentifierChar = exports.tokContexts = exports.TokContext = exports.keywordTypes = exports.tokTypes = exports.TokenType = exports.Node = exports.getLineInfo = exports.SourceLocation = exports.Position = exports.defaultOptions = exports.Parser = exports.version = undefined; | ||
exports.parse = parse; | ||
exports.parseExpressionAt = parseExpressionAt; | ||
exports.tokenizer = tokenizer; | ||
exports.version = void 0; | ||
var _state = require("./state.js"); | ||
exports.Parser = _state.Parser; | ||
require("./parseutil.js"); | ||
@@ -25,22 +27,47 @@ | ||
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"); | ||
var _util = require("./util"); | ||
exports.isNewLine = _whitespace.isNewLine; | ||
exports.lineBreak = _whitespace.lineBreak; | ||
exports.lineBreakG = _whitespace.lineBreakG; | ||
exports.nonASCIIwhitespace = _whitespace.nonASCIIwhitespace; | ||
var utils = _interopRequireWildcard(_util); | ||
var utils = _interopRequireWildcard(require("./util")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
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. | ||
@@ -61,24 +88,4 @@ // | ||
// [walk]: util/walk.js | ||
const version = exports.version = "8.1.0"; | ||
exports.Parser = _state.Parser; | ||
exports.defaultOptions = _options.defaultOptions; | ||
exports.Position = _locutil.Position; | ||
exports.SourceLocation = _locutil.SourceLocation; | ||
exports.getLineInfo = _locutil.getLineInfo; | ||
exports.Node = _node.Node; | ||
exports.TokenType = _tokentype.TokenType; | ||
exports.tokTypes = _tokentype.types; | ||
exports.keywordTypes = _tokentype.keywords; | ||
exports.TokContext = _tokencontext.TokContext; | ||
exports.tokContexts = _tokencontext.types; | ||
exports.isIdentifierChar = _identifier.isIdentifierChar; | ||
exports.isIdentifierStart = _identifier.isIdentifierStart; | ||
exports.Token = _tokenize.Token; | ||
exports.isNewLine = _whitespace.isNewLine; | ||
exports.lineBreak = _whitespace.lineBreak; | ||
exports.lineBreakG = _whitespace.lineBreakG; | ||
exports.nonASCIIwhitespace = _whitespace.nonASCIIwhitespace; | ||
const version = "8.7.0"; | ||
exports.version = version; | ||
_state.Parser.acorn = { | ||
@@ -104,31 +111,26 @@ Parser: _state.Parser, | ||
nonASCIIwhitespace: _whitespace.nonASCIIwhitespace | ||
}; // The main exported interface (under `self.acorn` when in the | ||
// browser) is a `parse` function that takes a code string and | ||
// returns an abstract syntax tree as specified by [Mozilla parser | ||
// API][api]. | ||
// | ||
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API | ||
// The main exported interface (under `self.acorn` when in the | ||
// browser) is a `parse` function that takes a code string and | ||
// returns an abstract syntax tree as specified by [Mozilla parser | ||
// API][api]. | ||
// | ||
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API | ||
};function parse(input, options) { | ||
function parse(input, options) { | ||
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 ============================ | ||
@@ -138,2 +140,3 @@ // =====================||||||||||||||||||||||||||||============================ | ||
const storedWordsRegexp = utils.wordsRegexp; | ||
@@ -144,7 +147,4 @@ const wordsRegexpCache = {}; | ||
if (!wordsRegexpCache[words]) wordsRegexpCache[words] = storedWordsRegexp(words); | ||
return wordsRegexpCache[words]; | ||
}; | ||
// =====================^^^^^^^^^^^^^^^^^^^^^^^^^^^^============================ | ||
}; // =====================^^^^^^^^^^^^^^^^^^^^^^^^^^^^============================ | ||
// =====================||||||||||||||||||||||||||||============================ | ||
@@ -151,0 +151,0 @@ // ===================== TestCafe performance patch ============================ |
@@ -7,5 +7,3 @@ "use strict"; | ||
const pp = _state.Parser.prototype; | ||
// This function is used to raise exceptions on parse errors. It | ||
const pp = _state.Parser.prototype; // This function is used to raise exceptions on parse errors. It | ||
// takes an offset integer (into the current `input`) to indicate | ||
@@ -20,3 +18,5 @@ // the location of the error, attaches the position to the end | ||
let err = new SyntaxError(message); | ||
err.pos = pos;err.loc = loc;err.raisedAt = this.pos; | ||
err.pos = pos; | ||
err.loc = loc; | ||
err.raisedAt = this.pos; | ||
throw err; | ||
@@ -23,0 +23,0 @@ }; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.SourceLocation = exports.Position = undefined; | ||
exports.SourceLocation = exports.Position = void 0; | ||
exports.getLineInfo = getLineInfo; | ||
@@ -11,3 +11,2 @@ | ||
// `startLoc` and `endLoc` properties. | ||
class Position { | ||
@@ -22,5 +21,7 @@ constructor(line, col) { | ||
} | ||
} | ||
exports.Position = Position; | ||
class SourceLocation { | ||
@@ -32,5 +33,4 @@ constructor(p, start, end) { | ||
} | ||
} | ||
exports.SourceLocation = SourceLocation; // 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 | ||
@@ -41,13 +41,12 @@ // want to find the line/column position for a given character | ||
exports.SourceLocation = SourceLocation; | ||
function getLineInfo(input, offset) { | ||
for (let line = 1, cur = 0;;) { | ||
_whitespace.lineBreakG.lastIndex = cur; | ||
let match = _whitespace.lineBreakG.exec(input); | ||
if (match && match.index < offset) { | ||
++line; | ||
cur = match.index + match[0].length; | ||
} else { | ||
return new Position(line, offset - cur); | ||
} | ||
let nextBreak = (0, _whitespace.nextLineBreak)(input, cur, offset); | ||
if (nextBreak < 0) return new Position(line, offset - cur); | ||
++line; | ||
cur = nextBreak; | ||
} | ||
} |
@@ -11,5 +11,9 @@ "use strict"; | ||
const pp = _state.Parser.prototype; | ||
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."); } | ||
// Convert existing expression atom to assignable pattern | ||
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; // Convert existing expression atom to assignable pattern | ||
// if possible. | ||
@@ -33,18 +37,6 @@ | ||
if (refDestructuringErrors) this.checkPatternErrors(refDestructuringErrors, true); | ||
for (var _iterator = node.properties, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
let prop = _ref; | ||
this.toAssignable(prop, isBinding); | ||
// Early error: | ||
for (var _iterator = _createForOfIteratorHelperLoose(node.properties), _step; !(_step = _iterator()).done;) { | ||
let prop = _step.value; | ||
this.toAssignable(prop, isBinding); // Early error: | ||
// AssignmentRestProperty[Yield, Await] : | ||
@@ -54,2 +46,3 @@ // `...` 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")) { | ||
@@ -59,2 +52,3 @@ this.raise(prop.argument.start, "Unexpected token"); | ||
} | ||
break; | ||
@@ -102,9 +96,10 @@ | ||
} 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++) { | ||
@@ -114,2 +109,3 @@ let elt = exprList[i]; | ||
} | ||
if (end) { | ||
@@ -119,6 +115,6 @@ let last = exprList[end - 1]; | ||
} | ||
return exprList; | ||
}; | ||
}; // Parses spread element. | ||
// Parses spread element. | ||
@@ -134,13 +130,9 @@ pp.parseSpread = function (refDestructuringErrors) { | ||
let node = this.startNode(); | ||
this.next(); | ||
this.next(); // RestElement inside of a function parameter must be an identifier | ||
// 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. | ||
@@ -160,2 +152,3 @@ pp.parseBindingAtom = function () { | ||
} | ||
return this.parseIdent(); | ||
@@ -167,4 +160,6 @@ }; | ||
first = true; | ||
while (!this.eat(close)) { | ||
if (first) first = false;else this.expect(_tokentype.types.comma); | ||
if (allowEmpty && this.type === _tokentype.types.comma) { | ||
@@ -187,2 +182,3 @@ elts.push(null); | ||
} | ||
return elts; | ||
@@ -193,5 +189,4 @@ }; | ||
return param; | ||
}; | ||
}; // Parses assignment pattern around given atom if possible. | ||
// Parses assignment pattern around given atom if possible. | ||
@@ -205,5 +200,3 @@ 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 | ||
@@ -272,2 +265,3 @@ // a variety of checks: | ||
pp.checkLValSimple = function (expr, bindingType = _scopeflags.BIND_NONE, checkClashes) { | ||
@@ -279,10 +273,14 @@ const isBind = bindingType !== _scopeflags.BIND_NONE; | ||
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) { | ||
if ((0, _util.has)(checkClashes, expr.name)) this.raiseRecoverable(expr.start, "Argument name clash"); | ||
if ((0, _util.hasOwn)(checkClashes, expr.name)) this.raiseRecoverable(expr.start, "Argument name clash"); | ||
checkClashes[expr.name] = true; | ||
} | ||
if (bindingType !== _scopeflags.BIND_OUTSIDE) this.declareName(expr.name, bindingType, expr.start); | ||
} | ||
break; | ||
@@ -310,37 +308,15 @@ | ||
case "ObjectPattern": | ||
for (var _iterator2 = expr.properties, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
let prop = _ref2; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(expr.properties), _step2; !(_step2 = _iterator2()).done;) { | ||
let prop = _step2.value; | ||
this.checkLValInnerPattern(prop, bindingType, checkClashes); | ||
} | ||
break; | ||
case "ArrayPattern": | ||
for (var _iterator3 = expr.elements, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
let elem = _ref3; | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(expr.elements), _step3; !(_step3 = _iterator3()).done;) { | ||
let elem = _step3.value; | ||
if (elem) this.checkLValInnerPattern(elem, bindingType, checkClashes); | ||
} | ||
break; | ||
@@ -347,0 +323,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
exports.Node = undefined; | ||
exports.Node = void 0; | ||
@@ -19,6 +19,7 @@ var _state = require("./state.js"); | ||
} | ||
} | ||
exports.Node = Node; // Start an AST node, attaching a start offset. | ||
} // Start an AST node, attaching a start offset. | ||
exports.Node = Node; | ||
const pp = _state.Parser.prototype; | ||
@@ -32,5 +33,4 @@ | ||
return new Node(this, pos, loc); | ||
}; | ||
}; // Finish an AST node, adding `type` and `end` properties. | ||
// Finish an AST node, adding `type` and `end` properties. | ||
@@ -47,5 +47,4 @@ function finishNodeAt(node, type, pos, loc) { | ||
return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc); | ||
}; | ||
}; // Finish node at given position | ||
// Finish node at given position | ||
@@ -58,4 +57,6 @@ pp.finishNodeAt = function (node, type, pos, loc) { | ||
let newNode = new Node(this, node.start, this.startLoc); | ||
for (let prop in node) newNode[prop] = node[prop]; | ||
return newNode; | ||
}; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.defaultOptions = undefined; | ||
exports.defaultOptions = void 0; | ||
exports.getOptions = getOptions; | ||
@@ -13,9 +13,9 @@ | ||
// These options are recognized (only `ecmaVersion` is required): | ||
const defaultOptions = exports.defaultOptions = { | ||
const defaultOptions = { | ||
// `ecmaVersion` indicates the ECMAScript version to parse. Must be | ||
// either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10 | ||
// (2019), 11 (2020), 12 (2021), or `"latest"` (the latest version | ||
// the library supports). This influences support for strict mode, | ||
// the set of reserved words, and support for new syntax features. | ||
// (2019), 11 (2020), 12 (2021), 13 (2022), or `"latest"` (the | ||
// latest version the library supports). This influences support | ||
// for strict mode, the set of reserved words, and support for | ||
// new syntax features. | ||
ecmaVersion: null, | ||
@@ -47,5 +47,9 @@ // `sourceType` indicates the mode the code should be parsed in. | ||
allowImportExportEverywhere: false, | ||
// By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022. | ||
// When enabled, await identifiers are allowed to appear at the top-level scope, | ||
// but they are still not allowed in non-async functions. | ||
allowAwaitOutsideFunction: false, | ||
allowAwaitOutsideFunction: null, | ||
// When enabled, super identifiers are not constrained to | ||
// appearing in methods and do not raise an error when they appear elsewhere. | ||
allowSuperOutsideMethod: null, | ||
// When enabled, hashbang directive in the beginning of file | ||
@@ -100,11 +104,11 @@ // is allowed and treated as a line comment. | ||
preserveParens: false | ||
}; // Interpret and default an options object | ||
// Interpret and default an options object | ||
exports.defaultOptions = defaultOptions; | ||
let warnedAboutEcmaVersion = false; | ||
};let warnedAboutEcmaVersion = false; | ||
function getOptions(opts) { | ||
let options = {}; | ||
for (let opt in defaultOptions) options[opt] = opts && (0, _util.has)(opts, opt) ? opts[opt] : defaultOptions[opt]; | ||
for (let opt in defaultOptions) options[opt] = opts && (0, _util.hasOwn)(opts, opt) ? opts[opt] : defaultOptions[opt]; | ||
@@ -118,2 +122,3 @@ if (options.ecmaVersion === "latest") { | ||
} | ||
options.ecmaVersion = 11; | ||
@@ -128,6 +133,7 @@ } else if (options.ecmaVersion >= 2015) { | ||
let tokens = options.onToken; | ||
options.onToken = token => tokens.push(token); | ||
} | ||
if ((0, _util.isArray)(options.onComment)) options.onComment = pushComment(options, options.onComment); | ||
return options; | ||
@@ -134,0 +140,0 @@ } |
@@ -12,7 +12,6 @@ "use strict"; | ||
const pp = _state.Parser.prototype; | ||
const pp = _state.Parser.prototype; // ## Parser utilities | ||
// ## Parser utilities | ||
const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/; | ||
const literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/; | ||
pp.strictDirective = function (start) { | ||
@@ -26,5 +25,4 @@ for (;;) { | ||
if ((match[1] || match[2]) === "use strict") return false; | ||
start += match[0].length; | ||
start += match[0].length; // Skip semicolon, if any. | ||
// Skip semicolon, if any. | ||
_whitespace.skipWhiteSpace.lastIndex = start; | ||
@@ -34,7 +32,6 @@ 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) { | ||
@@ -47,11 +44,9 @@ 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. | ||
@@ -62,11 +57,9 @@ 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. | ||
@@ -82,7 +75,6 @@ pp.canInsertSemicolon = function () { | ||
} | ||
}; | ||
// 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 () { | ||
@@ -98,12 +90,10 @@ if (!this.eat(_tokentype.types.semi) && !this.insertSemicolon()) this.unexpected(); | ||
} | ||
}; | ||
// 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. | ||
@@ -129,3 +119,2 @@ pp.unexpected = function (pos) { | ||
doubleProto = refDestructuringErrors.doubleProto; | ||
if (!andThrow) return shorthandAssign >= 0 || doubleProto >= 0; | ||
@@ -132,0 +121,0 @@ if (shorthandAssign >= 0) this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); |
"use strict"; | ||
exports.__esModule = true; | ||
exports.RegExpValidationState = undefined; | ||
exports.RegExpValidationState = void 0; | ||
@@ -10,6 +10,4 @@ var _identifier = require("./identifier.js"); | ||
var _unicodePropertyData = require("./unicode-property-data.js"); | ||
var _unicodePropertyData = _interopRequireDefault(require("./unicode-property-data.js")); | ||
var _unicodePropertyData2 = _interopRequireDefault(_unicodePropertyData); | ||
var _util = require("./util.js"); | ||
@@ -19,2 +17,8 @@ | ||
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; | ||
@@ -25,4 +29,4 @@ | ||
this.parser = parser; | ||
this.validFlags = `gim${parser.options.ecmaVersion >= 6 ? "uy" : ""}${parser.options.ecmaVersion >= 9 ? "s" : ""}`; | ||
this.unicodeProperties = _unicodePropertyData2.default[parser.options.ecmaVersion >= 12 ? 12 : parser.options.ecmaVersion]; | ||
this.validFlags = `gim${parser.options.ecmaVersion >= 6 ? "uy" : ""}${parser.options.ecmaVersion >= 9 ? "s" : ""}${parser.options.ecmaVersion >= 13 ? "d" : ""}`; | ||
this.unicodeProperties = _unicodePropertyData.default[parser.options.ecmaVersion >= 13 ? 13 : parser.options.ecmaVersion]; | ||
this.source = ""; | ||
@@ -54,16 +58,20 @@ this.flags = ""; | ||
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). | ||
// Otherwise, this returns the code unit of the index (can be a part of 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); | ||
@@ -76,10 +84,14 @@ return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c; | ||
const l = s.length; | ||
if (i >= l) { | ||
return l; | ||
} | ||
let c = s.charCodeAt(i), | ||
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; | ||
@@ -105,7 +117,10 @@ } | ||
} | ||
return false; | ||
} | ||
} | ||
exports.RegExpValidationState = RegExpValidationState; | ||
function codePointToString(ch) { | ||
@@ -116,3 +131,2 @@ if (ch <= 0xFFFF) return String.fromCharCode(ch); | ||
} | ||
/** | ||
@@ -124,2 +138,4 @@ * Validate the flags part of a given RegExpLiteral. | ||
*/ | ||
pp.validateRegExpFlags = function (state) { | ||
@@ -131,5 +147,7 @@ const validFlags = state.validFlags; | ||
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) { | ||
@@ -140,3 +158,2 @@ this.raise(state.start, "Duplicate regular expression flag"); | ||
}; | ||
/** | ||
@@ -148,6 +165,6 @@ * Validate the pattern part of a given RegExpLiteral. | ||
*/ | ||
pp.validateRegExpPattern = function (state) { | ||
this.regexp_pattern(state); | ||
// The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of | ||
this.regexp_pattern(state); // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of | ||
// parsing contains a |GroupName|, reparse with the goal symbol | ||
@@ -157,2 +174,3 @@ // |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) { | ||
@@ -162,5 +180,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) { | ||
@@ -175,3 +193,2 @@ state.pos = 0; | ||
state.backReferenceNames.length = 0; | ||
this.regexp_disjunction(state); | ||
@@ -181,26 +198,24 @@ | ||
// 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 = state.backReferenceNames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
for (var _iterator = _createForOfIteratorHelperLoose(state.backReferenceNames), _step; !(_step = _iterator()).done;) { | ||
const name = _step.value; | ||
const name = _ref; | ||
if (state.groupNames.indexOf(name) === -1) { | ||
@@ -210,26 +225,32 @@ 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) { | ||
@@ -246,2 +267,3 @@ if (this.regexp_eatAssertion(state)) { | ||
} | ||
return true; | ||
@@ -256,33 +278,59 @@ } | ||
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 | ||
// \b \B | ||
if (state.eat(0x5C /* \ */)) { | ||
if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) { | ||
if (state.eat(0x5C | ||
/* \ */ | ||
)) { | ||
if (state.eat(0x42 | ||
/* B */ | ||
) || state.eat(0x62 | ||
/* b */ | ||
)) { | ||
return true; | ||
} | ||
state.pos = start; | ||
} | ||
} // Lookahead / Lookbehind | ||
// Lookahead / Lookbehind | ||
if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) { | ||
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; | ||
@@ -295,28 +343,48 @@ return true; | ||
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; | ||
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 | ||
@@ -326,64 +394,103 @@ 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 /* ? */) { | ||
state.raise("Invalid group"); | ||
} | ||
} 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); | ||
}; | ||
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 | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier | ||
pp.regexp_eatInvalidBracedQuantifier = function (state) { | ||
@@ -393,8 +500,10 @@ 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)) { | ||
@@ -405,36 +514,76 @@ 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 /* } */ | ||
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 | ||
// But eat eager. | ||
// 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; | ||
} | ||
state.advance(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
// GroupSpecifier :: | ||
}; // GroupSpecifier :: | ||
// [empty] | ||
// `?` GroupName | ||
pp.regexp_groupSpecifier = function (state) { | ||
if (state.eat(0x3F /* ? */)) { | ||
if (state.eat(0x3F | ||
/* ? */ | ||
)) { | ||
if (this.regexp_eatGroupName(state)) { | ||
@@ -444,40 +593,51 @@ 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; | ||
}; | ||
// 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; | ||
}; | ||
// RegExpIdentifierStart :: | ||
}; // RegExpIdentifierStart :: | ||
// UnicodeIDStart | ||
@@ -487,2 +647,4 @@ // `$` | ||
// `\` RegExpUnicodeEscapeSequence[+U] | ||
pp.regexp_eatRegExpIdentifierStart = function (state) { | ||
@@ -494,5 +656,8 @@ const start = state.pos; | ||
if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
if (ch === 0x5C | ||
/* \ */ | ||
&& this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
ch = state.lastIntValue; | ||
} | ||
if (isRegExpIdentifierStart(ch)) { | ||
@@ -506,7 +671,9 @@ state.lastIntValue = ch; | ||
}; | ||
function isRegExpIdentifierStart(ch) { | ||
return (0, _identifier.isIdentifierStart)(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F; /* _ */ | ||
} | ||
// RegExpIdentifierPart :: | ||
return (0, _identifier.isIdentifierStart)(ch, true) || ch === 0x24 | ||
/* $ */ | ||
|| ch === 0x5F; | ||
/* _ */ | ||
} // RegExpIdentifierPart :: | ||
// UnicodeIDContinue | ||
@@ -518,2 +685,4 @@ // `$` | ||
// <ZWJ> | ||
pp.regexp_eatRegExpIdentifierPart = function (state) { | ||
@@ -525,5 +694,8 @@ const start = state.pos; | ||
if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
if (ch === 0x5C | ||
/* \ */ | ||
&& this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { | ||
ch = state.lastIntValue; | ||
} | ||
if (isRegExpIdentifierPart(ch)) { | ||
@@ -537,7 +709,15 @@ state.lastIntValue = ch; | ||
}; | ||
function isRegExpIdentifierPart(ch) { | ||
return (0, _identifier.isIdentifierChar)(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D; /* <ZWJ> */ | ||
} | ||
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 | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape | ||
pp.regexp_eatAtomEscape = function (state) { | ||
@@ -547,15 +727,23 @@ 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 */) { | ||
state.raise("Invalid unicode escape"); | ||
} | ||
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) { | ||
@@ -566,13 +754,20 @@ // 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)) { | ||
@@ -582,23 +777,34 @@ 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; | ||
@@ -608,39 +814,67 @@ 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 */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x6E /* n */) { | ||
state.lastIntValue = 0x0A; /* \n */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x76 /* v */) { | ||
state.lastIntValue = 0x0B; /* \v */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x66 /* f */) { | ||
state.lastIntValue = 0x0C; /* \f */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x72 /* r */) { | ||
state.lastIntValue = 0x0D; /* \r */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x74 | ||
/* t */ | ||
) { | ||
state.lastIntValue = 0x09; | ||
/* \t */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x6E | ||
/* n */ | ||
) { | ||
state.lastIntValue = 0x0A; | ||
/* \n */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x76 | ||
/* v */ | ||
) { | ||
state.lastIntValue = 0x0B; | ||
/* \v */ | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch === 0x66 | ||
/* f */ | ||
) { | ||
state.lastIntValue = 0x0C; | ||
/* \f */ | ||
state.advance(); | ||
return true; | ||
} | ||
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)) { | ||
@@ -651,9 +885,19 @@ state.lastIntValue = ch % 0x20; | ||
} | ||
return false; | ||
}; | ||
function isControlLetter(ch) { | ||
return ch >= 0x41 /* A */ && ch <= 0x5A /* Z */ || ch >= 0x61 /* a */ && ch <= 0x7A /* z */; | ||
} | ||
return ch >= 0x41 | ||
/* A */ | ||
&& ch <= 0x5A | ||
/* Z */ | ||
|| ch >= 0x61 | ||
/* a */ | ||
&& ch <= 0x7A | ||
/* z */ | ||
; | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence | ||
pp.regexp_eatRegExpUnicodeEscapeSequence = function (state, forceU = false) { | ||
@@ -663,9 +907,18 @@ const start = state.pos; | ||
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) { | ||
@@ -676,13 +929,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; | ||
@@ -693,7 +955,8 @@ } | ||
}; | ||
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) { | ||
@@ -704,6 +967,12 @@ if (state.switchU) { | ||
} | ||
if (state.eat(0x2F /* / */)) { | ||
state.lastIntValue = 0x2F; /* / */ | ||
if (state.eat(0x2F | ||
/* / */ | ||
)) { | ||
state.lastIntValue = 0x2F; | ||
/* / */ | ||
return true; | ||
} | ||
return false; | ||
@@ -713,3 +982,8 @@ } | ||
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; | ||
@@ -721,19 +995,32 @@ 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 */) { | ||
do { | ||
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */); | ||
state.advance(); | ||
} while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */); | ||
return true; | ||
} | ||
if (ch >= 0x31 | ||
/* 1 */ | ||
&& ch <= 0x39 | ||
/* 9 */ | ||
) { | ||
do { | ||
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 | ||
/* 0 */ | ||
); | ||
state.advance(); | ||
} 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) { | ||
@@ -748,8 +1035,18 @@ const ch = state.current(); | ||
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"); | ||
@@ -760,16 +1057,30 @@ } | ||
}; | ||
function isCharacterClassEscape(ch) { | ||
return ch === 0x64 /* d */ || ch === 0x44 /* D */ || ch === 0x73 /* s */ || ch === 0x53 /* S */ || ch === 0x77 /* w */ || ch === 0x57 /* W */ | ||
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; | ||
const start = state.pos; // UnicodePropertyName `=` UnicodePropertyValue | ||
// UnicodePropertyName `=` UnicodePropertyValue | ||
if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) { | ||
if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D | ||
/* = */ | ||
)) { | ||
const name = state.lastStringValue; | ||
if (this.regexp_eatUnicodePropertyValue(state)) { | ||
@@ -781,5 +1092,5 @@ const value = state.lastStringValue; | ||
} | ||
state.pos = start; | ||
// LoneUnicodePropertyNameOrValue | ||
state.pos = start; // LoneUnicodePropertyNameOrValue | ||
if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) { | ||
@@ -790,17 +1101,21 @@ const nameOrValue = state.lastStringValue; | ||
} | ||
return false; | ||
}; | ||
pp.regexp_validateUnicodePropertyNameAndValue = function (state, name, value) { | ||
if (!(0, _util.has)(state.unicodeProperties.nonBinary, name)) state.raise("Invalid property name"); | ||
if (!(0, _util.hasOwn)(state.unicodeProperties.nonBinary, name)) state.raise("Invalid property name"); | ||
if (!state.unicodeProperties.nonBinary[name].test(value)) state.raise("Invalid property value"); | ||
}; | ||
pp.regexp_validateUnicodePropertyNameOrValue = function (state, nameOrValue) { | ||
if (!state.unicodeProperties.binary.test(nameOrValue)) state.raise("Invalid property name"); | ||
}; | ||
}; // UnicodePropertyName :: | ||
// UnicodePropertyNameCharacters | ||
// UnicodePropertyName :: | ||
// UnicodePropertyNameCharacters | ||
pp.regexp_eatUnicodePropertyName = function (state) { | ||
let ch = 0; | ||
state.lastStringValue = ""; | ||
while (isUnicodePropertyNameCharacter(ch = state.current())) { | ||
@@ -810,13 +1125,17 @@ state.lastStringValue += codePointToString(ch); | ||
} | ||
return state.lastStringValue !== ""; | ||
}; | ||
function isUnicodePropertyNameCharacter(ch) { | ||
return isControlLetter(ch) || ch === 0x5F; /* _ */ | ||
} | ||
return isControlLetter(ch) || ch === 0x5F; | ||
/* _ */ | ||
} // UnicodePropertyValue :: | ||
// UnicodePropertyValueCharacters | ||
// UnicodePropertyValue :: | ||
// UnicodePropertyValueCharacters | ||
pp.regexp_eatUnicodePropertyValue = function (state) { | ||
let ch = 0; | ||
state.lastStringValue = ""; | ||
while (isUnicodePropertyValueCharacter(ch = state.current())) { | ||
@@ -826,39 +1145,55 @@ state.lastStringValue += codePointToString(ch); | ||
} | ||
return state.lastStringValue !== ""; | ||
}; | ||
function isUnicodePropertyValueCharacter(ch) { | ||
return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch); | ||
} | ||
} // LoneUnicodePropertyNameOrValue :: | ||
// UnicodePropertyValueCharacters | ||
// 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; | ||
}; | ||
// 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) { | ||
@@ -869,21 +1204,29 @@ 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-ClassAtomNoDash | ||
// 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; | ||
@@ -893,29 +1236,43 @@ } | ||
const ch = state.current(); | ||
if (ch !== 0x5D /* ] */) { | ||
state.lastIntValue = ch; | ||
state.advance(); | ||
return true; | ||
} | ||
if (ch !== 0x5D | ||
/* ] */ | ||
) { | ||
state.lastIntValue = ch; | ||
state.advance(); | ||
return true; | ||
} | ||
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; | ||
@@ -925,31 +1282,41 @@ } | ||
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 /* _ */) { | ||
state.lastIntValue = ch % 0x20; | ||
state.advance(); | ||
return true; | ||
} | ||
if (isDecimalDigit(ch) || ch === 0x5F | ||
/* _ */ | ||
) { | ||
state.lastIntValue = ch % 0x20; | ||
state.advance(); | ||
return true; | ||
} | ||
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) { | ||
@@ -959,13 +1326,21 @@ 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 */ | ||
} | ||
return ch >= 0x30 | ||
/* 0 */ | ||
&& ch <= 0x39; | ||
/* 9 */ | ||
} // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits | ||
pp.regexp_eatHexDigits = function (state) { | ||
@@ -975,2 +1350,3 @@ const start = state.pos; | ||
state.lastIntValue = 0; | ||
while (isHexDigit(ch = state.current())) { | ||
@@ -980,24 +1356,56 @@ 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 >= 0x61 /* a */ && ch <= 0x66 /* f */) { | ||
return 10 + (ch - 0x61 /* a */); | ||
} | ||
return ch - 0x30; /* 0 */ | ||
} | ||
if (ch >= 0x41 | ||
/* A */ | ||
&& ch <= 0x46 | ||
/* F */ | ||
) { | ||
return 10 + (ch - 0x41 | ||
/* A */ | ||
); | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence | ||
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 | ||
// 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)) { | ||
@@ -1011,30 +1419,42 @@ 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 */ | ||
} | ||
// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits | ||
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-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)) { | ||
@@ -1044,6 +1464,8 @@ state.pos = start; | ||
} | ||
state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); | ||
state.advance(); | ||
} | ||
return true; | ||
}; |
@@ -11,14 +11,16 @@ "use strict"; | ||
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 = []; | ||
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) { | ||
@@ -30,7 +32,7 @@ this.scopeStack.push(new Scope(flags)); | ||
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) { | ||
@@ -42,2 +44,3 @@ return scope.flags & _scopeflags.SCOPE_FUNCTION || !this.inModule && scope.flags & _scopeflags.SCOPE_TOP; | ||
let redeclared = false; | ||
if (bindingType === _scopeflags.BIND_LEXICAL) { | ||
@@ -58,2 +61,3 @@ 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) { | ||
@@ -63,2 +67,3 @@ redeclared = true; | ||
} | ||
scope.var.push(name); | ||
@@ -69,2 +74,3 @@ if (this.inModule && scope.flags & _scopeflags.SCOPE_TOP) delete this.undefinedExports[name]; | ||
} | ||
if (redeclared) this.raiseRecoverable(pos, `Identifier '${name}' has already been declared`); | ||
@@ -89,5 +95,5 @@ }; | ||
} | ||
}; | ||
}; // 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 () { | ||
@@ -94,0 +100,0 @@ for (let i = this.scopeStack.length - 1;; i--) { |
"use strict"; | ||
exports.__esModule = true; | ||
exports.SCOPE_VAR = exports.SCOPE_TOP = exports.SCOPE_SUPER = exports.SCOPE_SIMPLE_CATCH = exports.SCOPE_GENERATOR = exports.SCOPE_FUNCTION = exports.SCOPE_DIRECT_SUPER = exports.SCOPE_CLASS_STATIC_BLOCK = exports.SCOPE_ASYNC = exports.SCOPE_ARROW = exports.BIND_VAR = exports.BIND_SIMPLE_CATCH = exports.BIND_OUTSIDE = exports.BIND_NONE = exports.BIND_LEXICAL = exports.BIND_FUNCTION = void 0; | ||
exports.functionFlags = functionFlags; | ||
// Each scope gets a bitset that may contain these flags | ||
const SCOPE_TOP = exports.SCOPE_TOP = 1, | ||
SCOPE_FUNCTION = exports.SCOPE_FUNCTION = 2, | ||
SCOPE_VAR = exports.SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION, | ||
SCOPE_ASYNC = exports.SCOPE_ASYNC = 4, | ||
SCOPE_GENERATOR = exports.SCOPE_GENERATOR = 8, | ||
SCOPE_ARROW = exports.SCOPE_ARROW = 16, | ||
SCOPE_SIMPLE_CATCH = exports.SCOPE_SIMPLE_CATCH = 32, | ||
SCOPE_SUPER = exports.SCOPE_SUPER = 64, | ||
SCOPE_DIRECT_SUPER = exports.SCOPE_DIRECT_SUPER = 128; | ||
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; | ||
exports.SCOPE_VAR = SCOPE_VAR; | ||
exports.SCOPE_CLASS_STATIC_BLOCK = SCOPE_CLASS_STATIC_BLOCK; | ||
exports.SCOPE_DIRECT_SUPER = SCOPE_DIRECT_SUPER; | ||
exports.SCOPE_SUPER = SCOPE_SUPER; | ||
exports.SCOPE_SIMPLE_CATCH = SCOPE_SIMPLE_CATCH; | ||
exports.SCOPE_ARROW = SCOPE_ARROW; | ||
exports.SCOPE_GENERATOR = SCOPE_GENERATOR; | ||
exports.SCOPE_ASYNC = SCOPE_ASYNC; | ||
exports.SCOPE_FUNCTION = SCOPE_FUNCTION; | ||
exports.SCOPE_TOP = SCOPE_TOP; | ||
function functionFlags(async, generator) { | ||
return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0); | ||
} | ||
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 = exports.BIND_NONE = 0, | ||
const BIND_NONE = 0, | ||
// Not a binding | ||
BIND_VAR = exports.BIND_VAR = 1, | ||
BIND_VAR = 1, | ||
// Var-style binding | ||
BIND_LEXICAL = exports.BIND_LEXICAL = 2, | ||
BIND_LEXICAL = 2, | ||
// Let- or const-style binding | ||
BIND_FUNCTION = exports.BIND_FUNCTION = 3, | ||
BIND_FUNCTION = 3, | ||
// Function declaration | ||
BIND_SIMPLE_CATCH = exports.BIND_SIMPLE_CATCH = 4, | ||
BIND_SIMPLE_CATCH = 4, | ||
// Simple (identifier pattern) catch binding | ||
BIND_OUTSIDE = exports.BIND_OUTSIDE = 5; // Special case for function names as bound inside the function | ||
BIND_OUTSIDE = 5; // Special case for function names as bound inside the function | ||
exports.BIND_OUTSIDE = BIND_OUTSIDE; | ||
exports.BIND_SIMPLE_CATCH = BIND_SIMPLE_CATCH; | ||
exports.BIND_FUNCTION = BIND_FUNCTION; | ||
exports.BIND_LEXICAL = BIND_LEXICAL; | ||
exports.BIND_VAR = BIND_VAR; | ||
exports.BIND_NONE = BIND_NONE; |
112
lib/state.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.Parser = undefined; | ||
exports.Parser = void 0; | ||
@@ -24,2 +24,3 @@ var _identifier = require("./identifier.js"); | ||
let reserved = ""; | ||
if (options.allowReserved !== true) { | ||
@@ -29,2 +30,3 @@ reserved = _identifier.reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3]; | ||
} | ||
this.reservedWords = (0, _util.wordsRegexp)(reserved); | ||
@@ -34,12 +36,9 @@ 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; | ||
// Set up token state | ||
this.containsEsc = false; // Set up token state | ||
// The current position of the tokenizer in the input. | ||
// The current position of the tokenizer in the input. | ||
if (startPos) { | ||
@@ -52,48 +51,45 @@ this.pos = startPos; | ||
this.curLine = 1; | ||
} | ||
} // Properties of the current token: | ||
// Its type | ||
// 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(); | ||
// Position information for the previous token | ||
this.startLoc = this.endLoc = this.curPosition(); // Position information for the previous token | ||
this.lastTokEndLoc = this.lastTokStartLoc = null; | ||
this.lastTokStart = this.lastTokEnd = this.pos; | ||
// The context stack is used to superficially track syntactic | ||
this.lastTokStart = this.lastTokEnd = this.pos; // 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; | ||
this.exprAllowed = true; // Figure out if it's a module code. | ||
// Figure out if it's a module code. | ||
this.inModule = options.sourceType === "module"; | ||
this.strict = this.inModule || this.strictDirective(this.pos); | ||
this.strict = this.inModule || this.strictDirective(this.pos); // Used to signify the start of a potential arrow function | ||
// 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. | ||
// 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.yieldPos = this.awaitPos = this.awaitIdentPos = 0; // Labels in scope. | ||
// If enabled, skip leading hashbang line. | ||
if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2); | ||
this.labels = []; // Thus-far undefined exports. | ||
// Scope tracking for duplicate variable names (see scope.js) | ||
this.undefinedExports = Object.create(null); // If enabled, skip leading hashbang line. | ||
if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2); // Scope tracking for duplicate variable names (see scope.js) | ||
this.scopeStack = []; | ||
this.enterScope(_scopeflags.SCOPE_TOP); | ||
this.enterScope(_scopeflags.SCOPE_TOP); // For RegExp validation | ||
// For RegExp validation | ||
this.regexpState = null; | ||
this.regexpState = null; // 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 = []; | ||
} | ||
@@ -110,24 +106,54 @@ | ||
} | ||
get inGenerator() { | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_GENERATOR) > 0; | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit; | ||
} | ||
get inAsync() { | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_ASYNC) > 0; | ||
return (this.currentVarScope().flags & _scopeflags.SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit; | ||
} | ||
get canAwait() { | ||
for (let i = this.scopeStack.length - 1; i >= 0; i--) { | ||
let scope = this.scopeStack[i]; | ||
if (scope.inClassFieldInit || scope.flags & _scopeflags.SCOPE_CLASS_STATIC_BLOCK) return false; | ||
if (scope.flags & _scopeflags.SCOPE_FUNCTION) return (scope.flags & _scopeflags.SCOPE_ASYNC) > 0; | ||
} | ||
return this.inModule && this.options.ecmaVersion >= 13 || this.options.allowAwaitOutsideFunction; | ||
} | ||
get allowSuper() { | ||
return (this.currentThisScope().flags & _scopeflags.SCOPE_SUPER) > 0; | ||
const _this$currentThisScop = this.currentThisScope(), | ||
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 inNonArrowFunction() { | ||
return (this.currentThisScope().flags & _scopeflags.SCOPE_FUNCTION) > 0; | ||
get allowNewDotTarget() { | ||
const _this$currentThisScop2 = this.currentThisScope(), | ||
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; | ||
@@ -149,3 +175,5 @@ } | ||
} | ||
} | ||
exports.Parser = Parser; |
@@ -17,6 +17,9 @@ "use strict"; | ||
const pp = _state.Parser.prototype; | ||
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."); } | ||
// ### Statement parsing | ||
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; // ### Statement parsing | ||
// Parse a program. Initializes the parser, reads any number of | ||
@@ -30,2 +33,3 @@ // statements, and wraps them in a Program node. Optionally takes a | ||
if (!node.body) node.body = []; | ||
while (this.type !== _tokentype.types.eof) { | ||
@@ -35,20 +39,8 @@ let stmt = this.parseStatement(null, true, exports); | ||
} | ||
if (this.inModule) { | ||
for (var _iterator = Object.keys(this.undefinedExports), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
let name = _ref; | ||
this.raiseRecoverable(this.undefinedExports[name].start, `Export '${name}' is not defined`); | ||
} | ||
}this.adaptDirectivePrologue(node.body); | ||
if (this.inModule) for (var _i = 0, _Object$keys = Object.keys(this.undefinedExports); _i < _Object$keys.length; _i++) { | ||
let name = _Object$keys[_i]; | ||
this.raiseRecoverable(this.undefinedExports[name].start, `Export '${name}' is not defined`); | ||
} | ||
this.adaptDirectivePrologue(node.body); | ||
this.next(); | ||
@@ -59,4 +51,8 @@ node.sourceType = this.options.sourceType; | ||
const loopLabel = { kind: "loop" }, | ||
switchLabel = { kind: "switch" }; | ||
const loopLabel = { | ||
kind: "loop" | ||
}, | ||
switchLabel = { | ||
kind: "switch" | ||
}; | ||
@@ -66,35 +62,42 @@ pp.isLet = function (context) { | ||
_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) return true; // '[' | ||
if (nextCh === 91 || nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true; // '[', '/', astral | ||
if (context) return false; | ||
if (nextCh === 123) return true; // '{' | ||
if (nextCh === 123) return true; // '{' | ||
if ((0, _identifier.isIdentifierStart)(nextCh, true)) { | ||
let pos = next + 1; | ||
while ((0, _identifier.isIdentifierChar)(this.input.charCodeAt(pos), true)) ++pos; | ||
while ((0, _identifier.isIdentifierChar)(nextCh = this.input.charCodeAt(pos), true)) ++pos; | ||
if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) return true; | ||
let ident = this.input.slice(next, pos); | ||
if (!_identifier.keywordRelationalOperator.test(ident)) return true; | ||
} | ||
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; | ||
_whitespace.skipWhiteSpace.lastIndex = this.pos; | ||
let skip = _whitespace.skipWhiteSpace.exec(this.input); | ||
let next = this.pos + skip[0].length; | ||
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)(this.input.charAt(next + 8))); | ||
}; | ||
// Parse a single statement. | ||
let next = this.pos + skip[0].length, | ||
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. | ||
// | ||
@@ -106,2 +109,3 @@ // If expecting a statement and finding a slash operator, parse a | ||
pp.parseStatement = function (context, topLevel, exports) { | ||
@@ -115,17 +119,21 @@ let starttype = this.type, | ||
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) { | ||
case _tokentype.types._break:case _tokentype.types._continue: | ||
case _tokentype.types._break: | ||
case _tokentype.types._continue: | ||
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: | ||
@@ -137,27 +145,40 @@ // 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:case _tokentype.types._var: | ||
case _tokentype.types._const: | ||
case _tokentype.types._var: | ||
kind = kind || this.value; | ||
if (context && kind !== "var") this.unexpected(); | ||
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: | ||
@@ -167,3 +188,5 @@ case _tokentype.types._import: | ||
_whitespace.skipWhiteSpace.lastIndex = this.pos; | ||
let skip = _whitespace.skipWhiteSpace.exec(this.input); | ||
let next = this.pos + skip[0].length, | ||
@@ -179,4 +202,4 @@ nextCh = this.input.charCodeAt(next); | ||
} | ||
return starttype === _tokentype.types._import ? this.parseImport(node) : this.parseExport(node, exports); | ||
// If the statement does not start with a statement keyword or a | ||
@@ -187,2 +210,3 @@ // brace, it's an ExpressionStatement or LabeledStatement. We | ||
// Identifier node, we switch to interpreting it as a label. | ||
default: | ||
@@ -207,9 +231,10 @@ if (this.isAsyncFunction()) { | ||
this.semicolon(); | ||
} | ||
} // Verify that there is an actual destination to break or | ||
// continue to. | ||
// 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) { | ||
@@ -220,2 +245,3 @@ if (lab.kind != null && (isBreak || lab.kind === "loop")) break; | ||
} | ||
if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword); | ||
@@ -240,5 +266,3 @@ return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); | ||
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` | ||
@@ -251,8 +275,10 @@ // statement or expression, disallowing the `in` operator (see | ||
pp.parseForStatement = function (node) { | ||
this.next(); | ||
let awaitAt = this.options.ecmaVersion >= 9 && (this.inAsync || !this.inFunction && this.options.allowAwaitOutsideFunction) && this.eatContextual("await") ? this.lastTokStart : -1; | ||
let awaitAt = this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await") ? this.lastTokStart : -1; | ||
this.labels.push(loopLabel); | ||
this.enterScope(0); | ||
this.expect(_tokentype.types.parenL); | ||
if (this.type === _tokentype.types.semi) { | ||
@@ -262,3 +288,5 @@ if (awaitAt > -1) this.unexpected(awaitAt); | ||
} | ||
let isLet = this.isLet(); | ||
if (this.type === _tokentype.types._var || this.type === _tokentype.types._const || isLet) { | ||
@@ -270,2 +298,3 @@ let init = this.startNode(), | ||
this.finishNode(init, "VariableDeclaration"); | ||
if ((this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && init.declarations.length === 1) { | ||
@@ -277,10 +306,16 @@ 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; | ||
let refDestructuringErrors = new _parseutil.DestructuringErrors(); | ||
let init = this.parseExpression(true, refDestructuringErrors); | ||
if (this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) { | ||
let init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors); | ||
if (this.type === _tokentype.types._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) { | ||
if (this.options.ecmaVersion >= 9) { | ||
@@ -291,2 +326,4 @@ if (this.type === _tokentype.types._in) { | ||
} | ||
if (startsWithLet && isForOf) this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); | ||
this.toAssignable(init, false, refDestructuringErrors); | ||
@@ -298,2 +335,3 @@ this.checkLValPattern(init); | ||
} | ||
if (awaitAt > -1) this.unexpected(awaitAt); | ||
@@ -310,4 +348,4 @@ return this.parseFor(node, init); | ||
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"); | ||
@@ -320,5 +358,3 @@ node.alternate = this.eat(_tokentype.types._else) ? this.parseStatement("if") : null; | ||
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 | ||
@@ -328,3 +364,4 @@ // possibility to insert one. | ||
if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.argument = null;else { | ||
node.argument = this.parseExpression();this.semicolon(); | ||
node.argument = this.parseExpression(); | ||
this.semicolon(); | ||
} | ||
@@ -340,5 +377,3 @@ return this.finishNode(node, "ReturnStatement"); | ||
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 | ||
@@ -348,2 +383,3 @@ // adding statements to. | ||
let cur; | ||
for (let sawDefault = false; this.type !== _tokentype.types.braceR;) { | ||
@@ -356,2 +392,3 @@ if (this.type === _tokentype.types._case || this.type === _tokentype.types._default) { | ||
this.next(); | ||
if (isCase) { | ||
@@ -364,2 +401,3 @@ cur.test = this.parseExpression(); | ||
} | ||
this.expect(_tokentype.types.colon); | ||
@@ -371,5 +409,7 @@ } else { | ||
} | ||
this.exitScope(); | ||
if (cur) this.finishNode(cur, "SwitchCase"); | ||
this.next(); // Closing brace | ||
this.labels.pop(); | ||
@@ -385,5 +425,4 @@ return this.finishNode(node, "SwitchStatement"); | ||
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. | ||
@@ -396,5 +435,7 @@ const empty = []; | ||
node.handler = null; | ||
if (this.type === _tokentype.types._catch) { | ||
let clause = this.startNode(); | ||
this.next(); | ||
if (this.eat(_tokentype.types.parenL)) { | ||
@@ -411,2 +452,3 @@ clause.param = this.parseBindingAtom(); | ||
} | ||
clause.body = this.parseBlock(false); | ||
@@ -416,2 +458,3 @@ this.exitScope(); | ||
} | ||
node.finalizer = this.eat(_tokentype.types._finally) ? this.parseBlock() : null; | ||
@@ -452,20 +495,12 @@ if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause"); | ||
pp.parseLabeledStatement = function (node, maybeName, expr, context) { | ||
for (var _iterator2 = this.labels, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator = _createForOfIteratorHelperLoose(this.labels), _step; !(_step = _iterator()).done;) { | ||
let label = _step.value; | ||
if (label.name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared"); | ||
} | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
let kind = this.type.isLoop ? "loop" : this.type === _tokentype.types._switch ? "switch" : null; | ||
let label = _ref2; | ||
if (label.name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared"); | ||
}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) { | ||
@@ -477,3 +512,8 @@ // Update information about previous labels on this node | ||
} | ||
this.labels.push({ name: maybeName, kind, statementStart: this.start }); | ||
this.labels.push({ | ||
name: maybeName, | ||
kind, | ||
statementStart: this.start | ||
}); | ||
node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label"); | ||
@@ -489,8 +529,7 @@ this.labels.pop(); | ||
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) { | ||
@@ -500,2 +539,3 @@ node.body = []; | ||
if (createNewLexicalScope) this.enterScope(0); | ||
while (this.type !== _tokentype.types.braceR) { | ||
@@ -505,2 +545,3 @@ let stmt = this.parseStatement(null); | ||
} | ||
if (exitStrict) this.strict = false; | ||
@@ -510,8 +551,7 @@ 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) { | ||
@@ -528,7 +568,6 @@ 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) { | ||
@@ -541,2 +580,3 @@ const isForIn = this.type === _tokentype.types._in; | ||
} | ||
node.left = init; | ||
@@ -549,5 +589,4 @@ 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. | ||
@@ -557,5 +596,7 @@ pp.parseVar = function (node, isFor, kind) { | ||
node.kind = kind; | ||
for (;;) { | ||
let decl = this.startNode(); | ||
this.parseVarId(decl, kind); | ||
if (this.eat(_tokentype.types.eq)) { | ||
@@ -570,5 +611,7 @@ decl.init = this.parseMaybeAssign(isFor); | ||
} | ||
node.declarations.push(this.finishNode(decl, "VariableDeclarator")); | ||
if (!this.eat(_tokentype.types.comma)) break; | ||
} | ||
return node; | ||
@@ -584,10 +627,9 @@ }; | ||
FUNC_HANGING_STATEMENT = 2, | ||
FUNC_NULLABLE_ID = 4; | ||
// Parse a function declaration or literal (depending on the | ||
FUNC_NULLABLE_ID = 4; // 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 | ||
// Remove `allowExpressionBody` for 7.0.0, as it is only called with false | ||
pp.parseFunction = function (node, statement, allowExpressionBody, isAsync) { | ||
pp.parseFunction = function (node, statement, allowExpressionBody, isAsync, forInit) { | ||
this.initFunction(node); | ||
if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) { | ||
@@ -597,2 +639,3 @@ if (this.type === _tokentype.types.star && statement & FUNC_HANGING_STATEMENT) this.unexpected(); | ||
} | ||
if (this.options.ecmaVersion >= 8) node.async = !!isAsync; | ||
@@ -602,4 +645,3 @@ | ||
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 | ||
@@ -618,8 +660,5 @@ // mode depends on properties of the current scope (see | ||
this.enterScope((0, _scopeflags.functionFlags)(node.async, node.generator)); | ||
if (!(statement & FUNC_STATEMENT)) node.id = this.type === _tokentype.types.name ? this.parseIdent() : null; | ||
this.parseFunctionParams(node); | ||
this.parseFunctionBody(node, allowExpressionBody, false); | ||
this.parseFunctionBody(node, allowExpressionBody, false, forInit); | ||
this.yieldPos = oldYieldPos; | ||
@@ -635,34 +674,39 @@ this.awaitPos = oldAwaitPos; | ||
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(); | ||
this.next(); // ecma-262 14.6 Class Definitions | ||
// A class definition is always strict mode code. | ||
// ecma-262 14.6 Class Definitions | ||
// A class definition is always strict mode code. | ||
const oldStrict = this.strict; | ||
this.strict = true; | ||
this.parseClassId(node, isStatement); | ||
this.parseClassSuper(node); | ||
let classBody = this.startNode(); | ||
const privateNameMap = this.enterClassBody(); | ||
const classBody = this.startNode(); | ||
let hadConstructor = false; | ||
classBody.body = []; | ||
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") { | ||
if (hadConstructor) this.raise(element.start, "Duplicate constructor in the same class"); | ||
hadConstructor = true; | ||
} else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) { | ||
this.raiseRecoverable(element.key.start, `Identifier '#${element.key.name}' has already been declared`); | ||
} | ||
} | ||
} | ||
this.strict = oldStrict; | ||
this.next(); | ||
node.body = this.finishNode(classBody, "ClassBody"); | ||
this.exitClassBody(); | ||
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); | ||
@@ -673,54 +717,151 @@ }; | ||
if (this.eat(_tokentype.types.semi)) return null; | ||
const ecmaVersion = this.options.ecmaVersion; | ||
const node = this.startNode(); | ||
let keyName = ""; | ||
let isGenerator = false; | ||
let isAsync = false; | ||
let kind = "method"; | ||
let isStatic = false; | ||
let method = this.startNode(); | ||
const tryContextual = (k, noLineBreak = false) => { | ||
const start = this.start, | ||
startLoc = this.startLoc; | ||
if (!this.eatContextual(k)) return false; | ||
if (this.type !== _tokentype.types.parenL && (!noLineBreak || !this.canInsertSemicolon())) return true; | ||
if (method.key) this.unexpected(); | ||
method.computed = false; | ||
method.key = this.startNodeAt(start, startLoc); | ||
method.key.name = k; | ||
this.finishNode(method.key, "Identifier"); | ||
return false; | ||
}; | ||
if (this.eatContextual("static")) { | ||
// Parse static init block | ||
if (ecmaVersion >= 13 && this.eat(_tokentype.types.braceL)) { | ||
this.parseClassStaticBlock(node); | ||
return node; | ||
} | ||
method.kind = "method"; | ||
method.static = tryContextual("static"); | ||
let isGenerator = this.eat(_tokentype.types.star); | ||
let isAsync = false; | ||
if (!isGenerator) { | ||
if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) { | ||
if (this.isClassElementNameStart() || this.type === _tokentype.types.star) { | ||
isStatic = true; | ||
} else { | ||
keyName = "static"; | ||
} | ||
} | ||
node.static = isStatic; | ||
if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) { | ||
if ((this.isClassElementNameStart() || this.type === _tokentype.types.star) && !this.canInsertSemicolon()) { | ||
isAsync = true; | ||
isGenerator = this.options.ecmaVersion >= 9 && this.eat(_tokentype.types.star); | ||
} else if (tryContextual("get")) { | ||
method.kind = "get"; | ||
} else if (tryContextual("set")) { | ||
method.kind = "set"; | ||
} else { | ||
keyName = "async"; | ||
} | ||
} | ||
if (!method.key) this.parsePropertyName(method); | ||
let key = method.key; | ||
let allowsDirectSuper = false; | ||
if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) { | ||
if (method.kind !== "method") this.raise(key.start, "Constructor can't have get/set modifier"); | ||
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")) { | ||
if (this.isClassElementNameStart()) { | ||
kind = lastValue; | ||
} else { | ||
keyName = lastValue; | ||
} | ||
} | ||
} // Parse element name | ||
if (keyName) { | ||
// 'async', 'get', 'set', or 'static' were not a keyword contextually. | ||
// The last token is any of those. Make it the element name. | ||
node.computed = false; | ||
node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc); | ||
node.key.name = keyName; | ||
this.finishNode(node.key, "Identifier"); | ||
} else { | ||
this.parseClassElementName(node); | ||
} // 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. | ||
if (isConstructor && kind !== "method") this.raise(node.key.start, "Constructor can't have get/set modifier"); | ||
node.kind = isConstructor ? "constructor" : kind; | ||
this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper); | ||
} else { | ||
this.parseClassField(node); | ||
} | ||
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) { | ||
if (this.type === _tokentype.types.privateId) { | ||
if (this.value === "constructor") { | ||
this.raise(this.start, "Classes can't have an element named '#constructor'"); | ||
} | ||
element.computed = false; | ||
element.key = this.parsePrivateIdent(); | ||
} else { | ||
this.parsePropertyName(element); | ||
} | ||
}; | ||
pp.parseClassMethod = function (method, isGenerator, isAsync, allowsDirectSuper) { | ||
// Check key and flags | ||
const key = method.key; | ||
if (method.kind === "constructor") { | ||
if (isGenerator) this.raise(key.start, "Constructor can't be a generator"); | ||
if (isAsync) this.raise(key.start, "Constructor can't be an async method"); | ||
method.kind = "constructor"; | ||
allowsDirectSuper = constructorAllowsSuper; | ||
} else if (method.static && key.type === "Identifier" && key.name === "prototype") { | ||
} else if (method.static && checkKeyName(method, "prototype")) { | ||
this.raise(key.start, "Classes may not have a static property named prototype"); | ||
} // Parse value | ||
const value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper); // Check value | ||
if (method.kind === "get" && value.params.length !== 0) this.raiseRecoverable(value.start, "getter should have no params"); | ||
if (method.kind === "set" && value.params.length !== 1) this.raiseRecoverable(value.start, "setter should have exactly one param"); | ||
if (method.kind === "set" && value.params[0].type === "RestElement") this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); | ||
return this.finishNode(method, "MethodDefinition"); | ||
}; | ||
pp.parseClassField = function (field) { | ||
if (checkKeyName(field, "constructor")) { | ||
this.raise(field.key.start, "Classes can't have a field named 'constructor'"); | ||
} else if (field.static && checkKeyName(field, "prototype")) { | ||
this.raise(field.key.start, "Classes can't have a static field named 'prototype'"); | ||
} | ||
this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper); | ||
if (method.kind === "get" && method.value.params.length !== 0) this.raiseRecoverable(method.value.start, "getter should have no params"); | ||
if (method.kind === "set" && method.value.params.length !== 1) this.raiseRecoverable(method.value.start, "setter should have exactly one param"); | ||
if (method.kind === "set" && method.value.params[0].type === "RestElement") this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); | ||
return method; | ||
if (this.eat(_tokentype.types.eq)) { | ||
// To raise SyntaxError if 'arguments' exists in the initializer. | ||
const scope = this.currentThisScope(); | ||
const inClassFieldInit = scope.inClassFieldInit; | ||
scope.inClassFieldInit = true; | ||
field.value = this.parseMaybeAssign(); | ||
scope.inClassFieldInit = inClassFieldInit; | ||
} else { | ||
field.value = null; | ||
} | ||
this.semicolon(); | ||
return this.finishNode(field, "PropertyDefinition"); | ||
}; | ||
pp.parseClassMethod = function (method, isGenerator, isAsync, allowsDirectSuper) { | ||
method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper); | ||
return this.finishNode(method, "MethodDefinition"); | ||
pp.parseClassStaticBlock = function (node) { | ||
node.body = []; | ||
let oldLabels = this.labels; | ||
this.labels = []; | ||
this.enterScope(_scopeflags.SCOPE_CLASS_STATIC_BLOCK | _scopeflags.SCOPE_SUPER); | ||
while (this.type !== _tokentype.types.braceR) { | ||
let stmt = this.parseStatement(null); | ||
node.body.push(stmt); | ||
} | ||
this.next(); | ||
this.exitScope(); | ||
this.labels = oldLabels; | ||
return this.finishNode(node, "StaticBlock"); | ||
}; | ||
@@ -739,14 +880,70 @@ | ||
pp.parseClassSuper = function (node) { | ||
node.superClass = this.eat(_tokentype.types._extends) ? this.parseExprSubscripts() : null; | ||
node.superClass = this.eat(_tokentype.types._extends) ? this.parseExprSubscripts(false) : null; | ||
}; | ||
// Parses module export declaration. | ||
pp.enterClassBody = function () { | ||
const element = { | ||
declared: Object.create(null), | ||
used: [] | ||
}; | ||
this.privateNameStack.push(element); | ||
return element.declared; | ||
}; | ||
pp.exitClassBody = function () { | ||
const _this$privateNameStac = this.privateNameStack.pop(), | ||
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)) { | ||
if (parent) { | ||
parent.used.push(id); | ||
} else { | ||
this.raiseRecoverable(id.start, `Private field '#${id.name}' must be declared in an enclosing class`); | ||
} | ||
} | ||
} | ||
}; | ||
function isPrivateNameConflicted(privateNameMap, element) { | ||
const name = element.key.name; | ||
const curr = privateNameMap[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. | ||
if (curr === "iget" && next === "iset" || curr === "iset" && next === "iget" || curr === "sget" && next === "sset" || curr === "sset" && next === "sget") { | ||
privateNameMap[name] = "true"; | ||
return false; | ||
} else if (!curr) { | ||
privateNameMap[name] = next; | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
function checkKeyName(node, name) { | ||
const computed = node.computed, | ||
key = node.key; | ||
return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name); | ||
} // Parses module export declaration. | ||
pp.parseExport = function (node, exports) { | ||
this.next(); | ||
// export * from '...' | ||
this.next(); // export * from '...' | ||
if (this.eat(_tokentype.types.star)) { | ||
if (this.options.ecmaVersion >= 11) { | ||
if (this.eatContextual("as")) { | ||
node.exported = this.parseIdent(true); | ||
node.exported = this.parseModuleExportName(); | ||
this.checkExport(exports, node.exported.name, this.lastTokStart); | ||
@@ -757,2 +954,3 @@ } else { | ||
} | ||
this.expectContextual("from"); | ||
@@ -764,2 +962,3 @@ if (this.type !== _tokentype.types.string) this.unexpected(); | ||
} | ||
if (this.eat(_tokentype.types._default)) { | ||
@@ -769,2 +968,3 @@ // export default ... | ||
let isAsync; | ||
if (this.type === _tokentype.types._function || (isAsync = this.isAsyncFunction())) { | ||
@@ -782,5 +982,7 @@ let fNode = this.startNode(); | ||
} | ||
return this.finishNode(node, "ExportDefaultDeclaration"); | ||
} | ||
// export var|const|let|function|class ... | ||
} // export var|const|let|function|class ... | ||
if (this.shouldParseExportStatement()) { | ||
@@ -795,2 +997,3 @@ node.declaration = this.parseStatement(null); | ||
node.specifiers = this.parseExportSpecifiers(exports); | ||
if (this.eatContextual("from")) { | ||
@@ -800,20 +1003,12 @@ if (this.type !== _tokentype.types.string) this.unexpected(); | ||
} else { | ||
for (var _iterator3 = node.specifiers, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(node.specifiers), _step2; !(_step2 = _iterator2()).done;) { | ||
let spec = _step2.value; | ||
// check for keywords used as local names | ||
this.checkUnreserved(spec.local); // check if export is defined | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
this.checkLocalExport(spec.local); | ||
if (spec.local.type === "Literal") { | ||
this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`."); | ||
} | ||
let spec = _ref3; | ||
// check for keywords used as local names | ||
this.checkUnreserved(spec.local); | ||
// check if export is defined | ||
this.checkLocalExport(spec.local); | ||
} | ||
@@ -823,4 +1018,6 @@ | ||
} | ||
this.semicolon(); | ||
} | ||
return this.finishNode(node, "ExportNamedDeclaration"); | ||
@@ -831,3 +1028,3 @@ }; | ||
if (!exports) return; | ||
if ((0, _util.has)(exports, name)) this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); | ||
if ((0, _util.hasOwn)(exports, name)) this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); | ||
exports[name] = true; | ||
@@ -839,33 +1036,9 @@ }; | ||
if (type === "Identifier") this.checkExport(exports, pat.name, pat.start);else if (type === "ObjectPattern") { | ||
for (var _iterator4 = pat.properties, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
} | ||
let prop = _ref4; | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(pat.properties), _step3; !(_step3 = _iterator3()).done;) { | ||
let prop = _step3.value; | ||
this.checkPatternExport(exports, prop); | ||
} | ||
} else if (type === "ArrayPattern") { | ||
for (var _iterator5 = pat.elements, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
} | ||
let elt = _ref5; | ||
for (var _iterator4 = _createForOfIteratorHelperLoose(pat.elements), _step4; !(_step4 = _iterator4()).done;) { | ||
let elt = _step4.value; | ||
if (elt) this.checkPatternExport(exports, elt); | ||
@@ -878,16 +1051,5 @@ } | ||
if (!exports) return; | ||
for (var _iterator6 = decls, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
} else { | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
} | ||
let decl = _ref6; | ||
for (var _iterator5 = _createForOfIteratorHelperLoose(decls), _step5; !(_step5 = _iterator5()).done;) { | ||
let decl = _step5.value; | ||
this.checkPatternExport(exports, decl.id); | ||
@@ -899,11 +1061,11 @@ } | ||
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)) { | ||
@@ -916,15 +1078,15 @@ if (!first) { | ||
let node = this.startNode(); | ||
node.local = this.parseIdent(true); | ||
node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local; | ||
this.checkExport(exports, node.exported.name, node.exported.start); | ||
node.local = this.parseModuleExportName(); | ||
node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local; | ||
this.checkExport(exports, node.exported[node.exported.type === "Identifier" ? "name" : "value"], node.exported.start); | ||
nodes.push(this.finishNode(node, "ExportSpecifier")); | ||
} | ||
return nodes; | ||
}; | ||
}; // Parses import declaration. | ||
// Parses import declaration. | ||
pp.parseImport = function (node) { | ||
this.next(); | ||
// import '...' | ||
this.next(); // import '...' | ||
if (this.type === _tokentype.types.string) { | ||
@@ -938,7 +1100,7 @@ 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. | ||
@@ -948,2 +1110,3 @@ pp.parseImportSpecifiers = function () { | ||
first = true; | ||
if (this.type === _tokentype.types.name) { | ||
@@ -957,2 +1120,3 @@ // import defaultObj, { x, y as z } from '...' | ||
} | ||
if (this.type === _tokentype.types.star) { | ||
@@ -967,3 +1131,5 @@ let node = this.startNode(); | ||
} | ||
this.expect(_tokentype.types.braceL); | ||
while (!this.eat(_tokentype.types.braceR)) { | ||
@@ -976,3 +1142,4 @@ if (!first) { | ||
let node = this.startNode(); | ||
node.imported = this.parseIdent(true); | ||
node.imported = this.parseModuleExportName(); | ||
if (this.eatContextual("as")) { | ||
@@ -984,9 +1151,25 @@ node.local = this.parseIdent(); | ||
} | ||
this.checkLValSimple(node.local, _scopeflags.BIND_LEXICAL); | ||
nodes.push(this.finishNode(node, "ImportSpecifier")); | ||
} | ||
return nodes; | ||
}; | ||
// Set `ExpressionStatement#directive` property for directive prologues. | ||
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. | ||
pp.adaptDirectivePrologue = function (statements) { | ||
@@ -997,6 +1180,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] === "'"); | ||
}; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.types = exports.TokContext = undefined; | ||
exports.types = exports.TokContext = void 0; | ||
@@ -12,2 +12,5 @@ var _state = require("./state.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 { | ||
@@ -21,9 +24,7 @@ constructor(token, isExpr, preserveSpace, override, generator) { | ||
} | ||
} | ||
exports.TokContext = TokContext; // 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 | ||
const types = exports.types = { | ||
exports.TokContext = TokContext; | ||
const types = { | ||
b_stat: new TokContext("{", false), | ||
@@ -40,3 +41,3 @@ b_expr: new TokContext("{", true), | ||
}; | ||
exports.types = types; | ||
const pp = _state.Parser.prototype; | ||
@@ -48,10 +49,13 @@ | ||
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)); | ||
@@ -69,2 +73,3 @@ if (prevType === _tokentype.types._else || prevType === _tokentype.types.semi || prevType === _tokentype.types.eof || prevType === _tokentype.types.parenR || prevType === _tokentype.types.arrow) return true; | ||
} | ||
return false; | ||
@@ -77,6 +82,12 @@ }; | ||
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 | ||
// Token-specific context update code | ||
pp.overrideContext = function (tokenCtx) { | ||
if (this.curContext() !== tokenCtx) { | ||
this.context[this.context.length - 1] = tokenCtx; | ||
} | ||
}; // Token-specific context update code | ||
_tokentype.types.parenR.updateContext = _tokentype.types.braceR.updateContext = function () { | ||
@@ -87,6 +98,9 @@ if (this.context.length === 1) { | ||
} | ||
let out = this.context.pop(); | ||
if (out === types.b_stat && this.curContext().token === "function") { | ||
out = this.context.pop(); | ||
} | ||
this.exprAllowed = !out.isExpr; | ||
@@ -111,4 +125,3 @@ }; | ||
_tokentype.types.incDec.updateContext = function () { | ||
// tokExprAllowed stays unchanged | ||
_tokentype.types.incDec.updateContext = function () {// tokExprAllowed stays unchanged | ||
}; | ||
@@ -131,2 +144,3 @@ | ||
} | ||
this.exprAllowed = true; | ||
@@ -137,6 +151,8 @@ }; | ||
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; | ||
}; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.Token = undefined; | ||
exports.Token = void 0; | ||
@@ -21,3 +21,2 @@ var _identifier = require("./identifier.js"); | ||
// used for the onToken callback and the external tokenizer. | ||
class Token { | ||
@@ -32,9 +31,8 @@ constructor(p) { | ||
} | ||
} | ||
exports.Token = Token; // ## Tokenizer | ||
} // ## Tokenizer | ||
const pp = _state.Parser.prototype; | ||
// Move to the next token | ||
exports.Token = Token; | ||
const pp = _state.Parser.prototype; // Move to the next token | ||
@@ -44,3 +42,2 @@ pp.next = function (ignoreEscapeSequenceInKeyword) { | ||
if (this.options.onToken) this.options.onToken(new Token(this)); | ||
this.lastTokEnd = this.end; | ||
@@ -56,5 +53,5 @@ this.lastTokStart = this.start; | ||
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 () { | ||
@@ -70,11 +67,4 @@ 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). | ||
pp.curContext = function () { | ||
return this.context[this.context.length - 1]; | ||
}; | ||
// Read a single token, updating the parser object's token-related | ||
@@ -86,7 +76,5 @@ // properties. | ||
if (!curContext || !curContext.preserveSpace) this.skipSpace(); | ||
this.start = this.pos; | ||
if (this.options.locations) this.startLoc = this.curPosition(); | ||
if (this.pos >= this.input.length) return this.finishToken(_tokentype.types.eof); | ||
if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos()); | ||
@@ -98,4 +86,5 @@ }; | ||
// 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); | ||
@@ -106,5 +95,5 @@ }; | ||
let code = this.input.charCodeAt(this.pos); | ||
if (code <= 0xd7ff || code >= 0xe000) return code; | ||
if (code <= 0xd7ff || code >= 0xdc00) return code; | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
return (code << 10) + next - 0x35fdc00; | ||
return next <= 0xdbff || next >= 0xe000 ? code : (code << 10) + next - 0x35fdc00; | ||
}; | ||
@@ -118,10 +107,10 @@ | ||
this.pos = end + 2; | ||
if (this.options.locations) { | ||
_whitespace.lineBreakG.lastIndex = start; | ||
let match; | ||
while ((match = _whitespace.lineBreakG.exec(this.input)) && match.index < this.pos) { | ||
for (let nextBreak, pos = start; (nextBreak = (0, _whitespace.nextLineBreak)(this.input, pos, this.pos)) > -1;) { | ||
++this.curLine; | ||
this.lineStart = match.index + match[0].length; | ||
pos = this.lineStart = nextBreak; | ||
} | ||
} | ||
if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition()); | ||
@@ -134,19 +123,23 @@ }; | ||
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()); | ||
}; | ||
// 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) { | ||
case 32:case 160: | ||
case 32: | ||
case 160: | ||
// ' ' | ||
++this.pos; | ||
break; | ||
case 13: | ||
@@ -156,4 +149,8 @@ if (this.input.charCodeAt(this.pos + 1) === 10) { | ||
} | ||
case 10:case 8232:case 8233: | ||
case 10: | ||
case 8232: | ||
case 8233: | ||
++this.pos; | ||
if (this.options.locations) { | ||
@@ -163,3 +160,5 @@ ++this.curLine; | ||
} | ||
break; | ||
case 47: | ||
@@ -172,9 +171,13 @@ // '/' | ||
break; | ||
case 47: | ||
this.skipLineComment(2); | ||
break; | ||
default: | ||
break loop; | ||
} | ||
break; | ||
default: | ||
@@ -186,7 +189,6 @@ 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 | ||
@@ -196,2 +198,3 @@ // the token, so that the next one's `start` will point at the | ||
pp.finishToken = function (type, val) { | ||
@@ -203,8 +206,4 @@ this.end = this.pos; | ||
this.value = val; | ||
this.updateContext(prevType); | ||
}; | ||
// ### Token reading | ||
}; // ### Token reading | ||
// This is the function that is called to fetch the next token. It | ||
@@ -217,2 +216,4 @@ // is somewhat obscure, because it works in character codes rather | ||
// | ||
pp.readToken_dot = function () { | ||
@@ -222,2 +223,3 @@ 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) { | ||
@@ -236,5 +238,8 @@ // 46 = dot '.' | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (this.exprAllowed) { | ||
++this.pos;return this.readRegexp(); | ||
++this.pos; | ||
return this.readRegexp(); | ||
} | ||
if (next === 61) return this.finishOp(_tokentype.types.assign, 2); | ||
@@ -248,5 +253,4 @@ return this.finishOp(_tokentype.types.slash, 1); | ||
let size = 1; | ||
let tokentype = code === 42 ? _tokentype.types.star : _tokentype.types.modulo; | ||
let tokentype = code === 42 ? _tokentype.types.star : _tokentype.types.modulo; // exponentiation operator ** and **= | ||
// exponentiation operator ** and **= | ||
if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) { | ||
@@ -265,2 +269,3 @@ ++size; | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (next === code) { | ||
@@ -271,4 +276,6 @@ 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); | ||
@@ -288,2 +295,3 @@ return this.finishOp(code === 124 ? _tokentype.types.bitwiseOR : _tokentype.types.bitwiseAND, 1); | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (next === code) { | ||
@@ -296,4 +304,6 @@ 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); | ||
@@ -307,2 +317,3 @@ return this.finishOp(_tokentype.types.plusMin, 1); | ||
let size = 1; | ||
if (next === code) { | ||
@@ -313,2 +324,3 @@ 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) { | ||
@@ -320,2 +332,3 @@ // `<!--`, an XML-style comment that should be interpreted as a line comment | ||
} | ||
if (next === 61) size = 2; | ||
@@ -329,2 +342,3 @@ return this.finishOp(_tokentype.types.relational, size); | ||
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) { | ||
@@ -335,2 +349,3 @@ // '=>' | ||
} | ||
return this.finishOp(code === 61 ? _tokentype.types.eq : _tokentype.types.prefix, 1); | ||
@@ -342,4 +357,6 @@ }; | ||
const ecmaVersion = this.options.ecmaVersion; | ||
if (ecmaVersion >= 11) { | ||
let next = this.input.charCodeAt(this.pos + 1); | ||
if (next === 46) { | ||
@@ -349,2 +366,3 @@ let next2 = this.input.charCodeAt(this.pos + 2); | ||
} | ||
if (next === 63) { | ||
@@ -355,8 +373,29 @@ if (ecmaVersion >= 12) { | ||
} | ||
return this.finishOp(_tokentype.types.coalesce, 2); | ||
} | ||
} | ||
return this.finishOp(_tokentype.types.question, 1); | ||
}; | ||
pp.readToken_numberSign = function () { | ||
// '#' | ||
const ecmaVersion = this.options.ecmaVersion; | ||
let code = 35; // '#' | ||
if (ecmaVersion >= 13) { | ||
++this.pos; | ||
code = this.fullCharCodeAtPos(); | ||
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) { | ||
@@ -369,22 +408,39 @@ switch (code) { | ||
return this.readToken_dot(); | ||
// Punctuation tokens. | ||
// Punctuation tokens. | ||
case 40: | ||
++this.pos;return this.finishToken(_tokentype.types.parenL); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.parenL); | ||
case 41: | ||
++this.pos;return this.finishToken(_tokentype.types.parenR); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.parenR); | ||
case 59: | ||
++this.pos;return this.finishToken(_tokentype.types.semi); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.semi); | ||
case 44: | ||
++this.pos;return this.finishToken(_tokentype.types.comma); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.comma); | ||
case 91: | ||
++this.pos;return this.finishToken(_tokentype.types.bracketL); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.bracketL); | ||
case 93: | ||
++this.pos;return this.finishToken(_tokentype.types.bracketR); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.bracketR); | ||
case 123: | ||
++this.pos;return this.finishToken(_tokentype.types.braceL); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.braceL); | ||
case 125: | ||
++this.pos;return this.finishToken(_tokentype.types.braceR); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.braceR); | ||
case 58: | ||
++this.pos;return this.finishToken(_tokentype.types.colon); | ||
++this.pos; | ||
return this.finishToken(_tokentype.types.colon); | ||
@@ -401,4 +457,6 @@ case 96: | ||
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 | ||
@@ -409,11 +467,20 @@ } | ||
// number, or float. | ||
case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57: | ||
case 49: | ||
case 50: | ||
case 51: | ||
case 52: | ||
case 53: | ||
case 54: | ||
case 55: | ||
case 56: | ||
case 57: | ||
// 1-9 | ||
return this.readNumber(false); | ||
// Quotes produce strings. | ||
// Quotes produce strings. | ||
case 34:case 39: | ||
case 34: | ||
case 39: | ||
// '"', "'" | ||
return this.readString(code); | ||
// Operators are parsed inline in tiny state machines. '=' (61) is | ||
@@ -428,7 +495,9 @@ // often referred to. `finishOp` simply skips the amount of | ||
case 37:case 42: | ||
case 37: | ||
case 42: | ||
// '%*' | ||
return this.readToken_mult_modulo_exp(code); | ||
case 124:case 38: | ||
case 124: | ||
case 38: | ||
// '|&' | ||
@@ -441,11 +510,14 @@ return this.readToken_pipe_amp(code); | ||
case 43:case 45: | ||
case 43: | ||
case 45: | ||
// '+-' | ||
return this.readToken_plus_min(code); | ||
case 60:case 62: | ||
case 60: | ||
case 62: | ||
// '<>' | ||
return this.readToken_lt_gt(code); | ||
case 61:case 33: | ||
case 61: | ||
case 33: | ||
// '=!' | ||
@@ -461,2 +533,6 @@ return this.readToken_eq_excl(code); | ||
return this.finishOp(_tokentype.types.prefix, 1); | ||
case 35: | ||
// '#' | ||
return this.readToken_numberSign(); | ||
} | ||
@@ -477,2 +553,3 @@ | ||
start = this.pos; | ||
for (;;) { | ||
@@ -482,2 +559,3 @@ 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) { | ||
@@ -487,4 +565,6 @@ 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); | ||
@@ -494,38 +574,38 @@ ++this.pos; | ||
let flags = this.readWord1(); | ||
if (this.containsEsc) this.unexpected(flagsStart); | ||
if (this.containsEsc) this.unexpected(flagsStart); // Validate pattern | ||
// Validate pattern | ||
const state = this.regexpState || (this.regexpState = new _regexp.RegExpValidationState(this)); | ||
state.reset(start, pattern, flags); | ||
this.validateRegExpFlags(state); | ||
this.validateRegExpPattern(state); | ||
this.validateRegExpPattern(state); // Create Literal#value property value. | ||
// 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, { pattern, flags, value }); | ||
}; | ||
// Read an integer in the given radix. Return null if zero digits | ||
return this.finishToken(_tokentype.types.regexp, { | ||
pattern, | ||
flags, | ||
value | ||
}); | ||
}; // 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; | ||
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) { | ||
@@ -545,4 +625,4 @@ let code = this.input.charCodeAt(this.pos), | ||
else if (code >= 65) val = code - 65 + 10; // A | ||
else if (code >= 48 && code <= 57) val = code - 48; // 0-9 | ||
else val = Infinity; | ||
else if (code >= 48 && code <= 57) val = code - 48; // 0-9 | ||
else val = Infinity; | ||
if (val >= radix) break; | ||
@@ -555,3 +635,2 @@ lastCode = code; | ||
if (this.pos === start || len != null && this.pos - start !== len) return null; | ||
return total; | ||
@@ -563,5 +642,5 @@ }; | ||
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, "")); | ||
@@ -573,5 +652,5 @@ } | ||
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, "")); | ||
@@ -583,4 +662,6 @@ } | ||
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) { | ||
@@ -590,6 +671,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. | ||
@@ -602,2 +683,3 @@ pp.readNumber = function (startsWithDot) { | ||
let next = this.input.charCodeAt(this.pos); | ||
if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) { | ||
@@ -609,3 +691,5 @@ 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) { | ||
@@ -617,2 +701,3 @@ // '.' | ||
} | ||
if ((next === 69 || next === 101) && !octal) { | ||
@@ -622,11 +707,11 @@ // '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. | ||
@@ -647,2 +732,3 @@ pp.readCodePoint = function () { | ||
} | ||
return code; | ||
@@ -661,2 +747,3 @@ }; | ||
chunkStart = ++this.pos; | ||
for (;;) { | ||
@@ -666,2 +753,3 @@ if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant"); | ||
if (ch === quote) break; | ||
if (ch === 92) { | ||
@@ -672,12 +760,20 @@ // '\' | ||
chunkStart = this.pos; | ||
} else if (ch === 0x2028 || ch === 0x2029) { | ||
if (this.options.ecmaVersion < 10) this.raise(this.start, "Unterminated string constant"); | ||
++this.pos; | ||
if (this.options.locations) { | ||
this.curLine++; | ||
this.lineStart = this.pos; | ||
} | ||
} else { | ||
if ((0, _whitespace.isNewLine)(ch, this.options.ecmaVersion >= 10)) this.raise(this.start, "Unterminated string constant"); | ||
if ((0, _whitespace.isNewLine)(ch)) this.raise(this.start, "Unterminated string constant"); | ||
++this.pos; | ||
} | ||
} | ||
out += this.input.slice(chunkStart, this.pos++); | ||
return this.finishToken(_tokentype.types.string, out); | ||
}; | ||
}; // Reads template string tokens. | ||
// Reads template string tokens. | ||
@@ -688,2 +784,3 @@ const INVALID_TEMPLATE_ESCAPE_ERROR = {}; | ||
this.inTemplateElement = true; | ||
try { | ||
@@ -713,5 +810,7 @@ this.readTmplToken(); | ||
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) { | ||
@@ -728,5 +827,7 @@ // '`', '${' | ||
} | ||
out += this.input.slice(chunkStart, this.pos); | ||
return this.finishToken(_tokentype.types.template, out); | ||
} | ||
if (ch === 92) { | ||
@@ -740,8 +841,11 @@ // '\' | ||
++this.pos; | ||
switch (ch) { | ||
case 13: | ||
if (this.input.charCodeAt(this.pos) === 10) ++this.pos; | ||
case 10: | ||
out += "\n"; | ||
break; | ||
default: | ||
@@ -751,2 +855,3 @@ out += String.fromCharCode(ch); | ||
} | ||
if (this.options.locations) { | ||
@@ -756,2 +861,3 @@ ++this.curLine; | ||
} | ||
chunkStart = this.pos; | ||
@@ -762,5 +868,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 () { | ||
@@ -777,2 +883,3 @@ for (; this.pos < this.input.length; this.pos++) { | ||
} | ||
// falls through | ||
@@ -782,10 +889,9 @@ | ||
return this.finishToken(_tokentype.types.invalidTemplate, this.input.slice(this.start, this.pos)); | ||
// no default | ||
} | ||
} | ||
this.raise(this.start, "Unterminated template"); | ||
}; | ||
}; // Used to read escaped characters | ||
// Used to read escaped characters | ||
@@ -795,27 +901,49 @@ pp.readEscapedChar = function (inTemplate) { | ||
++this.pos; | ||
switch (ch) { | ||
case 110: | ||
return "\n"; // 'n' -> '\n' | ||
return "\n"; | ||
// 'n' -> '\n' | ||
case 114: | ||
return "\r"; // 'r' -> '\r' | ||
return "\r"; | ||
// 'r' -> '\r' | ||
case 120: | ||
return String.fromCharCode(this.readHexChar(2)); // 'x' | ||
return String.fromCharCode(this.readHexChar(2)); | ||
// 'x' | ||
case 117: | ||
return codePointToString(this.readCodePoint()); // 'u' | ||
return codePointToString(this.readCodePoint()); | ||
// 'u' | ||
case 116: | ||
return "\t"; // 't' -> '\t' | ||
return "\t"; | ||
// 't' -> '\t' | ||
case 98: | ||
return "\b"; // 'b' -> '\b' | ||
return "\b"; | ||
// 'b' -> '\b' | ||
case 118: | ||
return "\u000b"; // 'v' -> '\u000b' | ||
return "\u000b"; | ||
// 'v' -> '\u000b' | ||
case 102: | ||
return "\f"; // 'f' -> '\f' | ||
return "\f"; | ||
// 'f' -> '\f' | ||
case 13: | ||
if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n' | ||
if (this.input.charCodeAt(this.pos) === 10) ++this.pos; | ||
// '\r\n' | ||
case 10: | ||
// ' \n' | ||
if (this.options.locations) { | ||
this.lineStart = this.pos;++this.curLine; | ||
this.lineStart = this.pos; | ||
++this.curLine; | ||
} | ||
return ""; | ||
case 56: | ||
@@ -826,9 +954,9 @@ case 57: | ||
} | ||
if (inTemplate) { | ||
const codePos = this.pos - 1; | ||
this.invalidStringToken(codePos, "Invalid escape sequence in template string"); | ||
return null; | ||
} | ||
default: | ||
@@ -838,2 +966,3 @@ if (ch >= 48 && ch <= 55) { | ||
let octal = parseInt(octalStr, 8); | ||
if (octal > 255) { | ||
@@ -843,9 +972,13 @@ 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)) { | ||
@@ -856,7 +989,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'). | ||
@@ -868,5 +1001,3 @@ 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. | ||
@@ -877,2 +1008,3 @@ // | ||
pp.readWord1 = function () { | ||
@@ -884,4 +1016,6 @@ this.containsEsc = false; | ||
let astral = this.options.ecmaVersion >= 6; | ||
while (this.pos < this.input.length) { | ||
let ch = this.fullCharCodeAtPos(); | ||
if ((0, _identifier.isIdentifierChar)(ch, astral)) { | ||
@@ -904,17 +1038,20 @@ this.pos += ch <= 0xffff ? 1 : 2; | ||
} | ||
first = false; | ||
} | ||
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); | ||
}; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.types = exports.keywords = exports.TokenType = void 0; | ||
// ## 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,3 +25,2 @@ // expressions and divisions. It is set on all token types that can | ||
// continue jumps to that label. | ||
class TokenType { | ||
@@ -41,16 +39,25 @@ constructor(label, conf = {}) { | ||
} | ||
} | ||
exports.TokenType = TokenType; | ||
function binop(name, prec) { | ||
return new TokenType(name, { beforeExpr: true, binop: prec }); | ||
return new TokenType(name, { | ||
beforeExpr: true, | ||
binop: prec | ||
}); | ||
} | ||
const beforeExpr = { beforeExpr: true }, | ||
startsExpr = { startsExpr: true | ||
// Map keyword names to token types. | ||
const beforeExpr = { | ||
beforeExpr: true | ||
}, | ||
startsExpr = { | ||
startsExpr: true | ||
}; // Map keyword names to token types. | ||
};const keywords = exports.keywords = {}; | ||
const keywords = {}; // Succinct definitions of keyword token types | ||
// Succinct definitions of keyword token types | ||
exports.keywords = keywords; | ||
function kw(name, options = {}) { | ||
@@ -61,3 +68,3 @@ options.keyword = name; | ||
const types = exports.types = { | ||
const types = { | ||
num: new TokenType("num", startsExpr), | ||
@@ -67,10 +74,19 @@ regexp: new TokenType("regexp", startsExpr), | ||
name: new TokenType("name", startsExpr), | ||
privateId: new TokenType("privateId", startsExpr), | ||
eof: new TokenType("eof"), | ||
// Punctuation token types. | ||
bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }), | ||
bracketL: new TokenType("[", { | ||
beforeExpr: true, | ||
startsExpr: true | ||
}), | ||
bracketR: new TokenType("]"), | ||
braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }), | ||
braceL: new TokenType("{", { | ||
beforeExpr: true, | ||
startsExpr: true | ||
}), | ||
braceR: new TokenType("}"), | ||
parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }), | ||
parenL: new TokenType("(", { | ||
beforeExpr: true, | ||
startsExpr: true | ||
}), | ||
parenR: new TokenType(")"), | ||
@@ -88,4 +104,6 @@ comma: new TokenType(",", beforeExpr), | ||
backQuote: new TokenType("`", startsExpr), | ||
dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }), | ||
dollarBraceL: new TokenType("${", { | ||
beforeExpr: true, | ||
startsExpr: true | ||
}), | ||
// Operators. These carry several kinds of properties to help the | ||
@@ -104,7 +122,20 @@ // parser use them properly (the presence of these properties is | ||
// in AssignmentExpression nodes. | ||
eq: new TokenType("=", { beforeExpr: true, isAssign: true }), | ||
assign: new TokenType("_=", { beforeExpr: true, isAssign: true }), | ||
incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }), | ||
prefix: new TokenType("!/~", { beforeExpr: true, prefix: true, startsExpr: true }), | ||
eq: new TokenType("=", { | ||
beforeExpr: true, | ||
isAssign: true | ||
}), | ||
assign: new TokenType("_=", { | ||
beforeExpr: true, | ||
isAssign: true | ||
}), | ||
incDec: new TokenType("++/--", { | ||
prefix: true, | ||
postfix: true, | ||
startsExpr: true | ||
}), | ||
prefix: new TokenType("!/~", { | ||
beforeExpr: true, | ||
prefix: true, | ||
startsExpr: true | ||
}), | ||
logicalOR: binop("||", 1), | ||
@@ -118,9 +149,15 @@ logicalAND: binop("&&", 2), | ||
bitShift: binop("<</>>/>>>", 8), | ||
plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }), | ||
plusMin: new TokenType("+/-", { | ||
beforeExpr: true, | ||
binop: 9, | ||
prefix: true, | ||
startsExpr: true | ||
}), | ||
modulo: binop("%", 10), | ||
star: binop("*", 10), | ||
slash: binop("/", 10), | ||
starstar: new TokenType("**", { beforeExpr: true }), | ||
starstar: new TokenType("**", { | ||
beforeExpr: true | ||
}), | ||
coalesce: binop("??", 1), | ||
// Keyword token types. | ||
@@ -133,6 +170,11 @@ _break: kw("break"), | ||
_default: kw("default", beforeExpr), | ||
_do: kw("do", { isLoop: true, beforeExpr: true }), | ||
_do: kw("do", { | ||
isLoop: true, | ||
beforeExpr: true | ||
}), | ||
_else: kw("else", beforeExpr), | ||
_finally: kw("finally"), | ||
_for: kw("for", { isLoop: true }), | ||
_for: kw("for", { | ||
isLoop: true | ||
}), | ||
_function: kw("function", startsExpr), | ||
@@ -146,5 +188,10 @@ _if: kw("if"), | ||
_const: kw("const"), | ||
_while: kw("while", { isLoop: true }), | ||
_while: kw("while", { | ||
isLoop: true | ||
}), | ||
_with: kw("with"), | ||
_new: kw("new", { beforeExpr: true, startsExpr: true }), | ||
_new: kw("new", { | ||
beforeExpr: true, | ||
startsExpr: true | ||
}), | ||
_this: kw("this", startsExpr), | ||
@@ -159,7 +206,26 @@ _super: kw("super", startsExpr), | ||
_false: kw("false", startsExpr), | ||
_in: kw("in", { beforeExpr: true, binop: 7 }), | ||
_instanceof: kw("instanceof", { beforeExpr: true, binop: 7 }), | ||
_typeof: kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true }), | ||
_void: kw("void", { beforeExpr: true, prefix: true, startsExpr: true }), | ||
_delete: kw("delete", { beforeExpr: true, prefix: true, startsExpr: true }) | ||
}; | ||
_in: kw("in", { | ||
beforeExpr: true, | ||
binop: 7 | ||
}), | ||
_instanceof: kw("instanceof", { | ||
beforeExpr: true, | ||
binop: 7 | ||
}), | ||
_typeof: kw("typeof", { | ||
beforeExpr: true, | ||
prefix: true, | ||
startsExpr: true | ||
}), | ||
_void: kw("void", { | ||
beforeExpr: true, | ||
prefix: true, | ||
startsExpr: true | ||
}), | ||
_delete: kw("delete", { | ||
beforeExpr: true, | ||
prefix: true, | ||
startsExpr: true | ||
}) | ||
}; | ||
exports.types = types; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
@@ -10,3 +11,2 @@ var _util = require("./util.js"); | ||
// $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText) | ||
// #table-binary-unicode-properties | ||
@@ -17,2 +17,3 @@ const ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS"; | ||
const ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict"; | ||
const ecma13BinaryProperties = ecma12BinaryProperties; | ||
const unicodeBinaryProperties = { | ||
@@ -22,12 +23,13 @@ 9: ecma9BinaryProperties, | ||
11: ecma11BinaryProperties, | ||
12: ecma12BinaryProperties | ||
12: ecma12BinaryProperties, | ||
13: ecma13BinaryProperties | ||
}; // #table-unicode-general-category-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"; | ||
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-script-values | ||
const ecma9ScriptValues = "Adlam Adlm Ahom 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 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"; | ||
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"; | ||
const ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd"; | ||
const ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho"; | ||
const ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi"; | ||
const ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith"; | ||
const unicodeScriptValues = { | ||
@@ -37,8 +39,9 @@ 9: ecma9ScriptValues, | ||
11: ecma11ScriptValues, | ||
12: ecma12ScriptValues | ||
12: ecma12ScriptValues, | ||
13: ecma13ScriptValues | ||
}; | ||
const data = {}; | ||
const data = {}; | ||
function buildUnicodeData(ecmaVersion) { | ||
let d = data[ecmaVersion] = { | ||
const d = data[ecmaVersion] = { | ||
binary: (0, _util.wordsRegexp)(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues), | ||
@@ -51,3 +54,2 @@ nonBinary: { | ||
d.nonBinary.Script_Extensions = d.nonBinary.Script; | ||
d.nonBinary.gc = d.nonBinary.General_Category; | ||
@@ -57,8 +59,10 @@ d.nonBinary.sc = d.nonBinary.Script; | ||
} | ||
buildUnicodeData(9); | ||
buildUnicodeData(10); | ||
buildUnicodeData(11); | ||
buildUnicodeData(12); | ||
exports.default = data; | ||
module.exports = exports['default']; | ||
for (var _i = 0, _arr = [9, 10, 11, 12, 13]; _i < _arr.length; _i++) { | ||
const ecmaVersion = _arr[_i]; | ||
buildUnicodeData(ecmaVersion); | ||
} | ||
var _default = data; | ||
exports.default = _default; | ||
module.exports = exports["default"]; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.has = has; | ||
exports.loneSurrogate = exports.isArray = exports.hasOwn = void 0; | ||
exports.wordsRegexp = wordsRegexp; | ||
var _Object$prototype = Object.prototype; | ||
const hasOwnProperty = _Object$prototype.hasOwnProperty, | ||
const _Object$prototype = Object.prototype, | ||
hasOwnProperty = _Object$prototype.hasOwnProperty, | ||
toString = _Object$prototype.toString; | ||
// Checks if an object has a property. | ||
const hasOwn = Object.hasOwn || ((obj, propName) => hasOwnProperty.call(obj, propName)); | ||
function has(obj, propName) { | ||
return hasOwnProperty.call(obj, propName); | ||
} | ||
exports.hasOwn = hasOwn; | ||
const isArray = exports.isArray = Array.isArray || (obj => toString.call(obj) === "[object Array]"); | ||
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-\uDFFF]/u; | ||
exports.loneSurrogate = loneSurrogate; |
@@ -5,14 +5,28 @@ "use strict"; | ||
exports.isNewLine = isNewLine; | ||
exports.lineBreakG = exports.lineBreak = void 0; | ||
exports.nextLineBreak = nextLineBreak; | ||
exports.skipWhiteSpace = exports.nonASCIIwhitespace = void 0; | ||
// Matches a whole line break (where CRLF is considered a single | ||
// line break). Used to count lines. | ||
const lineBreak = /\r\n?|\n|\u2028|\u2029/; | ||
exports.lineBreak = lineBreak; | ||
const lineBreakG = new RegExp(lineBreak.source, "g"); | ||
exports.lineBreakG = lineBreakG; | ||
const lineBreak = exports.lineBreak = /\r\n?|\n|\u2028|\u2029/; | ||
const lineBreakG = exports.lineBreakG = new RegExp(lineBreak.source, "g"); | ||
function isNewLine(code) { | ||
return code === 10 || code === 13 || code === 0x2028 || code === 0x2029; | ||
} | ||
function isNewLine(code, ecma2019String) { | ||
return code === 10 || code === 13 || !ecma2019String && (code === 0x2028 || code === 0x2029); | ||
function nextLineBreak(code, from, end = code.length) { | ||
for (let i = from; i < end; i++) { | ||
let next = code.charCodeAt(i); | ||
if (isNewLine(next)) return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1; | ||
} | ||
return -1; | ||
} | ||
const nonASCIIwhitespace = exports.nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/; | ||
const skipWhiteSpace = exports.skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g; | ||
const nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/; | ||
exports.nonASCIIwhitespace = nonASCIIwhitespace; | ||
const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g; | ||
exports.skipWhiteSpace = skipWhiteSpace; |
{ | ||
"name": "acorn-hammerhead", | ||
"version": "0.5.0", | ||
"description": "", | ||
"version": "0.6.0", | ||
"description": "acorn.js parser adapted to TestCafe Hammerhead", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Developer Express Inc.", | ||
"url": "https://www.devexpress.com/" | ||
}, | ||
"main": "lib/index.js", | ||
@@ -14,9 +19,9 @@ "files": [ | ||
"devDependencies": { | ||
"babel-plugin-add-module-exports": "^0.1.2", | ||
"babel-plugin-transform-async-to-generator": "^6.24.1", | ||
"babel-preset-env": "^1.6.0", | ||
"@babel/core": "^7.17.8", | ||
"@babel/preset-env": "^7.16.11", | ||
"babel-plugin-add-module-exports": "^0.2.0", | ||
"del": "^3.0.0", | ||
"gulp": "^4.0.0", | ||
"gulp-babel": "^6.1.1", | ||
"publish-please": "^5.4.3" | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0", | ||
"publish-please": "^5.5.2" | ||
}, | ||
@@ -32,4 +37,2 @@ "scripts": { | ||
}, | ||
"author": "miherlosev <miherlosev@mail.ru> (http://devexpress.com/)", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -36,0 +39,0 @@ "url": "https://github.com/miherlosev/acorn-hammerhead/issues" |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
233421
9.23%25
4.17%5284
9.79%2
100%