From 98f56d179ce8c03a7243074f03beeabe5b769e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 6 Sep 2021 16:31:00 +0200 Subject: [PATCH] deps: update Acorn to v8.5.0 PR-URL: https://github.com/nodejs/node/pull/40015 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Jiawen Geng Reviewed-By: James M Snell --- deps/acorn/acorn-walk/CHANGELOG.md | 12 + deps/acorn/acorn-walk/dist/walk.d.ts | 2 + deps/acorn/acorn-walk/dist/walk.js | 2 +- deps/acorn/acorn-walk/dist/walk.mjs | 2 +- deps/acorn/acorn-walk/package.json | 2 +- deps/acorn/acorn/CHANGELOG.md | 20 + deps/acorn/acorn/README.md | 2 +- deps/acorn/acorn/dist/acorn.d.ts | 3 + deps/acorn/acorn/dist/acorn.js | 547 +++++++++++++++------------ deps/acorn/acorn/dist/acorn.mjs | 547 +++++++++++++++------------ deps/acorn/acorn/dist/bin.js | 48 ++- deps/acorn/acorn/package.json | 2 +- 12 files changed, 663 insertions(+), 526 deletions(-) diff --git a/deps/acorn/acorn-walk/CHANGELOG.md b/deps/acorn/acorn-walk/CHANGELOG.md index a9382d0db9abef..30ec5a5eec9911 100644 --- a/deps/acorn/acorn-walk/CHANGELOG.md +++ b/deps/acorn/acorn-walk/CHANGELOG.md @@ -1,3 +1,15 @@ +## 8.2.0 (2021-09-06) + +### New features + +Add support for walking ES2022 class static blocks. + +## 8.1.1 (2021-06-29) + +### Bug fixes + +Include `base` in the type declarations. + ## 8.1.0 (2021-04-24) ### New features diff --git a/deps/acorn/acorn-walk/dist/walk.d.ts b/deps/acorn/acorn-walk/dist/walk.d.ts index 00cc005f1245c5..2d81f01c166875 100644 --- a/deps/acorn/acorn-walk/dist/walk.d.ts +++ b/deps/acorn/acorn-walk/dist/walk.d.ts @@ -109,4 +109,6 @@ declare module "acorn-walk" { ): Found | undefined; export const findNodeAfter: typeof findNodeAround; + + export const base: RecursiveVisitors; } diff --git a/deps/acorn/acorn-walk/dist/walk.js b/deps/acorn/acorn-walk/dist/walk.js index 5582c907595e11..a7f81b0061a750 100644 --- a/deps/acorn/acorn-walk/dist/walk.js +++ b/deps/acorn/acorn-walk/dist/walk.js @@ -190,7 +190,7 @@ var base = {}; - base.Program = base.BlockStatement = function (node, st, c) { + base.Program = base.BlockStatement = base.StaticBlock = function (node, st, c) { for (var i = 0, list = node.body; i < list.length; i += 1) { var stmt = list[i]; diff --git a/deps/acorn/acorn-walk/dist/walk.mjs b/deps/acorn/acorn-walk/dist/walk.mjs index ea5d4b0bc2041f..89dd1f1f4f3557 100644 --- a/deps/acorn/acorn-walk/dist/walk.mjs +++ b/deps/acorn/acorn-walk/dist/walk.mjs @@ -184,7 +184,7 @@ function ignore(_node, _st, _c) {} var base = {}; -base.Program = base.BlockStatement = function (node, st, c) { +base.Program = base.BlockStatement = base.StaticBlock = function (node, st, c) { for (var i = 0, list = node.body; i < list.length; i += 1) { var stmt = list[i]; diff --git a/deps/acorn/acorn-walk/package.json b/deps/acorn/acorn-walk/package.json index 118bb0be2c72f5..8d75b9711c2e35 100644 --- a/deps/acorn/acorn-walk/package.json +++ b/deps/acorn/acorn-walk/package.json @@ -16,7 +16,7 @@ ], "./package.json": "./package.json" }, - "version": "8.1.0", + "version": "8.2.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ { diff --git a/deps/acorn/acorn/CHANGELOG.md b/deps/acorn/acorn/CHANGELOG.md index d69ad881253118..117c898c8ad156 100644 --- a/deps/acorn/acorn/CHANGELOG.md +++ b/deps/acorn/acorn/CHANGELOG.md @@ -1,3 +1,23 @@ +## 8.5.0 (2021-09-06) + +### Bug fixes + +Improve context-dependent tokenization in a number of corner cases. + +Fix location tracking after a 0x2028 or 0x2029 character in a string literal (which before did not increase the line number). + +Fix an issue where arrow function bodies in for loop context would inappropriately consume `in` operators. + +Fix wrong end locations stored on SequenceExpression nodes. + +Implement restriction that `for`/`of` loop LHS can't start with `let`. + +### New features + +Add support for ES2022 class static blocks. + +Allow multiple input files to be passed to the CLI tool. + ## 8.4.1 (2021-06-24) ### Bug fixes diff --git a/deps/acorn/acorn/README.md b/deps/acorn/acorn/README.md index f27a99444b6f3f..601e86c8fddfdb 100644 --- a/deps/acorn/acorn/README.md +++ b/deps/acorn/acorn/README.md @@ -54,7 +54,7 @@ required): - **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, partial support), 13 (2022, partial support) + 11 (2020), 12 (2021), 13 (2022, partial support) or `"latest"` (the latest the library supports). This influences support for strict mode, the set of reserved words, and support for new syntax features. diff --git a/deps/acorn/acorn/dist/acorn.d.ts b/deps/acorn/acorn/dist/acorn.d.ts index 8e8fbbcb426c3c..861b357fea3a64 100644 --- a/deps/acorn/acorn/dist/acorn.d.ts +++ b/deps/acorn/acorn/dist/acorn.d.ts @@ -173,6 +173,9 @@ declare namespace acorn { p_expr: TokContext q_tmpl: TokContext f_expr: TokContext + f_stat: TokContext + f_expr_gen: TokContext + f_gen: TokContext } function isIdentifierStart(code: number, astral?: boolean): boolean diff --git a/deps/acorn/acorn/dist/acorn.js b/deps/acorn/acorn/dist/acorn.js index af24e36cf16d2e..96e3b82d834408 100644 --- a/deps/acorn/acorn/dist/acorn.js +++ b/deps/acorn/acorn/dist/acorn.js @@ -252,8 +252,8 @@ var lineBreak = /\r\n?|\n|\u2028|\u2029/; var lineBreakG = new RegExp(lineBreak.source, "g"); - function isNewLine(code, ecma2019String) { - return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029)) + function isNewLine(code) { + return code === 10 || code === 13 || code === 0x2028 || code === 0x2029 } var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/; @@ -464,13 +464,14 @@ var SCOPE_TOP = 1, SCOPE_FUNCTION = 2, - SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION, SCOPE_ASYNC = 4, SCOPE_GENERATOR = 8, SCOPE_ARROW = 16, SCOPE_SIMPLE_CATCH = 32, SCOPE_SUPER = 64, - SCOPE_DIRECT_SUPER = 128; + SCOPE_DIRECT_SUPER = 128, + SCOPE_CLASS_STATIC_BLOCK = 256, + SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK; function functionFlags(async, generator) { return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0) @@ -570,7 +571,7 @@ this.privateNameStack = []; }; - var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },canAwait: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },inNonArrowFunction: { configurable: true } }; + var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },canAwait: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },allowNewDotTarget: { configurable: true },inClassStaticBlock: { configurable: true } }; Parser.prototype.parse = function parse () { var node = this.options.program || this.startNode(); @@ -584,7 +585,7 @@ prototypeAccessors.canAwait.get = function () { for (var i = this.scopeStack.length - 1; i >= 0; i--) { var scope = this.scopeStack[i]; - if (scope.inClassFieldInit) { return false } + if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) { return false } if (scope.flags & SCOPE_FUNCTION) { return (scope.flags & SCOPE_ASYNC) > 0 } } return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction @@ -597,11 +598,14 @@ }; prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 }; prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) }; - prototypeAccessors.inNonArrowFunction.get = function () { + prototypeAccessors.allowNewDotTarget.get = function () { var ref = this.currentThisScope(); var flags = ref.flags; var inClassFieldInit = ref.inClassFieldInit; - return (flags & SCOPE_FUNCTION) > 0 || inClassFieldInit + return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit + }; + prototypeAccessors.inClassStaticBlock.get = function () { + return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0 }; Parser.extend = function extend () { @@ -1010,14 +1014,16 @@ if (awaitAt > -1) { this.unexpected(awaitAt); } return this.parseFor(node, init$1) } + var startsWithLet = this.isContextual("let"), isForOf = false; var refDestructuringErrors = new DestructuringErrors; var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors); - if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) { + if (this.type === types._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) { if (this.options.ecmaVersion >= 9) { if (this.type === types._in) { if (awaitAt > -1) { this.unexpected(awaitAt); } } else { node.await = awaitAt > -1; } } + 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); this.checkLValPattern(init); return this.parseForIn(node, init) @@ -1300,7 +1306,7 @@ // `statement & FUNC_STATEMENT`). // Remove `allowExpressionBody` for 7.0.0, as it is only called with false - pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) { + pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) { this.initFunction(node); if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) { if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT)) @@ -1330,7 +1336,7 @@ { node.id = this.type === types.name ? this.parseIdent() : null; } this.parseFunctionParams(node); - this.parseFunctionBody(node, allowExpressionBody, false); + this.parseFunctionBody(node, allowExpressionBody, false, forInit); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; @@ -1369,7 +1375,7 @@ 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.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) { + } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) { this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared")); } } @@ -1390,16 +1396,21 @@ var isGenerator = false; var isAsync = false; var kind = "method"; + var isStatic = false; - // Parse modifiers - node.static = false; if (this.eatContextual("static")) { + // Parse static init block + if (ecmaVersion >= 13 && this.eat(types.braceL)) { + this.parseClassStaticBlock(node); + return node + } if (this.isClassElementNameStart() || this.type === types.star) { - node.static = true; + isStatic = true; } else { keyName = "static"; } } + node.static = isStatic; if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) { if ((this.isClassElementNameStart() || this.type === types.star) && !this.canInsertSemicolon()) { isAsync = true; @@ -1517,6 +1528,23 @@ return this.finishNode(field, "PropertyDefinition") }; + pp$1.parseClassStaticBlock = function(node) { + node.body = []; + + var oldLabels = this.labels; + this.labels = []; + this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER); + while (this.type !== types.braceR) { + var stmt = this.parseStatement(null); + node.body.push(stmt); + } + this.next(); + this.exitScope(); + this.labels = oldLabels; + + return this.finishNode(node, "StaticBlock") + }; + pp$1.parseClassId = function(node, isStatement) { if (this.type === types.name) { node.id = this.parseIdent(); @@ -1530,7 +1558,7 @@ }; pp$1.parseClassSuper = function(node) { - node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null; + node.superClass = this.eat(types._extends) ? this.parseExprSubscripts(false) : null; }; pp$1.enterClassBody = function() { @@ -2139,16 +2167,170 @@ } }; - // A recursive descent parser operates by defining functions for all + // The algorithm used to determine whether a regexp can appear at a + + var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) { + this.token = token; + this.isExpr = !!isExpr; + this.preserveSpace = !!preserveSpace; + this.override = override; + this.generator = !!generator; + }; + + var types$1 = { + b_stat: new TokContext("{", false), + b_expr: new TokContext("{", true), + b_tmpl: new TokContext("${", false), + p_stat: new TokContext("(", false), + p_expr: new TokContext("(", true), + q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }), + f_stat: new TokContext("function", false), + f_expr: new TokContext("function", true), + f_expr_gen: new TokContext("function", true, false, null, true), + f_gen: new TokContext("function", false, false, null, true) + }; var pp$3 = Parser.prototype; + pp$3.initialContext = function() { + return [types$1.b_stat] + }; + + pp$3.curContext = function() { + return this.context[this.context.length - 1] + }; + + pp$3.braceIsBlock = function(prevType) { + var parent = this.curContext(); + if (parent === types$1.f_expr || parent === types$1.f_stat) + { return true } + if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.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 === types._return || prevType === types.name && this.exprAllowed) + { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) } + if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) + { return true } + if (prevType === types.braceL) + { return parent === types$1.b_stat } + if (prevType === types._var || prevType === types._const || prevType === types.name) + { return false } + return !this.exprAllowed + }; + + pp$3.inGeneratorContext = function() { + for (var i = this.context.length - 1; i >= 1; i--) { + var context = this.context[i]; + if (context.token === "function") + { return context.generator } + } + return false + }; + + pp$3.updateContext = function(prevType) { + var update, type = this.type; + if (type.keyword && prevType === 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 + pp$3.overrideContext = function(tokenCtx) { + if (this.curContext() !== tokenCtx) { + this.context[this.context.length - 1] = tokenCtx; + } + }; + + // Token-specific context update code + + types.parenR.updateContext = types.braceR.updateContext = function() { + if (this.context.length === 1) { + this.exprAllowed = true; + return + } + var out = this.context.pop(); + if (out === types$1.b_stat && this.curContext().token === "function") { + out = this.context.pop(); + } + this.exprAllowed = !out.isExpr; + }; + + types.braceL.updateContext = function(prevType) { + this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr); + this.exprAllowed = true; + }; + + types.dollarBraceL.updateContext = function() { + this.context.push(types$1.b_tmpl); + this.exprAllowed = true; + }; + + types.parenL.updateContext = function(prevType) { + var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while; + this.context.push(statementParens ? types$1.p_stat : types$1.p_expr); + this.exprAllowed = true; + }; + + types.incDec.updateContext = function() { + // tokExprAllowed stays unchanged + }; + + types._function.updateContext = types._class.updateContext = function(prevType) { + if (prevType.beforeExpr && prevType !== types._else && + !(prevType === types.semi && this.curContext() !== types$1.p_stat) && + !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) && + !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) + { this.context.push(types$1.f_expr); } + else + { this.context.push(types$1.f_stat); } + this.exprAllowed = false; + }; + + types.backQuote.updateContext = function() { + if (this.curContext() === types$1.q_tmpl) + { this.context.pop(); } + else + { this.context.push(types$1.q_tmpl); } + this.exprAllowed = false; + }; + + types.star.updateContext = function(prevType) { + if (prevType === types._function) { + var index = this.context.length - 1; + if (this.context[index] === types$1.f_expr) + { this.context[index] = types$1.f_expr_gen; } + else + { this.context[index] = types$1.f_gen; } + } + this.exprAllowed = true; + }; + + types.name.updateContext = function(prevType) { + var allowed = false; + if (this.options.ecmaVersion >= 6 && prevType !== types.dot) { + if (this.value === "of" && !this.exprAllowed || + this.value === "yield" && this.inGeneratorContext()) + { allowed = true; } + } + this.exprAllowed = allowed; + }; + + // A recursive descent parser operates by defining functions for all + + var pp$4 = Parser.prototype; + // Check if property name clashes with already added. // Object/class getters and setters are not allowed to clash — // either with each other or with an init property — and in // strict mode, init properties are also not allowed to be repeated. - pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) { + pp$4.checkPropClash = function(prop, propHash, refDestructuringErrors) { if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement") { return } if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) @@ -2210,7 +2392,7 @@ // and object pattern might appear (so it's possible to raise // delayed syntax error at correct position). - pp$3.parseExpression = function(forInit, refDestructuringErrors) { + pp$4.parseExpression = function(forInit, refDestructuringErrors) { var startPos = this.start, startLoc = this.startLoc; var expr = this.parseMaybeAssign(forInit, refDestructuringErrors); if (this.type === types.comma) { @@ -2225,7 +2407,7 @@ // Parse an assignment expression. This includes applications of // operators like `+=`. - pp$3.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) { + pp$4.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) { if (this.isContextual("yield")) { if (this.inGenerator) { return this.parseYield(forInit) } // The tokenizer will assume an expression is allowed after @@ -2278,7 +2460,7 @@ // Parse a ternary conditional (`?:`) operator. - pp$3.parseMaybeConditional = function(forInit, refDestructuringErrors) { + pp$4.parseMaybeConditional = function(forInit, refDestructuringErrors) { var startPos = this.start, startLoc = this.startLoc; var expr = this.parseExprOps(forInit, refDestructuringErrors); if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } @@ -2295,9 +2477,9 @@ // Start the precedence parser. - pp$3.parseExprOps = function(forInit, refDestructuringErrors) { + pp$4.parseExprOps = function(forInit, refDestructuringErrors) { var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseMaybeUnary(refDestructuringErrors, false); + var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit); if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit) }; @@ -2308,7 +2490,7 @@ // defer further parser to one of its callers when it encounters an // operator that has a lower precedence than the set it is parsing. - pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) { + pp$4.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) { var prec = this.type.binop; if (prec != null && (!forInit || this.type !== types._in)) { if (prec > minPrec) { @@ -2322,7 +2504,7 @@ var op = this.value; this.next(); var startPos = this.start, startLoc = this.startLoc; - var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, forInit); + var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit); var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce); if ((logical && this.type === types.coalesce) || (coalesce && (this.type === types.logicalOR || this.type === types.logicalAND))) { this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"); @@ -2333,7 +2515,7 @@ return left }; - pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) { + pp$4.buildBinary = function(startPos, startLoc, left, right, op, logical) { var node = this.startNodeAt(startPos, startLoc); node.left = left; node.operator = op; @@ -2343,17 +2525,17 @@ // Parse unary operators, both prefix and postfix. - pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec) { + pp$4.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) { var startPos = this.start, startLoc = this.startLoc, expr; if (this.isContextual("await") && this.canAwait) { - expr = this.parseAwait(); + expr = this.parseAwait(forInit); sawUnary = true; } else if (this.type.prefix) { var node = this.startNode(), update = this.type === types.incDec; node.operator = this.value; node.prefix = true; this.next(); - node.argument = this.parseMaybeUnary(null, true, update); + 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" && @@ -2364,7 +2546,7 @@ else { sawUnary = true; } expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); } else { - expr = this.parseExprSubscripts(refDestructuringErrors); + expr = this.parseExprSubscripts(refDestructuringErrors, forInit); if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } while (this.type.postfix && !this.canInsertSemicolon()) { var node$1 = this.startNodeAt(startPos, startLoc); @@ -2381,7 +2563,7 @@ if (sawUnary) { this.unexpected(this.lastTokStart); } else - { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) } + { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false) } } else { return expr } @@ -2396,12 +2578,12 @@ // Parse call, dot, and `[]`-subscript expressions. - pp$3.parseExprSubscripts = function(refDestructuringErrors) { + pp$4.parseExprSubscripts = function(refDestructuringErrors, forInit) { var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseExprAtom(refDestructuringErrors); + var expr = this.parseExprAtom(refDestructuringErrors, forInit); if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")") { return expr } - var result = this.parseSubscripts(expr, startPos, startLoc); + var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit); if (refDestructuringErrors && result.type === "MemberExpression") { if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; } if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; } @@ -2410,14 +2592,14 @@ return result }; - pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) { + pp$4.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) { var 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; var optionalChained = false; while (true) { - var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained); + var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit); if (element.optional) { optionalChained = true; } if (element === base || element.type === "ArrowFunctionExpression") { @@ -2433,7 +2615,7 @@ } }; - pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) { + pp$4.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) { var optionalSupported = this.options.ecmaVersion >= 11; var optional = optionalSupported && this.eat(types.questionDot); if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); } @@ -2469,7 +2651,7 @@ this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; 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); this.yieldPos = oldYieldPos || this.yieldPos; @@ -2499,7 +2681,7 @@ // `new`, or an expression wrapped in punctuation like `()`, `[]`, // or `{}`. - pp$3.parseExprAtom = function(refDestructuringErrors) { + pp$4.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 === types.slash) { this.readRegexp(); } @@ -2531,17 +2713,19 @@ case types.name: var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc; var id = this.parseIdent(false); - if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(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(types._function)) { + this.overrideContext(types$1.f_expr); + return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit) + } if (canBeArrow && !this.canInsertSemicolon()) { if (this.eat(types.arrow)) - { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) } + { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit) } if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc && (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) { id = this.parseIdent(false); if (this.canInsertSemicolon() || !this.eat(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 @@ -2563,7 +2747,7 @@ return this.finishNode(node, "Literal") case types.parenL: - var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow); + var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit); if (refDestructuringErrors) { if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr)) { refDestructuringErrors.parenthesizedAssign = start; } @@ -2579,6 +2763,7 @@ return this.finishNode(node, "ArrayExpression") case types.braceL: + this.overrideContext(types$1.b_expr); return this.parseObj(false, refDestructuringErrors) case types._function: @@ -2607,7 +2792,7 @@ } }; - pp$3.parseExprImport = function() { + pp$4.parseExprImport = function() { var node = this.startNode(); // Consume `import` as an identifier for `import.meta`. @@ -2626,7 +2811,7 @@ } }; - pp$3.parseDynamicImport = function(node) { + pp$4.parseDynamicImport = function(node) { this.next(); // skip `(` // Parse node.source. @@ -2645,7 +2830,7 @@ return this.finishNode(node, "ImportExpression") }; - pp$3.parseImportMeta = function(node) { + pp$4.parseImportMeta = function(node) { this.next(); // skip `.` var containsEsc = this.containsEsc; @@ -2661,7 +2846,7 @@ return this.finishNode(node, "MetaProperty") }; - pp$3.parseLiteral = function(value) { + pp$4.parseLiteral = function(value) { var node = this.startNode(); node.value = value; node.raw = this.input.slice(this.start, this.end); @@ -2670,14 +2855,14 @@ return this.finishNode(node, "Literal") }; - pp$3.parseParenExpression = function() { + pp$4.parseParenExpression = function() { this.expect(types.parenL); var val = this.parseExpression(); this.expect(types.parenR); return val }; - pp$3.parseParenAndDistinguishExpression = function(canBeArrow) { + pp$4.parseParenAndDistinguishExpression = function(canBeArrow, forInit) { var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8; if (this.options.ecmaVersion >= 6) { this.next(); @@ -2702,7 +2887,7 @@ exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem)); } } - var innerEndPos = this.start, innerEndLoc = this.startLoc; + var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc; this.expect(types.parenR); if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) { @@ -2710,7 +2895,7 @@ this.checkYieldAwaitInDefaultParams(); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; - return this.parseParenArrowList(startPos, startLoc, exprList) + return this.parseParenArrowList(startPos, startLoc, exprList, forInit) } if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); } @@ -2739,12 +2924,12 @@ } }; - pp$3.parseParenItem = function(item) { + pp$4.parseParenItem = function(item) { return item }; - pp$3.parseParenArrowList = function(startPos, startLoc, exprList) { - return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList) + pp$4.parseParenArrowList = function(startPos, startLoc, exprList, forInit) { + return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, forInit) }; // New's precedence is slightly tricky. It must allow its argument to @@ -2755,7 +2940,7 @@ var empty$1 = []; - pp$3.parseNew = function() { + pp$4.parseNew = function() { if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); } var node = this.startNode(); var meta = this.parseIdent(true); @@ -2767,12 +2952,12 @@ { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); } 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") } var startPos = this.start, startLoc = this.startLoc, isImport = this.type === 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()"); } @@ -2783,7 +2968,7 @@ // Parse template expression. - pp$3.parseTemplateElement = function(ref) { + pp$4.parseTemplateElement = function(ref) { var isTagged = ref.isTagged; var elem = this.startNode(); @@ -2806,7 +2991,7 @@ return this.finishNode(elem, "TemplateElement") }; - pp$3.parseTemplate = function(ref) { + pp$4.parseTemplate = function(ref) { if ( ref === void 0 ) ref = {}; var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false; @@ -2826,7 +3011,7 @@ return this.finishNode(node, "TemplateLiteral") }; - pp$3.isAsyncProp = function(prop) { + pp$4.isAsyncProp = function(prop) { return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" && (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) && !lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) @@ -2834,7 +3019,7 @@ // Parse an object literal or binding pattern. - pp$3.parseObj = function(isPattern, refDestructuringErrors) { + pp$4.parseObj = function(isPattern, refDestructuringErrors) { var node = this.startNode(), first = true, propHash = {}; node.properties = []; this.next(); @@ -2851,7 +3036,7 @@ return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression") }; - pp$3.parseProperty = function(isPattern, refDestructuringErrors) { + pp$4.parseProperty = function(isPattern, refDestructuringErrors) { var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc; if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) { if (isPattern) { @@ -2902,7 +3087,7 @@ return this.finishNode(prop, "Property") }; - pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { + pp$4.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { if ((isGenerator || isAsync) && this.type === types.colon) { this.unexpected(); } @@ -2952,7 +3137,7 @@ } else { this.unexpected(); } }; - pp$3.parsePropertyName = function(prop) { + pp$4.parsePropertyName = function(prop) { if (this.options.ecmaVersion >= 6) { if (this.eat(types.bracketL)) { prop.computed = true; @@ -2968,7 +3153,7 @@ // Initialize empty function node. - pp$3.initFunction = function(node) { + pp$4.initFunction = function(node) { node.id = null; if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; } if (this.options.ecmaVersion >= 8) { node.async = false; } @@ -2976,7 +3161,7 @@ // Parse object or class method. - pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { + pp$4.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; this.initFunction(node); @@ -2993,7 +3178,7 @@ this.expect(types.parenL); node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8); this.checkYieldAwaitInDefaultParams(); - this.parseFunctionBody(node, false, true); + this.parseFunctionBody(node, false, true, false); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; @@ -3003,7 +3188,7 @@ // Parse arrow function expression with given parameters. - pp$3.parseArrowExpression = function(node, params, isAsync) { + pp$4.parseArrowExpression = function(node, params, isAsync, forInit) { var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW); @@ -3015,7 +3200,7 @@ this.awaitIdentPos = 0; node.params = this.toAssignableList(params, true); - this.parseFunctionBody(node, true, false); + this.parseFunctionBody(node, true, false, forInit); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; @@ -3025,12 +3210,12 @@ // Parse function body and check parameters. - pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) { + pp$4.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) { var isExpression = isArrowFunction && this.type !== types.braceL; var oldStrict = this.strict, useStrict = false; if (isExpression) { - node.body = this.parseMaybeAssign(); + node.body = this.parseMaybeAssign(forInit); node.expression = true; this.checkParams(node, false); } else { @@ -3062,7 +3247,7 @@ this.exitScope(); }; - pp$3.isSimpleParamList = function(params) { + pp$4.isSimpleParamList = function(params) { for (var i = 0, list = params; i < list.length; i += 1) { var param = list[i]; @@ -3075,7 +3260,7 @@ // Checks function params for various disallowed patterns such as using "eval" // or "arguments" and duplicate parameters. - pp$3.checkParams = function(node, allowDuplicates) { + pp$4.checkParams = function(node, allowDuplicates) { var nameHash = Object.create(null); for (var i = 0, list = node.params; i < list.length; i += 1) { @@ -3091,7 +3276,7 @@ // nothing in between them to be parsed as `null` (which is needed // for array literals). - pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) { + pp$4.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) { var elts = [], first = true; while (!this.eat(close)) { if (!first) { @@ -3114,7 +3299,7 @@ return elts }; - pp$3.checkUnreserved = function(ref) { + pp$4.checkUnreserved = function(ref) { var start = ref.start; var end = ref.end; var name = ref.name; @@ -3125,6 +3310,8 @@ { 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 && @@ -3141,7 +3328,7 @@ // when parsing properties), it will also convert keywords into // identifiers. - pp$3.parseIdent = function(liberal, isBinding) { + pp$4.parseIdent = function(liberal, isBinding) { var node = this.startNode(); if (this.type === types.name) { node.name = this.value; @@ -3169,7 +3356,7 @@ return node }; - pp$3.parsePrivateIdent = function() { + pp$4.parsePrivateIdent = function() { var node = this.startNode(); if (this.type === types.privateId) { node.name = this.value; @@ -3191,7 +3378,7 @@ // Parses yield expression inside generator. - pp$3.parseYield = function(forInit) { + pp$4.parseYield = function(forInit) { if (!this.yieldPos) { this.yieldPos = this.start; } var node = this.startNode(); @@ -3206,16 +3393,16 @@ return this.finishNode(node, "YieldExpression") }; - pp$3.parseAwait = function() { + pp$4.parseAwait = function(forInit) { if (!this.awaitPos) { this.awaitPos = this.start; } var node = this.startNode(); this.next(); - node.argument = this.parseMaybeUnary(null, true); + node.argument = this.parseMaybeUnary(null, true, false, forInit); return this.finishNode(node, "AwaitExpression") }; - var pp$4 = Parser.prototype; + var pp$5 = Parser.prototype; // This function is used to raise exceptions on parse errors. It // takes an offset integer (into the current `input`) to indicate @@ -3223,7 +3410,7 @@ // of the error message, and then raises a `SyntaxError` with that // message. - pp$4.raise = function(pos, message) { + pp$5.raise = function(pos, message) { var loc = getLineInfo(this.input, pos); message += " (" + loc.line + ":" + loc.column + ")"; var err = new SyntaxError(message); @@ -3231,15 +3418,15 @@ throw err }; - pp$4.raiseRecoverable = pp$4.raise; + pp$5.raiseRecoverable = pp$5.raise; - pp$4.curPosition = function() { + pp$5.curPosition = function() { if (this.options.locations) { return new Position(this.curLine, this.pos - this.lineStart) } }; - var pp$5 = Parser.prototype; + var pp$6 = Parser.prototype; var Scope = function Scope(flags) { this.flags = flags; @@ -3255,22 +3442,22 @@ // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names. - pp$5.enterScope = function(flags) { + pp$6.enterScope = function(flags) { this.scopeStack.push(new Scope(flags)); }; - pp$5.exitScope = function() { + pp$6.exitScope = function() { this.scopeStack.pop(); }; // 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$5.treatFunctionsAsVarInScope = function(scope) { + pp$6.treatFunctionsAsVarInScope = function(scope) { return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP) }; - pp$5.declareName = function(name, bindingType, pos) { + pp$6.declareName = function(name, bindingType, pos) { var redeclared = false; if (bindingType === BIND_LEXICAL) { var scope = this.currentScope(); @@ -3305,7 +3492,7 @@ if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); } }; - pp$5.checkLocalExport = function(id) { + pp$6.checkLocalExport = function(id) { // scope.functions must be empty as Module code is always strict. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 && this.scopeStack[0].var.indexOf(id.name) === -1) { @@ -3313,11 +3500,11 @@ } }; - pp$5.currentScope = function() { + pp$6.currentScope = function() { return this.scopeStack[this.scopeStack.length - 1] }; - pp$5.currentVarScope = function() { + pp$6.currentVarScope = function() { for (var i = this.scopeStack.length - 1;; i--) { var scope = this.scopeStack[i]; if (scope.flags & SCOPE_VAR) { return scope } @@ -3325,7 +3512,7 @@ }; // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`. - pp$5.currentThisScope = function() { + pp$6.currentThisScope = function() { for (var i = this.scopeStack.length - 1;; i--) { var scope = this.scopeStack[i]; if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope } @@ -3346,13 +3533,13 @@ // Start an AST node, attaching a start offset. - var pp$6 = Parser.prototype; + var pp$7 = Parser.prototype; - pp$6.startNode = function() { + pp$7.startNode = function() { return new Node(this, this.start, this.startLoc) }; - pp$6.startNodeAt = function(pos, loc) { + pp$7.startNodeAt = function(pos, loc) { return new Node(this, pos, loc) }; @@ -3368,165 +3555,22 @@ return node } - pp$6.finishNode = function(node, type) { + pp$7.finishNode = function(node, type) { return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc) }; // Finish node at given position - pp$6.finishNodeAt = function(node, type, pos, loc) { + pp$7.finishNodeAt = function(node, type, pos, loc) { return finishNodeAt.call(this, node, type, pos, loc) }; - pp$6.copyNode = function(node) { + pp$7.copyNode = function(node) { var newNode = new Node(this, node.start, this.startLoc); for (var prop in node) { newNode[prop] = node[prop]; } return newNode }; - // The algorithm used to determine whether a regexp can appear at a - - var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) { - this.token = token; - this.isExpr = !!isExpr; - this.preserveSpace = !!preserveSpace; - this.override = override; - this.generator = !!generator; - }; - - var types$1 = { - b_stat: new TokContext("{", false), - b_expr: new TokContext("{", true), - b_tmpl: new TokContext("${", false), - p_stat: new TokContext("(", false), - p_expr: new TokContext("(", true), - q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }), - f_stat: new TokContext("function", false), - f_expr: new TokContext("function", true), - f_expr_gen: new TokContext("function", true, false, null, true), - f_gen: new TokContext("function", false, false, null, true) - }; - - var pp$7 = Parser.prototype; - - pp$7.initialContext = function() { - return [types$1.b_stat] - }; - - pp$7.braceIsBlock = function(prevType) { - var parent = this.curContext(); - if (parent === types$1.f_expr || parent === types$1.f_stat) - { return true } - if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.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 === types._return || prevType === types.name && this.exprAllowed) - { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) } - if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) - { return true } - if (prevType === types.braceL) - { return parent === types$1.b_stat } - if (prevType === types._var || prevType === types._const || prevType === types.name) - { return false } - return !this.exprAllowed - }; - - pp$7.inGeneratorContext = function() { - for (var i = this.context.length - 1; i >= 1; i--) { - var context = this.context[i]; - if (context.token === "function") - { return context.generator } - } - return false - }; - - pp$7.updateContext = function(prevType) { - var update, type = this.type; - if (type.keyword && prevType === types.dot) - { this.exprAllowed = false; } - else if (update = type.updateContext) - { update.call(this, prevType); } - else - { this.exprAllowed = type.beforeExpr; } - }; - - // Token-specific context update code - - types.parenR.updateContext = types.braceR.updateContext = function() { - if (this.context.length === 1) { - this.exprAllowed = true; - return - } - var out = this.context.pop(); - if (out === types$1.b_stat && this.curContext().token === "function") { - out = this.context.pop(); - } - this.exprAllowed = !out.isExpr; - }; - - types.braceL.updateContext = function(prevType) { - this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr); - this.exprAllowed = true; - }; - - types.dollarBraceL.updateContext = function() { - this.context.push(types$1.b_tmpl); - this.exprAllowed = true; - }; - - types.parenL.updateContext = function(prevType) { - var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while; - this.context.push(statementParens ? types$1.p_stat : types$1.p_expr); - this.exprAllowed = true; - }; - - types.incDec.updateContext = function() { - // tokExprAllowed stays unchanged - }; - - types._function.updateContext = types._class.updateContext = function(prevType) { - if (prevType.beforeExpr && prevType !== types._else && - !(prevType === types.semi && this.curContext() !== types$1.p_stat) && - !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) && - !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) - { this.context.push(types$1.f_expr); } - else - { this.context.push(types$1.f_stat); } - this.exprAllowed = false; - }; - - types.backQuote.updateContext = function() { - if (this.curContext() === types$1.q_tmpl) - { this.context.pop(); } - else - { this.context.push(types$1.q_tmpl); } - this.exprAllowed = false; - }; - - types.star.updateContext = function(prevType) { - if (prevType === types._function) { - var index = this.context.length - 1; - if (this.context[index] === types$1.f_expr) - { this.context[index] = types$1.f_expr_gen; } - else - { this.context[index] = types$1.f_gen; } - } - this.exprAllowed = true; - }; - - types.name.updateContext = function(prevType) { - var allowed = false; - if (this.options.ecmaVersion >= 6 && prevType !== types.dot) { - if (this.value === "of" && !this.exprAllowed || - this.value === "yield" && this.inGeneratorContext()) - { allowed = true; } - } - this.exprAllowed = allowed; - }; - // This file contains Unicode properties extracted from the ECMAScript // specification. The lists are extracted like so: // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText) @@ -4697,10 +4741,6 @@ // Toggle strict mode. Re-reads the next number or string to please // pedantic tests (`"use strict"; 010;` should fail). - pp$9.curContext = function() { - return this.context[this.context.length - 1] - }; - // Read a single token, updating the parser object's token-related // properties. @@ -5220,8 +5260,15 @@ out += this.input.slice(chunkStart, this.pos); out += this.readEscapedChar(false); 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 (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); } + if (isNewLine(ch)) { this.raise(this.start, "Unterminated string constant"); } ++this.pos; } } @@ -5447,7 +5494,7 @@ // Acorn is a tiny, fast JavaScript parser written in JavaScript. - var version = "8.4.1"; + var version = "8.5.0"; Parser.acorn = { Parser: Parser, diff --git a/deps/acorn/acorn/dist/acorn.mjs b/deps/acorn/acorn/dist/acorn.mjs index 30833d4fdf9f75..96a8294589badc 100644 --- a/deps/acorn/acorn/dist/acorn.mjs +++ b/deps/acorn/acorn/dist/acorn.mjs @@ -246,8 +246,8 @@ var types = { var lineBreak = /\r\n?|\n|\u2028|\u2029/; var lineBreakG = new RegExp(lineBreak.source, "g"); -function isNewLine(code, ecma2019String) { - return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029)) +function isNewLine(code) { + return code === 10 || code === 13 || code === 0x2028 || code === 0x2029 } var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/; @@ -458,13 +458,14 @@ function pushComment(options, array) { var SCOPE_TOP = 1, SCOPE_FUNCTION = 2, - SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION, SCOPE_ASYNC = 4, SCOPE_GENERATOR = 8, SCOPE_ARROW = 16, SCOPE_SIMPLE_CATCH = 32, SCOPE_SUPER = 64, - SCOPE_DIRECT_SUPER = 128; + SCOPE_DIRECT_SUPER = 128, + SCOPE_CLASS_STATIC_BLOCK = 256, + SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK; function functionFlags(async, generator) { return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0) @@ -564,7 +565,7 @@ var Parser = function Parser(options, input, startPos) { this.privateNameStack = []; }; -var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },canAwait: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },inNonArrowFunction: { configurable: true } }; +var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },canAwait: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },allowNewDotTarget: { configurable: true },inClassStaticBlock: { configurable: true } }; Parser.prototype.parse = function parse () { var node = this.options.program || this.startNode(); @@ -578,7 +579,7 @@ prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().fl prototypeAccessors.canAwait.get = function () { for (var i = this.scopeStack.length - 1; i >= 0; i--) { var scope = this.scopeStack[i]; - if (scope.inClassFieldInit) { return false } + if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) { return false } if (scope.flags & SCOPE_FUNCTION) { return (scope.flags & SCOPE_ASYNC) > 0 } } return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction @@ -591,11 +592,14 @@ prototypeAccessors.allowSuper.get = function () { }; prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 }; prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) }; -prototypeAccessors.inNonArrowFunction.get = function () { +prototypeAccessors.allowNewDotTarget.get = function () { var ref = this.currentThisScope(); var flags = ref.flags; var inClassFieldInit = ref.inClassFieldInit; - return (flags & SCOPE_FUNCTION) > 0 || inClassFieldInit + return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit +}; +prototypeAccessors.inClassStaticBlock.get = function () { + return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0 }; Parser.extend = function extend () { @@ -1004,14 +1008,16 @@ pp$1.parseForStatement = function(node) { if (awaitAt > -1) { this.unexpected(awaitAt); } return this.parseFor(node, init$1) } + var startsWithLet = this.isContextual("let"), isForOf = false; var refDestructuringErrors = new DestructuringErrors; var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors); - if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) { + if (this.type === types._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) { if (this.options.ecmaVersion >= 9) { if (this.type === types._in) { if (awaitAt > -1) { this.unexpected(awaitAt); } } else { node.await = awaitAt > -1; } } + 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); this.checkLValPattern(init); return this.parseForIn(node, init) @@ -1294,7 +1300,7 @@ var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4; // `statement & FUNC_STATEMENT`). // Remove `allowExpressionBody` for 7.0.0, as it is only called with false -pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) { +pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) { this.initFunction(node); if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) { if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT)) @@ -1324,7 +1330,7 @@ pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) { { node.id = this.type === types.name ? this.parseIdent() : null; } this.parseFunctionParams(node); - this.parseFunctionBody(node, allowExpressionBody, false); + this.parseFunctionBody(node, allowExpressionBody, false, forInit); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; @@ -1363,7 +1369,7 @@ pp$1.parseClass = function(node, isStatement) { 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.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) { + } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) { this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared")); } } @@ -1384,16 +1390,21 @@ pp$1.parseClassElement = function(constructorAllowsSuper) { var isGenerator = false; var isAsync = false; var kind = "method"; + var isStatic = false; - // Parse modifiers - node.static = false; if (this.eatContextual("static")) { + // Parse static init block + if (ecmaVersion >= 13 && this.eat(types.braceL)) { + this.parseClassStaticBlock(node); + return node + } if (this.isClassElementNameStart() || this.type === types.star) { - node.static = true; + isStatic = true; } else { keyName = "static"; } } + node.static = isStatic; if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) { if ((this.isClassElementNameStart() || this.type === types.star) && !this.canInsertSemicolon()) { isAsync = true; @@ -1511,6 +1522,23 @@ pp$1.parseClassField = function(field) { return this.finishNode(field, "PropertyDefinition") }; +pp$1.parseClassStaticBlock = function(node) { + node.body = []; + + var oldLabels = this.labels; + this.labels = []; + this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER); + while (this.type !== types.braceR) { + var stmt = this.parseStatement(null); + node.body.push(stmt); + } + this.next(); + this.exitScope(); + this.labels = oldLabels; + + return this.finishNode(node, "StaticBlock") +}; + pp$1.parseClassId = function(node, isStatement) { if (this.type === types.name) { node.id = this.parseIdent(); @@ -1524,7 +1552,7 @@ pp$1.parseClassId = function(node, isStatement) { }; pp$1.parseClassSuper = function(node) { - node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null; + node.superClass = this.eat(types._extends) ? this.parseExprSubscripts(false) : null; }; pp$1.enterClassBody = function() { @@ -2133,16 +2161,170 @@ pp$2.checkLValInnerPattern = function(expr, bindingType, checkClashes) { } }; -// A recursive descent parser operates by defining functions for all +// The algorithm used to determine whether a regexp can appear at a + +var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) { + this.token = token; + this.isExpr = !!isExpr; + this.preserveSpace = !!preserveSpace; + this.override = override; + this.generator = !!generator; +}; + +var types$1 = { + b_stat: new TokContext("{", false), + b_expr: new TokContext("{", true), + b_tmpl: new TokContext("${", false), + p_stat: new TokContext("(", false), + p_expr: new TokContext("(", true), + q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }), + f_stat: new TokContext("function", false), + f_expr: new TokContext("function", true), + f_expr_gen: new TokContext("function", true, false, null, true), + f_gen: new TokContext("function", false, false, null, true) +}; var pp$3 = Parser.prototype; +pp$3.initialContext = function() { + return [types$1.b_stat] +}; + +pp$3.curContext = function() { + return this.context[this.context.length - 1] +}; + +pp$3.braceIsBlock = function(prevType) { + var parent = this.curContext(); + if (parent === types$1.f_expr || parent === types$1.f_stat) + { return true } + if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.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 === types._return || prevType === types.name && this.exprAllowed) + { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) } + if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) + { return true } + if (prevType === types.braceL) + { return parent === types$1.b_stat } + if (prevType === types._var || prevType === types._const || prevType === types.name) + { return false } + return !this.exprAllowed +}; + +pp$3.inGeneratorContext = function() { + for (var i = this.context.length - 1; i >= 1; i--) { + var context = this.context[i]; + if (context.token === "function") + { return context.generator } + } + return false +}; + +pp$3.updateContext = function(prevType) { + var update, type = this.type; + if (type.keyword && prevType === 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 +pp$3.overrideContext = function(tokenCtx) { + if (this.curContext() !== tokenCtx) { + this.context[this.context.length - 1] = tokenCtx; + } +}; + +// Token-specific context update code + +types.parenR.updateContext = types.braceR.updateContext = function() { + if (this.context.length === 1) { + this.exprAllowed = true; + return + } + var out = this.context.pop(); + if (out === types$1.b_stat && this.curContext().token === "function") { + out = this.context.pop(); + } + this.exprAllowed = !out.isExpr; +}; + +types.braceL.updateContext = function(prevType) { + this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr); + this.exprAllowed = true; +}; + +types.dollarBraceL.updateContext = function() { + this.context.push(types$1.b_tmpl); + this.exprAllowed = true; +}; + +types.parenL.updateContext = function(prevType) { + var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while; + this.context.push(statementParens ? types$1.p_stat : types$1.p_expr); + this.exprAllowed = true; +}; + +types.incDec.updateContext = function() { + // tokExprAllowed stays unchanged +}; + +types._function.updateContext = types._class.updateContext = function(prevType) { + if (prevType.beforeExpr && prevType !== types._else && + !(prevType === types.semi && this.curContext() !== types$1.p_stat) && + !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) && + !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) + { this.context.push(types$1.f_expr); } + else + { this.context.push(types$1.f_stat); } + this.exprAllowed = false; +}; + +types.backQuote.updateContext = function() { + if (this.curContext() === types$1.q_tmpl) + { this.context.pop(); } + else + { this.context.push(types$1.q_tmpl); } + this.exprAllowed = false; +}; + +types.star.updateContext = function(prevType) { + if (prevType === types._function) { + var index = this.context.length - 1; + if (this.context[index] === types$1.f_expr) + { this.context[index] = types$1.f_expr_gen; } + else + { this.context[index] = types$1.f_gen; } + } + this.exprAllowed = true; +}; + +types.name.updateContext = function(prevType) { + var allowed = false; + if (this.options.ecmaVersion >= 6 && prevType !== types.dot) { + if (this.value === "of" && !this.exprAllowed || + this.value === "yield" && this.inGeneratorContext()) + { allowed = true; } + } + this.exprAllowed = allowed; +}; + +// A recursive descent parser operates by defining functions for all + +var pp$4 = Parser.prototype; + // Check if property name clashes with already added. // Object/class getters and setters are not allowed to clash — // either with each other or with an init property — and in // strict mode, init properties are also not allowed to be repeated. -pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) { +pp$4.checkPropClash = function(prop, propHash, refDestructuringErrors) { if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement") { return } if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) @@ -2204,7 +2386,7 @@ pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) { // and object pattern might appear (so it's possible to raise // delayed syntax error at correct position). -pp$3.parseExpression = function(forInit, refDestructuringErrors) { +pp$4.parseExpression = function(forInit, refDestructuringErrors) { var startPos = this.start, startLoc = this.startLoc; var expr = this.parseMaybeAssign(forInit, refDestructuringErrors); if (this.type === types.comma) { @@ -2219,7 +2401,7 @@ pp$3.parseExpression = function(forInit, refDestructuringErrors) { // Parse an assignment expression. This includes applications of // operators like `+=`. -pp$3.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) { +pp$4.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) { if (this.isContextual("yield")) { if (this.inGenerator) { return this.parseYield(forInit) } // The tokenizer will assume an expression is allowed after @@ -2272,7 +2454,7 @@ pp$3.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse // Parse a ternary conditional (`?:`) operator. -pp$3.parseMaybeConditional = function(forInit, refDestructuringErrors) { +pp$4.parseMaybeConditional = function(forInit, refDestructuringErrors) { var startPos = this.start, startLoc = this.startLoc; var expr = this.parseExprOps(forInit, refDestructuringErrors); if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } @@ -2289,9 +2471,9 @@ pp$3.parseMaybeConditional = function(forInit, refDestructuringErrors) { // Start the precedence parser. -pp$3.parseExprOps = function(forInit, refDestructuringErrors) { +pp$4.parseExprOps = function(forInit, refDestructuringErrors) { var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseMaybeUnary(refDestructuringErrors, false); + var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit); if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit) }; @@ -2302,7 +2484,7 @@ pp$3.parseExprOps = function(forInit, refDestructuringErrors) { // defer further parser to one of its callers when it encounters an // operator that has a lower precedence than the set it is parsing. -pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) { +pp$4.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) { var prec = this.type.binop; if (prec != null && (!forInit || this.type !== types._in)) { if (prec > minPrec) { @@ -2316,7 +2498,7 @@ pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) var op = this.value; this.next(); var startPos = this.start, startLoc = this.startLoc; - var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, forInit); + var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit); var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce); if ((logical && this.type === types.coalesce) || (coalesce && (this.type === types.logicalOR || this.type === types.logicalAND))) { this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"); @@ -2327,7 +2509,7 @@ pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) return left }; -pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) { +pp$4.buildBinary = function(startPos, startLoc, left, right, op, logical) { var node = this.startNodeAt(startPos, startLoc); node.left = left; node.operator = op; @@ -2337,17 +2519,17 @@ pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) { // Parse unary operators, both prefix and postfix. -pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec) { +pp$4.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) { var startPos = this.start, startLoc = this.startLoc, expr; if (this.isContextual("await") && this.canAwait) { - expr = this.parseAwait(); + expr = this.parseAwait(forInit); sawUnary = true; } else if (this.type.prefix) { var node = this.startNode(), update = this.type === types.incDec; node.operator = this.value; node.prefix = true; this.next(); - node.argument = this.parseMaybeUnary(null, true, update); + 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" && @@ -2358,7 +2540,7 @@ pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec) { else { sawUnary = true; } expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); } else { - expr = this.parseExprSubscripts(refDestructuringErrors); + expr = this.parseExprSubscripts(refDestructuringErrors, forInit); if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } while (this.type.postfix && !this.canInsertSemicolon()) { var node$1 = this.startNodeAt(startPos, startLoc); @@ -2375,7 +2557,7 @@ pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec) { if (sawUnary) { this.unexpected(this.lastTokStart); } else - { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) } + { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false) } } else { return expr } @@ -2390,12 +2572,12 @@ function isPrivateFieldAccess(node) { // Parse call, dot, and `[]`-subscript expressions. -pp$3.parseExprSubscripts = function(refDestructuringErrors) { +pp$4.parseExprSubscripts = function(refDestructuringErrors, forInit) { var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseExprAtom(refDestructuringErrors); + var expr = this.parseExprAtom(refDestructuringErrors, forInit); if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")") { return expr } - var result = this.parseSubscripts(expr, startPos, startLoc); + var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit); if (refDestructuringErrors && result.type === "MemberExpression") { if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; } if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; } @@ -2404,14 +2586,14 @@ pp$3.parseExprSubscripts = function(refDestructuringErrors) { return result }; -pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) { +pp$4.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) { var 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; var optionalChained = false; while (true) { - var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained); + var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit); if (element.optional) { optionalChained = true; } if (element === base || element.type === "ArrowFunctionExpression") { @@ -2427,7 +2609,7 @@ pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) { } }; -pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) { +pp$4.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) { var optionalSupported = this.options.ecmaVersion >= 11; var optional = optionalSupported && this.eat(types.questionDot); if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); } @@ -2463,7 +2645,7 @@ pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArro this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; 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); this.yieldPos = oldYieldPos || this.yieldPos; @@ -2493,7 +2675,7 @@ pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArro // `new`, or an expression wrapped in punctuation like `()`, `[]`, // or `{}`. -pp$3.parseExprAtom = function(refDestructuringErrors) { +pp$4.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 === types.slash) { this.readRegexp(); } @@ -2525,17 +2707,19 @@ pp$3.parseExprAtom = function(refDestructuringErrors) { case types.name: var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc; var id = this.parseIdent(false); - if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(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(types._function)) { + this.overrideContext(types$1.f_expr); + return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit) + } if (canBeArrow && !this.canInsertSemicolon()) { if (this.eat(types.arrow)) - { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) } + { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit) } if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc && (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) { id = this.parseIdent(false); if (this.canInsertSemicolon() || !this.eat(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 @@ -2557,7 +2741,7 @@ pp$3.parseExprAtom = function(refDestructuringErrors) { return this.finishNode(node, "Literal") case types.parenL: - var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow); + var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit); if (refDestructuringErrors) { if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr)) { refDestructuringErrors.parenthesizedAssign = start; } @@ -2573,6 +2757,7 @@ pp$3.parseExprAtom = function(refDestructuringErrors) { return this.finishNode(node, "ArrayExpression") case types.braceL: + this.overrideContext(types$1.b_expr); return this.parseObj(false, refDestructuringErrors) case types._function: @@ -2601,7 +2786,7 @@ pp$3.parseExprAtom = function(refDestructuringErrors) { } }; -pp$3.parseExprImport = function() { +pp$4.parseExprImport = function() { var node = this.startNode(); // Consume `import` as an identifier for `import.meta`. @@ -2620,7 +2805,7 @@ pp$3.parseExprImport = function() { } }; -pp$3.parseDynamicImport = function(node) { +pp$4.parseDynamicImport = function(node) { this.next(); // skip `(` // Parse node.source. @@ -2639,7 +2824,7 @@ pp$3.parseDynamicImport = function(node) { return this.finishNode(node, "ImportExpression") }; -pp$3.parseImportMeta = function(node) { +pp$4.parseImportMeta = function(node) { this.next(); // skip `.` var containsEsc = this.containsEsc; @@ -2655,7 +2840,7 @@ pp$3.parseImportMeta = function(node) { return this.finishNode(node, "MetaProperty") }; -pp$3.parseLiteral = function(value) { +pp$4.parseLiteral = function(value) { var node = this.startNode(); node.value = value; node.raw = this.input.slice(this.start, this.end); @@ -2664,14 +2849,14 @@ pp$3.parseLiteral = function(value) { return this.finishNode(node, "Literal") }; -pp$3.parseParenExpression = function() { +pp$4.parseParenExpression = function() { this.expect(types.parenL); var val = this.parseExpression(); this.expect(types.parenR); return val }; -pp$3.parseParenAndDistinguishExpression = function(canBeArrow) { +pp$4.parseParenAndDistinguishExpression = function(canBeArrow, forInit) { var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8; if (this.options.ecmaVersion >= 6) { this.next(); @@ -2696,7 +2881,7 @@ pp$3.parseParenAndDistinguishExpression = function(canBeArrow) { exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem)); } } - var innerEndPos = this.start, innerEndLoc = this.startLoc; + var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc; this.expect(types.parenR); if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) { @@ -2704,7 +2889,7 @@ pp$3.parseParenAndDistinguishExpression = function(canBeArrow) { this.checkYieldAwaitInDefaultParams(); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; - return this.parseParenArrowList(startPos, startLoc, exprList) + return this.parseParenArrowList(startPos, startLoc, exprList, forInit) } if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); } @@ -2733,12 +2918,12 @@ pp$3.parseParenAndDistinguishExpression = function(canBeArrow) { } }; -pp$3.parseParenItem = function(item) { +pp$4.parseParenItem = function(item) { return item }; -pp$3.parseParenArrowList = function(startPos, startLoc, exprList) { - return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList) +pp$4.parseParenArrowList = function(startPos, startLoc, exprList, forInit) { + return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, forInit) }; // New's precedence is slightly tricky. It must allow its argument to @@ -2749,7 +2934,7 @@ pp$3.parseParenArrowList = function(startPos, startLoc, exprList) { var empty$1 = []; -pp$3.parseNew = function() { +pp$4.parseNew = function() { if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); } var node = this.startNode(); var meta = this.parseIdent(true); @@ -2761,12 +2946,12 @@ pp$3.parseNew = function() { { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); } 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") } var startPos = this.start, startLoc = this.startLoc, isImport = this.type === 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()"); } @@ -2777,7 +2962,7 @@ pp$3.parseNew = function() { // Parse template expression. -pp$3.parseTemplateElement = function(ref) { +pp$4.parseTemplateElement = function(ref) { var isTagged = ref.isTagged; var elem = this.startNode(); @@ -2800,7 +2985,7 @@ pp$3.parseTemplateElement = function(ref) { return this.finishNode(elem, "TemplateElement") }; -pp$3.parseTemplate = function(ref) { +pp$4.parseTemplate = function(ref) { if ( ref === void 0 ) ref = {}; var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false; @@ -2820,7 +3005,7 @@ pp$3.parseTemplate = function(ref) { return this.finishNode(node, "TemplateLiteral") }; -pp$3.isAsyncProp = function(prop) { +pp$4.isAsyncProp = function(prop) { return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" && (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) && !lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) @@ -2828,7 +3013,7 @@ pp$3.isAsyncProp = function(prop) { // Parse an object literal or binding pattern. -pp$3.parseObj = function(isPattern, refDestructuringErrors) { +pp$4.parseObj = function(isPattern, refDestructuringErrors) { var node = this.startNode(), first = true, propHash = {}; node.properties = []; this.next(); @@ -2845,7 +3030,7 @@ pp$3.parseObj = function(isPattern, refDestructuringErrors) { return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression") }; -pp$3.parseProperty = function(isPattern, refDestructuringErrors) { +pp$4.parseProperty = function(isPattern, refDestructuringErrors) { var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc; if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) { if (isPattern) { @@ -2896,7 +3081,7 @@ pp$3.parseProperty = function(isPattern, refDestructuringErrors) { return this.finishNode(prop, "Property") }; -pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { +pp$4.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { if ((isGenerator || isAsync) && this.type === types.colon) { this.unexpected(); } @@ -2946,7 +3131,7 @@ pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startP } else { this.unexpected(); } }; -pp$3.parsePropertyName = function(prop) { +pp$4.parsePropertyName = function(prop) { if (this.options.ecmaVersion >= 6) { if (this.eat(types.bracketL)) { prop.computed = true; @@ -2962,7 +3147,7 @@ pp$3.parsePropertyName = function(prop) { // Initialize empty function node. -pp$3.initFunction = function(node) { +pp$4.initFunction = function(node) { node.id = null; if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; } if (this.options.ecmaVersion >= 8) { node.async = false; } @@ -2970,7 +3155,7 @@ pp$3.initFunction = function(node) { // Parse object or class method. -pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { +pp$4.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; this.initFunction(node); @@ -2987,7 +3172,7 @@ pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { this.expect(types.parenL); node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8); this.checkYieldAwaitInDefaultParams(); - this.parseFunctionBody(node, false, true); + this.parseFunctionBody(node, false, true, false); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; @@ -2997,7 +3182,7 @@ pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { // Parse arrow function expression with given parameters. -pp$3.parseArrowExpression = function(node, params, isAsync) { +pp$4.parseArrowExpression = function(node, params, isAsync, forInit) { var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW); @@ -3009,7 +3194,7 @@ pp$3.parseArrowExpression = function(node, params, isAsync) { this.awaitIdentPos = 0; node.params = this.toAssignableList(params, true); - this.parseFunctionBody(node, true, false); + this.parseFunctionBody(node, true, false, forInit); this.yieldPos = oldYieldPos; this.awaitPos = oldAwaitPos; @@ -3019,12 +3204,12 @@ pp$3.parseArrowExpression = function(node, params, isAsync) { // Parse function body and check parameters. -pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) { +pp$4.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) { var isExpression = isArrowFunction && this.type !== types.braceL; var oldStrict = this.strict, useStrict = false; if (isExpression) { - node.body = this.parseMaybeAssign(); + node.body = this.parseMaybeAssign(forInit); node.expression = true; this.checkParams(node, false); } else { @@ -3056,7 +3241,7 @@ pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) { this.exitScope(); }; -pp$3.isSimpleParamList = function(params) { +pp$4.isSimpleParamList = function(params) { for (var i = 0, list = params; i < list.length; i += 1) { var param = list[i]; @@ -3069,7 +3254,7 @@ pp$3.isSimpleParamList = function(params) { // Checks function params for various disallowed patterns such as using "eval" // or "arguments" and duplicate parameters. -pp$3.checkParams = function(node, allowDuplicates) { +pp$4.checkParams = function(node, allowDuplicates) { var nameHash = Object.create(null); for (var i = 0, list = node.params; i < list.length; i += 1) { @@ -3085,7 +3270,7 @@ pp$3.checkParams = function(node, allowDuplicates) { // nothing in between them to be parsed as `null` (which is needed // for array literals). -pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) { +pp$4.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) { var elts = [], first = true; while (!this.eat(close)) { if (!first) { @@ -3108,7 +3293,7 @@ pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestruct return elts }; -pp$3.checkUnreserved = function(ref) { +pp$4.checkUnreserved = function(ref) { var start = ref.start; var end = ref.end; var name = ref.name; @@ -3119,6 +3304,8 @@ pp$3.checkUnreserved = function(ref) { { 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 && @@ -3135,7 +3322,7 @@ pp$3.checkUnreserved = function(ref) { // when parsing properties), it will also convert keywords into // identifiers. -pp$3.parseIdent = function(liberal, isBinding) { +pp$4.parseIdent = function(liberal, isBinding) { var node = this.startNode(); if (this.type === types.name) { node.name = this.value; @@ -3163,7 +3350,7 @@ pp$3.parseIdent = function(liberal, isBinding) { return node }; -pp$3.parsePrivateIdent = function() { +pp$4.parsePrivateIdent = function() { var node = this.startNode(); if (this.type === types.privateId) { node.name = this.value; @@ -3185,7 +3372,7 @@ pp$3.parsePrivateIdent = function() { // Parses yield expression inside generator. -pp$3.parseYield = function(forInit) { +pp$4.parseYield = function(forInit) { if (!this.yieldPos) { this.yieldPos = this.start; } var node = this.startNode(); @@ -3200,16 +3387,16 @@ pp$3.parseYield = function(forInit) { return this.finishNode(node, "YieldExpression") }; -pp$3.parseAwait = function() { +pp$4.parseAwait = function(forInit) { if (!this.awaitPos) { this.awaitPos = this.start; } var node = this.startNode(); this.next(); - node.argument = this.parseMaybeUnary(null, true); + node.argument = this.parseMaybeUnary(null, true, false, forInit); return this.finishNode(node, "AwaitExpression") }; -var pp$4 = Parser.prototype; +var pp$5 = Parser.prototype; // This function is used to raise exceptions on parse errors. It // takes an offset integer (into the current `input`) to indicate @@ -3217,7 +3404,7 @@ var pp$4 = Parser.prototype; // of the error message, and then raises a `SyntaxError` with that // message. -pp$4.raise = function(pos, message) { +pp$5.raise = function(pos, message) { var loc = getLineInfo(this.input, pos); message += " (" + loc.line + ":" + loc.column + ")"; var err = new SyntaxError(message); @@ -3225,15 +3412,15 @@ pp$4.raise = function(pos, message) { throw err }; -pp$4.raiseRecoverable = pp$4.raise; +pp$5.raiseRecoverable = pp$5.raise; -pp$4.curPosition = function() { +pp$5.curPosition = function() { if (this.options.locations) { return new Position(this.curLine, this.pos - this.lineStart) } }; -var pp$5 = Parser.prototype; +var pp$6 = Parser.prototype; var Scope = function Scope(flags) { this.flags = flags; @@ -3249,22 +3436,22 @@ var Scope = function Scope(flags) { // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names. -pp$5.enterScope = function(flags) { +pp$6.enterScope = function(flags) { this.scopeStack.push(new Scope(flags)); }; -pp$5.exitScope = function() { +pp$6.exitScope = function() { this.scopeStack.pop(); }; // 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$5.treatFunctionsAsVarInScope = function(scope) { +pp$6.treatFunctionsAsVarInScope = function(scope) { return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP) }; -pp$5.declareName = function(name, bindingType, pos) { +pp$6.declareName = function(name, bindingType, pos) { var redeclared = false; if (bindingType === BIND_LEXICAL) { var scope = this.currentScope(); @@ -3299,7 +3486,7 @@ pp$5.declareName = function(name, bindingType, pos) { if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); } }; -pp$5.checkLocalExport = function(id) { +pp$6.checkLocalExport = function(id) { // scope.functions must be empty as Module code is always strict. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 && this.scopeStack[0].var.indexOf(id.name) === -1) { @@ -3307,11 +3494,11 @@ pp$5.checkLocalExport = function(id) { } }; -pp$5.currentScope = function() { +pp$6.currentScope = function() { return this.scopeStack[this.scopeStack.length - 1] }; -pp$5.currentVarScope = function() { +pp$6.currentVarScope = function() { for (var i = this.scopeStack.length - 1;; i--) { var scope = this.scopeStack[i]; if (scope.flags & SCOPE_VAR) { return scope } @@ -3319,7 +3506,7 @@ pp$5.currentVarScope = function() { }; // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`. -pp$5.currentThisScope = function() { +pp$6.currentThisScope = function() { for (var i = this.scopeStack.length - 1;; i--) { var scope = this.scopeStack[i]; if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope } @@ -3340,13 +3527,13 @@ var Node = function Node(parser, pos, loc) { // Start an AST node, attaching a start offset. -var pp$6 = Parser.prototype; +var pp$7 = Parser.prototype; -pp$6.startNode = function() { +pp$7.startNode = function() { return new Node(this, this.start, this.startLoc) }; -pp$6.startNodeAt = function(pos, loc) { +pp$7.startNodeAt = function(pos, loc) { return new Node(this, pos, loc) }; @@ -3362,165 +3549,22 @@ function finishNodeAt(node, type, pos, loc) { return node } -pp$6.finishNode = function(node, type) { +pp$7.finishNode = function(node, type) { return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc) }; // Finish node at given position -pp$6.finishNodeAt = function(node, type, pos, loc) { +pp$7.finishNodeAt = function(node, type, pos, loc) { return finishNodeAt.call(this, node, type, pos, loc) }; -pp$6.copyNode = function(node) { +pp$7.copyNode = function(node) { var newNode = new Node(this, node.start, this.startLoc); for (var prop in node) { newNode[prop] = node[prop]; } return newNode }; -// The algorithm used to determine whether a regexp can appear at a - -var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) { - this.token = token; - this.isExpr = !!isExpr; - this.preserveSpace = !!preserveSpace; - this.override = override; - this.generator = !!generator; -}; - -var types$1 = { - b_stat: new TokContext("{", false), - b_expr: new TokContext("{", true), - b_tmpl: new TokContext("${", false), - p_stat: new TokContext("(", false), - p_expr: new TokContext("(", true), - q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }), - f_stat: new TokContext("function", false), - f_expr: new TokContext("function", true), - f_expr_gen: new TokContext("function", true, false, null, true), - f_gen: new TokContext("function", false, false, null, true) -}; - -var pp$7 = Parser.prototype; - -pp$7.initialContext = function() { - return [types$1.b_stat] -}; - -pp$7.braceIsBlock = function(prevType) { - var parent = this.curContext(); - if (parent === types$1.f_expr || parent === types$1.f_stat) - { return true } - if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.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 === types._return || prevType === types.name && this.exprAllowed) - { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) } - if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) - { return true } - if (prevType === types.braceL) - { return parent === types$1.b_stat } - if (prevType === types._var || prevType === types._const || prevType === types.name) - { return false } - return !this.exprAllowed -}; - -pp$7.inGeneratorContext = function() { - for (var i = this.context.length - 1; i >= 1; i--) { - var context = this.context[i]; - if (context.token === "function") - { return context.generator } - } - return false -}; - -pp$7.updateContext = function(prevType) { - var update, type = this.type; - if (type.keyword && prevType === types.dot) - { this.exprAllowed = false; } - else if (update = type.updateContext) - { update.call(this, prevType); } - else - { this.exprAllowed = type.beforeExpr; } -}; - -// Token-specific context update code - -types.parenR.updateContext = types.braceR.updateContext = function() { - if (this.context.length === 1) { - this.exprAllowed = true; - return - } - var out = this.context.pop(); - if (out === types$1.b_stat && this.curContext().token === "function") { - out = this.context.pop(); - } - this.exprAllowed = !out.isExpr; -}; - -types.braceL.updateContext = function(prevType) { - this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr); - this.exprAllowed = true; -}; - -types.dollarBraceL.updateContext = function() { - this.context.push(types$1.b_tmpl); - this.exprAllowed = true; -}; - -types.parenL.updateContext = function(prevType) { - var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while; - this.context.push(statementParens ? types$1.p_stat : types$1.p_expr); - this.exprAllowed = true; -}; - -types.incDec.updateContext = function() { - // tokExprAllowed stays unchanged -}; - -types._function.updateContext = types._class.updateContext = function(prevType) { - if (prevType.beforeExpr && prevType !== types._else && - !(prevType === types.semi && this.curContext() !== types$1.p_stat) && - !(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) && - !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) - { this.context.push(types$1.f_expr); } - else - { this.context.push(types$1.f_stat); } - this.exprAllowed = false; -}; - -types.backQuote.updateContext = function() { - if (this.curContext() === types$1.q_tmpl) - { this.context.pop(); } - else - { this.context.push(types$1.q_tmpl); } - this.exprAllowed = false; -}; - -types.star.updateContext = function(prevType) { - if (prevType === types._function) { - var index = this.context.length - 1; - if (this.context[index] === types$1.f_expr) - { this.context[index] = types$1.f_expr_gen; } - else - { this.context[index] = types$1.f_gen; } - } - this.exprAllowed = true; -}; - -types.name.updateContext = function(prevType) { - var allowed = false; - if (this.options.ecmaVersion >= 6 && prevType !== types.dot) { - if (this.value === "of" && !this.exprAllowed || - this.value === "yield" && this.inGeneratorContext()) - { allowed = true; } - } - this.exprAllowed = allowed; -}; - // This file contains Unicode properties extracted from the ECMAScript // specification. The lists are extracted like so: // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText) @@ -4691,10 +4735,6 @@ if (typeof Symbol !== "undefined") // Toggle strict mode. Re-reads the next number or string to please // pedantic tests (`"use strict"; 010;` should fail). -pp$9.curContext = function() { - return this.context[this.context.length - 1] -}; - // Read a single token, updating the parser object's token-related // properties. @@ -5214,8 +5254,15 @@ pp$9.readString = function(quote) { out += this.input.slice(chunkStart, this.pos); out += this.readEscapedChar(false); 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 (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); } + if (isNewLine(ch)) { this.raise(this.start, "Unterminated string constant"); } ++this.pos; } } @@ -5441,7 +5488,7 @@ pp$9.readWord = function() { // Acorn is a tiny, fast JavaScript parser written in JavaScript. -var version = "8.4.1"; +var version = "8.5.0"; Parser.acorn = { Parser: Parser, diff --git a/deps/acorn/acorn/dist/bin.js b/deps/acorn/acorn/dist/bin.js index 3c3ce22e520edc..d35d6ee9909209 100644 --- a/deps/acorn/acorn/dist/bin.js +++ b/deps/acorn/acorn/dist/bin.js @@ -4,21 +4,24 @@ var path = require('path'); var fs = require('fs'); var acorn = require('./acorn.js'); -var infile, forceFile, silent = false, compact = false, tokenize = false; +var inputFilePaths = [], forceFileName = false, fileMode = false, silent = false, compact = false, tokenize = false; var options = {}; function help(status) { var print = (status === 0) ? console.log : console.error; print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]"); - print(" [--tokenize] [--locations] [---allow-hash-bang] [--allow-await-outside-function] [--compact] [--silent] [--module] [--help] [--] [infile]"); + print(" [--tokenize] [--locations] [---allow-hash-bang] [--allow-await-outside-function] [--compact] [--silent] [--module] [--help] [--] [...]"); process.exit(status); } for (var i = 2; i < process.argv.length; ++i) { var arg = process.argv[i]; - if ((arg === "-" || arg[0] !== "-") && !infile) { infile = arg; } - else if (arg === "--" && !infile && i + 2 === process.argv.length) { forceFile = infile = process.argv[++i]; } - else if (arg === "--locations") { options.locations = true; } + if (arg[0] !== "-" || arg === "-") { inputFilePaths.push(arg); } + else if (arg === "--") { + inputFilePaths.push.apply(inputFilePaths, process.argv.slice(i + 1)); + forceFileName = true; + break + } else if (arg === "--locations") { options.locations = true; } else if (arg === "--allow-hash-bang") { options.allowHashBang = true; } else if (arg === "--allow-await-outside-function") { options.allowAwaitOutsideFunction = true; } else if (arg === "--silent") { silent = true; } @@ -35,31 +38,34 @@ for (var i = 2; i < process.argv.length; ++i) { } } -function run(code) { - var result; +function run(codeList) { + var result = [], fileIdx = 0; try { - if (!tokenize) { - result = acorn.parse(code, options); - } else { - result = []; - var tokenizer = acorn.tokenizer(code, options), token; - do { - token = tokenizer.getToken(); - result.push(token); - } while (token.type !== acorn.tokTypes.eof) - } + codeList.forEach(function (code, idx) { + fileIdx = idx; + if (!tokenize) { + result = acorn.parse(code, options); + options.program = result; + } else { + var tokenizer = acorn.tokenizer(code, options), token; + do { + token = tokenizer.getToken(); + result.push(token); + } while (token.type !== acorn.tokTypes.eof) + } + }); } catch (e) { - console.error(infile && infile !== "-" ? e.message.replace(/\(\d+:\d+\)$/, function (m) { return m.slice(0, 1) + infile + " " + m.slice(1); }) : e.message); + console.error(fileMode ? e.message.replace(/\(\d+:\d+\)$/, function (m) { return m.slice(0, 1) + inputFilePaths[fileIdx] + " " + m.slice(1); }) : e.message); process.exit(1); } if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); } } -if (forceFile || infile && infile !== "-") { - run(fs.readFileSync(infile, "utf8")); +if (fileMode = inputFilePaths.length && (forceFileName || !inputFilePaths.includes("-") || inputFilePaths.length !== 1)) { + run(inputFilePaths.map(function (path) { return fs.readFileSync(path, "utf8"); })); } else { var code = ""; process.stdin.resume(); process.stdin.on("data", function (chunk) { return code += chunk; }); - process.stdin.on("end", function () { return run(code); }); + process.stdin.on("end", function () { return run([code]); }); } diff --git a/deps/acorn/acorn/package.json b/deps/acorn/acorn/package.json index c691734ec30e5c..138b7873d373b3 100644 --- a/deps/acorn/acorn/package.json +++ b/deps/acorn/acorn/package.json @@ -16,7 +16,7 @@ ], "./package.json": "./package.json" }, - "version": "8.4.1", + "version": "8.5.0", "engines": {"node": ">=0.4.0"}, "maintainers": [ {