From a121f815109178e5ea49bdb7fc914efa8b741b56 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 13 May 2019 23:47:07 +0200 Subject: tools: update babel-eslint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is just a minor update to use the newest latest version. PR-URL: https://github.com/nodejs/node/pull/27670 Reviewed-By: Michaël Zasso Reviewed-By: Richard Lau Reviewed-By: Refael Ackermann (רפאל פלחי) Reviewed-By: Daijiro Wachi Reviewed-By: Ujjwal Sharma --- .../@babel/generator/lib/generators/base.js | 11 + .../@babel/generator/lib/generators/types.js | 5 + .../node_modules/@babel/generator/lib/printer.js | 2 +- .../node_modules/@babel/generator/package.json | 10 +- .../@babel/helper-split-export-declaration/LICENSE | 2 +- .../helper-split-export-declaration/lib/index.js | 2 +- .../helper-split-export-declaration/package.json | 8 +- .../node_modules/@babel/parser/lib/index.js | 11382 ++++++++++--------- .../node_modules/@babel/parser/package.json | 10 +- .../node_modules/@babel/template/LICENSE | 2 +- .../node_modules/@babel/template/lib/literal.js | 3 +- .../node_modules/@babel/template/lib/options.js | 22 +- .../node_modules/@babel/template/lib/parse.js | 75 +- .../node_modules/@babel/template/package.json | 7 +- .../@babel/traverse/lib/path/context.js | 4 +- .../node_modules/@babel/traverse/lib/path/index.js | 6 +- .../@babel/traverse/lib/path/inference/inferers.js | 5 + .../@babel/traverse/lib/path/lib/hoister.js | 6 +- .../@babel/traverse/lib/path/lib/virtual-types.js | 24 +- .../@babel/traverse/lib/path/replacement.js | 2 +- .../@babel/traverse/lib/scope/index.js | 16 +- .../node_modules/@babel/traverse/lib/visitors.js | 20 +- .../node_modules/@babel/traverse/package.json | 12 +- .../@babel/types/lib/asserts/generated/index.js | 16 +- .../@babel/types/lib/builders/builder.js | 2 +- .../@babel/types/lib/builders/generated/index.js | 16 +- .../@babel/types/lib/clone/cloneNode.js | 2 +- .../lib/converters/gatherSequenceExpressions.js | 2 +- .../@babel/types/lib/converters/valueToNode.js | 2 +- .../@babel/types/lib/definitions/core.js | 11 +- .../@babel/types/lib/definitions/experimental.js | 1 + .../@babel/types/lib/definitions/index.js | 22 + .../@babel/types/lib/definitions/misc.js | 15 +- .../@babel/types/lib/definitions/placeholders.js | 33 + .../@babel/types/lib/definitions/typescript.js | 2 +- .../@babel/types/lib/definitions/utils.js | 2 +- .../node_modules/@babel/types/lib/index.js | 9 + .../node_modules/@babel/types/lib/index.js.flow | 56 +- .../lib/modifications/flow/removeTypeDuplicates.js | 4 +- .../@babel/types/lib/modifications/inherits.js | 2 +- .../types/lib/modifications/removeProperties.js | 2 +- .../@babel/types/lib/validators/generated/index.js | 66 +- .../node_modules/@babel/types/lib/validators/is.js | 13 +- .../@babel/types/lib/validators/isBinding.js | 6 +- .../types/lib/validators/isNodesEquivalent.js | 8 +- .../types/lib/validators/isPlaceholderType.js | 21 + .../@babel/types/lib/validators/isReferenced.js | 21 +- .../node_modules/@babel/types/package.json | 8 +- .../@babel/types/scripts/generateTypeHelpers.js | 30 +- .../types/scripts/generators/generateValidators.js | 33 +- .../@babel/types/scripts/utils/formatCode.js | 11 - .../babel-eslint/node_modules/globals/globals.json | 1 + .../babel-eslint/node_modules/globals/package.json | 2 +- 53 files changed, 6474 insertions(+), 5581 deletions(-) create mode 100644 tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/placeholders.js create mode 100644 tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isPlaceholderType.js delete mode 100644 tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/utils/formatCode.js (limited to 'tools/node_modules') diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/base.js b/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/base.js index 117a61167c..f8e2130bf2 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/base.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/base.js @@ -10,6 +10,7 @@ exports.Noop = Noop; exports.Directive = Directive; exports.DirectiveLiteral = DirectiveLiteral; exports.InterpreterDirective = InterpreterDirective; +exports.Placeholder = Placeholder; function File(node) { if (node.program) { @@ -83,4 +84,14 @@ function DirectiveLiteral(node) { function InterpreterDirective(node) { this.token(`#!${node.value}\n`); +} + +function Placeholder(node) { + this.token("%%"); + this.print(node.name); + this.token("%%"); + + if (node.expectedNode === "Statement") { + this.semicolon(); + } } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/types.js b/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/types.js index 04a8a2fed8..12ae494fb7 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/types.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/generators/types.js @@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.Identifier = Identifier; +exports.ArgumentPlaceholder = ArgumentPlaceholder; exports.SpreadElement = exports.RestElement = RestElement; exports.ObjectPattern = exports.ObjectExpression = ObjectExpression; exports.ObjectMethod = ObjectMethod; @@ -49,6 +50,10 @@ function Identifier(node) { }); } +function ArgumentPlaceholder() { + this.token("?"); +} + function RestElement(node) { this.token("..."); this.print(node.argument, node); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/printer.js b/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/printer.js index 07f6de91e9..9458169f23 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/printer.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/generator/lib/printer.js @@ -296,7 +296,7 @@ class Printer { const loc = t().isProgram(node) || t().isFile(node) ? null : node.loc; this.withSource("start", loc, () => { - this[node.type](node, parent); + printMethod.call(this, node, parent); }); this._printTrailingComments(node); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/generator/package.json b/tools/node_modules/babel-eslint/node_modules/@babel/generator/package.json index 9f41959fc0..c1a8311407 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/generator/package.json +++ b/tools/node_modules/babel-eslint/node_modules/@babel/generator/package.json @@ -5,7 +5,7 @@ }, "bundleDependencies": false, "dependencies": { - "@babel/types": "^7.3.4", + "@babel/types": "^7.4.4", "jsesc": "^2.5.1", "lodash": "^4.17.11", "source-map": "^0.5.0", @@ -14,13 +14,13 @@ "deprecated": false, "description": "Turns an AST into code.", "devDependencies": { - "@babel/helper-fixtures": "^7.2.0", - "@babel/parser": "^7.3.4" + "@babel/helper-fixtures": "^7.4.4", + "@babel/parser": "^7.4.4" }, "files": [ "lib" ], - "gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741", + "gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba", "homepage": "https://babeljs.io/", "license": "MIT", "main": "lib/index.js", @@ -32,5 +32,5 @@ "type": "git", "url": "https://github.com/babel/babel/tree/master/packages/babel-generator" }, - "version": "7.3.4" + "version": "7.4.4" } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/LICENSE b/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/LICENSE index 620366eb90..f31575ec77 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/LICENSE +++ b/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2018 Sebastian McKenzie +Copyright (c) 2014-present Sebastian McKenzie and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/lib/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/lib/index.js index a04a7e4b92..ddb34bc351 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/lib/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/lib/index.js @@ -47,7 +47,7 @@ function splitExportDeclaration(exportDeclaration) { exportDeclaration.replaceWith(updatedDeclaration); if (needBindingRegistration) { - scope.registerBinding(isClassDeclaration ? "let" : "var", exportDeclaration); + scope.registerDeclaration(exportDeclaration); } return exportDeclaration; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/package.json b/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/package.json index a55949061a..8f3e0fdbd7 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/package.json +++ b/tools/node_modules/babel-eslint/node_modules/@babel/helper-split-export-declaration/package.json @@ -1,16 +1,20 @@ { "bundleDependencies": false, "dependencies": { - "@babel/types": "^7.0.0" + "@babel/types": "^7.4.4" }, "deprecated": false, "description": ">", + "gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba", "license": "MIT", "main": "lib/index.js", "name": "@babel/helper-split-export-declaration", + "publishConfig": { + "access": "public" + }, "repository": { "type": "git", "url": "https://github.com/babel/babel/tree/master/packages/babel-helper-split-export-declaration" }, - "version": "7.0.0" + "version": "7.4.4" } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/parser/lib/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/parser/lib/index.js index af6952e5d8..5c5e616572 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/parser/lib/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/parser/lib/index.js @@ -19,19 +19,21 @@ class TokenType { this.isAssign = !!conf.isAssign; this.prefix = !!conf.prefix; this.postfix = !!conf.postfix; - this.binop = conf.binop === 0 ? 0 : conf.binop || null; + this.binop = conf.binop != null ? conf.binop : null; this.updateContext = null; } } +const keywords = new Map(); -function KeywordTokenType(keyword, options = {}) { - return new TokenType(keyword, Object.assign({}, options, { - keyword - })); +function createKeyword(name, options = {}) { + options.keyword = name; + const token = new TokenType(name, options); + keywords.set(name, token); + return token; } -function BinopTokenType(name, binop) { +function createBinop(name, binop) { return new TokenType(name, { beforeExpr, binop @@ -134,137 +136,161 @@ const types = { prefix, startsExpr }), - pipeline: BinopTokenType("|>", 0), - nullishCoalescing: BinopTokenType("??", 1), - logicalOR: BinopTokenType("||", 1), - logicalAND: BinopTokenType("&&", 2), - bitwiseOR: BinopTokenType("|", 3), - bitwiseXOR: BinopTokenType("^", 4), - bitwiseAND: BinopTokenType("&", 5), - equality: BinopTokenType("==/!=", 6), - relational: BinopTokenType("", 7), - bitShift: BinopTokenType("<>", 8), + pipeline: createBinop("|>", 0), + nullishCoalescing: createBinop("??", 1), + logicalOR: createBinop("||", 1), + logicalAND: createBinop("&&", 2), + bitwiseOR: createBinop("|", 3), + bitwiseXOR: createBinop("^", 4), + bitwiseAND: createBinop("&", 5), + equality: createBinop("==/!=/===/!==", 6), + relational: createBinop("/<=/>=", 7), + bitShift: createBinop("<>/>>>", 8), plusMin: new TokenType("+/-", { beforeExpr, binop: 9, prefix, startsExpr }), - modulo: BinopTokenType("%", 10), - star: BinopTokenType("*", 10), - slash: BinopTokenType("/", 10), + modulo: createBinop("%", 10), + star: createBinop("*", 10), + slash: createBinop("/", 10), exponent: new TokenType("**", { beforeExpr, binop: 11, rightAssociative: true - }) -}; - -function makeKeywordProps(name, conf) { - return { - value: KeywordTokenType(name, conf), - enumerable: true - }; -} - -const keywords = Object.create(null, { - break: makeKeywordProps("break"), - case: makeKeywordProps("case", { + }), + _break: createKeyword("break"), + _case: createKeyword("case", { beforeExpr }), - catch: makeKeywordProps("catch"), - continue: makeKeywordProps("continue"), - debugger: makeKeywordProps("debugger"), - default: makeKeywordProps("default", { + _catch: createKeyword("catch"), + _continue: createKeyword("continue"), + _debugger: createKeyword("debugger"), + _default: createKeyword("default", { beforeExpr }), - do: makeKeywordProps("do", { + _do: createKeyword("do", { isLoop, beforeExpr }), - else: makeKeywordProps("else", { + _else: createKeyword("else", { beforeExpr }), - finally: makeKeywordProps("finally"), - for: makeKeywordProps("for", { + _finally: createKeyword("finally"), + _for: createKeyword("for", { isLoop }), - function: makeKeywordProps("function", { + _function: createKeyword("function", { startsExpr }), - if: makeKeywordProps("if"), - return: makeKeywordProps("return", { + _if: createKeyword("if"), + _return: createKeyword("return", { beforeExpr }), - switch: makeKeywordProps("switch"), - throw: makeKeywordProps("throw", { + _switch: createKeyword("switch"), + _throw: createKeyword("throw", { beforeExpr, prefix, startsExpr }), - try: makeKeywordProps("try"), - var: makeKeywordProps("var"), - const: makeKeywordProps("const"), - while: makeKeywordProps("while", { + _try: createKeyword("try"), + _var: createKeyword("var"), + _const: createKeyword("const"), + _while: createKeyword("while", { isLoop }), - with: makeKeywordProps("with"), - new: makeKeywordProps("new", { + _with: createKeyword("with"), + _new: createKeyword("new", { beforeExpr, startsExpr }), - this: makeKeywordProps("this", { + _this: createKeyword("this", { startsExpr }), - super: makeKeywordProps("super", { + _super: createKeyword("super", { startsExpr }), - class: makeKeywordProps("class", { + _class: createKeyword("class", { startsExpr }), - extends: makeKeywordProps("extends", { + _extends: createKeyword("extends", { beforeExpr }), - export: makeKeywordProps("export"), - import: makeKeywordProps("import", { + _export: createKeyword("export"), + _import: createKeyword("import", { startsExpr }), - null: makeKeywordProps("null", { + _null: createKeyword("null", { startsExpr }), - true: makeKeywordProps("true", { + _true: createKeyword("true", { startsExpr }), - false: makeKeywordProps("false", { + _false: createKeyword("false", { startsExpr }), - in: makeKeywordProps("in", { + _in: createKeyword("in", { beforeExpr, binop: 7 }), - instanceof: makeKeywordProps("instanceof", { + _instanceof: createKeyword("instanceof", { beforeExpr, binop: 7 }), - typeof: makeKeywordProps("typeof", { + _typeof: createKeyword("typeof", { beforeExpr, prefix, startsExpr }), - void: makeKeywordProps("void", { + _void: createKeyword("void", { beforeExpr, prefix, startsExpr }), - delete: makeKeywordProps("delete", { + _delete: createKeyword("delete", { beforeExpr, prefix, startsExpr }) -}); -Object.keys(keywords).forEach(name => { - types["_" + name] = keywords[name]; -}); +}; + +const SCOPE_OTHER = 0b000000000, + SCOPE_PROGRAM = 0b000000001, + SCOPE_FUNCTION = 0b000000010, + SCOPE_ASYNC = 0b000000100, + SCOPE_GENERATOR = 0b000001000, + SCOPE_ARROW = 0b000010000, + SCOPE_SIMPLE_CATCH = 0b000100000, + SCOPE_SUPER = 0b001000000, + SCOPE_DIRECT_SUPER = 0b010000000, + SCOPE_CLASS = 0b100000000, + SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION; +function functionFlags(isAsync, isGenerator) { + return SCOPE_FUNCTION | (isAsync ? SCOPE_ASYNC : 0) | (isGenerator ? SCOPE_GENERATOR : 0); +} +const BIND_KIND_VALUE = 0b00000000001, + BIND_KIND_TYPE = 0b00000000010, + BIND_SCOPE_VAR = 0b00000000100, + BIND_SCOPE_LEXICAL = 0b00000001000, + BIND_SCOPE_FUNCTION = 0b00000010000, + BIND_FLAGS_NONE = 0b00001000000, + BIND_FLAGS_CLASS = 0b00010000000, + BIND_FLAGS_TS_ENUM = 0b00100000000, + BIND_FLAGS_TS_CONST_ENUM = 0b01000000000, + BIND_FLAGS_TS_EXPORT_ONLY = 0b10000000000; +const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS, + BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0, + BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0, + BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0, + BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS, + BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0, + BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM, + BIND_TS_FN_TYPE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY, + BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE, + BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE, + BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM, + BIND_TS_NAMESPACE = BIND_TS_FN_TYPE; function isSimpleProperty(node) { return node != null && node.type === "Property" && node.kind === "init" && node.method === false; @@ -335,25 +361,28 @@ var estree = (superClass => class extends superClass { } } - checkLVal(expr, isBinding, checkClashes, contextDescription) { + checkLVal(expr, bindingType = BIND_NONE, checkClashes, contextDescription) { switch (expr.type) { case "ObjectPattern": expr.properties.forEach(prop => { - this.checkLVal(prop.type === "Property" ? prop.value : prop, isBinding, checkClashes, "object destructuring pattern"); + this.checkLVal(prop.type === "Property" ? prop.value : prop, bindingType, checkClashes, "object destructuring pattern"); }); break; default: - super.checkLVal(expr, isBinding, checkClashes, contextDescription); + super.checkLVal(expr, bindingType, checkClashes, contextDescription); } } checkPropClash(prop, propHash) { - if (prop.computed || !isSimpleProperty(prop)) return; + if (prop.type === "SpreadElement" || prop.computed || prop.method || prop.shorthand) { + return; + } + const key = prop.key; const name = key.type === "Identifier" ? key.name : String(key.value); - if (name === "__proto__") { + if (name === "__proto__" && prop.kind === "init") { if (propHash.proto) { this.raise(key.start, "Redefinition of __proto__ property"); } @@ -398,8 +427,8 @@ var estree = (superClass => class extends superClass { delete node.directives; } - pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) { - this.parseMethod(method, isGenerator, isAsync, isConstructor, "MethodDefinition"); + pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { + this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true); if (method.typeParameters) { method.value.typeParameters = method.typeParameters; @@ -439,17 +468,19 @@ var estree = (superClass => class extends superClass { return node; } - parseFunctionBody(node, allowExpression) { - super.parseFunctionBody(node, allowExpression); + parseFunctionBody(node, allowExpression, isMethod = false) { + super.parseFunctionBody(node, allowExpression, isMethod); node.expression = node.body.type !== "BlockStatement"; } - parseMethod(node, isGenerator, isAsync, isConstructor, type) { + parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) { let funcNode = this.startNode(); funcNode.kind = node.kind; - funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, "FunctionExpression"); + funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope); + funcNode.type = "FunctionExpression"; delete funcNode.kind; node.value = funcNode; + type = type === "ClassMethod" ? "MethodDefinition" : type; return this.finishNode(node, type); } @@ -581,7 +612,7 @@ types.name.updateContext = function (prevType) { let allowed = false; if (prevType !== types.dot) { - if (this.state.value === "of" && !this.state.exprAllowed || this.state.value === "yield" && this.state.inGenerator) { + if (this.state.value === "of" && !this.state.exprAllowed || this.state.value === "yield" && this.scope.inGenerator) { allowed = true; } } @@ -612,7 +643,7 @@ types.parenL.updateContext = function (prevType) { types.incDec.updateContext = function () {}; types._function.updateContext = types._class.updateContext = function (prevType) { - if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else && !(prevType === types._return && lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start))) && !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) { + if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else && !(prevType === types._return && lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))) && !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) { this.state.context.push(types$1.functionExpression); } else { this.state.context.push(types$1.functionStatement); @@ -646,18 +677,17 @@ function isStrictReservedWord(word, inModule) { function isStrictBindReservedWord(word, inModule) { return isReservedWord(word, inModule) || reservedWordsStrictBindSet.has(word); } -const keywords$1 = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "while", "with", "null", "true", "false", "instanceof", "typeof", "void", "delete", "new", "in", "this", "const", "class", "extends", "export", "import", "super"]); function isKeyword(word) { - return keywords$1.has(word); + return keywords.has(word); } const keywordRelationalOperator = /^in(stanceof)?$/; -let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7b9\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; -let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; +let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; +let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; -const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 477, 28, 11, 0, 9, 21, 190, 52, 76, 44, 33, 24, 27, 35, 30, 0, 12, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 54, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 86, 26, 230, 43, 117, 63, 32, 0, 257, 0, 11, 39, 8, 0, 22, 0, 12, 39, 3, 3, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 270, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 68, 12, 0, 67, 12, 65, 1, 31, 6129, 15, 754, 9486, 286, 82, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 60, 67, 1213, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541]; -const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 525, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 4, 9, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 280, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 2214, 6, 110, 6, 6, 9, 792487, 239]; +const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 477, 28, 11, 0, 9, 21, 155, 22, 13, 52, 76, 44, 33, 24, 27, 35, 30, 0, 12, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 0, 33, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 230, 43, 117, 63, 32, 0, 161, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 270, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 754, 9486, 286, 50, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 2357, 44, 11, 6, 17, 0, 370, 43, 1301, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541]; +const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 525, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 4, 9, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 232, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 419, 13, 1495, 6, 110, 6, 6, 9, 792487, 239]; function isInAstralSet(code, set) { let pos = 0x10000; @@ -745,13 +775,21 @@ var flow = (superClass => class extends superClass { return this.getPluginOption("flow", "all") || this.flowPragma === "flow"; } + finishToken(type, val) { + if (type !== types.string && type !== types.semi && type !== types.interpreterDirective) { + if (this.flowPragma === undefined) { + this.flowPragma = null; + } + } + + return super.finishToken(type, val); + } + addComment(comment) { if (this.flowPragma === undefined) { const matches = FLOW_PRAGMA_REGEX.exec(comment.value); - if (!matches) { - this.flowPragma = null; - } else if (matches[1] === "flow") { + if (!matches) ; else if (matches[1] === "flow") { this.flowPragma = "flow"; } else if (matches[1] === "noflow") { this.flowPragma = "noflow"; @@ -841,7 +879,7 @@ var flow = (superClass => class extends superClass { [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser(); typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation"); id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation"); - this.finishNode(id, id.type); + this.resetEndLocation(id); this.semicolon(); return this.finishNode(node, "DeclareFunction"); } @@ -853,12 +891,12 @@ var flow = (superClass => class extends superClass { return this.flowParseDeclareFunction(node); } else if (this.match(types._var)) { return this.flowParseDeclareVariable(node); - } else if (this.isContextual("module")) { - if (this.lookahead().type === types.dot) { + } else if (this.eatContextual("module")) { + if (this.match(types.dot)) { return this.flowParseDeclareModuleExports(node); } else { if (insideModule) { - this.unexpected(null, "`declare module` cannot be used inside another `declare module`"); + this.unexpected(this.state.lastTokStart, "`declare module` cannot be used inside another `declare module`"); } return this.flowParseDeclareModule(node); @@ -884,7 +922,7 @@ var flow = (superClass => class extends superClass { } flowParseDeclareModule(node) { - this.next(); + this.scope.enter(SCOPE_OTHER); if (this.match(types.string)) { node.id = this.parseExprAtom(); @@ -900,13 +938,12 @@ var flow = (superClass => class extends superClass { let bodyNode = this.startNode(); if (this.match(types._import)) { - const lookahead = this.lookahead(); + this.next(); - if (lookahead.value !== "type" && lookahead.value !== "typeof") { - this.unexpected(null, "Imports within a `declare module` body must always be `import type` or `import typeof`"); + if (!this.isContextual("type") && !this.isContextual("typeof")) { + this.unexpected(this.state.lastTokStart, "Imports within a `declare module` body must always be `import type` or `import typeof`"); } - this.next(); this.parseImport(bodyNode); } else { this.expectContextual("declare", "Only declares and type imports are allowed inside declare module"); @@ -916,6 +953,7 @@ var flow = (superClass => class extends superClass { body.push(bodyNode); } + this.scope.exit(); this.expect(types.braceR); this.finishNode(bodyNode, "BlockStatement"); let kind = null; @@ -984,8 +1022,7 @@ var flow = (superClass => class extends superClass { } flowParseDeclareModuleExports(node) { - this.expectContextual("module"); - this.expect(types.dot); + this.next(); this.expectContextual("exports"); node.typeAnnotation = this.flowParseTypeAnnotation(); this.semicolon(); @@ -995,13 +1032,15 @@ var flow = (superClass => class extends superClass { flowParseDeclareTypeAlias(node) { this.next(); this.flowParseTypeAlias(node); - return this.finishNode(node, "DeclareTypeAlias"); + node.type = "DeclareTypeAlias"; + return node; } flowParseDeclareOpaqueType(node) { this.next(); this.flowParseOpaqueType(node, true); - return this.finishNode(node, "DeclareOpaqueType"); + node.type = "DeclareOpaqueType"; + return node; } flowParseDeclareInterface(node) { @@ -1091,6 +1130,7 @@ var flow = (superClass => class extends superClass { flowParseTypeAlias(node) { node.id = this.flowParseRestrictedIdentifier(); + this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start); if (this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(); @@ -1106,6 +1146,7 @@ var flow = (superClass => class extends superClass { flowParseOpaqueType(node, declare) { this.expectContextual("type"); node.id = this.flowParseRestrictedIdentifier(true); + this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start); if (this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(); @@ -1583,7 +1624,7 @@ var flow = (superClass => class extends superClass { node.types = []; this.expect(types.bracketL); - while (this.state.pos < this.state.length && !this.match(types.bracketR)) { + while (this.state.pos < this.length && !this.match(types.bracketR)) { node.types.push(this.flowParseType()); if (this.match(types.bracketR)) break; this.expect(types.comma); @@ -1920,7 +1961,7 @@ var flow = (superClass => class extends superClass { if (this.match(types.colon)) { ident.typeAnnotation = this.flowParseTypeAnnotation(); - this.finishNode(ident, ident.type); + this.resetEndLocation(ident); } return ident; @@ -1928,7 +1969,8 @@ var flow = (superClass => class extends superClass { typeCastToParameter(node) { node.expression.typeAnnotation = node.typeAnnotation; - return this.finishNodeAt(node.expression, node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end); + this.resetEndLocation(node.expression, node.typeAnnotation.end, node.typeAnnotation.loc.end); + return node.expression; } flowParseVariance() { @@ -1950,22 +1992,22 @@ var flow = (superClass => class extends superClass { return variance; } - parseFunctionBody(node, allowExpressionBody) { + parseFunctionBody(node, allowExpressionBody, isMethod = false) { if (allowExpressionBody) { - return this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true)); + return this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod)); } - return super.parseFunctionBody(node, false); + return super.parseFunctionBody(node, false, isMethod); } - parseFunctionBodyAndFinish(node, type, allowExpressionBody) { - if (!allowExpressionBody && this.match(types.colon)) { + parseFunctionBodyAndFinish(node, type, isMethod = false) { + if (this.match(types.colon)) { const typeNode = this.startNode(); [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser(); node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null; } - super.parseFunctionBodyAndFinish(node, type, allowExpressionBody); + super.parseFunctionBodyAndFinish(node, type, isMethod); } parseStatement(context, topLevel) { @@ -2108,7 +2150,9 @@ var flow = (superClass => class extends superClass { if (node.type === "ArrowFunctionExpression") { if (node.typeParameters || !node.returnType) { this.toAssignableList(node.params, true, "arrow function parameters"); - super.checkFunctionNameAndParams(node, true); + this.scope.enter(functionFlags(false, false) | SCOPE_ARROW); + super.checkParams(node, false, true); + this.scope.exit(); } else { arrows.push(node); } @@ -2157,6 +2201,7 @@ var flow = (superClass => class extends superClass { if (this.eat(types.question)) { node.optional = true; + this.resetEndLocation(node); } if (this.match(types.colon)) { @@ -2248,7 +2293,7 @@ var flow = (superClass => class extends superClass { } getTokenFromCode(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (code === 123 && next === 124) { return this.finishOp(types.braceBarL, 2); @@ -2294,9 +2339,9 @@ var flow = (superClass => class extends superClass { return exprList; } - checkLVal(expr, isBinding, checkClashes, contextDescription) { + checkLVal(expr, bindingType = BIND_NONE, checkClashes, contextDescription) { if (expr.type !== "TypeCastExpression") { - return super.checkLVal(expr, isBinding, checkClashes, contextDescription); + return super.checkLVal(expr, bindingType, checkClashes, contextDescription); } } @@ -2328,7 +2373,7 @@ var flow = (superClass => class extends superClass { return !this.match(types.colon) && super.isNonstaticConstructor(method); } - pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) { + pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { if (method.variance) { this.unexpected(method.variance.start); } @@ -2339,7 +2384,7 @@ var flow = (superClass => class extends superClass { method.typeParameters = this.flowParseTypeParameterDeclaration(false); } - super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor); + super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper); } pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { @@ -2422,7 +2467,7 @@ var flow = (superClass => class extends superClass { param.typeAnnotation = this.flowParseTypeAnnotation(); } - this.finishNode(param, param.type); + this.resetEndLocation(param); return param; } @@ -2446,7 +2491,7 @@ var flow = (superClass => class extends superClass { parseImportSpecifierLocal(node, specifier, type, contextDescription) { specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true) : this.parseIdentifier(); - this.checkLVal(specifier.local, true, undefined, contextDescription); + this.checkLVal(specifier.local, BIND_LEXICAL, undefined, contextDescription); node.specifiers.push(this.finishNode(specifier, type)); } @@ -2534,18 +2579,18 @@ var flow = (superClass => class extends superClass { this.checkReservedWord(specifier.local.name, specifier.start, true, true); } - this.checkLVal(specifier.local, true, undefined, "import specifier"); + this.checkLVal(specifier.local, BIND_LEXICAL, undefined, "import specifier"); node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); } - parseFunctionParams(node) { + parseFunctionParams(node, allowModifiers) { const kind = node.kind; if (kind !== "get" && kind !== "set" && this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(false); } - super.parseFunctionParams(node); + super.parseFunctionParams(node, allowModifiers); } parseVarId(decl, kind) { @@ -2553,7 +2598,7 @@ var flow = (superClass => class extends superClass { if (this.match(types.colon)) { decl.id.typeAnnotation = this.flowParseTypeAnnotation(); - this.finishNode(decl.id, decl.id.type); + this.resetEndLocation(decl.id); } } @@ -2658,12 +2703,12 @@ var flow = (superClass => class extends superClass { } } - checkFunctionNameAndParams(node, isArrowFunction) { + checkParams(node, allowDuplicates, isArrowFunction) { if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) { return; } - return super.checkFunctionNameAndParams(node, isArrowFunction); + return super.checkParams(node, allowDuplicates, isArrowFunction); } parseParenAndDistinguishExpression(canBeArrow) { @@ -2700,7 +2745,7 @@ var flow = (superClass => class extends superClass { return super.parseSubscripts(base, startPos, startLoc, noCalls); } - parseSubscript(base, startPos, startLoc, noCalls, subscriptState) { + parseSubscript(base, startPos, startLoc, noCalls, subscriptState, maybeAsyncArrow) { if (this.match(types.questionDot) && this.isLookaheadRelational("<")) { this.expectPlugin("optionalChaining"); subscriptState.optionalChainMember = true; @@ -2743,7 +2788,7 @@ var flow = (superClass => class extends superClass { } } - return super.parseSubscript(base, startPos, startLoc, noCalls, subscriptState); + return super.parseSubscript(base, startPos, startLoc, noCalls, subscriptState, maybeAsyncArrow); } parseNewArguments(node) { @@ -2775,7 +2820,7 @@ var flow = (superClass => class extends superClass { } readToken_mult_modulo(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (code === 42 && next === 47 && this.state.hasFlowComment) { this.state.hasFlowComment = false; @@ -2788,7 +2833,7 @@ var flow = (superClass => class extends superClass { } readToken_pipe_amp(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (code === 124 && next === 125) { this.finishOp(types.braceBarR, 2); @@ -2821,7 +2866,7 @@ var flow = (superClass => class extends superClass { } if (this.state.hasFlowComment) { - const end = this.state.input.indexOf("*-/", this.state.pos += 2); + const end = this.input.indexOf("*-/", this.state.pos += 2); if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); this.state.pos = end + 3; return; @@ -2836,18 +2881,18 @@ var flow = (superClass => class extends superClass { } = this.state; let shiftToFirstNonWhiteSpace = 2; - while ([32, 9].includes(this.state.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) { + while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) { shiftToFirstNonWhiteSpace++; } - const ch2 = this.state.input.charCodeAt(shiftToFirstNonWhiteSpace + pos); - const ch3 = this.state.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1); + const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos); + const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1); if (ch2 === 58 && ch3 === 58) { return shiftToFirstNonWhiteSpace + 2; } - if (this.state.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") { + if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") { return shiftToFirstNonWhiteSpace + 12; } @@ -2859,7 +2904,7 @@ var flow = (superClass => class extends superClass { } hasFlowCommentCompletion() { - const end = this.state.input.indexOf("*/", this.state.pos); + const end = this.input.indexOf("*/", this.state.pos); if (end === -1) { this.raise(this.state.pos, "Unterminated comment"); @@ -3181,11 +3226,11 @@ var jsx = (superClass => class extends superClass { let chunkStart = this.state.pos; for (;;) { - if (this.state.pos >= this.state.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated JSX contents"); } - const ch = this.state.input.charCodeAt(this.state.pos); + const ch = this.input.charCodeAt(this.state.pos); switch (ch) { case 60: @@ -3199,18 +3244,18 @@ var jsx = (superClass => class extends superClass { return super.getTokenFromCode(ch); } - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); return this.finishToken(types.jsxText, out); case 38: - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); out += this.jsxReadEntity(); chunkStart = this.state.pos; break; default: if (isNewLine(ch)) { - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); out += this.jsxReadNewLine(true); chunkStart = this.state.pos; } else { @@ -3222,11 +3267,11 @@ var jsx = (superClass => class extends superClass { } jsxReadNewLine(normalizeCRLF) { - const ch = this.state.input.charCodeAt(this.state.pos); + const ch = this.input.charCodeAt(this.state.pos); let out; ++this.state.pos; - if (ch === 13 && this.state.input.charCodeAt(this.state.pos) === 10) { + if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) { ++this.state.pos; out = normalizeCRLF ? "\n" : "\r\n"; } else { @@ -3243,19 +3288,19 @@ var jsx = (superClass => class extends superClass { let chunkStart = ++this.state.pos; for (;;) { - if (this.state.pos >= this.state.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated string constant"); } - const ch = this.state.input.charCodeAt(this.state.pos); + const ch = this.input.charCodeAt(this.state.pos); if (ch === quote) break; if (ch === 38) { - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); out += this.jsxReadEntity(); chunkStart = this.state.pos; } else if (isNewLine(ch)) { - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); out += this.jsxReadNewLine(false); chunkStart = this.state.pos; } else { @@ -3263,7 +3308,7 @@ var jsx = (superClass => class extends superClass { } } - out += this.state.input.slice(chunkStart, this.state.pos++); + out += this.input.slice(chunkStart, this.state.pos++); return this.finishToken(types.string, out); } @@ -3271,11 +3316,11 @@ var jsx = (superClass => class extends superClass { let str = ""; let count = 0; let entity; - let ch = this.state.input[this.state.pos]; + let ch = this.input[this.state.pos]; const startPos = ++this.state.pos; - while (this.state.pos < this.state.length && count++ < 10) { - ch = this.state.input[this.state.pos++]; + while (this.state.pos < this.length && count++ < 10) { + ch = this.input[this.state.pos++]; if (ch === ";") { if (str[0] === "#") { @@ -3315,10 +3360,10 @@ var jsx = (superClass => class extends superClass { const start = this.state.pos; do { - ch = this.state.input.charCodeAt(++this.state.pos); + ch = this.input.charCodeAt(++this.state.pos); } while (isIdentifierChar(ch) || ch === 45); - return this.finishToken(types.jsxName, this.state.input.slice(start, this.state.pos)); + return this.finishToken(types.jsxName, this.input.slice(start, this.state.pos)); } jsxParseIdentifier() { @@ -3367,7 +3412,9 @@ var jsx = (superClass => class extends superClass { switch (this.state.type) { case types.braceL: - node = this.jsxParseExpressionContainer(); + node = this.startNode(); + this.next(); + node = this.jsxParseExpressionContainer(node); if (node.expression.type === "JSXEmptyExpression") { throw this.raise(node.start, "JSX attributes must only be assigned a non-empty expression"); @@ -3389,19 +3436,14 @@ var jsx = (superClass => class extends superClass { return this.finishNodeAt(node, "JSXEmptyExpression", this.state.start, this.state.startLoc); } - jsxParseSpreadChild() { - const node = this.startNode(); - this.expect(types.braceL); - this.expect(types.ellipsis); + jsxParseSpreadChild(node) { + this.next(); node.expression = this.parseExpression(); this.expect(types.braceR); return this.finishNode(node, "JSXSpreadChild"); } - jsxParseExpressionContainer() { - const node = this.startNode(); - this.next(); - + jsxParseExpressionContainer(node) { if (this.match(types.braceR)) { node.expression = this.jsxParseEmptyExpression(); } else { @@ -3492,13 +3534,18 @@ var jsx = (superClass => class extends superClass { break; case types.braceL: - if (this.lookahead().type === types.ellipsis) { - children.push(this.jsxParseSpreadChild()); - } else { - children.push(this.jsxParseExpressionContainer()); - } + { + const node = this.startNode(); + this.next(); + + if (this.match(types.ellipsis)) { + children.push(this.jsxParseSpreadChild(node)); + } else { + children.push(this.jsxParseExpressionContainer(node)); + } - break; + break; + } default: throw this.unexpected(); @@ -3545,7 +3592,7 @@ var jsx = (superClass => class extends superClass { return this.parseLiteral(this.state.value, "JSXText"); } else if (this.match(types.jsxTagStart)) { return this.jsxParseElement(); - } else if (this.isRelational("<") && this.state.input.charCodeAt(this.state.pos) !== 33) { + } else if (this.isRelational("<") && this.input.charCodeAt(this.state.pos) !== 33) { this.finishToken(types.jsxTagStart); return this.jsxParseElement(); } else { @@ -3576,7 +3623,7 @@ var jsx = (superClass => class extends superClass { } } - if (code === 60 && this.state.exprAllowed && this.state.input.charCodeAt(this.state.pos + 1) !== 33) { + if (code === 60 && this.state.exprAllowed && this.input.charCodeAt(this.state.pos + 1) !== 33) { ++this.state.pos; return this.finishToken(types.jsxTagStart); } @@ -3608,1846 +3655,1567 @@ var jsx = (superClass => class extends superClass { }); -const defaultOptions = { - sourceType: "script", - sourceFilename: undefined, - startLine: 1, - allowAwaitOutsideFunction: false, - allowReturnOutsideFunction: false, - allowImportExportEverywhere: false, - allowSuperOutsideMethod: false, - plugins: [], - strictMode: null, - ranges: false, - tokens: false -}; -function getOptions(opts) { - const options = {}; - - for (const key in defaultOptions) { - options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key]; +class Scope { + constructor(flags) { + this.var = []; + this.lexical = []; + this.functions = []; + this.flags = flags; } - return options; } +class ScopeHandler { + constructor(raise, inModule) { + this.scopeStack = []; + this.undefinedExports = new Map(); + this.raise = raise; + this.inModule = inModule; + } -class Position { - constructor(line, col) { - this.line = line; - this.column = col; + get inFunction() { + return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0; } -} -class SourceLocation { - constructor(start, end) { - this.start = start; - this.end = end; + get inGenerator() { + return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0; } -} -function getLineInfo(input, offset) { - let line = 1; - let lineStart = 0; - let match; - lineBreakG.lastIndex = 0; + get inAsync() { + return (this.currentVarScope().flags & SCOPE_ASYNC) > 0; + } - while ((match = lineBreakG.exec(input)) && match.index < offset) { - line++; - lineStart = lineBreakG.lastIndex; + get allowSuper() { + return (this.currentThisScope().flags & SCOPE_SUPER) > 0; } - return new Position(line, offset - lineStart); -} + get allowDirectSuper() { + return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0; + } -class BaseParser { - constructor() { - this.sawUnambiguousESM = false; + get inNonArrowFunction() { + return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0; } - hasPlugin(name) { - return this.plugins.has(name); + get treatFunctionsAsVar() { + return this.treatFunctionsAsVarInScope(this.currentScope()); } - getPluginOption(plugin, name) { - if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name]; + createScope(flags) { + return new Scope(flags); } -} + enter(flags) { + this.scopeStack.push(this.createScope(flags)); + } -function last(stack) { - return stack[stack.length - 1]; -} + exit() { + this.scopeStack.pop(); + } -class CommentsParser extends BaseParser { - addComment(comment) { - if (this.filename) comment.loc.filename = this.filename; - this.state.trailingComments.push(comment); - this.state.leadingComments.push(comment); + treatFunctionsAsVarInScope(scope) { + return !!(scope.flags & SCOPE_FUNCTION || !this.inModule && scope.flags & SCOPE_PROGRAM); } - processComment(node) { - if (node.type === "Program" && node.body.length > 0) return; - const stack = this.state.commentStack; - let firstChild, lastChild, trailingComments, i, j; + declareName(name, bindingType, pos) { + let scope = this.currentScope(); - if (this.state.trailingComments.length > 0) { - if (this.state.trailingComments[0].start >= node.end) { - trailingComments = this.state.trailingComments; - this.state.trailingComments = []; + if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) { + this.checkRedeclarationInScope(scope, name, bindingType, pos); + + if (bindingType & BIND_SCOPE_FUNCTION) { + scope.functions.push(name); } else { - this.state.trailingComments.length = 0; + scope.lexical.push(name); } - } else if (stack.length > 0) { - const lastInStack = last(stack); - if (lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) { - trailingComments = lastInStack.trailingComments; - delete lastInStack.trailingComments; + if (bindingType & BIND_SCOPE_LEXICAL) { + this.maybeExportDefined(scope, name); + } + } else if (bindingType & BIND_SCOPE_VAR) { + for (let i = this.scopeStack.length - 1; i >= 0; --i) { + scope = this.scopeStack[i]; + this.checkRedeclarationInScope(scope, name, bindingType, pos); + scope.var.push(name); + this.maybeExportDefined(scope, name); + if (scope.flags & SCOPE_VAR) break; } } - if (stack.length > 0 && last(stack).start >= node.start) { - firstChild = stack.pop(); + if (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); } + } - while (stack.length > 0 && last(stack).start >= node.start) { - lastChild = stack.pop(); + maybeExportDefined(scope, name) { + if (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); + } + } + + checkRedeclarationInScope(scope, name, bindingType, pos) { + if (this.isRedeclaredInScope(scope, name, bindingType)) { + this.raise(pos, `Identifier '${name}' has already been declared`); } + } - if (!lastChild && firstChild) lastChild = firstChild; + isRedeclaredInScope(scope, name, bindingType) { + if (!(bindingType & BIND_KIND_VALUE)) return false; - if (firstChild && this.state.leadingComments.length > 0) { - const lastComment = last(this.state.leadingComments); + if (bindingType & BIND_SCOPE_LEXICAL) { + return scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1; + } - if (firstChild.type === "ObjectProperty") { - if (lastComment.start >= node.start) { - if (this.state.commentPreviousNode) { - for (j = 0; j < this.state.leadingComments.length; j++) { - if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) { - this.state.leadingComments.splice(j, 1); - j--; - } - } + if (bindingType & BIND_SCOPE_FUNCTION) { + return scope.lexical.indexOf(name) > -1 || !this.treatFunctionsAsVarInScope(scope) && scope.var.indexOf(name) > -1; + } - if (this.state.leadingComments.length > 0) { - firstChild.trailingComments = this.state.leadingComments; - this.state.leadingComments = []; - } - } - } - } else if (node.type === "CallExpression" && node.arguments && node.arguments.length) { - const lastArg = last(node.arguments); + return scope.lexical.indexOf(name) > -1 && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical[0] === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.indexOf(name) > -1; + } - if (lastArg && lastComment.start >= lastArg.start && lastComment.end <= node.end) { - if (this.state.commentPreviousNode) { - for (j = 0; j < this.state.leadingComments.length; j++) { - if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) { - this.state.leadingComments.splice(j, 1); - j--; - } - } + checkLocalExport(id) { + if (this.scopeStack[0].lexical.indexOf(id.name) === -1 && this.scopeStack[0].var.indexOf(id.name) === -1 && this.scopeStack[0].functions.indexOf(id.name) === -1) { + this.undefinedExports.set(id.name, id.start); + } + } - if (this.state.leadingComments.length > 0) { - lastArg.trailingComments = this.state.leadingComments; - this.state.leadingComments = []; - } - } - } + currentScope() { + return this.scopeStack[this.scopeStack.length - 1]; + } + + currentVarScope() { + for (let i = this.scopeStack.length - 1;; i--) { + const scope = this.scopeStack[i]; + + if (scope.flags & SCOPE_VAR) { + return scope; } } + } - if (lastChild) { - if (lastChild.leadingComments) { - if (lastChild !== node && lastChild.leadingComments.length > 0 && last(lastChild.leadingComments).end <= node.start) { - node.leadingComments = lastChild.leadingComments; - delete lastChild.leadingComments; - } else { - for (i = lastChild.leadingComments.length - 2; i >= 0; --i) { - if (lastChild.leadingComments[i].end <= node.start) { - node.leadingComments = lastChild.leadingComments.splice(0, i + 1); - break; - } - } - } + currentThisScope() { + for (let i = this.scopeStack.length - 1;; i--) { + const scope = this.scopeStack[i]; + + if ((scope.flags & SCOPE_VAR || scope.flags & SCOPE_CLASS) && !(scope.flags & SCOPE_ARROW)) { + return scope; } - } else if (this.state.leadingComments.length > 0) { - if (last(this.state.leadingComments).end <= node.start) { - if (this.state.commentPreviousNode) { - for (j = 0; j < this.state.leadingComments.length; j++) { - if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) { - this.state.leadingComments.splice(j, 1); - j--; - } - } - } + } + } - if (this.state.leadingComments.length > 0) { - node.leadingComments = this.state.leadingComments; - this.state.leadingComments = []; - } - } else { - for (i = 0; i < this.state.leadingComments.length; i++) { - if (this.state.leadingComments[i].end > node.start) { - break; - } - } +} - const leadingComments = this.state.leadingComments.slice(0, i); +class TypeScriptScope extends Scope { + constructor(...args) { + super(...args); + this.types = []; + this.enums = []; + this.constEnums = []; + this.classes = []; + this.exportOnlyBindings = []; + } - if (leadingComments.length) { - node.leadingComments = leadingComments; - } +} - trailingComments = this.state.leadingComments.slice(i); +class TypeScriptScopeHandler extends ScopeHandler { + createScope(flags) { + return new TypeScriptScope(flags); + } - if (trailingComments.length === 0) { - trailingComments = null; - } - } + declareName(name, bindingType, pos) { + const scope = this.currentScope(); + + if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) { + this.maybeExportDefined(scope, name); + scope.exportOnlyBindings.push(name); + return; } - this.state.commentPreviousNode = node; + super.declareName(...arguments); - if (trailingComments) { - if (trailingComments.length && trailingComments[0].start >= node.start && last(trailingComments).end <= node.end) { - node.innerComments = trailingComments; - } else { - node.trailingComments = trailingComments; + if (bindingType & BIND_KIND_TYPE) { + if (!(bindingType & BIND_KIND_VALUE)) { + this.checkRedeclarationInScope(scope, name, bindingType, pos); + this.maybeExportDefined(scope, name); } + + scope.types.push(name); } - stack.push(node); + if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.push(name); + if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.push(name); + if (bindingType & BIND_FLAGS_CLASS) scope.classes.push(name); } -} + isRedeclaredInScope(scope, name, bindingType) { + if (scope.enums.indexOf(name) > -1) { + if (bindingType & BIND_FLAGS_TS_ENUM) { + const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM); + const wasConst = scope.constEnums.indexOf(name) > -1; + return isConst !== wasConst; + } -class LocationParser extends CommentsParser { - raise(pos, message, { - missingPluginNames, - code - } = {}) { - const loc = getLineInfo(this.state.input, pos); - message += ` (${loc.line}:${loc.column})`; - const err = new SyntaxError(message); - err.pos = pos; - err.loc = loc; + return true; + } - if (missingPluginNames) { - err.missingPlugin = missingPluginNames; + if (bindingType & BIND_FLAGS_CLASS && scope.classes.indexOf(name) > -1) { + if (scope.lexical.indexOf(name) > -1) { + return !!(bindingType & BIND_KIND_VALUE); + } else { + return false; + } } - if (code !== undefined) { - err.code = code; + if (bindingType & BIND_KIND_TYPE && scope.types.indexOf(name) > -1) { + return true; } - throw err; + return super.isRedeclaredInScope(...arguments); } -} - -class State { - constructor() { - this.potentialArrowAt = -1; - this.noArrowAt = []; - this.noArrowParamsConversionAt = []; - this.commaAfterSpreadAt = -1; - this.inFunction = false; - this.inParameters = false; - this.maybeInArrowParameters = false; - this.inGenerator = false; - this.inMethod = false; - this.inAsync = false; - this.inPipeline = false; - this.inType = false; - this.noAnonFunctionType = false; - this.inPropertyName = false; - this.inClassProperty = false; - this.hasFlowComment = false; - this.isIterator = false; - this.topicContext = { - maxNumOfResolvableTopics: 0, - maxTopicIndex: null - }; - this.classLevel = 0; - this.labels = []; - this.decoratorStack = [[]]; - this.yieldPos = 0; - this.awaitPos = 0; - this.tokens = []; - this.comments = []; - this.trailingComments = []; - this.leadingComments = []; - this.commentStack = []; - this.commentPreviousNode = null; - this.pos = 0; - this.lineStart = 0; - this.type = types.eof; - this.value = null; - this.start = 0; - this.end = 0; - this.lastTokEndLoc = null; - this.lastTokStartLoc = null; - this.lastTokStart = 0; - this.lastTokEnd = 0; - this.context = [types$1.braceStatement]; - this.exprAllowed = true; - this.containsEsc = false; - this.containsOctal = false; - this.octalPosition = null; - this.exportedIdentifiers = []; - this.invalidTemplateEscapePosition = null; + checkLocalExport(id) { + if (this.scopeStack[0].types.indexOf(id.name) === -1 && this.scopeStack[0].exportOnlyBindings.indexOf(id.name) === -1) { + super.checkLocalExport(id); + } } - init(options, input) { - this.strict = options.strictMode === false ? false : options.sourceType === "module"; - this.input = input; - this.length = input.length; - this.curLine = options.startLine; - this.startLoc = this.endLoc = this.curPosition(); +} + +function nonNull(x) { + if (x == null) { + throw new Error(`Unexpected ${x} value.`); } - curPosition() { - return new Position(this.curLine, this.pos - this.lineStart); + return x; +} + +function assert(x) { + if (!x) { + throw new Error("Assert fail"); } +} - clone(skipArrays) { - const state = new State(); - const keys = Object.keys(this); +function keywordTypeFromName(value) { + switch (value) { + case "any": + return "TSAnyKeyword"; - for (let i = 0, length = keys.length; i < length; i++) { - const key = keys[i]; - let val = this[key]; + case "boolean": + return "TSBooleanKeyword"; - if ((!skipArrays || key === "context") && Array.isArray(val)) { - val = val.slice(); - } + case "bigint": + return "TSBigIntKeyword"; - state[key] = val; - } + case "never": + return "TSNeverKeyword"; - return state; - } + case "number": + return "TSNumberKeyword"; -} + case "object": + return "TSObjectKeyword"; -var _isDigit = function isDigit(code) { - return code >= 48 && code <= 57; -}; + case "string": + return "TSStringKeyword"; -const VALID_REGEX_FLAGS = new Set(["g", "m", "s", "i", "y", "u"]); -const forbiddenNumericSeparatorSiblings = { - decBinOct: [46, 66, 69, 79, 95, 98, 101, 111], - hex: [46, 88, 95, 120] -}; -const allowedNumericSeparatorSiblings = {}; -allowedNumericSeparatorSiblings.bin = [48, 49]; -allowedNumericSeparatorSiblings.oct = [...allowedNumericSeparatorSiblings.bin, 50, 51, 52, 53, 54, 55]; -allowedNumericSeparatorSiblings.dec = [...allowedNumericSeparatorSiblings.oct, 56, 57]; -allowedNumericSeparatorSiblings.hex = [...allowedNumericSeparatorSiblings.dec, 65, 66, 67, 68, 69, 70, 97, 98, 99, 100, 101, 102]; -class Token { - constructor(state) { - this.type = state.type; - this.value = state.value; - this.start = state.start; - this.end = state.end; - this.loc = new SourceLocation(state.startLoc, state.endLoc); - } + case "symbol": + return "TSSymbolKeyword"; -} -class Tokenizer extends LocationParser { - constructor(options, input) { - super(); - this.state = new State(); - this.state.init(options, input); - this.isLookahead = false; - } + case "undefined": + return "TSUndefinedKeyword"; - next() { - if (this.options.tokens && !this.isLookahead) { - this.state.tokens.push(new Token(this.state)); - } + case "unknown": + return "TSUnknownKeyword"; - this.state.lastTokEnd = this.state.end; - this.state.lastTokStart = this.state.start; - this.state.lastTokEndLoc = this.state.endLoc; - this.state.lastTokStartLoc = this.state.startLoc; - this.nextToken(); + default: + return undefined; } +} - eat(type) { - if (this.match(type)) { - this.next(); - return true; - } else { - return false; - } +var typescript = (superClass => class extends superClass { + getScopeHandler() { + return TypeScriptScopeHandler; } - match(type) { - return this.state.type === type; + tsIsIdentifier() { + return this.match(types.name); } - lookahead() { - const old = this.state; - this.state = old.clone(true); - this.isLookahead = true; + tsNextTokenCanFollowModifier() { this.next(); - this.isLookahead = false; - const curr = this.state; - this.state = old; - return curr; + return !this.hasPrecedingLineBreak() && !this.match(types.parenL) && !this.match(types.parenR) && !this.match(types.colon) && !this.match(types.eq) && !this.match(types.question) && !this.match(types.bang); } - setStrict(strict) { - this.state.strict = strict; - if (!this.match(types.num) && !this.match(types.string)) return; - this.state.pos = this.state.start; + tsParseModifier(allowedModifiers) { + if (!this.match(types.name)) { + return undefined; + } - while (this.state.pos < this.state.lineStart) { - this.state.lineStart = this.state.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; - --this.state.curLine; + const modifier = this.state.value; + + if (allowedModifiers.indexOf(modifier) !== -1 && this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) { + return modifier; } - this.nextToken(); + return undefined; } - curContext() { - return this.state.context[this.state.context.length - 1]; - } + tsIsListTerminator(kind) { + switch (kind) { + case "EnumMembers": + case "TypeMembers": + return this.match(types.braceR); - nextToken() { - const curContext = this.curContext(); - if (!curContext || !curContext.preserveSpace) this.skipSpace(); - this.state.containsOctal = false; - this.state.octalPosition = null; - this.state.start = this.state.pos; - this.state.startLoc = this.state.curPosition(); + case "HeritageClauseElement": + return this.match(types.braceL); - if (this.state.pos >= this.state.length) { - this.finishToken(types.eof); - return; - } + case "TupleElementTypes": + return this.match(types.bracketR); - if (curContext.override) { - curContext.override(this); - } else { - this.getTokenFromCode(this.state.input.codePointAt(this.state.pos)); + case "TypeParametersOrArguments": + return this.isRelational(">"); } + + throw new Error("Unreachable"); } - pushComment(block, text, start, end, startLoc, endLoc) { - const comment = { - type: block ? "CommentBlock" : "CommentLine", - value: text, - start: start, - end: end, - loc: new SourceLocation(startLoc, endLoc) - }; + tsParseList(kind, parseElement) { + const result = []; - if (!this.isLookahead) { - if (this.options.tokens) this.state.tokens.push(comment); - this.state.comments.push(comment); - this.addComment(comment); + while (!this.tsIsListTerminator(kind)) { + result.push(parseElement()); } - } - skipBlockComment() { - const startLoc = this.state.curPosition(); - const start = this.state.pos; - const end = this.state.input.indexOf("*/", this.state.pos += 2); - if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); - this.state.pos = end + 2; - lineBreakG.lastIndex = start; - let match; + return result; + } - while ((match = lineBreakG.exec(this.state.input)) && match.index < this.state.pos) { - ++this.state.curLine; - this.state.lineStart = match.index + match[0].length; - } + tsParseDelimitedList(kind, parseElement) { + return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true)); + } - this.pushComment(true, this.state.input.slice(start + 2, end), start, this.state.pos, startLoc, this.state.curPosition()); + tsTryParseDelimitedList(kind, parseElement) { + return this.tsParseDelimitedListWorker(kind, parseElement, false); } - skipLineComment(startSkip) { - const start = this.state.pos; - const startLoc = this.state.curPosition(); - let ch = this.state.input.charCodeAt(this.state.pos += startSkip); + tsParseDelimitedListWorker(kind, parseElement, expectSuccess) { + const result = []; - if (this.state.pos < this.state.length) { - while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.state.length) { - ch = this.state.input.charCodeAt(this.state.pos); + while (true) { + if (this.tsIsListTerminator(kind)) { + break; } - } - this.pushComment(false, this.state.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition()); - } + const element = parseElement(); - skipSpace() { - loop: while (this.state.pos < this.state.length) { - const ch = this.state.input.charCodeAt(this.state.pos); + if (element == null) { + return undefined; + } - switch (ch) { - case 32: - case 160: - case 9: - ++this.state.pos; - break; - - case 13: - if (this.state.input.charCodeAt(this.state.pos + 1) === 10) { - ++this.state.pos; - } - - case 10: - case 8232: - case 8233: - ++this.state.pos; - ++this.state.curLine; - this.state.lineStart = this.state.pos; - break; - - case 47: - switch (this.state.input.charCodeAt(this.state.pos + 1)) { - case 42: - this.skipBlockComment(); - break; - - case 47: - this.skipLineComment(2); - break; - - default: - break loop; - } + result.push(element); - break; + if (this.eat(types.comma)) { + continue; + } - default: - if (isWhitespace(ch)) { - ++this.state.pos; - } else { - break loop; - } + if (this.tsIsListTerminator(kind)) { + break; + } + if (expectSuccess) { + this.expect(types.comma); } + + return undefined; } - } - finishToken(type, val) { - this.state.end = this.state.pos; - this.state.endLoc = this.state.curPosition(); - const prevType = this.state.type; - this.state.type = type; - this.state.value = val; - this.updateContext(prevType); + return result; } - readToken_numberSign() { - if (this.state.pos === 0 && this.readToken_interpreter()) { - return; + tsParseBracketedList(kind, parseElement, bracket, skipFirstToken) { + if (!skipFirstToken) { + if (bracket) { + this.expect(types.bracketL); + } else { + this.expectRelational("<"); + } } - const nextPos = this.state.pos + 1; - const next = this.state.input.charCodeAt(nextPos); - - if (next >= 48 && next <= 57) { - this.raise(this.state.pos, "Unexpected digit after hash token"); - } + const result = this.tsParseDelimitedList(kind, parseElement); - if ((this.hasPlugin("classPrivateProperties") || this.hasPlugin("classPrivateMethods")) && this.state.classLevel > 0) { - ++this.state.pos; - this.finishToken(types.hash); - return; - } else if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { - this.finishOp(types.hash, 1); + if (bracket) { + this.expect(types.bracketR); } else { - this.raise(this.state.pos, "Unexpected character '#'"); + this.expectRelational(">"); } + + return result; } - readToken_dot() { - const next = this.state.input.charCodeAt(this.state.pos + 1); + tsParseImportType() { + const node = this.startNode(); + this.expect(types._import); + this.expect(types.parenL); - if (next >= 48 && next <= 57) { - this.readNumber(true); - return; + if (!this.match(types.string)) { + throw this.unexpected(null, "Argument in a type import must be a string literal"); } - const next2 = this.state.input.charCodeAt(this.state.pos + 2); + node.argument = this.parseExprAtom(); + this.expect(types.parenR); - if (next === 46 && next2 === 46) { - this.state.pos += 3; - this.finishToken(types.ellipsis); - } else { - ++this.state.pos; - this.finishToken(types.dot); + if (this.eat(types.dot)) { + node.qualifier = this.tsParseEntityName(true); } - } - readToken_slash() { - if (this.state.exprAllowed && !this.state.inType) { - ++this.state.pos; - this.readRegexp(); - return; + if (this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); } - const next = this.state.input.charCodeAt(this.state.pos + 1); - - if (next === 61) { - this.finishOp(types.assign, 2); - } else { - this.finishOp(types.slash, 1); - } + return this.finishNode(node, "TSImportType"); } - readToken_interpreter() { - if (this.state.pos !== 0 || this.state.length < 2) return false; - const start = this.state.pos; - this.state.pos += 1; - let ch = this.state.input.charCodeAt(this.state.pos); - if (ch !== 33) return false; + tsParseEntityName(allowReservedWords) { + let entity = this.parseIdentifier(); - while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.state.length) { - ch = this.state.input.charCodeAt(this.state.pos); + while (this.eat(types.dot)) { + const node = this.startNodeAtNode(entity); + node.left = entity; + node.right = this.parseIdentifier(allowReservedWords); + entity = this.finishNode(node, "TSQualifiedName"); } - const value = this.state.input.slice(start + 2, this.state.pos); - this.finishToken(types.interpreterDirective, value); - return true; + return entity; } - readToken_mult_modulo(code) { - let type = code === 42 ? types.star : types.modulo; - let width = 1; - let next = this.state.input.charCodeAt(this.state.pos + 1); - const exprAllowed = this.state.exprAllowed; + tsParseTypeReference() { + const node = this.startNode(); + node.typeName = this.tsParseEntityName(false); - if (code === 42 && next === 42) { - width++; - next = this.state.input.charCodeAt(this.state.pos + 2); - type = types.exponent; + if (!this.hasPrecedingLineBreak() && this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); } - if (next === 61 && !exprAllowed) { - width++; - type = types.assign; - } + return this.finishNode(node, "TSTypeReference"); + } - this.finishOp(type, width); + tsParseThisTypePredicate(lhs) { + this.next(); + const node = this.startNodeAtNode(lhs); + node.parameterName = lhs; + node.typeAnnotation = this.tsParseTypeAnnotation(false); + return this.finishNode(node, "TSTypePredicate"); } - readToken_pipe_amp(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + tsParseThisTypeNode() { + const node = this.startNode(); + this.next(); + return this.finishNode(node, "TSThisType"); + } - if (next === code) { - if (this.state.input.charCodeAt(this.state.pos + 2) === 61) { - this.finishOp(types.assign, 3); - } else { - this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2); - } + tsParseTypeQuery() { + const node = this.startNode(); + this.expect(types._typeof); - return; + if (this.match(types._import)) { + node.exprName = this.tsParseImportType(); + } else { + node.exprName = this.tsParseEntityName(true); } - if (code === 124) { - if (next === 62) { - this.finishOp(types.pipeline, 2); - return; - } - } + return this.finishNode(node, "TSTypeQuery"); + } - if (next === 61) { - this.finishOp(types.assign, 2); - return; - } + tsParseTypeParameter() { + const node = this.startNode(); + node.name = this.parseIdentifierName(node.start); + node.constraint = this.tsEatThenParseType(types._extends); + node.default = this.tsEatThenParseType(types.eq); + return this.finishNode(node, "TSTypeParameter"); + } - this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1); + tsTryParseTypeParameters() { + if (this.isRelational("<")) { + return this.tsParseTypeParameters(); + } } - readToken_caret() { - const next = this.state.input.charCodeAt(this.state.pos + 1); + tsParseTypeParameters() { + const node = this.startNode(); - if (next === 61) { - this.finishOp(types.assign, 2); + if (this.isRelational("<") || this.match(types.jsxTagStart)) { + this.next(); } else { - this.finishOp(types.bitwiseXOR, 1); + this.unexpected(); } - } - - readToken_plus_min(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); - if (next === code) { - if (next === 45 && !this.inModule && this.state.input.charCodeAt(this.state.pos + 2) === 62 && lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.pos))) { - this.skipLineComment(3); - this.skipSpace(); - this.nextToken(); - return; - } + node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true); + return this.finishNode(node, "TSTypeParameterDeclaration"); + } - this.finishOp(types.incDec, 2); - return; + tsTryNextParseConstantContext() { + if (this.lookahead().type === types._const) { + this.next(); + return this.tsParseTypeReference(); } - if (next === 61) { - this.finishOp(types.assign, 2); - } else { - this.finishOp(types.plusMin, 1); - } + return null; } - readToken_lt_gt(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); - let size = 1; + tsFillSignature(returnToken, signature) { + const returnTokenRequired = returnToken === types.arrow; + signature.typeParameters = this.tsTryParseTypeParameters(); + this.expect(types.parenL); + signature.parameters = this.tsParseBindingListForSignature(); - if (next === code) { - size = code === 62 && this.state.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2; + if (returnTokenRequired) { + signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); + } else if (this.match(returnToken)) { + signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); + } + } - if (this.state.input.charCodeAt(this.state.pos + size) === 61) { - this.finishOp(types.assign, size + 1); - return; + tsParseBindingListForSignature() { + return this.parseBindingList(types.parenR).map(pattern => { + if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") { + throw this.unexpected(pattern.start, `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${pattern.type}`); } - this.finishOp(types.bitShift, size); - return; - } + return pattern; + }); + } - if (next === 33 && code === 60 && !this.inModule && this.state.input.charCodeAt(this.state.pos + 2) === 45 && this.state.input.charCodeAt(this.state.pos + 3) === 45) { - this.skipLineComment(4); - this.skipSpace(); - this.nextToken(); - return; - } - - if (next === 61) { - size = 2; + tsParseTypeMemberSemicolon() { + if (!this.eat(types.comma)) { + this.semicolon(); } - - this.finishOp(types.relational, size); } - readToken_eq_excl(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + tsParseSignatureMember(kind, node) { + this.tsFillSignature(types.colon, node); + this.tsParseTypeMemberSemicolon(); + return this.finishNode(node, kind); + } - if (next === 61) { - this.finishOp(types.equality, this.state.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2); - return; - } + tsIsUnambiguouslyIndexSignature() { + this.next(); + return this.eat(types.name) && this.match(types.colon); + } - if (code === 61 && next === 62) { - this.state.pos += 2; - this.finishToken(types.arrow); - return; + tsTryParseIndexSignature(node) { + if (!(this.match(types.bracketL) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) { + return undefined; } - this.finishOp(code === 61 ? types.eq : types.bang, 1); + this.expect(types.bracketL); + const id = this.parseIdentifier(); + id.typeAnnotation = this.tsParseTypeAnnotation(); + this.resetEndLocation(id); + this.expect(types.bracketR); + node.parameters = [id]; + const type = this.tsTryParseTypeAnnotation(); + if (type) node.typeAnnotation = type; + this.tsParseTypeMemberSemicolon(); + return this.finishNode(node, "TSIndexSignature"); } - readToken_question() { - const next = this.state.input.charCodeAt(this.state.pos + 1); - const next2 = this.state.input.charCodeAt(this.state.pos + 2); + tsParsePropertyOrMethodSignature(node, readonly) { + if (this.eat(types.question)) node.optional = true; + const nodeAny = node; - if (next === 63 && !this.state.inType) { - if (next2 === 61) { - this.finishOp(types.assign, 3); - } else { - this.finishOp(types.nullishCoalescing, 2); - } - } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) { - this.state.pos += 2; - this.finishToken(types.questionDot); + if (!readonly && (this.match(types.parenL) || this.isRelational("<"))) { + const method = nodeAny; + this.tsFillSignature(types.colon, method); + this.tsParseTypeMemberSemicolon(); + return this.finishNode(method, "TSMethodSignature"); } else { - ++this.state.pos; - this.finishToken(types.question); + const property = nodeAny; + if (readonly) property.readonly = true; + const type = this.tsTryParseTypeAnnotation(); + if (type) property.typeAnnotation = type; + this.tsParseTypeMemberSemicolon(); + return this.finishNode(property, "TSPropertySignature"); } } - getTokenFromCode(code) { - switch (code) { - case 46: - this.readToken_dot(); - return; + tsParseTypeMember() { + const node = this.startNode(); - case 40: - ++this.state.pos; - this.finishToken(types.parenL); - return; + if (this.match(types.parenL) || this.isRelational("<")) { + return this.tsParseSignatureMember("TSCallSignatureDeclaration", node); + } - case 41: - ++this.state.pos; - this.finishToken(types.parenR); - return; + if (this.match(types._new)) { + const id = this.startNode(); + this.next(); - case 59: - ++this.state.pos; - this.finishToken(types.semi); - return; + if (this.match(types.parenL) || this.isRelational("<")) { + return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node); + } else { + node.key = this.createIdentifier(id, "new"); + return this.tsParsePropertyOrMethodSignature(node, false); + } + } - case 44: - ++this.state.pos; - this.finishToken(types.comma); - return; + const readonly = !!this.tsParseModifier(["readonly"]); + const idx = this.tsTryParseIndexSignature(node); - case 91: - ++this.state.pos; - this.finishToken(types.bracketL); - return; + if (idx) { + if (readonly) node.readonly = true; + return idx; + } - case 93: - ++this.state.pos; - this.finishToken(types.bracketR); - return; + this.parsePropertyName(node); + return this.tsParsePropertyOrMethodSignature(node, readonly); + } - case 123: - ++this.state.pos; - this.finishToken(types.braceL); - return; + tsParseTypeLiteral() { + const node = this.startNode(); + node.members = this.tsParseObjectTypeMembers(); + return this.finishNode(node, "TSTypeLiteral"); + } - case 125: - ++this.state.pos; - this.finishToken(types.braceR); - return; + tsParseObjectTypeMembers() { + this.expect(types.braceL); + const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this)); + this.expect(types.braceR); + return members; + } - case 58: - if (this.hasPlugin("functionBind") && this.state.input.charCodeAt(this.state.pos + 1) === 58) { - this.finishOp(types.doubleColon, 2); - } else { - ++this.state.pos; - this.finishToken(types.colon); - } + tsIsStartOfMappedType() { + this.next(); - return; + if (this.eat(types.plusMin)) { + return this.isContextual("readonly"); + } - case 63: - this.readToken_question(); - return; + if (this.isContextual("readonly")) { + this.next(); + } - case 96: - ++this.state.pos; - this.finishToken(types.backQuote); - return; + if (!this.match(types.bracketL)) { + return false; + } - case 48: - { - const next = this.state.input.charCodeAt(this.state.pos + 1); + this.next(); - if (next === 120 || next === 88) { - this.readRadixNumber(16); - return; - } + if (!this.tsIsIdentifier()) { + return false; + } - if (next === 111 || next === 79) { - this.readRadixNumber(8); - return; - } + this.next(); + return this.match(types._in); + } - if (next === 98 || next === 66) { - this.readRadixNumber(2); - return; - } - } + tsParseMappedTypeParameter() { + const node = this.startNode(); + node.name = this.parseIdentifierName(node.start); + node.constraint = this.tsExpectThenParseType(types._in); + return this.finishNode(node, "TSTypeParameter"); + } - case 49: - case 50: - case 51: - case 52: - case 53: - case 54: - case 55: - case 56: - case 57: - this.readNumber(false); - return; + tsParseMappedType() { + const node = this.startNode(); + this.expect(types.braceL); - case 34: - case 39: - this.readString(code); - return; + if (this.match(types.plusMin)) { + node.readonly = this.state.value; + this.next(); + this.expectContextual("readonly"); + } else if (this.eatContextual("readonly")) { + node.readonly = true; + } - case 47: - this.readToken_slash(); - return; + this.expect(types.bracketL); + node.typeParameter = this.tsParseMappedTypeParameter(); + this.expect(types.bracketR); - case 37: - case 42: - this.readToken_mult_modulo(code); - return; + if (this.match(types.plusMin)) { + node.optional = this.state.value; + this.next(); + this.expect(types.question); + } else if (this.eat(types.question)) { + node.optional = true; + } - case 124: - case 38: - this.readToken_pipe_amp(code); - return; + node.typeAnnotation = this.tsTryParseType(); + this.semicolon(); + this.expect(types.braceR); + return this.finishNode(node, "TSMappedType"); + } - case 94: - this.readToken_caret(); - return; + tsParseTupleType() { + const node = this.startNode(); + node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false); + let seenOptionalElement = false; + node.elementTypes.forEach(elementNode => { + if (elementNode.type === "TSOptionalType") { + seenOptionalElement = true; + } else if (seenOptionalElement && elementNode.type !== "TSRestType") { + this.raise(elementNode.start, "A required element cannot follow an optional element."); + } + }); + return this.finishNode(node, "TSTupleType"); + } - case 43: - case 45: - this.readToken_plus_min(code); - return; - - case 60: - case 62: - this.readToken_lt_gt(code); - return; - - case 61: - case 33: - this.readToken_eq_excl(code); - return; + tsParseTupleElementType() { + if (this.match(types.ellipsis)) { + const restNode = this.startNode(); + this.next(); + restNode.typeAnnotation = this.tsParseType(); + this.checkCommaAfterRest(); + return this.finishNode(restNode, "TSRestType"); + } - case 126: - this.finishOp(types.tilde, 1); - return; + const type = this.tsParseType(); - case 64: - ++this.state.pos; - this.finishToken(types.at); - return; + if (this.eat(types.question)) { + const optionalTypeNode = this.startNodeAtNode(type); + optionalTypeNode.typeAnnotation = type; + return this.finishNode(optionalTypeNode, "TSOptionalType"); + } - case 35: - this.readToken_numberSign(); - return; + return type; + } - case 92: - this.readWord(); - return; + tsParseParenthesizedType() { + const node = this.startNode(); + this.expect(types.parenL); + node.typeAnnotation = this.tsParseType(); + this.expect(types.parenR); + return this.finishNode(node, "TSParenthesizedType"); + } - default: - if (isIdentifierStart(code)) { - this.readWord(); - return; - } + tsParseFunctionOrConstructorType(type) { + const node = this.startNode(); + if (type === "TSConstructorType") { + this.expect(types._new); } - this.raise(this.state.pos, `Unexpected character '${String.fromCodePoint(code)}'`); - } - - finishOp(type, size) { - const str = this.state.input.slice(this.state.pos, this.state.pos + size); - this.state.pos += size; - this.finishToken(type, str); + this.tsFillSignature(types.arrow, node); + return this.finishNode(node, type); } - readRegexp() { - const start = this.state.pos; - let escaped, inClass; - - for (;;) { - if (this.state.pos >= this.state.length) { - this.raise(start, "Unterminated regular expression"); - } + tsParseLiteralTypeNode() { + const node = this.startNode(); - const ch = this.state.input.charAt(this.state.pos); + node.literal = (() => { + switch (this.state.type) { + case types.num: + case types.string: + case types._true: + case types._false: + return this.parseExprAtom(); - if (lineBreak.test(ch)) { - this.raise(start, "Unterminated regular expression"); + default: + throw this.unexpected(); } + })(); - if (escaped) { - escaped = false; - } else { - if (ch === "[") { - inClass = true; - } else if (ch === "]" && inClass) { - inClass = false; - } else if (ch === "/" && !inClass) { - break; - } + return this.finishNode(node, "TSLiteralType"); + } - escaped = ch === "\\"; - } + tsParseTemplateLiteralType() { + const node = this.startNode(); + const templateNode = this.parseTemplate(false); - ++this.state.pos; + if (templateNode.expressions.length > 0) { + throw this.raise(templateNode.expressions[0].start, "Template literal types cannot have any substitution"); } - const content = this.state.input.slice(start, this.state.pos); - ++this.state.pos; - let mods = ""; + node.literal = templateNode; + return this.finishNode(node, "TSLiteralType"); + } - while (this.state.pos < this.state.length) { - const char = this.state.input[this.state.pos]; - const charCode = this.state.input.codePointAt(this.state.pos); + tsParseNonArrayType() { + switch (this.state.type) { + case types.name: + case types._void: + case types._null: + { + const type = this.match(types._void) ? "TSVoidKeyword" : this.match(types._null) ? "TSNullKeyword" : keywordTypeFromName(this.state.value); - if (VALID_REGEX_FLAGS.has(char)) { - if (mods.indexOf(char) > -1) { - this.raise(this.state.pos + 1, "Duplicate regular expression flag"); + if (type !== undefined && this.lookahead().type !== types.dot) { + const node = this.startNode(); + this.next(); + return this.finishNode(node, type); + } + + return this.tsParseTypeReference(); } - ++this.state.pos; - mods += char; - } else if (isIdentifierChar(charCode) || charCode === 92) { - this.raise(this.state.pos + 1, "Invalid regular expression flag"); - } else { - break; - } - } + case types.string: + case types.num: + case types._true: + case types._false: + return this.tsParseLiteralTypeNode(); - this.finishToken(types.regexp, { - pattern: content, - flags: mods - }); - } + case types.plusMin: + if (this.state.value === "-") { + const node = this.startNode(); - readInt(radix, len) { - const start = this.state.pos; - const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct; - const allowedSiblings = radix === 16 ? allowedNumericSeparatorSiblings.hex : radix === 10 ? allowedNumericSeparatorSiblings.dec : radix === 8 ? allowedNumericSeparatorSiblings.oct : allowedNumericSeparatorSiblings.bin; - let total = 0; + if (this.lookahead().type !== types.num) { + throw this.unexpected(); + } - for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { - const code = this.state.input.charCodeAt(this.state.pos); - let val; + node.literal = this.parseMaybeUnary(); + return this.finishNode(node, "TSLiteralType"); + } - if (this.hasPlugin("numericSeparator")) { - const prev = this.state.input.charCodeAt(this.state.pos - 1); - const next = this.state.input.charCodeAt(this.state.pos + 1); + break; - if (code === 95) { - if (allowedSiblings.indexOf(next) === -1) { - this.raise(this.state.pos, "Invalid or unexpected token"); - } + case types._this: + { + const thisKeyword = this.tsParseThisTypeNode(); - if (forbiddenSiblings.indexOf(prev) > -1 || forbiddenSiblings.indexOf(next) > -1 || Number.isNaN(next)) { - this.raise(this.state.pos, "Invalid or unexpected token"); + if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { + return this.tsParseThisTypePredicate(thisKeyword); + } else { + return thisKeyword; } - - ++this.state.pos; - continue; } - } - if (code >= 97) { - val = code - 97 + 10; - } else if (code >= 65) { - val = code - 65 + 10; - } else if (_isDigit(code)) { - val = code - 48; - } else { - val = Infinity; - } + case types._typeof: + return this.tsParseTypeQuery(); - if (val >= radix) break; - ++this.state.pos; - total = total * radix + val; - } + case types._import: + return this.tsParseImportType(); - if (this.state.pos === start || len != null && this.state.pos - start !== len) { - return null; - } + case types.braceL: + return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral(); - return total; - } + case types.bracketL: + return this.tsParseTupleType(); - readRadixNumber(radix) { - const start = this.state.pos; - let isBigInt = false; - this.state.pos += 2; - const val = this.readInt(radix); + case types.parenL: + return this.tsParseParenthesizedType(); - if (val == null) { - this.raise(this.state.start + 2, "Expected number in radix " + radix); + case types.backQuote: + return this.tsParseTemplateLiteralType(); } - if (this.hasPlugin("bigInt")) { - if (this.state.input.charCodeAt(this.state.pos) === 110) { - ++this.state.pos; - isBigInt = true; - } - } + throw this.unexpected(); + } - if (isIdentifierStart(this.state.input.codePointAt(this.state.pos))) { - this.raise(this.state.pos, "Identifier directly after number"); - } + tsParseArrayTypeOrHigher() { + let type = this.tsParseNonArrayType(); - if (isBigInt) { - const str = this.state.input.slice(start, this.state.pos).replace(/[_n]/g, ""); - this.finishToken(types.bigint, str); - return; + while (!this.hasPrecedingLineBreak() && this.eat(types.bracketL)) { + if (this.match(types.bracketR)) { + const node = this.startNodeAtNode(type); + node.elementType = type; + this.expect(types.bracketR); + type = this.finishNode(node, "TSArrayType"); + } else { + const node = this.startNodeAtNode(type); + node.objectType = type; + node.indexType = this.tsParseType(); + this.expect(types.bracketR); + type = this.finishNode(node, "TSIndexedAccessType"); + } } - this.finishToken(types.num, val); + return type; } - readNumber(startsWithDot) { - const start = this.state.pos; - let isFloat = false; - let isBigInt = false; + tsParseTypeOperator(operator) { + const node = this.startNode(); + this.expectContextual(operator); + node.operator = operator; + node.typeAnnotation = this.tsParseTypeOperatorOrHigher(); - if (!startsWithDot && this.readInt(10) === null) { - this.raise(start, "Invalid number"); + if (operator === "readonly") { + this.tsCheckTypeAnnotationForReadOnly(node); } - let octal = this.state.pos - start >= 2 && this.state.input.charCodeAt(start) === 48; + return this.finishNode(node, "TSTypeOperator"); + } - if (octal) { - if (this.state.strict) { - this.raise(start, "Legacy octal literals are not allowed in strict mode"); - } + tsCheckTypeAnnotationForReadOnly(node) { + switch (node.typeAnnotation.type) { + case "TSTupleType": + case "TSArrayType": + return; - if (/[89]/.test(this.state.input.slice(start, this.state.pos))) { - octal = false; - } + default: + this.raise(node.start, "'readonly' type modifier is only permitted on array and tuple literal types."); } + } - let next = this.state.input.charCodeAt(this.state.pos); + tsParseInferType() { + const node = this.startNode(); + this.expectContextual("infer"); + const typeParameter = this.startNode(); + typeParameter.name = this.parseIdentifierName(typeParameter.start); + node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter"); + return this.finishNode(node, "TSInferType"); + } - if (next === 46 && !octal) { - ++this.state.pos; - this.readInt(10); - isFloat = true; - next = this.state.input.charCodeAt(this.state.pos); - } + tsParseTypeOperatorOrHigher() { + const operator = ["keyof", "unique", "readonly"].find(kw => this.isContextual(kw)); + return operator ? this.tsParseTypeOperator(operator) : this.isContextual("infer") ? this.tsParseInferType() : this.tsParseArrayTypeOrHigher(); + } - if ((next === 69 || next === 101) && !octal) { - next = this.state.input.charCodeAt(++this.state.pos); + tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) { + this.eat(operator); + let type = parseConstituentType(); - if (next === 43 || next === 45) { - ++this.state.pos; + if (this.match(operator)) { + const types = [type]; + + while (this.eat(operator)) { + types.push(parseConstituentType()); } - if (this.readInt(10) === null) this.raise(start, "Invalid number"); - isFloat = true; - next = this.state.input.charCodeAt(this.state.pos); + const node = this.startNodeAtNode(type); + node.types = types; + type = this.finishNode(node, kind); } - if (this.hasPlugin("bigInt")) { - if (next === 110) { - if (isFloat || octal) this.raise(start, "Invalid BigIntLiteral"); - ++this.state.pos; - isBigInt = true; - } - } + return type; + } - if (isIdentifierStart(this.state.input.codePointAt(this.state.pos))) { - this.raise(this.state.pos, "Identifier directly after number"); - } + tsParseIntersectionTypeOrHigher() { + return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), types.bitwiseAND); + } - const str = this.state.input.slice(start, this.state.pos).replace(/[_n]/g, ""); + tsParseUnionTypeOrHigher() { + return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), types.bitwiseOR); + } - if (isBigInt) { - this.finishToken(types.bigint, str); - return; + tsIsStartOfFunctionType() { + if (this.isRelational("<")) { + return true; } - const val = octal ? parseInt(str, 8) : parseFloat(str); - this.finishToken(types.num, val); + return this.match(types.parenL) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this)); } - readCodePoint(throwOnInvalid) { - const ch = this.state.input.charCodeAt(this.state.pos); - let code; + tsSkipParameterStart() { + if (this.match(types.name) || this.match(types._this)) { + this.next(); + return true; + } - if (ch === 123) { - const codePos = ++this.state.pos; - code = this.readHexChar(this.state.input.indexOf("}", this.state.pos) - this.state.pos, throwOnInvalid); - ++this.state.pos; + if (this.match(types.braceL)) { + let braceStackCounter = 1; + this.next(); - if (code === null) { - --this.state.invalidTemplateEscapePosition; - } else if (code > 0x10ffff) { - if (throwOnInvalid) { - this.raise(codePos, "Code point out of bounds"); - } else { - this.state.invalidTemplateEscapePosition = codePos - 2; - return null; + while (braceStackCounter > 0) { + if (this.match(types.braceL)) { + ++braceStackCounter; + } else if (this.match(types.braceR)) { + --braceStackCounter; } + + this.next(); } - } else { - code = this.readHexChar(4, throwOnInvalid); + + return true; } - return code; - } + if (this.match(types.bracketL)) { + let braceStackCounter = 1; + this.next(); - readString(quote) { - let out = "", - chunkStart = ++this.state.pos; + while (braceStackCounter > 0) { + if (this.match(types.bracketL)) { + ++braceStackCounter; + } else if (this.match(types.bracketR)) { + --braceStackCounter; + } - for (;;) { - if (this.state.pos >= this.state.length) { - this.raise(this.state.start, "Unterminated string constant"); + this.next(); } - const ch = this.state.input.charCodeAt(this.state.pos); - if (ch === quote) break; - - if (ch === 92) { - out += this.state.input.slice(chunkStart, this.state.pos); - out += this.readEscapedChar(false); - chunkStart = this.state.pos; - } else if (ch === 8232 || ch === 8233) { - ++this.state.pos; - ++this.state.curLine; - } else if (isNewLine(ch)) { - this.raise(this.state.start, "Unterminated string constant"); - } else { - ++this.state.pos; - } + return true; } - out += this.state.input.slice(chunkStart, this.state.pos++); - this.finishToken(types.string, out); + return false; } - readTmplToken() { - let out = "", - chunkStart = this.state.pos, - containsInvalid = false; - - for (;;) { - if (this.state.pos >= this.state.length) { - this.raise(this.state.start, "Unterminated template"); - } - - const ch = this.state.input.charCodeAt(this.state.pos); + tsIsUnambiguouslyStartOfFunctionType() { + this.next(); - if (ch === 96 || ch === 36 && this.state.input.charCodeAt(this.state.pos + 1) === 123) { - if (this.state.pos === this.state.start && this.match(types.template)) { - if (ch === 36) { - this.state.pos += 2; - this.finishToken(types.dollarBraceL); - return; - } else { - ++this.state.pos; - this.finishToken(types.backQuote); - return; - } - } + if (this.match(types.parenR) || this.match(types.ellipsis)) { + return true; + } - out += this.state.input.slice(chunkStart, this.state.pos); - this.finishToken(types.template, containsInvalid ? null : out); - return; + if (this.tsSkipParameterStart()) { + if (this.match(types.colon) || this.match(types.comma) || this.match(types.question) || this.match(types.eq)) { + return true; } - if (ch === 92) { - out += this.state.input.slice(chunkStart, this.state.pos); - const escaped = this.readEscapedChar(true); + if (this.match(types.parenR)) { + this.next(); - if (escaped === null) { - containsInvalid = true; - } else { - out += escaped; + if (this.match(types.arrow)) { + return true; } + } + } - chunkStart = this.state.pos; - } else if (isNewLine(ch)) { - out += this.state.input.slice(chunkStart, this.state.pos); - ++this.state.pos; - - switch (ch) { - case 13: - if (this.state.input.charCodeAt(this.state.pos) === 10) { - ++this.state.pos; - } - - case 10: - out += "\n"; - break; + return false; + } - default: - out += String.fromCharCode(ch); - break; - } + tsParseTypeOrTypePredicateAnnotation(returnToken) { + return this.tsInType(() => { + const t = this.startNode(); + this.expect(returnToken); + const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); - ++this.state.curLine; - this.state.lineStart = this.state.pos; - chunkStart = this.state.pos; - } else { - ++this.state.pos; + if (!typePredicateVariable) { + return this.tsParseTypeAnnotation(false, t); } - } + + const type = this.tsParseTypeAnnotation(false); + const node = this.startNodeAtNode(typePredicateVariable); + node.parameterName = typePredicateVariable; + node.typeAnnotation = type; + t.typeAnnotation = this.finishNode(node, "TSTypePredicate"); + return this.finishNode(t, "TSTypeAnnotation"); + }); } - readEscapedChar(inTemplate) { - const throwOnInvalid = !inTemplate; - const ch = this.state.input.charCodeAt(++this.state.pos); - ++this.state.pos; + tsTryParseTypeOrTypePredicateAnnotation() { + return this.match(types.colon) ? this.tsParseTypeOrTypePredicateAnnotation(types.colon) : undefined; + } - switch (ch) { - case 110: - return "\n"; + tsTryParseTypeAnnotation() { + return this.match(types.colon) ? this.tsParseTypeAnnotation() : undefined; + } - case 114: - return "\r"; + tsTryParseType() { + return this.tsEatThenParseType(types.colon); + } - case 120: - { - const code = this.readHexChar(2, throwOnInvalid); - return code === null ? null : String.fromCharCode(code); - } + tsParseTypePredicatePrefix() { + const id = this.parseIdentifier(); - case 117: - { - const code = this.readCodePoint(throwOnInvalid); - return code === null ? null : String.fromCodePoint(code); - } + if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { + this.next(); + return id; + } + } - case 116: - return "\t"; + tsParseTypeAnnotation(eatColon = true, t = this.startNode()) { + this.tsInType(() => { + if (eatColon) this.expect(types.colon); + t.typeAnnotation = this.tsParseType(); + }); + return this.finishNode(t, "TSTypeAnnotation"); + } - case 98: - return "\b"; + tsParseType() { + assert(this.state.inType); + const type = this.tsParseNonConditionalType(); - case 118: - return "\u000b"; + if (this.hasPrecedingLineBreak() || !this.eat(types._extends)) { + return type; + } - case 102: - return "\f"; + const node = this.startNodeAtNode(type); + node.checkType = type; + node.extendsType = this.tsParseNonConditionalType(); + this.expect(types.question); + node.trueType = this.tsParseType(); + this.expect(types.colon); + node.falseType = this.tsParseType(); + return this.finishNode(node, "TSConditionalType"); + } - case 13: - if (this.state.input.charCodeAt(this.state.pos) === 10) { - ++this.state.pos; - } + tsParseNonConditionalType() { + if (this.tsIsStartOfFunctionType()) { + return this.tsParseFunctionOrConstructorType("TSFunctionType"); + } - case 10: - this.state.lineStart = this.state.pos; - ++this.state.curLine; + if (this.match(types._new)) { + return this.tsParseFunctionOrConstructorType("TSConstructorType"); + } - case 8232: - case 8233: - return ""; + return this.tsParseUnionTypeOrHigher(); + } - default: - if (ch >= 48 && ch <= 55) { - const codePos = this.state.pos - 1; - let octalStr = this.state.input.substr(this.state.pos - 1, 3).match(/^[0-7]+/)[0]; - let octal = parseInt(octalStr, 8); + tsParseTypeAssertion() { + const node = this.startNode(); - if (octal > 255) { - octalStr = octalStr.slice(0, -1); - octal = parseInt(octalStr, 8); - } + const _const = this.tsTryNextParseConstantContext(); - if (octal > 0) { - if (inTemplate) { - this.state.invalidTemplateEscapePosition = codePos; - return null; - } else if (this.state.strict) { - this.raise(codePos, "Octal literal in strict mode"); - } else if (!this.state.containsOctal) { - this.state.containsOctal = true; - this.state.octalPosition = codePos; - } - } + node.typeAnnotation = _const || this.tsNextThenParseType(); + this.expectRelational(">"); + node.expression = this.parseMaybeUnary(); + return this.finishNode(node, "TSTypeAssertion"); + } - this.state.pos += octalStr.length - 1; - return String.fromCharCode(octal); - } + tsParseHeritageClause(descriptor) { + const originalStart = this.state.start; + const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", this.tsParseExpressionWithTypeArguments.bind(this)); - return String.fromCharCode(ch); + if (!delimitedList.length) { + this.raise(originalStart, `'${descriptor}' list cannot be empty.`); } + + return delimitedList; } - readHexChar(len, throwOnInvalid) { - const codePos = this.state.pos; - const n = this.readInt(16, len); + tsParseExpressionWithTypeArguments() { + const node = this.startNode(); + node.expression = this.tsParseEntityName(false); - if (n === null) { - if (throwOnInvalid) { - this.raise(codePos, "Bad character escape sequence"); - } else { - this.state.pos = codePos - 1; - this.state.invalidTemplateEscapePosition = codePos - 1; - } + if (this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); } - return n; + return this.finishNode(node, "TSExpressionWithTypeArguments"); } - readWord1() { - let word = ""; - this.state.containsEsc = false; - const start = this.state.pos; - let chunkStart = this.state.pos; - - while (this.state.pos < this.state.length) { - const ch = this.state.input.codePointAt(this.state.pos); + tsParseInterfaceDeclaration(node) { + node.id = this.parseIdentifier(); + this.checkLVal(node.id, BIND_TS_INTERFACE, undefined, "typescript interface declaration"); + node.typeParameters = this.tsTryParseTypeParameters(); - if (isIdentifierChar(ch)) { - this.state.pos += ch <= 0xffff ? 1 : 2; - } else if (this.state.isIterator && ch === 64) { - ++this.state.pos; - } else if (ch === 92) { - this.state.containsEsc = true; - word += this.state.input.slice(chunkStart, this.state.pos); - const escStart = this.state.pos; - const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar; + if (this.eat(types._extends)) { + node.extends = this.tsParseHeritageClause("extends"); + } - if (this.state.input.charCodeAt(++this.state.pos) !== 117) { - this.raise(this.state.pos, "Expecting Unicode escape sequence \\uXXXX"); - } + const body = this.startNode(); + body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this)); + node.body = this.finishNode(body, "TSInterfaceBody"); + return this.finishNode(node, "TSInterfaceDeclaration"); + } - ++this.state.pos; - const esc = this.readCodePoint(true); + tsParseTypeAliasDeclaration(node) { + node.id = this.parseIdentifier(); + this.checkLVal(node.id, BIND_TS_TYPE, undefined, "typescript type alias"); + node.typeParameters = this.tsTryParseTypeParameters(); + node.typeAnnotation = this.tsExpectThenParseType(types.eq); + this.semicolon(); + return this.finishNode(node, "TSTypeAliasDeclaration"); + } - if (!identifierCheck(esc, true)) { - this.raise(escStart, "Invalid Unicode escape"); - } + tsInNoContext(cb) { + const oldContext = this.state.context; + this.state.context = [oldContext[0]]; - word += String.fromCodePoint(esc); - chunkStart = this.state.pos; - } else { - break; - } + try { + return cb(); + } finally { + this.state.context = oldContext; } - - return word + this.state.input.slice(chunkStart, this.state.pos); } - isIterator(word) { - return word === "@@iterator" || word === "@@asyncIterator"; + tsInType(cb) { + const oldInType = this.state.inType; + this.state.inType = true; + + try { + return cb(); + } finally { + this.state.inType = oldInType; + } } - readWord() { - const word = this.readWord1(); - const type = keywords[word] || types.name; + tsEatThenParseType(token) { + return !this.match(token) ? undefined : this.tsNextThenParseType(); + } - if (type.keyword && this.state.containsEsc) { - this.raise(this.state.pos, `Escape sequence in keyword ${word}`); - } + tsExpectThenParseType(token) { + return this.tsDoThenParseType(() => this.expect(token)); + } - if (this.state.isIterator && (!this.isIterator(word) || !this.state.inType)) { - this.raise(this.state.pos, `Invalid identifier ${word}`); - } + tsNextThenParseType() { + return this.tsDoThenParseType(() => this.next()); + } - this.finishToken(type, word); + tsDoThenParseType(cb) { + return this.tsInType(() => { + cb(); + return this.tsParseType(); + }); } - braceIsBlock(prevType) { - const parent = this.curContext(); + tsParseEnumMember() { + const node = this.startNode(); + node.id = this.match(types.string) ? this.parseExprAtom() : this.parseIdentifier(true); - if (parent === types$1.functionExpression || parent === types$1.functionStatement) { - return true; + if (this.eat(types.eq)) { + node.initializer = this.parseMaybeAssign(); } - if (prevType === types.colon && (parent === types$1.braceStatement || parent === types$1.braceExpression)) { - return !parent.isExpr; - } + return this.finishNode(node, "TSEnumMember"); + } - if (prevType === types._return || prevType === types.name && this.state.exprAllowed) { - return lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start)); - } + tsParseEnumDeclaration(node, isConst) { + if (isConst) node.const = true; + node.id = this.parseIdentifier(); + this.checkLVal(node.id, isConst ? BIND_TS_CONST_ENUM : BIND_TS_ENUM, undefined, "typescript enum declaration"); + this.expect(types.braceL); + node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this)); + this.expect(types.braceR); + return this.finishNode(node, "TSEnumDeclaration"); + } - if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) { - return true; - } + tsParseModuleBlock() { + const node = this.startNode(); + this.scope.enter(SCOPE_OTHER); + this.expect(types.braceL); + this.parseBlockOrModuleBlockBody(node.body = [], undefined, true, types.braceR); + this.scope.exit(); + return this.finishNode(node, "TSModuleBlock"); + } - if (prevType === types.braceL) { - return parent === types$1.braceStatement; - } + tsParseModuleOrNamespaceDeclaration(node, nested = false) { + node.id = this.parseIdentifier(); - if (prevType === types._var || prevType === types._const || prevType === types.name) { - return false; + if (!nested) { + this.checkLVal(node.id, BIND_TS_NAMESPACE, null, "module or namespace declaration"); } - if (prevType === types.relational) { - return true; + if (this.eat(types.dot)) { + const inner = this.startNode(); + this.tsParseModuleOrNamespaceDeclaration(inner, true); + node.body = inner; + } else { + node.body = this.tsParseModuleBlock(); } - return !this.state.exprAllowed; + return this.finishNode(node, "TSModuleDeclaration"); } - updateContext(prevType) { - const type = this.state.type; - let update; + tsParseAmbientExternalModuleDeclaration(node) { + if (this.isContextual("global")) { + node.global = true; + node.id = this.parseIdentifier(); + } else if (this.match(types.string)) { + node.id = this.parseExprAtom(); + } else { + this.unexpected(); + } - if (type.keyword && (prevType === types.dot || prevType === types.questionDot)) { - this.state.exprAllowed = false; - } else if (update = type.updateContext) { - update.call(this, prevType); + if (this.match(types.braceL)) { + node.body = this.tsParseModuleBlock(); } else { - this.state.exprAllowed = type.beforeExpr; + this.semicolon(); } + + return this.finishNode(node, "TSModuleDeclaration"); } -} + tsParseImportEqualsDeclaration(node, isExport) { + node.isExport = isExport || false; + node.id = this.parseIdentifier(); + this.expect(types.eq); + node.moduleReference = this.tsParseModuleReference(); + this.semicolon(); + return this.finishNode(node, "TSImportEqualsDeclaration"); + } -class UtilParser extends Tokenizer { - addExtra(node, key, val) { - if (!node) return; - const extra = node.extra = node.extra || {}; - extra[key] = val; + tsIsExternalModuleReference() { + return this.isContextual("require") && this.lookahead().type === types.parenL; } - isRelational(op) { - return this.match(types.relational) && this.state.value === op; + tsParseModuleReference() { + return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false); } - isLookaheadRelational(op) { - const l = this.lookahead(); - return l.type === types.relational && l.value === op; - } - - expectRelational(op) { - if (this.isRelational(op)) { - this.next(); - } else { - this.unexpected(null, types.relational); - } - } + tsParseExternalModuleReference() { + const node = this.startNode(); + this.expectContextual("require"); + this.expect(types.parenL); - eatRelational(op) { - if (this.isRelational(op)) { - this.next(); - return true; + if (!this.match(types.string)) { + throw this.unexpected(); } - return false; - } - - isContextual(name) { - return this.match(types.name) && this.state.value === name && !this.state.containsEsc; - } - - isLookaheadContextual(name) { - const l = this.lookahead(); - return l.type === types.name && l.value === name; + node.expression = this.parseExprAtom(); + this.expect(types.parenR); + return this.finishNode(node, "TSExternalModuleReference"); } - eatContextual(name) { - return this.isContextual(name) && this.eat(types.name); + tsLookAhead(f) { + const state = this.state.clone(); + const res = f(); + this.state = state; + return res; } - expectContextual(name, message) { - if (!this.eatContextual(name)) this.unexpected(null, message); - } + tsTryParseAndCatch(f) { + const state = this.state.clone(); - canInsertSemicolon() { - return this.match(types.eof) || this.match(types.braceR) || this.hasPrecedingLineBreak(); - } + try { + return f(); + } catch (e) { + if (e instanceof SyntaxError) { + this.state = state; + return undefined; + } - hasPrecedingLineBreak() { - return lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start)); + throw e; + } } - isLineTerminator() { - return this.eat(types.semi) || this.canInsertSemicolon(); - } + tsTryParse(f) { + const state = this.state.clone(); + const result = f(); - semicolon() { - if (!this.isLineTerminator()) this.unexpected(null, types.semi); + if (result !== undefined && result !== false) { + return result; + } else { + this.state = state; + return undefined; + } } - expect(type, pos) { - this.eat(type) || this.unexpected(pos, type); - } + nodeWithSamePosition(original, type) { + const node = this.startNodeAtNode(original); + node.type = type; + node.end = original.end; + node.loc.end = original.loc.end; - unexpected(pos, messageOrType = "Unexpected token") { - if (typeof messageOrType !== "string") { - messageOrType = `Unexpected token, expected "${messageOrType.label}"`; + if (original.leadingComments) { + node.leadingComments = original.leadingComments; } - throw this.raise(pos != null ? pos : this.state.start, messageOrType); - } - - expectPlugin(name, pos) { - if (!this.hasPlugin(name)) { - throw this.raise(pos != null ? pos : this.state.start, `This experimental syntax requires enabling the parser plugin: '${name}'`, { - missingPluginNames: [name] - }); + if (original.trailingComments) { + node.trailingComments = original.trailingComments; } - return true; + if (original.innerComments) node.innerComments = original.innerComments; + return node; } - expectOnePlugin(names, pos) { - if (!names.some(n => this.hasPlugin(n))) { - throw this.raise(pos != null ? pos : this.state.start, `This experimental syntax requires enabling one of the following parser plugin(s): '${names.join(", ")}'`, { - missingPluginNames: names - }); + tsTryParseDeclare(nany) { + if (this.isLineTerminator()) { + return; } - } - checkYieldAwaitInDefaultParams() { - if (this.state.yieldPos && (!this.state.awaitPos || this.state.yieldPos < this.state.awaitPos)) { - this.raise(this.state.yieldPos, "Yield cannot be used as name inside a generator function"); - } + let starttype = this.state.type; + let kind; - if (this.state.awaitPos) { - this.raise(this.state.awaitPos, "Await cannot be used as name inside an async function"); + if (this.isContextual("let")) { + starttype = types._var; + kind = "let"; } - } -} + switch (starttype) { + case types._function: + return this.parseFunctionStatement(nany, false, true); -class Node { - constructor(parser, pos, loc) { - this.type = ""; - this.start = pos; - this.end = 0; - this.loc = new SourceLocation(loc); - if (parser && parser.options.ranges) this.range = [pos, 0]; - if (parser && parser.filename) this.loc.filename = parser.filename; - } + case types._class: + return this.parseClass(nany, true, false); - __clone() { - const newNode = new Node(); - const keys = Object.keys(this); + case types._const: + if (this.match(types._const) && this.isLookaheadContextual("enum")) { + this.expect(types._const); + this.expectContextual("enum"); + return this.tsParseEnumDeclaration(nany, true); + } - for (let i = 0, length = keys.length; i < length; i++) { - const key = keys[i]; + case types._var: + kind = kind || this.state.value; + return this.parseVarStatement(nany, kind); - if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") { - newNode[key] = this[key]; - } - } + case types.name: + { + const value = this.state.value; - return newNode; + if (value === "global") { + return this.tsParseAmbientExternalModuleDeclaration(nany); + } else { + return this.tsParseDeclaration(nany, value, true); + } + } + } } -} - -class NodeUtils extends UtilParser { - startNode() { - return new Node(this, this.state.start, this.state.startLoc); + tsTryParseExportDeclaration() { + return this.tsParseDeclaration(this.startNode(), this.state.value, true); } - startNodeAt(pos, loc) { - return new Node(this, pos, loc); - } + tsParseExpressionStatement(node, expr) { + switch (expr.name) { + case "declare": + { + const declaration = this.tsTryParseDeclare(node); - startNodeAtNode(type) { - return this.startNodeAt(type.start, type.loc.start); - } + if (declaration) { + declaration.declare = true; + return declaration; + } - finishNode(node, type) { - return this.finishNodeAt(node, type, this.state.lastTokEnd, this.state.lastTokEndLoc); - } + break; + } - finishNodeAt(node, type, pos, loc) { - node.type = type; - node.end = pos; - node.loc.end = loc; - if (this.options.ranges) node.range[1] = pos; - this.processComment(node); - return node; - } + case "global": + if (this.match(types.braceL)) { + const mod = node; + mod.global = true; + mod.id = expr; + mod.body = this.tsParseModuleBlock(); + return this.finishNode(mod, "TSModuleDeclaration"); + } - resetStartLocation(node, start, startLoc) { - node.start = start; - node.loc.start = startLoc; - if (this.options.ranges) node.range[0] = start; - } + break; - resetStartLocationFromNode(node, locationNode) { - this.resetStartLocation(node, locationNode.start, locationNode.loc.start); + default: + return this.tsParseDeclaration(node, expr.name, false); + } } -} - -class LValParser extends NodeUtils { - toAssignable(node, isBinding, contextDescription) { - if (node) { - switch (node.type) { - case "Identifier": - case "ObjectPattern": - case "ArrayPattern": - case "AssignmentPattern": - break; + tsParseDeclaration(node, value, next) { + switch (value) { + case "abstract": + if (this.tsCheckLineTerminatorAndMatch(types._class, next)) { + const cls = node; + cls.abstract = true; - case "ObjectExpression": - node.type = "ObjectPattern"; + if (next) { + this.next(); - for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) { - const prop = node.properties[i]; - const isLast = i === last; - this.toAssignableObjectExpressionProp(prop, isBinding, isLast); + if (!this.match(types._class)) { + this.unexpected(null, types._class); + } } - break; + return this.parseClass(cls, true, false); + } - case "ObjectProperty": - this.toAssignable(node.value, isBinding, contextDescription); - break; + break; - case "SpreadElement": - { - this.checkToRestConversion(node); - node.type = "RestElement"; - const arg = node.argument; - this.toAssignable(arg, isBinding, contextDescription); - break; - } - - case "ArrayExpression": - node.type = "ArrayPattern"; - this.toAssignableList(node.elements, isBinding, contextDescription); - break; - - case "AssignmentExpression": - if (node.operator === "=") { - node.type = "AssignmentPattern"; - delete node.operator; - } else { - this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); - } - - break; - - case "MemberExpression": - if (!isBinding) break; - - default: - { - const message = "Invalid left-hand side" + (contextDescription ? " in " + contextDescription : "expression"); - this.raise(node.start, message); - } - } - } - - return node; - } + case "enum": + if (next || this.match(types.name)) { + if (next) this.next(); + return this.tsParseEnumDeclaration(node, false); + } - toAssignableObjectExpressionProp(prop, isBinding, isLast) { - if (prop.type === "ObjectMethod") { - const error = prop.kind === "get" || prop.kind === "set" ? "Object pattern can't contain getter or setter" : "Object pattern can't contain methods"; - this.raise(prop.key.start, error); - } else if (prop.type === "SpreadElement" && !isLast) { - this.raiseRestNotLast(prop.start, "property"); - } else { - this.toAssignable(prop, isBinding, "object destructuring pattern"); - } - } + break; - toAssignableList(exprList, isBinding, contextDescription) { - let end = exprList.length; + case "interface": + if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + if (next) this.next(); + return this.tsParseInterfaceDeclaration(node); + } - if (end) { - const last = exprList[end - 1]; + break; - if (last && last.type === "RestElement") { - --end; - } else if (last && last.type === "SpreadElement") { - last.type = "RestElement"; - const arg = last.argument; - this.toAssignable(arg, isBinding, contextDescription); + case "module": + if (next) this.next(); - if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern" && arg.type !== "ObjectPattern") { - this.unexpected(arg.start); + if (this.match(types.string)) { + return this.tsParseAmbientExternalModuleDeclaration(node); + } else if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + return this.tsParseModuleOrNamespaceDeclaration(node); } - --end; - } - } + break; - for (let i = 0; i < end; i++) { - const elt = exprList[i]; + case "namespace": + if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + if (next) this.next(); + return this.tsParseModuleOrNamespaceDeclaration(node); + } - if (elt) { - this.toAssignable(elt, isBinding, contextDescription); + break; - if (elt.type === "RestElement") { - this.raiseRestNotLast(elt.start, "element"); + case "type": + if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + if (next) this.next(); + return this.tsParseTypeAliasDeclaration(node); } - } - } - return exprList; + break; + } } - toReferencedList(exprList, isParenthesizedExpr) { - return exprList; + tsCheckLineTerminatorAndMatch(tokenType, next) { + return (next || this.match(tokenType)) && !this.isLineTerminator(); } - toReferencedListDeep(exprList, isParenthesizedExpr) { - this.toReferencedList(exprList, isParenthesizedExpr); + tsTryParseGenericAsyncArrowFunction(startPos, startLoc) { + if (!this.isRelational("<")) { + return undefined; + } - for (let _i = 0; _i < exprList.length; _i++) { - const expr = exprList[_i]; + const res = this.tsTryParseAndCatch(() => { + const node = this.startNodeAt(startPos, startLoc); + node.typeParameters = this.tsParseTypeParameters(); + super.parseFunctionParams(node); + node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); + this.expect(types.arrow); + return node; + }); - if (expr && expr.type === "ArrayExpression") { - this.toReferencedListDeep(expr.elements); - } + if (!res) { + return undefined; } - return exprList; + return this.parseArrowExpression(res, null, true); } - parseSpread(refShorthandDefaultPos, refNeedsArrowPos) { + tsParseTypeArguments() { const node = this.startNode(); - this.next(); - node.argument = this.parseMaybeAssign(false, refShorthandDefaultPos, undefined, refNeedsArrowPos); + node.params = this.tsInType(() => this.tsInNoContext(() => { + this.expectRelational("<"); + return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this)); + })); + this.state.exprAllowed = false; + this.expectRelational(">"); + return this.finishNode(node, "TSTypeParameterInstantiation"); + } - if (this.state.commaAfterSpreadAt === -1 && this.match(types.comma)) { - this.state.commaAfterSpreadAt = this.state.start; + tsIsDeclarationStart() { + if (this.match(types.name)) { + switch (this.state.value) { + case "abstract": + case "declare": + case "enum": + case "interface": + case "module": + case "namespace": + case "type": + return true; + } } - return this.finishNode(node, "SpreadElement"); + return false; } - parseRest() { - const node = this.startNode(); - this.next(); - node.argument = this.parseBindingAtom(); - return this.finishNode(node, "RestElement"); + isExportDefaultSpecifier() { + if (this.tsIsDeclarationStart()) return false; + return super.isExportDefaultSpecifier(); } - parseBindingAtom() { - switch (this.state.type) { - case types.name: - return this.parseIdentifier(); - - case types.bracketL: - { - const node = this.startNode(); - this.next(); - node.elements = this.parseBindingList(types.bracketR, true); - return this.finishNode(node, "ArrayPattern"); - } - - case types.braceL: - return this.parseObj(true); + parseAssignableListItem(allowModifiers, decorators) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + let accessibility; + let readonly = false; - default: - throw this.unexpected(); + if (allowModifiers) { + accessibility = this.parseAccessModifier(); + readonly = !!this.tsParseModifier(["readonly"]); } - } - - parseBindingList(close, allowEmpty, allowModifiers) { - const elts = []; - let first = true; - while (!this.eat(close)) { - if (first) { - first = false; - } else { - this.expect(types.comma); - } + const left = this.parseMaybeDefault(); + this.parseAssignableListItemTypes(left); + const elt = this.parseMaybeDefault(left.start, left.loc.start, left); - if (allowEmpty && this.match(types.comma)) { - elts.push(null); - } else if (this.eat(close)) { - break; - } else if (this.match(types.ellipsis)) { - elts.push(this.parseAssignableListItemTypes(this.parseRest())); - this.checkCommaAfterRest(close, this.state.inFunction && this.state.inParameters ? "parameter" : "element"); - this.expect(close); - break; - } else { - const decorators = []; + if (accessibility || readonly) { + const pp = this.startNodeAt(startPos, startLoc); - if (this.match(types.at) && this.hasPlugin("decorators")) { - this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters"); - } + if (decorators.length) { + pp.decorators = decorators; + } - while (this.match(types.at)) { - decorators.push(this.parseDecorator()); - } + if (accessibility) pp.accessibility = accessibility; + if (readonly) pp.readonly = readonly; - elts.push(this.parseAssignableListItem(allowModifiers, decorators)); + if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { + throw this.raise(pp.start, "A parameter property may not be declared using a binding pattern."); } - } - return elts; - } - - parseAssignableListItem(allowModifiers, decorators) { - const left = this.parseMaybeDefault(); - this.parseAssignableListItemTypes(left); - const elt = this.parseMaybeDefault(left.start, left.loc.start, left); + pp.parameter = elt; + return this.finishNode(pp, "TSParameterProperty"); + } if (decorators.length) { left.decorators = decorators; @@ -5456,5187 +5224,6028 @@ class LValParser extends NodeUtils { return elt; } - parseAssignableListItemTypes(param) { - return param; + parseFunctionBodyAndFinish(node, type, isMethod = false) { + if (this.match(types.colon)) { + node.returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon); + } + + const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" ? "TSDeclareMethod" : undefined; + + if (bodilessType && !this.match(types.braceL) && this.isLineTerminator()) { + this.finishNode(node, bodilessType); + return; + } + + super.parseFunctionBodyAndFinish(node, type, isMethod); } - parseMaybeDefault(startPos, startLoc, left) { - startLoc = startLoc || this.state.startLoc; - startPos = startPos || this.state.start; - left = left || this.parseBindingAtom(); - if (!this.eat(types.eq)) return left; - const node = this.startNodeAt(startPos, startLoc); - node.left = left; - node.right = this.parseMaybeAssign(); - return this.finishNode(node, "AssignmentPattern"); + checkFunctionStatementId(node) { + if (!node.body && node.id) { + this.checkLVal(node.id, BIND_TS_FN_TYPE, null, "function name"); + } else { + super.checkFunctionStatementId(...arguments); + } } - checkLVal(expr, isBinding, checkClashes, contextDescription) { - switch (expr.type) { - case "Identifier": - if (this.state.strict && isStrictBindReservedWord(expr.name, this.inModule)) { - this.raise(expr.start, `${isBinding ? "Binding" : "Assigning to"} '${expr.name}' in strict mode`); - } + parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow) { + if (!this.hasPrecedingLineBreak() && this.match(types.bang)) { + this.state.exprAllowed = false; + this.next(); + const nonNullExpression = this.startNodeAt(startPos, startLoc); + nonNullExpression.expression = base; + return this.finishNode(nonNullExpression, "TSNonNullExpression"); + } - if (checkClashes) { - const key = `_${expr.name}`; + if (this.isRelational("<")) { + const result = this.tsTryParseAndCatch(() => { + if (!noCalls && this.atPossibleAsync(base)) { + const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc); - if (checkClashes[key]) { - this.raise(expr.start, "Argument name clash in strict mode"); - } else { - checkClashes[key] = true; + if (asyncArrowFn) { + return asyncArrowFn; } } - break; - - case "MemberExpression": - if (isBinding) this.raise(expr.start, "Binding member expression"); - break; - - case "ObjectPattern": - for (let _i2 = 0, _expr$properties = expr.properties; _i2 < _expr$properties.length; _i2++) { - let prop = _expr$properties[_i2]; - if (prop.type === "ObjectProperty") prop = prop.value; - this.checkLVal(prop, isBinding, checkClashes, "object destructuring pattern"); - } - - break; - - case "ArrayPattern": - for (let _i3 = 0, _expr$elements = expr.elements; _i3 < _expr$elements.length; _i3++) { - const elem = _expr$elements[_i3]; + const node = this.startNodeAt(startPos, startLoc); + node.callee = base; + const typeArguments = this.tsParseTypeArguments(); - if (elem) { - this.checkLVal(elem, isBinding, checkClashes, "array destructuring pattern"); + if (typeArguments) { + if (!noCalls && this.eat(types.parenL)) { + node.arguments = this.parseCallExpressionArguments(types.parenR, false); + node.typeParameters = typeArguments; + return this.finishCallExpression(node); + } else if (this.match(types.backQuote)) { + return this.parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments); } } - break; + this.unexpected(); + }); + if (result) return result; + } - case "AssignmentPattern": - this.checkLVal(expr.left, isBinding, checkClashes, "assignment pattern"); - break; + return super.parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow); + } - case "RestElement": - this.checkLVal(expr.argument, isBinding, checkClashes, "rest element"); - break; + parseNewArguments(node) { + if (this.isRelational("<")) { + const typeParameters = this.tsTryParseAndCatch(() => { + const args = this.tsParseTypeArguments(); + if (!this.match(types.parenL)) this.unexpected(); + return args; + }); - default: - { - const message = (isBinding ? "Binding invalid" : "Invalid") + " left-hand side" + (contextDescription ? " in " + contextDescription : "expression"); - this.raise(expr.start, message); - } + if (typeParameters) { + node.typeParameters = typeParameters; + } } - } - checkToRestConversion(node) { - if (node.argument.type !== "Identifier" && node.argument.type !== "MemberExpression") { - this.raise(node.argument.start, "Invalid rest operator's argument"); - } + super.parseNewArguments(node); } - checkCommaAfterRest(close, kind) { - if (this.match(types.comma)) { - if (this.lookahead().type === close) { - this.raiseCommaAfterRest(this.state.start, kind); + parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) { + if (nonNull(types._in.binop) > minPrec && !this.hasPrecedingLineBreak() && this.isContextual("as")) { + const node = this.startNodeAt(leftStartPos, leftStartLoc); + node.expression = left; + + const _const = this.tsTryNextParseConstantContext(); + + if (_const) { + node.typeAnnotation = _const; } else { - this.raiseRestNotLast(this.state.start, kind); + node.typeAnnotation = this.tsNextThenParseType(); } - } - } - checkCommaAfterRestFromSpread(kind) { - if (this.state.commaAfterSpreadAt > -1) { - this.raiseCommaAfterRest(this.state.commaAfterSpreadAt, kind); + this.finishNode(node, "TSAsExpression"); + return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); } - } - raiseCommaAfterRest(pos, kind) { - this.raise(pos, `A trailing comma is not permitted after the rest ${kind}`); + return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn); } - raiseRestNotLast(pos, kind) { - this.raise(pos, `The rest ${kind} must be the last ${kind}`); - } + checkReservedWord(word, startLoc, checkKeywords, isBinding) {} -} + checkDuplicateExports() {} -class ExpressionParser extends LValParser { - checkPropClash(prop, propHash) { - if (prop.computed || prop.kind) return; - const key = prop.key; - const name = key.type === "Identifier" ? key.name : String(key.value); + parseImport(node) { + if (this.match(types.name) && this.lookahead().type === types.eq) { + return this.tsParseImportEqualsDeclaration(node); + } - if (name === "__proto__") { - if (propHash.proto) { - this.raise(key.start, "Redefinition of __proto__ property"); - } + return super.parseImport(node); + } - propHash.proto = true; + parseExport(node) { + if (this.match(types._import)) { + this.expect(types._import); + return this.tsParseImportEqualsDeclaration(node, true); + } else if (this.eat(types.eq)) { + const assign = node; + assign.expression = this.parseExpression(); + this.semicolon(); + return this.finishNode(assign, "TSExportAssignment"); + } else if (this.eatContextual("as")) { + const decl = node; + this.expectContextual("namespace"); + decl.id = this.parseIdentifier(); + this.semicolon(); + return this.finishNode(decl, "TSNamespaceExportDeclaration"); + } else { + return super.parseExport(node); } } - getExpression() { - this.nextToken(); - const expr = this.parseExpression(); + isAbstractClass() { + return this.isContextual("abstract") && this.lookahead().type === types._class; + } - if (!this.match(types.eof)) { - this.unexpected(); + parseExportDefaultExpression() { + if (this.isAbstractClass()) { + const cls = this.startNode(); + this.next(); + this.parseClass(cls, true, true); + cls.abstract = true; + return cls; } - expr.comments = this.state.comments; - return expr; - } + if (this.state.value === "interface") { + const result = this.tsParseDeclaration(this.startNode(), this.state.value, true); + if (result) return result; + } - parseExpression(noIn, refShorthandDefaultPos) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - const expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos); + return super.parseExportDefaultExpression(); + } - if (this.match(types.comma)) { - const node = this.startNodeAt(startPos, startLoc); - node.expressions = [expr]; + parseStatementContent(context, topLevel) { + if (this.state.type === types._const) { + const ahead = this.lookahead(); - while (this.eat(types.comma)) { - node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos)); + if (ahead.type === types.name && ahead.value === "enum") { + const node = this.startNode(); + this.expect(types._const); + this.expectContextual("enum"); + return this.tsParseEnumDeclaration(node, true); } - - this.toReferencedList(node.expressions); - return this.finishNode(node, "SequenceExpression"); } - return expr; + return super.parseStatementContent(context, topLevel); } - parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - - if (this.isContextual("yield")) { - if (this.state.inGenerator) { - let left = this.parseYield(noIn); + parseAccessModifier() { + return this.tsParseModifier(["public", "protected", "private"]); + } - if (afterLeftParse) { - left = afterLeftParse.call(this, left, startPos, startLoc); - } + parseClassMember(classBody, member, state, constructorAllowsSuper) { + const accessibility = this.parseAccessModifier(); + if (accessibility) member.accessibility = accessibility; + super.parseClassMember(classBody, member, state, constructorAllowsSuper); + } - return left; - } else { - this.state.exprAllowed = false; - } - } + parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper) { + const methodOrProp = member; + const prop = member; + const propOrIdx = member; + let abstract = false, + readonly = false; + const mod = this.tsParseModifier(["abstract", "readonly"]); - const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; - this.state.commaAfterSpreadAt = -1; - let failOnShorthandAssign; + switch (mod) { + case "readonly": + readonly = true; + abstract = !!this.tsParseModifier(["abstract"]); + break; - if (refShorthandDefaultPos) { - failOnShorthandAssign = false; - } else { - refShorthandDefaultPos = { - start: 0 - }; - failOnShorthandAssign = true; + case "abstract": + abstract = true; + readonly = !!this.tsParseModifier(["readonly"]); + break; } - if (this.match(types.parenL) || this.match(types.name)) { - this.state.potentialArrowAt = this.state.start; - } + if (abstract) methodOrProp.abstract = true; + if (readonly) propOrIdx.readonly = true; - let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos); + if (!abstract && !isStatic && !methodOrProp.accessibility) { + const idx = this.tsTryParseIndexSignature(member); - if (afterLeftParse) { - left = afterLeftParse.call(this, left, startPos, startLoc); + if (idx) { + classBody.body.push(idx); + return; + } } - if (this.state.type.isAssign) { - const node = this.startNodeAt(startPos, startLoc); - const operator = this.state.value; - node.operator = operator; + if (readonly) { + methodOrProp.static = isStatic; + this.parseClassPropertyName(prop); + this.parsePostMemberNameModifiers(methodOrProp); + this.pushClassProperty(classBody, prop); + return; + } - if (operator === "??=") { - this.expectPlugin("nullishCoalescingOperator"); - this.expectPlugin("logicalAssignment"); - } + super.parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper); + } - if (operator === "||=" || operator === "&&=") { - this.expectPlugin("logicalAssignment"); - } + parsePostMemberNameModifiers(methodOrProp) { + const optional = this.eat(types.question); + if (optional) methodOrProp.optional = true; + } - node.left = this.match(types.eq) ? this.toAssignable(left, undefined, "assignment expression") : left; - refShorthandDefaultPos.start = 0; - this.checkLVal(left, undefined, undefined, "assignment expression"); - let patternErrorMsg; - let elementName; - - if (left.type === "ObjectPattern") { - patternErrorMsg = "`({a}) = 0` use `({a} = 0)`"; - elementName = "property"; - } else if (left.type === "ArrayPattern") { - patternErrorMsg = "`([a]) = 0` use `([a] = 0)`"; - elementName = "element"; - } + parseExpressionStatement(node, expr) { + const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined; + return decl || super.parseExpressionStatement(node, expr); + } - if (patternErrorMsg && left.extra && left.extra.parenthesized) { - this.raise(left.start, `You're trying to assign to a parenthesized expression, eg. instead of ${patternErrorMsg}`); - } + shouldParseExportDeclaration() { + if (this.tsIsDeclarationStart()) return true; + return super.shouldParseExportDeclaration(); + } - if (elementName) this.checkCommaAfterRestFromSpread(elementName); - this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; - this.next(); - node.right = this.parseMaybeAssign(noIn); - return this.finishNode(node, "AssignmentExpression"); - } else if (failOnShorthandAssign && refShorthandDefaultPos.start) { - this.unexpected(refShorthandDefaultPos.start); + parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) { + if (!refNeedsArrowPos || !this.match(types.question)) { + return super.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos); } - this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; - return left; - } + const state = this.state.clone(); - parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - const potentialArrowAt = this.state.potentialArrowAt; - const expr = this.parseExprOps(noIn, refShorthandDefaultPos); + try { + return super.parseConditional(expr, noIn, startPos, startLoc); + } catch (err) { + if (!(err instanceof SyntaxError)) { + throw err; + } - if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) { + this.state = state; + refNeedsArrowPos.start = err.pos || this.state.start; return expr; } - - if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr; - return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos); } - parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) { + parseParenItem(node, startPos, startLoc) { + node = super.parseParenItem(node, startPos, startLoc); + if (this.eat(types.question)) { - const node = this.startNodeAt(startPos, startLoc); - node.test = expr; - node.consequent = this.parseMaybeAssign(); - this.expect(types.colon); - node.alternate = this.parseMaybeAssign(noIn); - return this.finishNode(node, "ConditionalExpression"); + node.optional = true; + this.resetEndLocation(node); } - return expr; + if (this.match(types.colon)) { + const typeCastNode = this.startNodeAt(startPos, startLoc); + typeCastNode.expression = node; + typeCastNode.typeAnnotation = this.tsParseTypeAnnotation(); + return this.finishNode(typeCastNode, "TSTypeCastExpression"); + } + + return node; } - parseExprOps(noIn, refShorthandDefaultPos) { + parseExportDeclaration(node) { const startPos = this.state.start; const startLoc = this.state.startLoc; - const potentialArrowAt = this.state.potentialArrowAt; - const expr = this.parseMaybeUnary(refShorthandDefaultPos); + const isDeclare = this.eatContextual("declare"); + let declaration; - if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) { - return expr; + if (this.match(types.name)) { + declaration = this.tsTryParseExportDeclaration(); } - if (refShorthandDefaultPos && refShorthandDefaultPos.start) { - return expr; + if (!declaration) { + declaration = super.parseExportDeclaration(node); } - return this.parseExprOp(expr, startPos, startLoc, -1, noIn); - } - - parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) { - const prec = this.state.type.binop; - - if (prec != null && (!noIn || !this.match(types._in))) { - if (prec > minPrec) { - const node = this.startNodeAt(leftStartPos, leftStartLoc); - const operator = this.state.value; - node.left = left; - node.operator = operator; - - if (operator === "**" && left.type === "UnaryExpression" && !(left.extra && left.extra.parenthesized)) { - this.raise(left.argument.start, "Illegal expression. Wrap left hand side or entire exponentiation in parentheses."); - } - - const op = this.state.type; + if (declaration && isDeclare) { + this.resetStartLocation(declaration, startPos, startLoc); + declaration.declare = true; + } - if (op === types.pipeline) { - this.expectPlugin("pipelineOperator"); - this.state.inPipeline = true; - this.checkPipelineAtInfixOperator(left, leftStartPos); - } else if (op === types.nullishCoalescing) { - this.expectPlugin("nullishCoalescingOperator"); - } + return declaration; + } - this.next(); + parseClassId(node, isStatement, optionalId) { + if ((!isStatement || optionalId) && this.isContextual("implements")) { + return; + } - if (op === types.pipeline && this.getPluginOption("pipelineOperator", "proposal") === "minimal") { - if (this.match(types.name) && this.state.value === "await" && this.state.inAsync) { - throw this.raise(this.state.start, `Unexpected "await" after pipeline body; await must have parentheses in minimal proposal`); - } - } + super.parseClassId(...arguments); + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) node.typeParameters = typeParameters; + } - node.right = this.parseExprOpRightExpr(op, prec, noIn); - this.finishNode(node, op === types.logicalOR || op === types.logicalAND || op === types.nullishCoalescing ? "LogicalExpression" : "BinaryExpression"); - return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); - } + parseClassProperty(node) { + if (!node.optional && this.eat(types.bang)) { + node.definite = true; } - return left; + const type = this.tsTryParseTypeAnnotation(); + if (type) node.typeAnnotation = type; + return super.parseClassProperty(node); } - parseExprOpRightExpr(op, prec, noIn) { - switch (op) { - case types.pipeline: - if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - return this.withTopicPermittingContext(() => { - return this.parseSmartPipelineBody(this.parseExprOpBaseRightExpr(op, prec, noIn), startPos, startLoc); - }); - } - - default: - return this.parseExprOpBaseRightExpr(op, prec, noIn); - } + pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) method.typeParameters = typeParameters; + super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper); } - parseExprOpBaseRightExpr(op, prec, noIn) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - return this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, op.rightAssociative ? prec - 1 : prec, noIn); + pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) method.typeParameters = typeParameters; + super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); } - parseMaybeUnary(refShorthandDefaultPos) { - if (this.isContextual("await") && (this.state.inAsync || !this.state.inFunction && this.options.allowAwaitOutsideFunction)) { - return this.parseAwait(); - } else if (this.state.type.prefix) { - const node = this.startNode(); - const update = this.match(types.incDec); - node.operator = this.state.value; - node.prefix = true; + parseClassSuper(node) { + super.parseClassSuper(node); - if (node.operator === "throw") { - this.expectPlugin("throwExpressions"); - } + if (node.superClass && this.isRelational("<")) { + node.superTypeParameters = this.tsParseTypeArguments(); + } - this.next(); - node.argument = this.parseMaybeUnary(); + if (this.eatContextual("implements")) { + node.implements = this.tsParseHeritageClause("implements"); + } + } - if (refShorthandDefaultPos && refShorthandDefaultPos.start) { - this.unexpected(refShorthandDefaultPos.start); - } + parseObjPropValue(prop, ...args) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) prop.typeParameters = typeParameters; + super.parseObjPropValue(prop, ...args); + } - if (update) { - this.checkLVal(node.argument, undefined, undefined, "prefix operation"); - } else if (this.state.strict && node.operator === "delete") { - const arg = node.argument; + parseFunctionParams(node, allowModifiers) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) node.typeParameters = typeParameters; + super.parseFunctionParams(node, allowModifiers); + } - if (arg.type === "Identifier") { - this.raise(node.start, "Deleting local variable in strict mode"); - } else if (arg.type === "MemberExpression" && arg.property.type === "PrivateName") { - this.raise(node.start, "Deleting a private field is not allowed"); - } - } + parseVarId(decl, kind) { + super.parseVarId(decl, kind); - return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); + if (decl.id.type === "Identifier" && this.eat(types.bang)) { + decl.definite = true; } - const startPos = this.state.start; - const startLoc = this.state.startLoc; - let expr = this.parseExprSubscripts(refShorthandDefaultPos); - if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr; + const type = this.tsTryParseTypeAnnotation(); - while (this.state.type.postfix && !this.canInsertSemicolon()) { - const node = this.startNodeAt(startPos, startLoc); - node.operator = this.state.value; - node.prefix = false; - node.argument = expr; - this.checkLVal(expr, undefined, undefined, "postfix operation"); - this.next(); - expr = this.finishNode(node, "UpdateExpression"); + if (type) { + decl.id.typeAnnotation = type; + this.resetEndLocation(decl.id); } - - return expr; } - parseExprSubscripts(refShorthandDefaultPos) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - const potentialArrowAt = this.state.potentialArrowAt; - const expr = this.parseExprAtom(refShorthandDefaultPos); - - if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) { - return expr; - } - - if (refShorthandDefaultPos && refShorthandDefaultPos.start) { - return expr; + parseAsyncArrowFromCallExpression(node, call) { + if (this.match(types.colon)) { + node.returnType = this.tsParseTypeAnnotation(); } - return this.parseSubscripts(expr, startPos, startLoc); + return super.parseAsyncArrowFromCallExpression(node, call); } - parseSubscripts(base, startPos, startLoc, noCalls) { - const state = { - optionalChainMember: false, - stop: false - }; + parseMaybeAssign(...args) { + let jsxError; - do { - base = this.parseSubscript(base, startPos, startLoc, noCalls, state); - } while (!state.stop); + if (this.match(types.jsxTagStart)) { + const context = this.curContext(); + assert(context === types$1.j_oTag); + assert(this.state.context[this.state.context.length - 2] === types$1.j_expr); + const state = this.state.clone(); - return base; - } - - parseSubscript(base, startPos, startLoc, noCalls, state) { - if (!noCalls && this.eat(types.doubleColon)) { - const node = this.startNodeAt(startPos, startLoc); - node.object = base; - node.callee = this.parseNoCallExpr(); - state.stop = true; - return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls); - } else if (this.match(types.questionDot)) { - this.expectPlugin("optionalChaining"); - state.optionalChainMember = true; + try { + return super.parseMaybeAssign(...args); + } catch (err) { + if (!(err instanceof SyntaxError)) { + throw err; + } - if (noCalls && this.lookahead().type === types.parenL) { - state.stop = true; - return base; + this.state = state; + assert(this.curContext() === types$1.j_oTag); + this.state.context.pop(); + assert(this.curContext() === types$1.j_expr); + this.state.context.pop(); + jsxError = err; } + } - this.next(); - const node = this.startNodeAt(startPos, startLoc); - - if (this.eat(types.bracketL)) { - node.object = base; - node.property = this.parseExpression(); - node.computed = true; - node.optional = true; - this.expect(types.bracketR); - return this.finishNode(node, "OptionalMemberExpression"); - } else if (this.eat(types.parenL)) { - const possibleAsync = this.atPossibleAsync(base); - node.callee = base; - node.arguments = this.parseCallExpressionArguments(types.parenR, possibleAsync); - node.optional = true; - return this.finishNode(node, "OptionalCallExpression"); - } else { - node.object = base; - node.property = this.parseIdentifier(true); - node.computed = false; - node.optional = true; - return this.finishNode(node, "OptionalMemberExpression"); - } - } else if (this.eat(types.dot)) { - const node = this.startNodeAt(startPos, startLoc); - node.object = base; - node.property = this.parseMaybePrivateName(); - node.computed = false; + if (jsxError === undefined && !this.isRelational("<")) { + return super.parseMaybeAssign(...args); + } - if (state.optionalChainMember) { - node.optional = false; - return this.finishNode(node, "OptionalMemberExpression"); - } + let arrowExpression; + let typeParameters; + const state = this.state.clone(); - return this.finishNode(node, "MemberExpression"); - } else if (this.eat(types.bracketL)) { - const node = this.startNodeAt(startPos, startLoc); - node.object = base; - node.property = this.parseExpression(); - node.computed = true; - this.expect(types.bracketR); + try { + typeParameters = this.tsParseTypeParameters(); + arrowExpression = super.parseMaybeAssign(...args); - if (state.optionalChainMember) { - node.optional = false; - return this.finishNode(node, "OptionalMemberExpression"); + if (arrowExpression.type !== "ArrowFunctionExpression" || arrowExpression.extra && arrowExpression.extra.parenthesized) { + this.unexpected(); } - - return this.finishNode(node, "MemberExpression"); - } else if (!noCalls && this.match(types.parenL)) { - const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; - const oldYieldPos = this.state.yieldPos; - const oldAwaitPos = this.state.awaitPos; - this.state.maybeInArrowParameters = true; - this.state.yieldPos = 0; - this.state.awaitPos = 0; - const possibleAsync = this.atPossibleAsync(base); - this.next(); - let node = this.startNodeAt(startPos, startLoc); - node.callee = base; - const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; - this.state.commaAfterSpreadAt = -1; - node.arguments = this.parseCallExpressionArguments(types.parenR, possibleAsync, base.type === "Import"); - - if (!state.optionalChainMember) { - this.finishCallExpression(node); - } else { - this.finishOptionalCallExpression(node); + } catch (err) { + if (!(err instanceof SyntaxError)) { + throw err; } - if (possibleAsync && this.shouldParseAsyncArrow()) { - state.stop = true; - this.checkCommaAfterRestFromSpread("parameter"); - node = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); - this.checkYieldAwaitInDefaultParams(); - this.state.yieldPos = oldYieldPos; - this.state.awaitPos = oldAwaitPos; - } else { - this.toReferencedListDeep(node.arguments); - this.state.yieldPos = oldYieldPos || this.state.yieldPos; - this.state.awaitPos = oldAwaitPos || this.state.awaitPos; + if (jsxError) { + throw jsxError; } - this.state.maybeInArrowParameters = oldMaybeInArrowParameters; - this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; - return node; - } else if (this.match(types.backQuote)) { - return this.parseTaggedTemplateExpression(startPos, startLoc, base, state); - } else { - state.stop = true; - return base; + assert(!this.hasPlugin("jsx")); + this.state = state; + return super.parseMaybeAssign(...args); } - } - - parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments) { - const node = this.startNodeAt(startPos, startLoc); - node.tag = base; - node.quasi = this.parseTemplate(true); - if (typeArguments) node.typeParameters = typeArguments; - if (state.optionalChainMember) { - this.raise(startPos, "Tagged Template Literals are not allowed in optionalChain"); + if (typeParameters && typeParameters.params.length !== 0) { + this.resetStartLocationFromNode(arrowExpression, typeParameters); } - return this.finishNode(node, "TaggedTemplateExpression"); + arrowExpression.typeParameters = typeParameters; + return arrowExpression; } - atPossibleAsync(base) { - return !this.state.containsEsc && this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon(); + parseMaybeUnary(refShorthandDefaultPos) { + if (!this.hasPlugin("jsx") && this.isRelational("<")) { + return this.tsParseTypeAssertion(); + } else { + return super.parseMaybeUnary(refShorthandDefaultPos); + } } - finishCallExpression(node) { - if (node.callee.type === "Import") { - if (node.arguments.length !== 1) { - this.raise(node.start, "import() requires exactly one argument"); - } + parseArrow(node) { + if (this.match(types.colon)) { + const state = this.state.clone(); - const importArg = node.arguments[0]; + try { + const returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon); - if (importArg && importArg.type === "SpreadElement") { - this.raise(importArg.start, "... is not allowed in import()"); + if (this.canInsertSemicolon() || !this.match(types.arrow)) { + this.state = state; + return undefined; + } + + node.returnType = returnType; + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + } else { + throw err; + } } } - return this.finishNode(node, "CallExpression"); + return super.parseArrow(node); } - finishOptionalCallExpression(node) { - if (node.callee.type === "Import") { - if (node.arguments.length !== 1) { - this.raise(node.start, "import() requires exactly one argument"); + parseAssignableListItemTypes(param) { + if (this.eat(types.question)) { + if (param.type !== "Identifier") { + throw this.raise(param.start, "A binding pattern parameter cannot be optional in an implementation signature."); } - const importArg = node.arguments[0]; - - if (importArg && importArg.type === "SpreadElement") { - this.raise(importArg.start, "... is not allowed in import()"); - } + param.optional = true; } - return this.finishNode(node, "OptionalCallExpression"); + const type = this.tsTryParseTypeAnnotation(); + if (type) param.typeAnnotation = type; + this.resetEndLocation(param); + return param; } - parseCallExpressionArguments(close, possibleAsyncArrow, dynamicImport) { - const elts = []; - let innerParenStart; - let first = true; + toAssignable(node, isBinding, contextDescription) { + switch (node.type) { + case "TSTypeCastExpression": + return super.toAssignable(this.typeCastToParameter(node), isBinding, contextDescription); - while (!this.eat(close)) { - if (first) { - first = false; - } else { - this.expect(types.comma); + case "TSParameterProperty": + return super.toAssignable(node, isBinding, contextDescription); - if (this.eat(close)) { - if (dynamicImport) { - this.raise(this.state.lastTokStart, "Trailing comma is disallowed inside import(...) arguments"); - } + case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": + node.expression = this.toAssignable(node.expression, isBinding, contextDescription); + return node; - break; - } - } + default: + return super.toAssignable(node, isBinding, contextDescription); + } + } - if (this.match(types.parenL) && !innerParenStart) { - innerParenStart = this.state.start; - } + checkLVal(expr, bindingType = BIND_NONE, checkClashes, contextDescription) { + switch (expr.type) { + case "TSTypeCastExpression": + return; - elts.push(this.parseExprListItem(false, possibleAsyncArrow ? { - start: 0 - } : undefined, possibleAsyncArrow ? { - start: 0 - } : undefined)); - } + case "TSParameterProperty": + this.checkLVal(expr.parameter, bindingType, checkClashes, "parameter property"); + return; - if (possibleAsyncArrow && innerParenStart && this.shouldParseAsyncArrow()) { - this.unexpected(); - } + case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": + this.checkLVal(expr.expression, bindingType, checkClashes, contextDescription); + return; - return elts; + default: + super.checkLVal(expr, bindingType, checkClashes, contextDescription); + return; + } } - shouldParseAsyncArrow() { - return this.match(types.arrow); - } + parseBindingAtom() { + switch (this.state.type) { + case types._this: + return this.parseIdentifier(true); - parseAsyncArrowFromCallExpression(node, call) { - this.expect(types.arrow); - this.parseArrowExpression(node, call.arguments, true); - return node; + default: + return super.parseBindingAtom(); + } } - parseNoCallExpr() { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true); - } - - parseExprAtom(refShorthandDefaultPos) { - if (this.state.type === types.slash) this.readRegexp(); - const canBeArrow = this.state.potentialArrowAt === this.state.start; - let node; + parseMaybeDecoratorArguments(expr) { + if (this.isRelational("<")) { + const typeArguments = this.tsParseTypeArguments(); - switch (this.state.type) { - case types._super: - if (!this.state.inMethod && !this.state.inClassProperty && !this.options.allowSuperOutsideMethod) { - this.raise(this.state.start, "super is only allowed in object methods and classes"); - } + if (this.match(types.parenL)) { + const call = super.parseMaybeDecoratorArguments(expr); + call.typeParameters = typeArguments; + return call; + } - node = this.startNode(); - this.next(); + this.unexpected(this.state.start, types.parenL); + } - if (!this.match(types.parenL) && !this.match(types.bracketL) && !this.match(types.dot)) { - this.unexpected(); - } + return super.parseMaybeDecoratorArguments(expr); + } - if (this.match(types.parenL) && this.state.inMethod !== "constructor" && !this.options.allowSuperOutsideMethod) { - this.raise(node.start, "super() is only valid inside a class constructor. " + "Make sure the method name is spelled exactly as 'constructor'."); - } + isClassMethod() { + return this.isRelational("<") || super.isClassMethod(); + } - return this.finishNode(node, "Super"); + isClassProperty() { + return this.match(types.bang) || this.match(types.colon) || super.isClassProperty(); + } - case types._import: - if (this.lookahead().type === types.dot) { - return this.parseImportMetaProperty(); - } + parseMaybeDefault(...args) { + const node = super.parseMaybeDefault(...args); - this.expectPlugin("dynamicImport"); - node = this.startNode(); - this.next(); + if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) { + this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, " + "e.g. instead of `age = 25: number` use `age: number = 25`"); + } - if (!this.match(types.parenL)) { - this.unexpected(null, types.parenL); - } + return node; + } - return this.finishNode(node, "Import"); + getTokenFromCode(code) { + if (this.state.inType && (code === 62 || code === 60)) { + return this.finishOp(types.relational, 1); + } else { + return super.getTokenFromCode(code); + } + } - case types._this: - node = this.startNode(); - this.next(); - return this.finishNode(node, "ThisExpression"); + toAssignableList(exprList, isBinding, contextDescription) { + for (let i = 0; i < exprList.length; i++) { + const expr = exprList[i]; + if (!expr) continue; - case types.name: - { - node = this.startNode(); - const containsEsc = this.state.containsEsc; - const id = this.parseIdentifier(); + switch (expr.type) { + case "TSTypeCastExpression": + exprList[i] = this.typeCastToParameter(expr); + break; - if (!containsEsc && id.name === "async" && this.match(types._function) && !this.canInsertSemicolon()) { - this.next(); - return this.parseFunction(node, false, false, true); - } else if (canBeArrow && id.name === "async" && this.match(types.name) && !this.canInsertSemicolon()) { - const oldInAsync = this.state.inAsync; - this.state.inAsync = true; - const params = [this.parseIdentifier()]; - this.expect(types.arrow); - this.parseArrowExpression(node, params, true); - this.state.inAsync = oldInAsync; - return node; - } + case "TSAsExpression": + case "TSTypeAssertion": + this.raise(expr.start, "Unexpected type cast in parameter position."); + break; + } + } - if (canBeArrow && this.match(types.arrow) && !this.canInsertSemicolon()) { - this.next(); - this.parseArrowExpression(node, [id], false); - return node; - } + return super.toAssignableList(exprList, isBinding, contextDescription); + } - return id; - } + typeCastToParameter(node) { + node.expression.typeAnnotation = node.typeAnnotation; + this.resetEndLocation(node.expression, node.typeAnnotation.end, node.typeAnnotation.loc.end); + return node.expression; + } - case types._do: - { - this.expectPlugin("doExpressions"); - const node = this.startNode(); - this.next(); - const oldInFunction = this.state.inFunction; - const oldLabels = this.state.labels; - this.state.labels = []; - this.state.inFunction = false; - node.body = this.parseBlock(false); - this.state.inFunction = oldInFunction; - this.state.labels = oldLabels; - return this.finishNode(node, "DoExpression"); - } + toReferencedList(exprList, isInParens) { + for (let i = 0; i < exprList.length; i++) { + const expr = exprList[i]; - case types.regexp: - { - const value = this.state.value; - node = this.parseLiteral(value.value, "RegExpLiteral"); - node.pattern = value.pattern; - node.flags = value.flags; - return node; - } + if (expr && expr._exprListItem && expr.type === "TsTypeCastExpression") { + this.raise(expr.start, "Did not expect a type annotation here."); + } + } - case types.num: - return this.parseLiteral(this.state.value, "NumericLiteral"); + return exprList; + } - case types.bigint: - return this.parseLiteral(this.state.value, "BigIntLiteral"); + shouldParseArrow() { + return this.match(types.colon) || super.shouldParseArrow(); + } - case types.string: - return this.parseLiteral(this.state.value, "StringLiteral"); + shouldParseAsyncArrow() { + return this.match(types.colon) || super.shouldParseAsyncArrow(); + } - case types._null: - node = this.startNode(); - this.next(); - return this.finishNode(node, "NullLiteral"); + canHaveLeadingDecorator() { + return super.canHaveLeadingDecorator() || this.isAbstractClass(); + } - case types._true: - case types._false: - return this.parseBooleanLiteral(); + jsxParseOpeningElementAfterName(node) { + if (this.isRelational("<")) { + const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArguments()); + if (typeArguments) node.typeParameters = typeArguments; + } - case types.parenL: - return this.parseParenAndDistinguishExpression(canBeArrow); + return super.jsxParseOpeningElementAfterName(node); + } - case types.bracketL: - node = this.startNode(); - this.next(); - node.elements = this.parseExprList(types.bracketR, true, refShorthandDefaultPos); + getGetterSetterExpectedParamCount(method) { + const baseCount = super.getGetterSetterExpectedParamCount(method); + const firstParam = method.params[0]; + const hasContextParam = firstParam && firstParam.type === "Identifier" && firstParam.name === "this"; + return hasContextParam ? baseCount + 1 : baseCount; + } - if (!this.state.maybeInArrowParameters) { - this.toReferencedList(node.elements); - } +}); - return this.finishNode(node, "ArrayExpression"); +types.placeholder = new TokenType("%%", { + startsExpr: true +}); +var placeholders = (superClass => class extends superClass { + parsePlaceholder(expectedNode) { + if (this.match(types.placeholder)) { + const node = this.startNode(); + this.next(); + this.assertNoSpace("Unexpected space in placeholder."); + node.name = super.parseIdentifier(true); + this.assertNoSpace("Unexpected space in placeholder."); + this.expect(types.placeholder); + return this.finishPlaceholder(node, expectedNode); + } + } - case types.braceL: - return this.parseObj(false, refShorthandDefaultPos); + finishPlaceholder(node, expectedNode) { + const isFinished = !!(node.expectedNode && node.type === "Placeholder"); + node.expectedNode = expectedNode; + return isFinished ? node : this.finishNode(node, "Placeholder"); + } - case types._function: - return this.parseFunctionExpression(); + getTokenFromCode(code) { + if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) { + return this.finishOp(types.placeholder, 2); + } - case types.at: - this.parseDecorators(); + return super.getTokenFromCode(...arguments); + } - case types._class: - node = this.startNode(); - this.takeDecorators(node); - return this.parseClass(node, false); + parseExprAtom() { + return this.parsePlaceholder("Expression") || super.parseExprAtom(...arguments); + } - case types._new: - return this.parseNew(); + parseIdentifier() { + return this.parsePlaceholder("Identifier") || super.parseIdentifier(...arguments); + } - case types.backQuote: - return this.parseTemplate(false); + checkReservedWord(word) { + if (word !== undefined) super.checkReservedWord(...arguments); + } - case types.doubleColon: - { - node = this.startNode(); - this.next(); - node.object = null; - const callee = node.callee = this.parseNoCallExpr(); + parseBindingAtom() { + return this.parsePlaceholder("Pattern") || super.parseBindingAtom(...arguments); + } - if (callee.type === "MemberExpression") { - return this.finishNode(node, "BindExpression"); - } else { - throw this.raise(callee.start, "Binding should be performed on object property."); - } - } + checkLVal(expr) { + if (expr.type !== "Placeholder") super.checkLVal(...arguments); + } - case types.hash: - { - if (this.state.inPipeline) { - node = this.startNode(); + toAssignable(node) { + if (node && node.type === "Placeholder" && node.expectedNode === "Expression") { + node.expectedNode = "Pattern"; + return node; + } - if (this.getPluginOption("pipelineOperator", "proposal") !== "smart") { - this.raise(node.start, "Primary Topic Reference found but pipelineOperator not passed 'smart' for 'proposal' option."); - } + return super.toAssignable(...arguments); + } - this.next(); + verifyBreakContinue(node) { + if (node.label && node.label.type === "Placeholder") return; + super.verifyBreakContinue(...arguments); + } - if (this.primaryTopicReferenceIsAllowedInCurrentTopicContext()) { - this.registerTopicReference(); - return this.finishNode(node, "PipelinePrimaryTopicReference"); - } else { - throw this.raise(node.start, `Topic reference was used in a lexical context without topic binding`); - } - } - } + parseExpressionStatement(node, expr) { + if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) { + return super.parseExpressionStatement(...arguments); + } - default: - throw this.unexpected(); + if (this.match(types.colon)) { + const stmt = node; + stmt.label = this.finishPlaceholder(expr, "Identifier"); + this.next(); + stmt.body = this.parseStatement("label"); + return this.finishNode(stmt, "LabeledStatement"); } + + this.semicolon(); + node.name = expr.name; + return this.finishPlaceholder(node, "Statement"); } - parseBooleanLiteral() { - const node = this.startNode(); - node.value = this.match(types._true); - this.next(); - return this.finishNode(node, "BooleanLiteral"); + parseBlock() { + return this.parsePlaceholder("BlockStatement") || super.parseBlock(...arguments); } - parseMaybePrivateName() { - const isPrivate = this.match(types.hash); + parseFunctionId() { + return this.parsePlaceholder("Identifier") || super.parseFunctionId(...arguments); + } - if (isPrivate) { - this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]); - const node = this.startNode(); - const columnHashEnd = this.state.end; - this.next(); - const columnIdentifierStart = this.state.start; - const spacesBetweenHashAndIdentifier = columnIdentifierStart - columnHashEnd; + parseClass(node, isStatement, optionalId) { + const type = isStatement ? "ClassDeclaration" : "ClassExpression"; + this.next(); + this.takeDecorators(node); + const placeholder = this.parsePlaceholder("Identifier"); - if (spacesBetweenHashAndIdentifier != 0) { - this.raise(columnIdentifierStart, "Unexpected space between # and identifier"); + if (placeholder) { + if (this.match(types._extends) || this.match(types.placeholder) || this.match(types.braceL)) { + node.id = placeholder; + } else if (optionalId || !isStatement) { + node.id = null; + node.body = this.finishPlaceholder(placeholder, "ClassBody"); + return this.finishNode(node, type); + } else { + this.unexpected(null, "A class name is required"); } - - node.id = this.parseIdentifier(true); - return this.finishNode(node, "PrivateName"); } else { - return this.parseIdentifier(true); + this.parseClassId(node, isStatement, optionalId); } + + this.parseClassSuper(node); + node.body = this.parsePlaceholder("ClassBody") || this.parseClassBody(!!node.superClass); + return this.finishNode(node, type); } - parseFunctionExpression() { - const node = this.startNode(); - let meta = this.startNode(); - this.next(); - meta = this.createIdentifier(meta, "function"); + parseExport(node) { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseExport(...arguments); - if (this.state.inGenerator && this.eat(types.dot)) { - return this.parseMetaProperty(node, meta, "sent"); + if (!this.isContextual("from") && !this.match(types.comma)) { + node.specifiers = []; + node.source = null; + node.declaration = this.finishPlaceholder(placeholder, "Declaration"); + return this.finishNode(node, "ExportNamedDeclaration"); } - return this.parseFunction(node, false); + this.expectPlugin("exportDefaultFrom"); + const specifier = this.startNode(); + specifier.exported = placeholder; + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + return super.parseExport(node); } - parseMetaProperty(node, meta, propertyName) { - node.meta = meta; - - if (meta.name === "function" && propertyName === "sent") { - if (this.isContextual(propertyName)) { - this.expectPlugin("functionSent"); - } else if (!this.hasPlugin("functionSent")) { - this.unexpected(); - } + maybeParseExportDefaultSpecifier(node) { + if (node.specifiers && node.specifiers.length > 0) { + return true; } - const containsEsc = this.state.containsEsc; - node.property = this.parseIdentifier(true); + return super.maybeParseExportDefaultSpecifier(...arguments); + } - if (node.property.name !== propertyName || containsEsc) { - this.raise(node.property.start, `The only valid meta property for ${meta.name} is ${meta.name}.${propertyName}`); + checkExport(node) { + const { + specifiers + } = node; + + if (specifiers && specifiers.length) { + node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder"); } - return this.finishNode(node, "MetaProperty"); + super.checkExport(node); + node.specifiers = specifiers; } - parseImportMetaProperty() { - const node = this.startNode(); - const id = this.parseIdentifier(true); - this.expect(types.dot); + parseImport(node) { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseImport(...arguments); + node.specifiers = []; - if (id.name === "import") { - if (this.isContextual("meta")) { - this.expectPlugin("importMeta"); - } else if (!this.hasPlugin("importMeta")) { - this.raise(id.start, `Dynamic imports require a parameter: import('a.js')`); - } + if (!this.isContextual("from") && !this.match(types.comma)) { + node.source = this.finishPlaceholder(placeholder, "StringLiteral"); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); } - if (!this.inModule) { - this.raise(id.start, `import.meta may appear only with 'sourceType: "module"'`, { - code: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED" - }); - } + const specifier = this.startNodeAtNode(placeholder); + specifier.local = placeholder; + this.finishNode(specifier, "ImportDefaultSpecifier"); + node.specifiers.push(specifier); - this.sawUnambiguousESM = true; - return this.parseMetaProperty(node, id, "meta"); - } + if (this.eat(types.comma)) { + const hasStarImport = this.maybeParseStarImportSpecifier(node); + if (!hasStarImport) this.parseNamedImportSpecifiers(node); + } - parseLiteral(value, type, startPos, startLoc) { - startPos = startPos || this.state.start; - startLoc = startLoc || this.state.startLoc; - const node = this.startNodeAt(startPos, startLoc); - this.addExtra(node, "rawValue", value); - this.addExtra(node, "raw", this.state.input.slice(startPos, this.state.end)); - node.value = value; - this.next(); - return this.finishNode(node, type); + this.expectContextual("from"); + node.source = this.parseImportSource(); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); } - parseParenExpression() { - this.expect(types.parenL); - const val = this.parseExpression(); - this.expect(types.parenR); - return val; + parseImportSource() { + return this.parsePlaceholder("StringLiteral") || super.parseImportSource(...arguments); } - parseParenAndDistinguishExpression(canBeArrow) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - let val; - this.expect(types.parenL); - const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; - const oldYieldPos = this.state.yieldPos; - const oldAwaitPos = this.state.awaitPos; - this.state.maybeInArrowParameters = true; - this.state.yieldPos = 0; - this.state.awaitPos = 0; - const innerStartPos = this.state.start; - const innerStartLoc = this.state.startLoc; - const exprList = []; - const refShorthandDefaultPos = { - start: 0 - }; - const refNeedsArrowPos = { - start: 0 - }; - let first = true; - let spreadStart; - let optionalCommaStart; - - while (!this.match(types.parenR)) { - if (first) { - first = false; - } else { - this.expect(types.comma, refNeedsArrowPos.start || null); - - if (this.match(types.parenR)) { - optionalCommaStart = this.state.start; - break; - } - } +}); - if (this.match(types.ellipsis)) { - const spreadNodeStartPos = this.state.start; - const spreadNodeStartLoc = this.state.startLoc; - spreadStart = this.state.start; - exprList.push(this.parseParenItem(this.parseRest(), spreadNodeStartPos, spreadNodeStartLoc)); - this.checkCommaAfterRest(types.parenR, "parameter"); - break; - } else { - exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos)); - } +function hasPlugin(plugins, name) { + return plugins.some(plugin => { + if (Array.isArray(plugin)) { + return plugin[0] === name; + } else { + return plugin === name; } - - const innerEndPos = this.state.start; - const innerEndLoc = this.state.startLoc; - this.expect(types.parenR); - this.state.maybeInArrowParameters = oldMaybeInArrowParameters; - let arrowNode = this.startNodeAt(startPos, startLoc); - - if (canBeArrow && this.shouldParseArrow() && (arrowNode = this.parseArrow(arrowNode))) { - this.checkYieldAwaitInDefaultParams(); - this.state.yieldPos = oldYieldPos; - this.state.awaitPos = oldAwaitPos; - - for (let _i = 0; _i < exprList.length; _i++) { - const param = exprList[_i]; - - if (param.extra && param.extra.parenthesized) { - this.unexpected(param.extra.parenStart); - } - } - - this.parseArrowExpression(arrowNode, exprList, false); - return arrowNode; + }); +} +function getPluginOption(plugins, name, option) { + const plugin = plugins.find(plugin => { + if (Array.isArray(plugin)) { + return plugin[0] === name; + } else { + return plugin === name; } + }); - this.state.yieldPos = oldYieldPos || this.state.yieldPos; - this.state.awaitPos = oldAwaitPos || this.state.awaitPos; + if (plugin && Array.isArray(plugin)) { + return plugin[1][option]; + } - if (!exprList.length) { - this.unexpected(this.state.lastTokStart); + return null; +} +const PIPELINE_PROPOSALS = ["minimal", "smart"]; +function validatePlugins(plugins) { + if (hasPlugin(plugins, "decorators")) { + if (hasPlugin(plugins, "decorators-legacy")) { + throw new Error("Cannot use the decorators and decorators-legacy plugin together"); } - if (optionalCommaStart) this.unexpected(optionalCommaStart); - if (spreadStart) this.unexpected(spreadStart); + const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport"); - if (refShorthandDefaultPos.start) { - this.unexpected(refShorthandDefaultPos.start); + if (decoratorsBeforeExport == null) { + throw new Error("The 'decorators' plugin requires a 'decoratorsBeforeExport' option," + " whose value must be a boolean. If you are migrating from" + " Babylon/Babel 6 or want to use the old decorators proposal, you" + " should use the 'decorators-legacy' plugin instead of 'decorators'."); + } else if (typeof decoratorsBeforeExport !== "boolean") { + throw new Error("'decoratorsBeforeExport' must be a boolean."); } + } - if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start); - this.toReferencedListDeep(exprList, true); - - if (exprList.length > 1) { - val = this.startNodeAt(innerStartPos, innerStartLoc); - val.expressions = exprList; - this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); - } else { - val = exprList[0]; - } + if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) { + throw new Error("Cannot combine flow and typescript plugins."); + } - this.addExtra(val, "parenthesized", true); - this.addExtra(val, "parenStart", startPos); - return val; + if (hasPlugin(plugins, "pipelineOperator") && !PIPELINE_PROPOSALS.includes(getPluginOption(plugins, "pipelineOperator", "proposal"))) { + throw new Error("'pipelineOperator' requires 'proposal' option whose value should be one of: " + PIPELINE_PROPOSALS.map(p => `'${p}'`).join(", ")); } +} +const mixinPlugins = { + estree, + jsx, + flow, + typescript, + placeholders +}; +const mixinPluginNames = Object.keys(mixinPlugins); - shouldParseArrow() { - return !this.canInsertSemicolon(); +const defaultOptions = { + sourceType: "script", + sourceFilename: undefined, + startLine: 1, + allowAwaitOutsideFunction: false, + allowReturnOutsideFunction: false, + allowImportExportEverywhere: false, + allowSuperOutsideMethod: false, + plugins: [], + strictMode: null, + ranges: false, + tokens: false, + createParenthesizedExpressions: false +}; +function getOptions(opts) { + const options = {}; + + for (let _i = 0, _Object$keys = Object.keys(defaultOptions); _i < _Object$keys.length; _i++) { + const key = _Object$keys[_i]; + options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key]; } - parseArrow(node) { - if (this.eat(types.arrow)) { - return node; - } + return options; +} + +class Position { + constructor(line, col) { + this.line = line; + this.column = col; } - parseParenItem(node, startPos, startLoc) { - return node; +} +class SourceLocation { + constructor(start, end) { + this.start = start; + this.end = end; } - parseNew() { - const node = this.startNode(); - const meta = this.parseIdentifier(true); +} +function getLineInfo(input, offset) { + let line = 1; + let lineStart = 0; + let match; + lineBreakG.lastIndex = 0; - if (this.eat(types.dot)) { - const metaProp = this.parseMetaProperty(node, meta, "target"); + while ((match = lineBreakG.exec(input)) && match.index < offset) { + line++; + lineStart = lineBreakG.lastIndex; + } - if (!this.state.inFunction && !this.state.inClassProperty) { - let error = "new.target can only be used in functions"; + return new Position(line, offset - lineStart); +} - if (this.hasPlugin("classProperties")) { - error += " or class properties"; - } +class BaseParser { + constructor() { + this.sawUnambiguousESM = false; + } - this.raise(metaProp.start, error); - } + hasPlugin(name) { + return this.plugins.has(name); + } - return metaProp; - } + getPluginOption(plugin, name) { + if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name]; + } - node.callee = this.parseNoCallExpr(); - - if (node.callee.type === "Import") { - this.raise(node.callee.start, "Cannot use new with import(...)"); - } else if (node.callee.type === "OptionalMemberExpression" || node.callee.type === "OptionalCallExpression") { - this.raise(this.state.lastTokEnd, "constructors in/after an Optional Chain are not allowed"); - } else if (this.eat(types.questionDot)) { - this.raise(this.state.start, "constructors in/after an Optional Chain are not allowed"); - } +} - this.parseNewArguments(node); - return this.finishNode(node, "NewExpression"); - } +function last(stack) { + return stack[stack.length - 1]; +} - parseNewArguments(node) { - if (this.eat(types.parenL)) { - const args = this.parseExprList(types.parenR); - this.toReferencedList(args); - node.arguments = args; - } else { - node.arguments = []; - } +class CommentsParser extends BaseParser { + addComment(comment) { + if (this.filename) comment.loc.filename = this.filename; + this.state.trailingComments.push(comment); + this.state.leadingComments.push(comment); } - parseTemplateElement(isTagged) { - const elem = this.startNode(); + processComment(node) { + if (node.type === "Program" && node.body.length > 0) return; + const stack = this.state.commentStack; + let firstChild, lastChild, trailingComments, i, j; - if (this.state.value === null) { - if (!isTagged) { - this.raise(this.state.invalidTemplateEscapePosition || 0, "Invalid escape sequence in template"); + if (this.state.trailingComments.length > 0) { + if (this.state.trailingComments[0].start >= node.end) { + trailingComments = this.state.trailingComments; + this.state.trailingComments = []; } else { - this.state.invalidTemplateEscapePosition = null; + this.state.trailingComments.length = 0; } - } + } else if (stack.length > 0) { + const lastInStack = last(stack); - elem.value = { - raw: this.state.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"), - cooked: this.state.value - }; - this.next(); - elem.tail = this.match(types.backQuote); - return this.finishNode(elem, "TemplateElement"); - } + if (lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) { + trailingComments = lastInStack.trailingComments; + delete lastInStack.trailingComments; + } + } - parseTemplate(isTagged) { - const node = this.startNode(); - this.next(); - node.expressions = []; - let curElt = this.parseTemplateElement(isTagged); - node.quasis = [curElt]; + if (stack.length > 0 && last(stack).start >= node.start) { + firstChild = stack.pop(); + } - while (!curElt.tail) { - this.expect(types.dollarBraceL); - node.expressions.push(this.parseExpression()); - this.expect(types.braceR); - node.quasis.push(curElt = this.parseTemplateElement(isTagged)); + while (stack.length > 0 && last(stack).start >= node.start) { + lastChild = stack.pop(); } - this.next(); - return this.finishNode(node, "TemplateLiteral"); - } + if (!lastChild && firstChild) lastChild = firstChild; - parseObj(isPattern, refShorthandDefaultPos) { - let decorators = []; - const propHash = Object.create(null); - let first = true; - const node = this.startNode(); - node.properties = []; - this.next(); + if (firstChild && this.state.leadingComments.length > 0) { + const lastComment = last(this.state.leadingComments); - while (!this.eat(types.braceR)) { - if (first) { - first = false; - } else { - this.expect(types.comma); - if (this.eat(types.braceR)) break; - } + if (firstChild.type === "ObjectProperty") { + if (lastComment.start >= node.start) { + if (this.state.commentPreviousNode) { + for (j = 0; j < this.state.leadingComments.length; j++) { + if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) { + this.state.leadingComments.splice(j, 1); + j--; + } + } - if (this.match(types.at)) { - if (this.hasPlugin("decorators")) { - this.raise(this.state.start, "Stage 2 decorators disallow object literal property decorators"); - } else { - while (this.match(types.at)) { - decorators.push(this.parseDecorator()); + if (this.state.leadingComments.length > 0) { + firstChild.trailingComments = this.state.leadingComments; + this.state.leadingComments = []; + } } } - } - - let prop = this.startNode(), - isGenerator = false, - isAsync = false, - startPos, - startLoc; + } else if (node.type === "CallExpression" && node.arguments && node.arguments.length) { + const lastArg = last(node.arguments); - if (decorators.length) { - prop.decorators = decorators; - decorators = []; - } + if (lastArg && lastComment.start >= lastArg.start && lastComment.end <= node.end) { + if (this.state.commentPreviousNode) { + for (j = 0; j < this.state.leadingComments.length; j++) { + if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) { + this.state.leadingComments.splice(j, 1); + j--; + } + } - if (this.match(types.ellipsis)) { - prop = this.parseSpread(isPattern ? { - start: 0 - } : undefined); - node.properties.push(prop); - - if (isPattern) { - this.toAssignable(prop, true, "object pattern"); - this.checkCommaAfterRest(types.braceR, "property"); - this.expect(types.braceR); - break; + if (this.state.leadingComments.length > 0) { + lastArg.trailingComments = this.state.leadingComments; + this.state.leadingComments = []; + } + } } - - continue; - } - - prop.method = false; - - if (isPattern || refShorthandDefaultPos) { - startPos = this.state.start; - startLoc = this.state.startLoc; } + } - if (!isPattern) { - isGenerator = this.eat(types.star); + if (lastChild) { + if (lastChild.leadingComments) { + if (lastChild !== node && lastChild.leadingComments.length > 0 && last(lastChild.leadingComments).end <= node.start) { + node.leadingComments = lastChild.leadingComments; + delete lastChild.leadingComments; + } else { + for (i = lastChild.leadingComments.length - 2; i >= 0; --i) { + if (lastChild.leadingComments[i].end <= node.start) { + node.leadingComments = lastChild.leadingComments.splice(0, i + 1); + break; + } + } + } } + } else if (this.state.leadingComments.length > 0) { + if (last(this.state.leadingComments).end <= node.start) { + if (this.state.commentPreviousNode) { + for (j = 0; j < this.state.leadingComments.length; j++) { + if (this.state.leadingComments[j].end < this.state.commentPreviousNode.end) { + this.state.leadingComments.splice(j, 1); + j--; + } + } + } - const containsEsc = this.state.containsEsc; - - if (!isPattern && this.isContextual("async")) { - if (isGenerator) this.unexpected(); - const asyncId = this.parseIdentifier(); - - if (this.match(types.colon) || this.match(types.parenL) || this.match(types.braceR) || this.match(types.eq) || this.match(types.comma)) { - prop.key = asyncId; - prop.computed = false; - } else { - isAsync = true; - isGenerator = this.eat(types.star); - this.parsePropertyName(prop); + if (this.state.leadingComments.length > 0) { + node.leadingComments = this.state.leadingComments; + this.state.leadingComments = []; } } else { - this.parsePropertyName(prop); - } + for (i = 0; i < this.state.leadingComments.length; i++) { + if (this.state.leadingComments[i].end > node.start) { + break; + } + } - this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc); - this.checkPropClash(prop, propHash); + const leadingComments = this.state.leadingComments.slice(0, i); - if (prop.shorthand) { - this.addExtra(prop, "shorthand", true); - } + if (leadingComments.length) { + node.leadingComments = leadingComments; + } - node.properties.push(prop); - } + trailingComments = this.state.leadingComments.slice(i); - if (decorators.length) { - this.raise(this.state.start, "You have trailing decorators with no property"); + if (trailingComments.length === 0) { + trailingComments = null; + } + } } - return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); - } - - isGetterOrSetterMethod(prop, isPattern) { - return !isPattern && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.match(types.string) || this.match(types.num) || this.match(types.bracketL) || this.match(types.name) || !!this.state.type.keyword); - } - - checkGetterSetterParams(method) { - const paramCount = method.kind === "get" ? 0 : 1; - const start = method.start; + this.state.commentPreviousNode = node; - if (method.params.length !== paramCount) { - if (method.kind === "get") { - this.raise(start, "getter must not have any formal parameters"); + if (trailingComments) { + if (trailingComments.length && trailingComments[0].start >= node.start && last(trailingComments).end <= node.end) { + node.innerComments = trailingComments; } else { - this.raise(start, "setter must have exactly one formal parameter"); + node.trailingComments = trailingComments; } } - if (method.kind === "set" && method.params[0].type === "RestElement") { - this.raise(start, "setter function argument must not be a rest parameter"); - } + stack.push(node); } - parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) { - if (isAsync || isGenerator || this.match(types.parenL)) { - if (isPattern) this.unexpected(); - prop.kind = "method"; - prop.method = true; - return this.parseMethod(prop, isGenerator, isAsync, false, "ObjectMethod"); - } +} - if (!containsEsc && this.isGetterOrSetterMethod(prop, isPattern)) { - if (isGenerator || isAsync) this.unexpected(); - prop.kind = prop.key.name; - this.parsePropertyName(prop); - this.parseMethod(prop, false, false, false, "ObjectMethod"); - this.checkGetterSetterParams(prop); - return prop; - } +class LocationParser extends CommentsParser { + getLocationForPosition(pos) { + let loc; + if (pos === this.state.start) loc = this.state.startLoc;else if (pos === this.state.lastTokStart) loc = this.state.lastTokStartLoc;else if (pos === this.state.end) loc = this.state.endLoc;else if (pos === this.state.lastTokEnd) loc = this.state.lastTokEndLoc;else loc = getLineInfo(this.input, pos); + return loc; } - parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) { - prop.shorthand = false; + raise(pos, message, { + missingPluginNames, + code + } = {}) { + const loc = this.getLocationForPosition(pos); + message += ` (${loc.line}:${loc.column})`; + const err = new SyntaxError(message); + err.pos = pos; + err.loc = loc; - if (this.eat(types.colon)) { - prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos); - return this.finishNode(prop, "ObjectProperty"); + if (missingPluginNames) { + err.missingPlugin = missingPluginNames; } - if (!prop.computed && prop.key.type === "Identifier") { - this.checkReservedWord(prop.key.name, prop.key.start, true, true); + if (code !== undefined) { + err.code = code; + } - if (isPattern) { - prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); - } else if (this.match(types.eq) && refShorthandDefaultPos) { - if (!refShorthandDefaultPos.start) { - refShorthandDefaultPos.start = this.state.start; - } + throw err; + } - prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); - } else { - prop.value = prop.key.__clone(); - } +} - prop.shorthand = true; - return this.finishNode(prop, "ObjectProperty"); +class State { + constructor() { + this.potentialArrowAt = -1; + this.noArrowAt = []; + this.noArrowParamsConversionAt = []; + this.commaAfterSpreadAt = -1; + this.inParameters = false; + this.maybeInArrowParameters = false; + this.inPipeline = false; + this.inType = false; + this.noAnonFunctionType = false; + this.inPropertyName = false; + this.inClassProperty = false; + this.hasFlowComment = false; + this.isIterator = false; + this.topicContext = { + maxNumOfResolvableTopics: 0, + maxTopicIndex: null + }; + this.classLevel = 0; + this.labels = []; + this.decoratorStack = [[]]; + this.yieldPos = 0; + this.awaitPos = 0; + this.tokens = []; + this.comments = []; + this.trailingComments = []; + this.leadingComments = []; + this.commentStack = []; + this.commentPreviousNode = null; + this.pos = 0; + this.lineStart = 0; + this.type = types.eof; + this.value = null; + this.start = 0; + this.end = 0; + this.lastTokEndLoc = null; + this.lastTokStartLoc = null; + this.lastTokStart = 0; + this.lastTokEnd = 0; + this.context = [types$1.braceStatement]; + this.exprAllowed = true; + this.containsEsc = false; + this.containsOctal = false; + this.octalPosition = null; + this.exportedIdentifiers = []; + this.invalidTemplateEscapePosition = null; + } + + init(options) { + this.strict = options.strictMode === false ? false : options.sourceType === "module"; + this.curLine = options.startLine; + this.startLoc = this.endLoc = this.curPosition(); + } + + curPosition() { + return new Position(this.curLine, this.pos - this.lineStart); + } + + clone(skipArrays) { + const state = new State(); + const keys = Object.keys(this); + + for (let i = 0, length = keys.length; i < length; i++) { + const key = keys[i]; + let val = this[key]; + + if (!skipArrays && Array.isArray(val)) { + val = val.slice(); + } + + state[key] = val; } + + return state; } - parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc) { - const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos); - if (!node) this.unexpected(); - return node; +} + +var _isDigit = function isDigit(code) { + return code >= 48 && code <= 57; +}; +const VALID_REGEX_FLAGS = new Set(["g", "m", "s", "i", "y", "u"]); +const forbiddenNumericSeparatorSiblings = { + decBinOct: [46, 66, 69, 79, 95, 98, 101, 111], + hex: [46, 88, 95, 120] +}; +const allowedNumericSeparatorSiblings = {}; +allowedNumericSeparatorSiblings.bin = [48, 49]; +allowedNumericSeparatorSiblings.oct = [...allowedNumericSeparatorSiblings.bin, 50, 51, 52, 53, 54, 55]; +allowedNumericSeparatorSiblings.dec = [...allowedNumericSeparatorSiblings.oct, 56, 57]; +allowedNumericSeparatorSiblings.hex = [...allowedNumericSeparatorSiblings.dec, 65, 66, 67, 68, 69, 70, 97, 98, 99, 100, 101, 102]; +class Token { + constructor(state) { + this.type = state.type; + this.value = state.value; + this.start = state.start; + this.end = state.end; + this.loc = new SourceLocation(state.startLoc, state.endLoc); } - parsePropertyName(prop) { - if (this.eat(types.bracketL)) { - prop.computed = true; - prop.key = this.parseMaybeAssign(); - this.expect(types.bracketR); +} +class Tokenizer extends LocationParser { + constructor(options, input) { + super(); + this.state = new State(); + this.state.init(options); + this.input = input; + this.length = input.length; + this.isLookahead = false; + } + + next() { + if (this.options.tokens && !this.isLookahead) { + this.state.tokens.push(new Token(this.state)); + } + + this.state.lastTokEnd = this.state.end; + this.state.lastTokStart = this.state.start; + this.state.lastTokEndLoc = this.state.endLoc; + this.state.lastTokStartLoc = this.state.startLoc; + this.nextToken(); + } + + eat(type) { + if (this.match(type)) { + this.next(); + return true; } else { - const oldInPropertyName = this.state.inPropertyName; - this.state.inPropertyName = true; - prop.key = this.match(types.num) || this.match(types.string) ? this.parseExprAtom() : this.parseMaybePrivateName(); + return false; + } + } - if (prop.key.type !== "PrivateName") { - prop.computed = false; - } + match(type) { + return this.state.type === type; + } - this.state.inPropertyName = oldInPropertyName; + lookahead() { + const old = this.state; + this.state = old.clone(true); + this.isLookahead = true; + this.next(); + this.isLookahead = false; + const curr = this.state; + this.state = old; + return curr; + } + + setStrict(strict) { + this.state.strict = strict; + if (!this.match(types.num) && !this.match(types.string)) return; + this.state.pos = this.state.start; + + while (this.state.pos < this.state.lineStart) { + this.state.lineStart = this.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; + --this.state.curLine; } - return prop.key; + this.nextToken(); } - initFunction(node, isAsync) { - node.id = null; - node.generator = false; - node.async = !!isAsync; + curContext() { + return this.state.context[this.state.context.length - 1]; } - parseMethod(node, isGenerator, isAsync, isConstructor, type) { - const oldInFunc = this.state.inFunction; - const oldInMethod = this.state.inMethod; - const oldInAsync = this.state.inAsync; - const oldInGenerator = this.state.inGenerator; - const oldYieldPos = this.state.yieldPos; - const oldAwaitPos = this.state.awaitPos; - this.state.inFunction = true; - this.state.inMethod = node.kind || true; - this.state.inAsync = isAsync; - this.state.inGenerator = isGenerator; - this.state.yieldPos = 0; - this.state.awaitPos = 0; - this.initFunction(node, isAsync); - node.generator = !!isGenerator; - const allowModifiers = isConstructor; - this.parseFunctionParams(node, allowModifiers); - this.checkYieldAwaitInDefaultParams(); - this.parseFunctionBodyAndFinish(node, type); - this.state.inFunction = oldInFunc; - this.state.inMethod = oldInMethod; - this.state.inAsync = oldInAsync; - this.state.inGenerator = oldInGenerator; - this.state.yieldPos = oldYieldPos; - this.state.awaitPos = oldAwaitPos; - return node; + nextToken() { + const curContext = this.curContext(); + if (!curContext || !curContext.preserveSpace) this.skipSpace(); + this.state.containsOctal = false; + this.state.octalPosition = null; + this.state.start = this.state.pos; + this.state.startLoc = this.state.curPosition(); + + if (this.state.pos >= this.length) { + this.finishToken(types.eof); + return; + } + + if (curContext.override) { + curContext.override(this); + } else { + this.getTokenFromCode(this.input.codePointAt(this.state.pos)); + } } - parseArrowExpression(node, params, isAsync) { - this.initFunction(node, isAsync); - const oldInFunc = this.state.inFunction; - const oldInAsync = this.state.inAsync; - const oldInGenerator = this.state.inGenerator; - const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; - const oldYieldPos = this.state.yieldPos; - const oldAwaitPos = this.state.awaitPos; - this.state.inFunction = true; - this.state.inAsync = isAsync; - this.state.inGenerator = false; - this.state.maybeInArrowParameters = false; - this.state.yieldPos = 0; - this.state.awaitPos = 0; - if (params) this.setArrowFunctionParameters(node, params); - this.parseFunctionBody(node, true); - this.state.inAsync = oldInAsync; - this.state.inGenerator = oldInGenerator; - this.state.inFunction = oldInFunc; - this.state.maybeInArrowParameters = oldMaybeInArrowParameters; - this.state.yieldPos = oldYieldPos; - this.state.awaitPos = oldAwaitPos; - return this.finishNode(node, "ArrowFunctionExpression"); + pushComment(block, text, start, end, startLoc, endLoc) { + const comment = { + type: block ? "CommentBlock" : "CommentLine", + value: text, + start: start, + end: end, + loc: new SourceLocation(startLoc, endLoc) + }; + if (this.options.tokens) this.state.tokens.push(comment); + this.state.comments.push(comment); + this.addComment(comment); } - setArrowFunctionParameters(node, params) { - node.params = this.toAssignableList(params, true, "arrow function parameters"); + skipBlockComment() { + const startLoc = this.state.curPosition(); + const start = this.state.pos; + const end = this.input.indexOf("*/", this.state.pos += 2); + if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); + this.state.pos = end + 2; + lineBreakG.lastIndex = start; + let match; + + while ((match = lineBreakG.exec(this.input)) && match.index < this.state.pos) { + ++this.state.curLine; + this.state.lineStart = match.index + match[0].length; + } + + if (this.isLookahead) return; + this.pushComment(true, this.input.slice(start + 2, end), start, this.state.pos, startLoc, this.state.curPosition()); + } + + skipLineComment(startSkip) { + const start = this.state.pos; + const startLoc = this.state.curPosition(); + let ch = this.input.charCodeAt(this.state.pos += startSkip); + + if (this.state.pos < this.length) { + while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.length) { + ch = this.input.charCodeAt(this.state.pos); + } + } + + if (this.isLookahead) return; + this.pushComment(false, this.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition()); } - isStrictBody(node) { - const isBlockStatement = node.body.type === "BlockStatement"; + skipSpace() { + loop: while (this.state.pos < this.length) { + const ch = this.input.charCodeAt(this.state.pos); + + switch (ch) { + case 32: + case 160: + case 9: + ++this.state.pos; + break; + + case 13: + if (this.input.charCodeAt(this.state.pos + 1) === 10) { + ++this.state.pos; + } + + case 10: + case 8232: + case 8233: + ++this.state.pos; + ++this.state.curLine; + this.state.lineStart = this.state.pos; + break; + + case 47: + switch (this.input.charCodeAt(this.state.pos + 1)) { + case 42: + this.skipBlockComment(); + break; + + case 47: + this.skipLineComment(2); + break; + + default: + break loop; + } + + break; + + default: + if (isWhitespace(ch)) { + ++this.state.pos; + } else { + break loop; + } + + } + } + } + + finishToken(type, val) { + this.state.end = this.state.pos; + this.state.endLoc = this.state.curPosition(); + const prevType = this.state.type; + this.state.type = type; + this.state.value = val; + if (!this.isLookahead) this.updateContext(prevType); + } + + readToken_numberSign() { + if (this.state.pos === 0 && this.readToken_interpreter()) { + return; + } + + const nextPos = this.state.pos + 1; + const next = this.input.charCodeAt(nextPos); + + if (next >= 48 && next <= 57) { + this.raise(this.state.pos, "Unexpected digit after hash token"); + } + + if ((this.hasPlugin("classPrivateProperties") || this.hasPlugin("classPrivateMethods")) && this.state.classLevel > 0) { + ++this.state.pos; + this.finishToken(types.hash); + return; + } else if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { + this.finishOp(types.hash, 1); + } else { + this.raise(this.state.pos, "Unexpected character '#'"); + } + } + + readToken_dot() { + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next >= 48 && next <= 57) { + this.readNumber(true); + return; + } + + const next2 = this.input.charCodeAt(this.state.pos + 2); + + if (next === 46 && next2 === 46) { + this.state.pos += 3; + this.finishToken(types.ellipsis); + } else { + ++this.state.pos; + this.finishToken(types.dot); + } + } + + readToken_slash() { + if (this.state.exprAllowed && !this.state.inType) { + ++this.state.pos; + this.readRegexp(); + return; + } + + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next === 61) { + this.finishOp(types.assign, 2); + } else { + this.finishOp(types.slash, 1); + } + } + + readToken_interpreter() { + if (this.state.pos !== 0 || this.length < 2) return false; + const start = this.state.pos; + this.state.pos += 1; + let ch = this.input.charCodeAt(this.state.pos); + if (ch !== 33) return false; + + while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.length) { + ch = this.input.charCodeAt(this.state.pos); + } + + const value = this.input.slice(start + 2, this.state.pos); + this.finishToken(types.interpreterDirective, value); + return true; + } + + readToken_mult_modulo(code) { + let type = code === 42 ? types.star : types.modulo; + let width = 1; + let next = this.input.charCodeAt(this.state.pos + 1); + const exprAllowed = this.state.exprAllowed; + + if (code === 42 && next === 42) { + width++; + next = this.input.charCodeAt(this.state.pos + 2); + type = types.exponent; + } + + if (next === 61 && !exprAllowed) { + width++; + type = types.assign; + } + + this.finishOp(type, width); + } + + readToken_pipe_amp(code) { + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next === code) { + if (this.input.charCodeAt(this.state.pos + 2) === 61) { + this.finishOp(types.assign, 3); + } else { + this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2); + } + + return; + } + + if (code === 124) { + if (next === 62) { + this.finishOp(types.pipeline, 2); + return; + } + } + + if (next === 61) { + this.finishOp(types.assign, 2); + return; + } + + this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1); + } + + readToken_caret() { + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next === 61) { + this.finishOp(types.assign, 2); + } else { + this.finishOp(types.bitwiseXOR, 1); + } + } + + readToken_plus_min(code) { + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next === code) { + if (next === 45 && !this.inModule && this.input.charCodeAt(this.state.pos + 2) === 62 && (this.state.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos)))) { + this.skipLineComment(3); + this.skipSpace(); + this.nextToken(); + return; + } + + this.finishOp(types.incDec, 2); + return; + } + + if (next === 61) { + this.finishOp(types.assign, 2); + } else { + this.finishOp(types.plusMin, 1); + } + } + + readToken_lt_gt(code) { + const next = this.input.charCodeAt(this.state.pos + 1); + let size = 1; + + if (next === code) { + size = code === 62 && this.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2; + + if (this.input.charCodeAt(this.state.pos + size) === 61) { + this.finishOp(types.assign, size + 1); + return; + } + + this.finishOp(types.bitShift, size); + return; + } + + if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.state.pos + 2) === 45 && this.input.charCodeAt(this.state.pos + 3) === 45) { + this.skipLineComment(4); + this.skipSpace(); + this.nextToken(); + return; + } + + if (next === 61) { + size = 2; + } + + this.finishOp(types.relational, size); + } + + readToken_eq_excl(code) { + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next === 61) { + this.finishOp(types.equality, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2); + return; + } + + if (code === 61 && next === 62) { + this.state.pos += 2; + this.finishToken(types.arrow); + return; + } + + this.finishOp(code === 61 ? types.eq : types.bang, 1); + } + + readToken_question() { + const next = this.input.charCodeAt(this.state.pos + 1); + const next2 = this.input.charCodeAt(this.state.pos + 2); + + if (next === 63 && !this.state.inType) { + if (next2 === 61) { + this.finishOp(types.assign, 3); + } else { + this.finishOp(types.nullishCoalescing, 2); + } + } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) { + this.state.pos += 2; + this.finishToken(types.questionDot); + } else { + ++this.state.pos; + this.finishToken(types.question); + } + } + + getTokenFromCode(code) { + switch (code) { + case 46: + this.readToken_dot(); + return; + + case 40: + ++this.state.pos; + this.finishToken(types.parenL); + return; + + case 41: + ++this.state.pos; + this.finishToken(types.parenR); + return; + + case 59: + ++this.state.pos; + this.finishToken(types.semi); + return; + + case 44: + ++this.state.pos; + this.finishToken(types.comma); + return; + + case 91: + ++this.state.pos; + this.finishToken(types.bracketL); + return; + + case 93: + ++this.state.pos; + this.finishToken(types.bracketR); + return; + + case 123: + ++this.state.pos; + this.finishToken(types.braceL); + return; + + case 125: + ++this.state.pos; + this.finishToken(types.braceR); + return; + + case 58: + if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) { + this.finishOp(types.doubleColon, 2); + } else { + ++this.state.pos; + this.finishToken(types.colon); + } + + return; + + case 63: + this.readToken_question(); + return; + + case 96: + ++this.state.pos; + this.finishToken(types.backQuote); + return; + + case 48: + { + const next = this.input.charCodeAt(this.state.pos + 1); + + if (next === 120 || next === 88) { + this.readRadixNumber(16); + return; + } + + if (next === 111 || next === 79) { + this.readRadixNumber(8); + return; + } + + if (next === 98 || next === 66) { + this.readRadixNumber(2); + return; + } + } + + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + this.readNumber(false); + return; + + case 34: + case 39: + this.readString(code); + return; + + case 47: + this.readToken_slash(); + return; + + case 37: + case 42: + this.readToken_mult_modulo(code); + return; + + case 124: + case 38: + this.readToken_pipe_amp(code); + return; + + case 94: + this.readToken_caret(); + return; + + case 43: + case 45: + this.readToken_plus_min(code); + return; + + case 60: + case 62: + this.readToken_lt_gt(code); + return; + + case 61: + case 33: + this.readToken_eq_excl(code); + return; + + case 126: + this.finishOp(types.tilde, 1); + return; + + case 64: + ++this.state.pos; + this.finishToken(types.at); + return; + + case 35: + this.readToken_numberSign(); + return; - if (isBlockStatement && node.body.directives.length) { - for (let _i2 = 0, _node$body$directives = node.body.directives; _i2 < _node$body$directives.length; _i2++) { - const directive = _node$body$directives[_i2]; + case 92: + this.readWord(); + return; - if (directive.value.value === "use strict") { - return true; + default: + if (isIdentifierStart(code)) { + this.readWord(); + return; } - } + } - return false; + this.raise(this.state.pos, `Unexpected character '${String.fromCodePoint(code)}'`); } - parseFunctionBodyAndFinish(node, type, allowExpressionBody) { - this.parseFunctionBody(node, allowExpressionBody); - this.finishNode(node, type); + finishOp(type, size) { + const str = this.input.slice(this.state.pos, this.state.pos + size); + this.state.pos += size; + this.finishToken(type, str); } - parseFunctionBody(node, allowExpression) { - const isExpression = allowExpression && !this.match(types.braceL); - const oldInParameters = this.state.inParameters; - this.state.inParameters = false; - - if (isExpression) { - node.body = this.parseMaybeAssign(); - } else { - const oldInFunc = this.state.inFunction; - const oldLabels = this.state.labels; - this.state.inFunction = true; - this.state.labels = []; - node.body = this.parseBlock(true); - this.state.inFunction = oldInFunc; - this.state.labels = oldLabels; - } - - this.checkFunctionNameAndParams(node, allowExpression); - this.state.inParameters = oldInParameters; - } + readRegexp() { + const start = this.state.pos; + let escaped, inClass; - checkFunctionNameAndParams(node, isArrowFunction) { - const isStrict = this.isStrictBody(node); - const checkLVal = this.state.strict || isStrict || isArrowFunction; - const oldStrict = this.state.strict; - if (isStrict) this.state.strict = isStrict; + for (;;) { + if (this.state.pos >= this.length) { + this.raise(start, "Unterminated regular expression"); + } - if (checkLVal) { - const nameHash = Object.create(null); + const ch = this.input.charAt(this.state.pos); - if (node.id) { - this.checkLVal(node.id, true, undefined, "function name"); + if (lineBreak.test(ch)) { + this.raise(start, "Unterminated regular expression"); } - for (let _i3 = 0, _node$params = node.params; _i3 < _node$params.length; _i3++) { - const param = _node$params[_i3]; - - if (isStrict && param.type !== "Identifier") { - this.raise(param.start, "Non-simple parameter in strict mode"); + if (escaped) { + escaped = false; + } else { + if (ch === "[") { + inClass = true; + } else if (ch === "]" && inClass) { + inClass = false; + } else if (ch === "/" && !inClass) { + break; } - this.checkLVal(param, true, nameHash, "function parameter list"); + escaped = ch === "\\"; } + + ++this.state.pos; } - this.state.strict = oldStrict; - } + const content = this.input.slice(start, this.state.pos); + ++this.state.pos; + let mods = ""; - parseExprList(close, allowEmpty, refShorthandDefaultPos) { - const elts = []; - let first = true; + while (this.state.pos < this.length) { + const char = this.input[this.state.pos]; + const charCode = this.input.codePointAt(this.state.pos); - while (!this.eat(close)) { - if (first) { - first = false; + if (VALID_REGEX_FLAGS.has(char)) { + if (mods.indexOf(char) > -1) { + this.raise(this.state.pos + 1, "Duplicate regular expression flag"); + } + + ++this.state.pos; + mods += char; + } else if (isIdentifierChar(charCode) || charCode === 92) { + this.raise(this.state.pos + 1, "Invalid regular expression flag"); } else { - this.expect(types.comma); - if (this.eat(close)) break; + break; } - - elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos)); } - return elts; + this.finishToken(types.regexp, { + pattern: content, + flags: mods + }); } - parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos) { - let elt; - - if (allowEmpty && this.match(types.comma)) { - elt = null; - } else if (this.match(types.ellipsis)) { - const spreadNodeStartPos = this.state.start; - const spreadNodeStartLoc = this.state.startLoc; - elt = this.parseParenItem(this.parseSpread(refShorthandDefaultPos, refNeedsArrowPos), spreadNodeStartPos, spreadNodeStartLoc); - } else { - elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos); - } + readInt(radix, len) { + const start = this.state.pos; + const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct; + const allowedSiblings = radix === 16 ? allowedNumericSeparatorSiblings.hex : radix === 10 ? allowedNumericSeparatorSiblings.dec : radix === 8 ? allowedNumericSeparatorSiblings.oct : allowedNumericSeparatorSiblings.bin; + let total = 0; - return elt; - } + for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { + const code = this.input.charCodeAt(this.state.pos); + let val; - parseIdentifier(liberal) { - const node = this.startNode(); - const name = this.parseIdentifierName(node.start, liberal); - return this.createIdentifier(node, name); - } + if (this.hasPlugin("numericSeparator")) { + const prev = this.input.charCodeAt(this.state.pos - 1); + const next = this.input.charCodeAt(this.state.pos + 1); - createIdentifier(node, name) { - node.name = name; - node.loc.identifierName = name; - return this.finishNode(node, "Identifier"); - } + if (code === 95) { + if (allowedSiblings.indexOf(next) === -1) { + this.raise(this.state.pos, "Invalid or unexpected token"); + } - parseIdentifierName(pos, liberal) { - let name; + if (forbiddenSiblings.indexOf(prev) > -1 || forbiddenSiblings.indexOf(next) > -1 || Number.isNaN(next)) { + this.raise(this.state.pos, "Invalid or unexpected token"); + } - if (this.match(types.name)) { - name = this.state.value; - } else if (this.state.type.keyword) { - name = this.state.type.keyword; + ++this.state.pos; + continue; + } + } - if ((name === "class" || name === "function") && (this.state.lastTokEnd !== this.state.lastTokStart + 1 || this.state.input.charCodeAt(this.state.lastTokStart) !== 46)) { - this.state.context.pop(); + if (code >= 97) { + val = code - 97 + 10; + } else if (code >= 65) { + val = code - 65 + 10; + } else if (_isDigit(code)) { + val = code - 48; + } else { + val = Infinity; } - } else { - throw this.unexpected(); + + if (val >= radix) break; + ++this.state.pos; + total = total * radix + val; } - if (!liberal) { - this.checkReservedWord(name, this.state.start, !!this.state.type.keyword, false); + if (this.state.pos === start || len != null && this.state.pos - start !== len) { + return null; } - this.next(); - return name; + return total; } - checkReservedWord(word, startLoc, checkKeywords, isBinding) { - const state = this.state; + readRadixNumber(radix) { + const start = this.state.pos; + let isBigInt = false; + this.state.pos += 2; + const val = this.readInt(radix); - if (state.inGenerator && word === "yield") { - this.raise(startLoc, "Can not use 'yield' as identifier inside a generator"); + if (val == null) { + this.raise(this.state.start + 2, "Expected number in radix " + radix); } - if (state.inAsync && word === "await") { - this.raise(startLoc, "Can not use 'await' as identifier inside an async function"); + if (this.hasPlugin("bigInt")) { + if (this.input.charCodeAt(this.state.pos) === 110) { + ++this.state.pos; + isBigInt = true; + } } - if (state.inClassProperty && word === "arguments") { - this.raise(startLoc, "'arguments' is not allowed in class field initializer"); + if (isIdentifierStart(this.input.codePointAt(this.state.pos))) { + this.raise(this.state.pos, "Identifier directly after number"); } - if (checkKeywords && isKeyword(word)) { - this.raise(startLoc, `Unexpected keyword '${word}'`); + if (isBigInt) { + const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, ""); + this.finishToken(types.bigint, str); + return; } - const reservedTest = !state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord; + this.finishToken(types.num, val); + } - if (reservedTest(word, this.inModule)) { - if (!state.inAsync && word === "await") { - this.raise(startLoc, "Can not use keyword 'await' outside an async function"); - } + readNumber(startsWithDot) { + const start = this.state.pos; + let isFloat = false; + let isBigInt = false; - this.raise(startLoc, `Unexpected reserved word '${word}'`); + if (!startsWithDot && this.readInt(10) === null) { + this.raise(start, "Invalid number"); } - } - parseAwait() { - if (!this.state.awaitPos) { - this.state.awaitPos = this.state.start; + let octal = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48; + + if (octal) { + if (this.state.strict) { + this.raise(start, "Legacy octal literals are not allowed in strict mode"); + } + + if (/[89]/.test(this.input.slice(start, this.state.pos))) { + octal = false; + } } - const node = this.startNode(); - this.next(); + let next = this.input.charCodeAt(this.state.pos); - if (this.state.inParameters) { - this.raise(node.start, "await is not allowed in async function parameters"); + if (next === 46 && !octal) { + ++this.state.pos; + this.readInt(10); + isFloat = true; + next = this.input.charCodeAt(this.state.pos); } - if (this.match(types.star)) { - this.raise(node.start, "await* has been removed from the async functions proposal. Use Promise.all() instead."); + if ((next === 69 || next === 101) && !octal) { + next = this.input.charCodeAt(++this.state.pos); + + if (next === 43 || next === 45) { + ++this.state.pos; + } + + if (this.readInt(10) === null) this.raise(start, "Invalid number"); + isFloat = true; + next = this.input.charCodeAt(this.state.pos); } - node.argument = this.parseMaybeUnary(); - return this.finishNode(node, "AwaitExpression"); - } + if (this.hasPlugin("bigInt")) { + if (next === 110) { + if (isFloat || octal) this.raise(start, "Invalid BigIntLiteral"); + ++this.state.pos; + isBigInt = true; + } + } - parseYield(noIn) { - if (!this.state.yieldPos) { - this.state.yieldPos = this.state.start; + if (isIdentifierStart(this.input.codePointAt(this.state.pos))) { + this.raise(this.state.pos, "Identifier directly after number"); } - const node = this.startNode(); + const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, ""); - if (this.state.inParameters) { - this.raise(node.start, "yield is not allowed in generator parameters"); + if (isBigInt) { + this.finishToken(types.bigint, str); + return; } - this.next(); + const val = octal ? parseInt(str, 8) : parseFloat(str); + this.finishToken(types.num, val); + } + + readCodePoint(throwOnInvalid) { + const ch = this.input.charCodeAt(this.state.pos); + let code; + + if (ch === 123) { + const codePos = ++this.state.pos; + code = this.readHexChar(this.input.indexOf("}", this.state.pos) - this.state.pos, throwOnInvalid); + ++this.state.pos; - if (this.match(types.semi) || !this.match(types.star) && !this.state.type.startsExpr || this.canInsertSemicolon()) { - node.delegate = false; - node.argument = null; + if (code === null) { + --this.state.invalidTemplateEscapePosition; + } else if (code > 0x10ffff) { + if (throwOnInvalid) { + this.raise(codePos, "Code point out of bounds"); + } else { + this.state.invalidTemplateEscapePosition = codePos - 2; + return null; + } + } } else { - node.delegate = this.eat(types.star); - node.argument = this.parseMaybeAssign(noIn); + code = this.readHexChar(4, throwOnInvalid); } - return this.finishNode(node, "YieldExpression"); + return code; } - checkPipelineAtInfixOperator(left, leftStartPos) { - if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { - if (left.type === "SequenceExpression") { - throw this.raise(leftStartPos, `Pipeline head should not be a comma-separated sequence expression`); + readString(quote) { + let out = "", + chunkStart = ++this.state.pos; + + for (;;) { + if (this.state.pos >= this.length) { + this.raise(this.state.start, "Unterminated string constant"); } - } - } - parseSmartPipelineBody(childExpression, startPos, startLoc) { - const pipelineStyle = this.checkSmartPipelineBodyStyle(childExpression); - this.checkSmartPipelineBodyEarlyErrors(childExpression, pipelineStyle, startPos); - return this.parseSmartPipelineBodyInStyle(childExpression, pipelineStyle, startPos, startLoc); - } + const ch = this.input.charCodeAt(this.state.pos); + if (ch === quote) break; - checkSmartPipelineBodyEarlyErrors(childExpression, pipelineStyle, startPos) { - if (this.match(types.arrow)) { - throw this.raise(this.state.start, `Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized`); - } else if (pipelineStyle === "PipelineTopicExpression" && childExpression.type === "SequenceExpression") { - throw this.raise(startPos, `Pipeline body may not be a comma-separated sequence expression`); + if (ch === 92) { + out += this.input.slice(chunkStart, this.state.pos); + out += this.readEscapedChar(false); + chunkStart = this.state.pos; + } else if (ch === 8232 || ch === 8233) { + ++this.state.pos; + ++this.state.curLine; + } else if (isNewLine(ch)) { + this.raise(this.state.start, "Unterminated string constant"); + } else { + ++this.state.pos; + } } + + out += this.input.slice(chunkStart, this.state.pos++); + this.finishToken(types.string, out); } - parseSmartPipelineBodyInStyle(childExpression, pipelineStyle, startPos, startLoc) { - const bodyNode = this.startNodeAt(startPos, startLoc); + readTmplToken() { + let out = "", + chunkStart = this.state.pos, + containsInvalid = false; - switch (pipelineStyle) { - case "PipelineBareFunction": - bodyNode.callee = childExpression; - break; + for (;;) { + if (this.state.pos >= this.length) { + this.raise(this.state.start, "Unterminated template"); + } - case "PipelineBareConstructor": - bodyNode.callee = childExpression.callee; - break; + const ch = this.input.charCodeAt(this.state.pos); - case "PipelineBareAwaitedFunction": - bodyNode.callee = childExpression.argument; - break; + if (ch === 96 || ch === 36 && this.input.charCodeAt(this.state.pos + 1) === 123) { + if (this.state.pos === this.state.start && this.match(types.template)) { + if (ch === 36) { + this.state.pos += 2; + this.finishToken(types.dollarBraceL); + return; + } else { + ++this.state.pos; + this.finishToken(types.backQuote); + return; + } + } - case "PipelineTopicExpression": - if (!this.topicReferenceWasUsedInCurrentTopicContext()) { - throw this.raise(startPos, `Pipeline is in topic style but does not use topic reference`); + out += this.input.slice(chunkStart, this.state.pos); + this.finishToken(types.template, containsInvalid ? null : out); + return; + } + + if (ch === 92) { + out += this.input.slice(chunkStart, this.state.pos); + const escaped = this.readEscapedChar(true); + + if (escaped === null) { + containsInvalid = true; + } else { + out += escaped; } - bodyNode.expression = childExpression; - break; + chunkStart = this.state.pos; + } else if (isNewLine(ch)) { + out += this.input.slice(chunkStart, this.state.pos); + ++this.state.pos; - default: - throw this.raise(startPos, `Unknown pipeline style ${pipelineStyle}`); - } + switch (ch) { + case 13: + if (this.input.charCodeAt(this.state.pos) === 10) { + ++this.state.pos; + } - return this.finishNode(bodyNode, pipelineStyle); - } + case 10: + out += "\n"; + break; - checkSmartPipelineBodyStyle(expression) { - switch (expression.type) { - default: - return this.isSimpleReference(expression) ? "PipelineBareFunction" : "PipelineTopicExpression"; + default: + out += String.fromCharCode(ch); + break; + } + + ++this.state.curLine; + this.state.lineStart = this.state.pos; + chunkStart = this.state.pos; + } else { + ++this.state.pos; + } } } - isSimpleReference(expression) { - switch (expression.type) { - case "MemberExpression": - return !expression.computed && this.isSimpleReference(expression.object); + readEscapedChar(inTemplate) { + const throwOnInvalid = !inTemplate; + const ch = this.input.charCodeAt(++this.state.pos); + ++this.state.pos; - case "Identifier": - return true; + switch (ch) { + case 110: + return "\n"; - default: - return false; - } - } + case 114: + return "\r"; - withTopicPermittingContext(callback) { - const outerContextTopicState = this.state.topicContext; - this.state.topicContext = { - maxNumOfResolvableTopics: 1, - maxTopicIndex: null - }; + case 120: + { + const code = this.readHexChar(2, throwOnInvalid); + return code === null ? null : String.fromCharCode(code); + } - try { - return callback(); - } finally { - this.state.topicContext = outerContextTopicState; - } - } + case 117: + { + const code = this.readCodePoint(throwOnInvalid); + return code === null ? null : String.fromCodePoint(code); + } - withTopicForbiddingContext(callback) { - const outerContextTopicState = this.state.topicContext; - this.state.topicContext = { - maxNumOfResolvableTopics: 0, - maxTopicIndex: null - }; + case 116: + return "\t"; - try { - return callback(); - } finally { - this.state.topicContext = outerContextTopicState; - } - } + case 98: + return "\b"; - registerTopicReference() { - this.state.topicContext.maxTopicIndex = 0; - } + case 118: + return "\u000b"; - primaryTopicReferenceIsAllowedInCurrentTopicContext() { - return this.state.topicContext.maxNumOfResolvableTopics >= 1; - } + case 102: + return "\f"; - topicReferenceWasUsedInCurrentTopicContext() { - return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0; - } + case 13: + if (this.input.charCodeAt(this.state.pos) === 10) { + ++this.state.pos; + } -} + case 10: + this.state.lineStart = this.state.pos; + ++this.state.curLine; -const empty = []; -const loopLabel = { - kind: "loop" -}; -const switchLabel = { - kind: "switch" -}; -class StatementParser extends ExpressionParser { - parseTopLevel(file, program) { - program.sourceType = this.options.sourceType; - program.interpreter = this.parseInterpreterDirective(); - this.parseBlockBody(program, true, true, types.eof); - file.program = this.finishNode(program, "Program"); - file.comments = this.state.comments; - if (this.options.tokens) file.tokens = this.state.tokens; - return this.finishNode(file, "File"); - } + case 8232: + case 8233: + return ""; - stmtToDirective(stmt) { - const expr = stmt.expression; - const directiveLiteral = this.startNodeAt(expr.start, expr.loc.start); - const directive = this.startNodeAt(stmt.start, stmt.loc.start); - const raw = this.state.input.slice(expr.start, expr.end); - const val = directiveLiteral.value = raw.slice(1, -1); - this.addExtra(directiveLiteral, "raw", raw); - this.addExtra(directiveLiteral, "rawValue", val); - directive.value = this.finishNodeAt(directiveLiteral, "DirectiveLiteral", expr.end, expr.loc.end); - return this.finishNodeAt(directive, "Directive", stmt.end, stmt.loc.end); - } + default: + if (ch >= 48 && ch <= 55) { + const codePos = this.state.pos - 1; + let octalStr = this.input.substr(this.state.pos - 1, 3).match(/^[0-7]+/)[0]; + let octal = parseInt(octalStr, 8); - parseInterpreterDirective() { - if (!this.match(types.interpreterDirective)) { - return null; - } + if (octal > 255) { + octalStr = octalStr.slice(0, -1); + octal = parseInt(octalStr, 8); + } + + this.state.pos += octalStr.length - 1; + const next = this.input.charCodeAt(this.state.pos); + + if (octalStr !== "0" || next === 56 || next === 57) { + if (inTemplate) { + this.state.invalidTemplateEscapePosition = codePos; + return null; + } else if (this.state.strict) { + this.raise(codePos, "Octal literal in strict mode"); + } else if (!this.state.containsOctal) { + this.state.containsOctal = true; + this.state.octalPosition = codePos; + } + } - const node = this.startNode(); - node.value = this.state.value; - this.next(); - return this.finishNode(node, "InterpreterDirective"); - } + return String.fromCharCode(octal); + } - isLet(context) { - if (!this.isContextual("let")) { - return false; + return String.fromCharCode(ch); } + } - skipWhiteSpace.lastIndex = this.state.pos; - const skip = skipWhiteSpace.exec(this.state.input); - const next = this.state.pos + skip[0].length; - const nextCh = this.state.input.charCodeAt(next); - if (nextCh === 91) return true; - if (context) return false; - if (nextCh === 123) return true; - - if (isIdentifierStart(nextCh)) { - let pos = next + 1; + readHexChar(len, throwOnInvalid) { + const codePos = this.state.pos; + const n = this.readInt(16, len); - while (isIdentifierChar(this.state.input.charCodeAt(pos))) { - ++pos; + if (n === null) { + if (throwOnInvalid) { + this.raise(codePos, "Bad character escape sequence"); + } else { + this.state.pos = codePos - 1; + this.state.invalidTemplateEscapePosition = codePos - 1; } - - const ident = this.state.input.slice(next, pos); - if (!keywordRelationalOperator.test(ident)) return true; } - return false; + return n; } - parseStatement(context, topLevel) { - if (this.match(types.at)) { - this.parseDecorators(true); - } + readWord1() { + let word = ""; + this.state.containsEsc = false; + const start = this.state.pos; + let chunkStart = this.state.pos; - return this.parseStatementContent(context, topLevel); - } + while (this.state.pos < this.length) { + const ch = this.input.codePointAt(this.state.pos); - parseStatementContent(context, topLevel) { - let starttype = this.state.type; - const node = this.startNode(); - let kind; + if (isIdentifierChar(ch)) { + this.state.pos += ch <= 0xffff ? 1 : 2; + } else if (this.state.isIterator && ch === 64) { + ++this.state.pos; + } else if (ch === 92) { + this.state.containsEsc = true; + word += this.input.slice(chunkStart, this.state.pos); + const escStart = this.state.pos; + const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar; - if (this.isLet(context)) { - starttype = types._var; - kind = "let"; - } + if (this.input.charCodeAt(++this.state.pos) !== 117) { + this.raise(this.state.pos, "Expecting Unicode escape sequence \\uXXXX"); + } - switch (starttype) { - case types._break: - case types._continue: - return this.parseBreakContinueStatement(node, starttype.keyword); + ++this.state.pos; + const esc = this.readCodePoint(true); - case types._debugger: - return this.parseDebuggerStatement(node); + if (!identifierCheck(esc, true)) { + this.raise(escStart, "Invalid Unicode escape"); + } - case types._do: - return this.parseDoStatement(node); + word += String.fromCodePoint(esc); + chunkStart = this.state.pos; + } else { + break; + } + } - case types._for: - return this.parseForStatement(node); + return word + this.input.slice(chunkStart, this.state.pos); + } - case types._function: - { - if (this.lookahead().type === types.dot) break; + isIterator(word) { + return word === "@@iterator" || word === "@@asyncIterator"; + } - if (context && (this.state.strict || context !== "if" && context !== "label")) { - this.raise(this.state.start, "Function declaration not allowed in this context"); - } + readWord() { + const word = this.readWord1(); + const type = keywords.get(word) || types.name; - const result = this.parseFunctionStatement(node); + if (type.keyword && this.state.containsEsc) { + this.raise(this.state.pos, `Escape sequence in keyword ${word}`); + } - if (context && result.generator) { - this.unexpected(node.start); - } + if (this.state.isIterator && (!this.isIterator(word) || !this.state.inType)) { + this.raise(this.state.pos, `Invalid identifier ${word}`); + } - return result; - } + this.finishToken(type, word); + } - case types._class: - if (context) this.unexpected(); - return this.parseClass(node, true); + braceIsBlock(prevType) { + const parent = this.curContext(); - case types._if: - return this.parseIfStatement(node); + if (parent === types$1.functionExpression || parent === types$1.functionStatement) { + return true; + } - case types._return: - return this.parseReturnStatement(node); + if (prevType === types.colon && (parent === types$1.braceStatement || parent === types$1.braceExpression)) { + return !parent.isExpr; + } - case types._switch: - return this.parseSwitchStatement(node); + if (prevType === types._return || prevType === types.name && this.state.exprAllowed) { + return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)); + } - case types._throw: - return this.parseThrowStatement(node); + if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) { + return true; + } - case types._try: - return this.parseTryStatement(node); + if (prevType === types.braceL) { + return parent === types$1.braceStatement; + } - case types._const: - case types._var: - kind = kind || this.state.value; - if (context && kind !== "var") this.unexpected(); - return this.parseVarStatement(node, kind); + if (prevType === types._var || prevType === types._const || prevType === types.name) { + return false; + } - case types._while: - return this.parseWhileStatement(node); + if (prevType === types.relational) { + return true; + } - case types._with: - return this.parseWithStatement(node); + return !this.state.exprAllowed; + } - case types.braceL: - return this.parseBlock(); + updateContext(prevType) { + const type = this.state.type; + let update; - case types.semi: - return this.parseEmptyStatement(node); + if (type.keyword && (prevType === types.dot || prevType === types.questionDot)) { + this.state.exprAllowed = false; + } else if (update = type.updateContext) { + update.call(this, prevType); + } else { + this.state.exprAllowed = type.beforeExpr; + } + } - case types._export: - case types._import: - { - const nextToken = this.lookahead(); +} - if (nextToken.type === types.parenL || nextToken.type === types.dot) { - break; - } +const literal = /^('|")((?:\\?.)*?)\1/; +class UtilParser extends Tokenizer { + addExtra(node, key, val) { + if (!node) return; + const extra = node.extra = node.extra || {}; + extra[key] = val; + } - if (!this.options.allowImportExportEverywhere && !topLevel) { - this.raise(this.state.start, "'import' and 'export' may only appear at the top level"); - } + isRelational(op) { + return this.match(types.relational) && this.state.value === op; + } - this.next(); - let result; + isLookaheadRelational(op) { + const l = this.lookahead(); + return l.type === types.relational && l.value === op; + } - if (starttype === types._import) { - result = this.parseImport(node); + expectRelational(op) { + if (this.isRelational(op)) { + this.next(); + } else { + this.unexpected(null, types.relational); + } + } - if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) { - this.sawUnambiguousESM = true; - } - } else { - result = this.parseExport(node); + eatRelational(op) { + if (this.isRelational(op)) { + this.next(); + return true; + } - if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") { - this.sawUnambiguousESM = true; - } - } + return false; + } - this.assertModuleNodeAllowed(node); - return result; - } + isContextual(name) { + return this.match(types.name) && this.state.value === name && !this.state.containsEsc; + } - case types.name: - if (this.isContextual("async")) { - const state = this.state.clone(); - this.next(); + isLookaheadContextual(name) { + const l = this.lookahead(); + return l.type === types.name && l.value === name; + } - if (this.match(types._function) && !this.canInsertSemicolon()) { - if (context) { - this.raise(this.state.lastTokStart, "Function declaration not allowed in this context"); - } + eatContextual(name) { + return this.isContextual(name) && this.eat(types.name); + } - this.next(); - return this.parseFunction(node, true, false, true); - } else { - this.state = state; - } - } + expectContextual(name, message) { + if (!this.eatContextual(name)) this.unexpected(null, message); + } - } + canInsertSemicolon() { + return this.match(types.eof) || this.match(types.braceR) || this.hasPrecedingLineBreak(); + } - const maybeName = this.state.value; - const expr = this.parseExpression(); + hasPrecedingLineBreak() { + return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)); + } - if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon)) { - return this.parseLabeledStatement(node, maybeName, expr, context); - } else { - return this.parseExpressionStatement(node, expr); - } + isLineTerminator() { + return this.eat(types.semi) || this.canInsertSemicolon(); } - assertModuleNodeAllowed(node) { - if (!this.options.allowImportExportEverywhere && !this.inModule) { - this.raise(node.start, `'import' and 'export' may appear only with 'sourceType: "module"'`, { - code: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED" - }); - } + semicolon() { + if (!this.isLineTerminator()) this.unexpected(null, types.semi); } - takeDecorators(node) { - const decorators = this.state.decoratorStack[this.state.decoratorStack.length - 1]; + expect(type, pos) { + this.eat(type) || this.unexpected(pos, type); + } - if (decorators.length) { - node.decorators = decorators; - this.resetStartLocationFromNode(node, decorators[0]); - this.state.decoratorStack[this.state.decoratorStack.length - 1] = []; + assertNoSpace(message = "Unexpected space.") { + if (this.state.start > this.state.lastTokEnd) { + this.raise(this.state.lastTokEnd, message); } } - canHaveLeadingDecorator() { - return this.match(types._class); - } + unexpected(pos, messageOrType = "Unexpected token") { + if (typeof messageOrType !== "string") { + messageOrType = `Unexpected token, expected "${messageOrType.label}"`; + } - parseDecorators(allowExport) { - const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1]; + throw this.raise(pos != null ? pos : this.state.start, messageOrType); + } - while (this.match(types.at)) { - const decorator = this.parseDecorator(); - currentContextDecorators.push(decorator); + expectPlugin(name, pos) { + if (!this.hasPlugin(name)) { + throw this.raise(pos != null ? pos : this.state.start, `This experimental syntax requires enabling the parser plugin: '${name}'`, { + missingPluginNames: [name] + }); } - if (this.match(types._export)) { - if (!allowExport) { - this.unexpected(); - } + return true; + } - if (this.hasPlugin("decorators") && !this.getPluginOption("decorators", "decoratorsBeforeExport")) { - this.raise(this.state.start, "Using the export keyword between a decorator and a class is not allowed. " + "Please use `export @dec class` instead."); - } - } else if (!this.canHaveLeadingDecorator()) { - this.raise(this.state.start, "Leading decorators must be attached to a class declaration"); + expectOnePlugin(names, pos) { + if (!names.some(n => this.hasPlugin(n))) { + throw this.raise(pos != null ? pos : this.state.start, `This experimental syntax requires enabling one of the following parser plugin(s): '${names.join(", ")}'`, { + missingPluginNames: names + }); } } - parseDecorator() { - this.expectOnePlugin(["decorators-legacy", "decorators"]); - const node = this.startNode(); - this.next(); + checkYieldAwaitInDefaultParams() { + if (this.state.yieldPos && (!this.state.awaitPos || this.state.yieldPos < this.state.awaitPos)) { + this.raise(this.state.yieldPos, "Yield cannot be used as name inside a generator function"); + } - if (this.hasPlugin("decorators")) { - this.state.decoratorStack.push([]); - const startPos = this.state.start; - const startLoc = this.state.startLoc; - let expr; + if (this.state.awaitPos) { + this.raise(this.state.awaitPos, "Await cannot be used as name inside an async function"); + } + } - if (this.eat(types.parenL)) { - expr = this.parseExpression(); - this.expect(types.parenR); - } else { - expr = this.parseIdentifier(false); + strictDirective(start) { + for (;;) { + skipWhiteSpace.lastIndex = start; + start += skipWhiteSpace.exec(this.input)[0].length; + const match = literal.exec(this.input.slice(start)); + if (!match) break; + if (match[2] === "use strict") return true; + start += match[0].length; + skipWhiteSpace.lastIndex = start; + start += skipWhiteSpace.exec(this.input)[0].length; - while (this.eat(types.dot)) { - const node = this.startNodeAt(startPos, startLoc); - node.object = expr; - node.property = this.parseIdentifier(true); - node.computed = false; - expr = this.finishNode(node, "MemberExpression"); - } + if (this.input[start] === ";") { + start++; } - - node.expression = this.parseMaybeDecoratorArguments(expr); - this.state.decoratorStack.pop(); - } else { - node.expression = this.parseMaybeAssign(); } - return this.finishNode(node, "Decorator"); + return false; } - parseMaybeDecoratorArguments(expr) { - if (this.eat(types.parenL)) { - const node = this.startNodeAtNode(expr); - node.callee = expr; - node.arguments = this.parseCallExpressionArguments(types.parenR, false); - this.toReferencedList(node.arguments); - return this.finishNode(node, "CallExpression"); - } +} - return expr; +class Node { + constructor(parser, pos, loc) { + this.type = ""; + this.start = pos; + this.end = 0; + this.loc = new SourceLocation(loc); + if (parser && parser.options.ranges) this.range = [pos, 0]; + if (parser && parser.filename) this.loc.filename = parser.filename; } - parseBreakContinueStatement(node, keyword) { - const isBreak = keyword === "break"; - this.next(); - - if (this.isLineTerminator()) { - node.label = null; - } else if (!this.match(types.name)) { - this.unexpected(); - } else { - node.label = this.parseIdentifier(); - this.semicolon(); - } - - let i; + __clone() { + const newNode = new Node(); + const keys = Object.keys(this); - for (i = 0; i < this.state.labels.length; ++i) { - const lab = this.state.labels[i]; + for (let i = 0, length = keys.length; i < length; i++) { + const key = keys[i]; - if (node.label == null || lab.name === node.label.name) { - if (lab.kind != null && (isBreak || lab.kind === "loop")) break; - if (node.label && isBreak) break; + if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") { + newNode[key] = this[key]; } } - if (i === this.state.labels.length) { - this.raise(node.start, "Unsyntactic " + keyword); - } + return newNode; + } - return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); +} + +class NodeUtils extends UtilParser { + startNode() { + return new Node(this, this.state.start, this.state.startLoc); } - parseDebuggerStatement(node) { - this.next(); - this.semicolon(); - return this.finishNode(node, "DebuggerStatement"); + startNodeAt(pos, loc) { + return new Node(this, pos, loc); } - parseDoStatement(node) { - this.next(); - this.state.labels.push(loopLabel); - node.body = this.withTopicForbiddingContext(() => this.parseStatement("do")); - this.state.labels.pop(); - this.expect(types._while); - node.test = this.parseParenExpression(); - this.eat(types.semi); - return this.finishNode(node, "DoWhileStatement"); + startNodeAtNode(type) { + return this.startNodeAt(type.start, type.loc.start); } - parseForStatement(node) { - this.next(); - this.state.labels.push(loopLabel); - let awaitAt = -1; + finishNode(node, type) { + return this.finishNodeAt(node, type, this.state.lastTokEnd, this.state.lastTokEndLoc); + } - if ((this.state.inAsync || !this.state.inFunction && this.options.allowAwaitOutsideFunction) && this.eatContextual("await")) { - awaitAt = this.state.lastTokStart; - } + finishNodeAt(node, type, pos, loc) { - this.expect(types.parenL); + node.type = type; + node.end = pos; + node.loc.end = loc; + if (this.options.ranges) node.range[1] = pos; + this.processComment(node); + return node; + } - if (this.match(types.semi)) { - if (awaitAt > -1) { - this.unexpected(awaitAt); - } + resetStartLocation(node, start, startLoc) { + node.start = start; + node.loc.start = startLoc; + if (this.options.ranges) node.range[0] = start; + } - return this.parseFor(node, null); - } + resetEndLocation(node, end = this.state.lastTokEnd, endLoc = this.state.lastTokEndLoc) { + node.end = end; + node.loc.end = endLoc; + if (this.options.ranges) node.range[1] = end; + } - const isLet = this.isLet(); + resetStartLocationFromNode(node, locationNode) { + this.resetStartLocation(node, locationNode.start, locationNode.loc.start); + } - if (this.match(types._var) || this.match(types._const) || isLet) { - const init = this.startNode(); - const kind = isLet ? "let" : this.state.value; - this.next(); - this.parseVar(init, true, kind); - this.finishNode(init, "VariableDeclaration"); +} + +class LValParser extends NodeUtils { + toAssignable(node, isBinding, contextDescription) { + if (node) { + switch (node.type) { + case "Identifier": + case "ObjectPattern": + case "ArrayPattern": + case "AssignmentPattern": + break; - if (this.match(types._in) || this.isContextual("of")) { - if (init.declarations.length === 1) { - const declaration = init.declarations[0]; - const isForInInitializer = kind === "var" && declaration.init && declaration.id.type != "ObjectPattern" && declaration.id.type != "ArrayPattern" && !this.isContextual("of"); + case "ObjectExpression": + node.type = "ObjectPattern"; - if (this.state.strict && isForInInitializer) { - this.raise(this.state.start, "for-in initializer in strict mode"); - } else if (isForInInitializer || !declaration.init) { - return this.parseForIn(node, init, awaitAt); + for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) { + const prop = node.properties[i]; + const isLast = i === last; + this.toAssignableObjectExpressionProp(prop, isBinding, isLast); } - } - } - - if (awaitAt > -1) { - this.unexpected(awaitAt); - } - return this.parseFor(node, init); - } + break; - const refShorthandDefaultPos = { - start: 0 - }; - const init = this.parseExpression(true, refShorthandDefaultPos); + case "ObjectProperty": + this.toAssignable(node.value, isBinding, contextDescription); + break; - if (this.match(types._in) || this.isContextual("of")) { - const description = this.isContextual("of") ? "for-of statement" : "for-in statement"; - this.toAssignable(init, undefined, description); - this.checkLVal(init, undefined, undefined, description); - return this.parseForIn(node, init, awaitAt); - } else if (refShorthandDefaultPos.start) { - this.unexpected(refShorthandDefaultPos.start); - } + case "SpreadElement": + { + this.checkToRestConversion(node); + node.type = "RestElement"; + const arg = node.argument; + this.toAssignable(arg, isBinding, contextDescription); + break; + } - if (awaitAt > -1) { - this.unexpected(awaitAt); - } + case "ArrayExpression": + node.type = "ArrayPattern"; + this.toAssignableList(node.elements, isBinding, contextDescription); + break; - return this.parseFor(node, init); - } + case "AssignmentExpression": + if (node.operator === "=") { + node.type = "AssignmentPattern"; + delete node.operator; + } else { + this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); + } - parseFunctionStatement(node) { - this.next(); - return this.parseFunction(node, true); - } + break; - parseIfStatement(node) { - this.next(); - node.test = this.parseParenExpression(); - node.consequent = this.parseStatement("if"); - node.alternate = this.eat(types._else) ? this.parseStatement("if") : null; - return this.finishNode(node, "IfStatement"); - } + case "ParenthesizedExpression": + node.expression = this.toAssignable(node.expression, isBinding, contextDescription); + break; - parseReturnStatement(node) { - if (!this.state.inFunction && !this.options.allowReturnOutsideFunction) { - this.raise(this.state.start, "'return' outside of function"); + case "MemberExpression": + if (!isBinding) break; + + default: + { + const message = "Invalid left-hand side" + (contextDescription ? " in " + contextDescription : "expression"); + this.raise(node.start, message); + } + } } - this.next(); + return node; + } - if (this.isLineTerminator()) { - node.argument = null; + toAssignableObjectExpressionProp(prop, isBinding, isLast) { + if (prop.type === "ObjectMethod") { + const error = prop.kind === "get" || prop.kind === "set" ? "Object pattern can't contain getter or setter" : "Object pattern can't contain methods"; + this.raise(prop.key.start, error); + } else if (prop.type === "SpreadElement" && !isLast) { + this.raiseRestNotLast(prop.start); } else { - node.argument = this.parseExpression(); - this.semicolon(); + this.toAssignable(prop, isBinding, "object destructuring pattern"); } - - return this.finishNode(node, "ReturnStatement"); } - parseSwitchStatement(node) { - this.next(); - node.discriminant = this.parseParenExpression(); - const cases = node.cases = []; - this.expect(types.braceL); - this.state.labels.push(switchLabel); - let cur; + toAssignableList(exprList, isBinding, contextDescription) { + let end = exprList.length; - for (let sawDefault; !this.match(types.braceR);) { - if (this.match(types._case) || this.match(types._default)) { - const isCase = this.match(types._case); - if (cur) this.finishNode(cur, "SwitchCase"); - cases.push(cur = this.startNode()); - cur.consequent = []; - this.next(); + if (end) { + const last = exprList[end - 1]; - if (isCase) { - cur.test = this.parseExpression(); - } else { - if (sawDefault) { - this.raise(this.state.lastTokStart, "Multiple default clauses"); - } + if (last && last.type === "RestElement") { + --end; + } else if (last && last.type === "SpreadElement") { + last.type = "RestElement"; + const arg = last.argument; + this.toAssignable(arg, isBinding, contextDescription); - sawDefault = true; - cur.test = null; + if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern" && arg.type !== "ObjectPattern") { + this.unexpected(arg.start); } - this.expect(types.colon); - } else { - if (cur) { - cur.consequent.push(this.parseStatement(null)); - } else { - this.unexpected(); - } + --end; } } - if (cur) this.finishNode(cur, "SwitchCase"); - this.next(); - this.state.labels.pop(); - return this.finishNode(node, "SwitchStatement"); - } + for (let i = 0; i < end; i++) { + const elt = exprList[i]; - parseThrowStatement(node) { - this.next(); + if (elt) { + this.toAssignable(elt, isBinding, contextDescription); - if (lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start))) { - this.raise(this.state.lastTokEnd, "Illegal newline after throw"); + if (elt.type === "RestElement") { + this.raiseRestNotLast(elt.start); + } + } } - node.argument = this.parseExpression(); - this.semicolon(); - return this.finishNode(node, "ThrowStatement"); + return exprList; } - parseTryStatement(node) { - this.next(); - node.block = this.parseBlock(); - node.handler = null; + toReferencedList(exprList, isParenthesizedExpr) { + return exprList; + } - if (this.match(types._catch)) { - const clause = this.startNode(); - this.next(); + toReferencedListDeep(exprList, isParenthesizedExpr) { + this.toReferencedList(exprList, isParenthesizedExpr); - if (this.match(types.parenL)) { - this.expect(types.parenL); - clause.param = this.parseBindingAtom(); - const clashes = Object.create(null); - this.checkLVal(clause.param, true, clashes, "catch clause"); - this.expect(types.parenR); - } else { - clause.param = null; - } + for (let _i = 0; _i < exprList.length; _i++) { + const expr = exprList[_i]; - clause.body = this.withTopicForbiddingContext(() => this.parseBlock(false)); - node.handler = this.finishNode(clause, "CatchClause"); + if (expr && expr.type === "ArrayExpression") { + this.toReferencedListDeep(expr.elements); + } } - node.guardedHandlers = empty; - node.finalizer = this.eat(types._finally) ? this.parseBlock() : null; + return exprList; + } - if (!node.handler && !node.finalizer) { - this.raise(node.start, "Missing catch or finally clause"); + parseSpread(refShorthandDefaultPos, refNeedsArrowPos) { + const node = this.startNode(); + this.next(); + node.argument = this.parseMaybeAssign(false, refShorthandDefaultPos, undefined, refNeedsArrowPos); + + if (this.state.commaAfterSpreadAt === -1 && this.match(types.comma)) { + this.state.commaAfterSpreadAt = this.state.start; } - return this.finishNode(node, "TryStatement"); + return this.finishNode(node, "SpreadElement"); } - parseVarStatement(node, kind) { + parseRestBinding() { + const node = this.startNode(); this.next(); - this.parseVar(node, false, kind); - this.semicolon(); - return this.finishNode(node, "VariableDeclaration"); + node.argument = this.parseBindingAtom(); + return this.finishNode(node, "RestElement"); } - parseWhileStatement(node) { - this.next(); - node.test = this.parseParenExpression(); - this.state.labels.push(loopLabel); - node.body = this.withTopicForbiddingContext(() => this.parseStatement("while")); - this.state.labels.pop(); - return this.finishNode(node, "WhileStatement"); - } + parseBindingAtom() { + switch (this.state.type) { + case types.bracketL: + { + const node = this.startNode(); + this.next(); + node.elements = this.parseBindingList(types.bracketR, true); + return this.finishNode(node, "ArrayPattern"); + } - parseWithStatement(node) { - if (this.state.strict) { - this.raise(this.state.start, "'with' in strict mode"); + case types.braceL: + return this.parseObj(true); } - this.next(); - node.object = this.parseParenExpression(); - node.body = this.withTopicForbiddingContext(() => this.parseStatement("with")); - return this.finishNode(node, "WithStatement"); + return this.parseIdentifier(); } - parseEmptyStatement(node) { - this.next(); - return this.finishNode(node, "EmptyStatement"); - } + parseBindingList(close, allowEmpty, allowModifiers) { + const elts = []; + let first = true; - parseLabeledStatement(node, maybeName, expr, context) { - for (let _i = 0, _this$state$labels = this.state.labels; _i < _this$state$labels.length; _i++) { - const label = _this$state$labels[_i]; + while (!this.eat(close)) { + if (first) { + first = false; + } else { + this.expect(types.comma); + } - if (label.name === maybeName) { - this.raise(expr.start, `Label '${maybeName}' is already declared`); + if (allowEmpty && this.match(types.comma)) { + elts.push(null); + } else if (this.eat(close)) { + break; + } else if (this.match(types.ellipsis)) { + elts.push(this.parseAssignableListItemTypes(this.parseRestBinding())); + this.checkCommaAfterRest(); + this.expect(close); + break; + } else { + const decorators = []; + + if (this.match(types.at) && this.hasPlugin("decorators")) { + this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters"); + } + + while (this.match(types.at)) { + decorators.push(this.parseDecorator()); + } + + elts.push(this.parseAssignableListItem(allowModifiers, decorators)); } } - const kind = this.state.type.isLoop ? "loop" : this.match(types._switch) ? "switch" : null; + return elts; + } - for (let i = this.state.labels.length - 1; i >= 0; i--) { - const label = this.state.labels[i]; + parseAssignableListItem(allowModifiers, decorators) { + const left = this.parseMaybeDefault(); + this.parseAssignableListItemTypes(left); + const elt = this.parseMaybeDefault(left.start, left.loc.start, left); - if (label.statementStart === node.start) { - label.statementStart = this.state.start; - label.kind = kind; - } else { - break; - } + if (decorators.length) { + left.decorators = decorators; } - this.state.labels.push({ - name: maybeName, - kind: kind, - statementStart: this.state.start - }); - node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label"); - this.state.labels.pop(); - node.label = expr; - return this.finishNode(node, "LabeledStatement"); + return elt; } - parseExpressionStatement(node, expr) { - node.expression = expr; - this.semicolon(); - return this.finishNode(node, "ExpressionStatement"); + parseAssignableListItemTypes(param) { + return param; } - parseBlock(allowDirectives) { - const node = this.startNode(); - this.expect(types.braceL); - this.parseBlockBody(node, allowDirectives, false, types.braceR); - return this.finishNode(node, "BlockStatement"); + parseMaybeDefault(startPos, startLoc, left) { + startLoc = startLoc || this.state.startLoc; + startPos = startPos || this.state.start; + left = left || this.parseBindingAtom(); + if (!this.eat(types.eq)) return left; + const node = this.startNodeAt(startPos, startLoc); + node.left = left; + node.right = this.parseMaybeAssign(); + return this.finishNode(node, "AssignmentPattern"); } - isValidDirective(stmt) { - return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized; - } + checkLVal(expr, bindingType = BIND_NONE, checkClashes, contextDescription) { + switch (expr.type) { + case "Identifier": + if (this.state.strict && isStrictBindReservedWord(expr.name, this.inModule)) { + this.raise(expr.start, `${bindingType === BIND_NONE ? "Assigning to" : "Binding"} '${expr.name}' in strict mode`); + } - parseBlockBody(node, allowDirectives, topLevel, end) { - const body = node.body = []; - const directives = node.directives = []; - this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end); - } + if (checkClashes) { + const key = `_${expr.name}`; - parseBlockOrModuleBlockBody(body, directives, topLevel, end) { - let parsedNonDirective = false; - let oldStrict; - let octalPosition; + if (checkClashes[key]) { + this.raise(expr.start, "Argument name clash"); + } else { + checkClashes[key] = true; + } + } - while (!this.eat(end)) { - if (!parsedNonDirective && this.state.containsOctal && !octalPosition) { - octalPosition = this.state.octalPosition; - } + if (!(bindingType & BIND_NONE)) { + this.scope.declareName(expr.name, bindingType, expr.start); + } - const stmt = this.parseStatement(null, topLevel); + break; - if (directives && !parsedNonDirective && this.isValidDirective(stmt)) { - const directive = this.stmtToDirective(stmt); - directives.push(directive); + case "MemberExpression": + if (bindingType !== BIND_NONE) { + this.raise(expr.start, "Binding member expression"); + } - if (oldStrict === undefined && directive.value.value === "use strict") { - oldStrict = this.state.strict; - this.setStrict(true); + break; - if (octalPosition) { - this.raise(octalPosition, "Octal literal in strict mode"); + case "ObjectPattern": + for (let _i2 = 0, _expr$properties = expr.properties; _i2 < _expr$properties.length; _i2++) { + let prop = _expr$properties[_i2]; + if (prop.type === "ObjectProperty") prop = prop.value; + this.checkLVal(prop, bindingType, checkClashes, "object destructuring pattern"); + } + + break; + + case "ArrayPattern": + for (let _i3 = 0, _expr$elements = expr.elements; _i3 < _expr$elements.length; _i3++) { + const elem = _expr$elements[_i3]; + + if (elem) { + this.checkLVal(elem, bindingType, checkClashes, "array destructuring pattern"); } } - continue; - } + break; - parsedNonDirective = true; - body.push(stmt); - } + case "AssignmentPattern": + this.checkLVal(expr.left, bindingType, checkClashes, "assignment pattern"); + break; - if (oldStrict === false) { - this.setStrict(false); + case "RestElement": + this.checkLVal(expr.argument, bindingType, checkClashes, "rest element"); + break; + + case "ParenthesizedExpression": + this.checkLVal(expr.expression, bindingType, checkClashes, "parenthesized expression"); + break; + + default: + { + const message = (bindingType === BIND_NONE ? "Invalid" : "Binding invalid") + " left-hand side" + (contextDescription ? " in " + contextDescription : "expression"); + this.raise(expr.start, message); + } } } - parseFor(node, init) { - node.init = init; - this.expect(types.semi); - node.test = this.match(types.semi) ? null : this.parseExpression(); - this.expect(types.semi); - node.update = this.match(types.parenR) ? null : this.parseExpression(); - this.expect(types.parenR); - node.body = this.withTopicForbiddingContext(() => this.parseStatement("for")); - this.state.labels.pop(); - return this.finishNode(node, "ForStatement"); + checkToRestConversion(node) { + if (node.argument.type !== "Identifier" && node.argument.type !== "MemberExpression") { + this.raise(node.argument.start, "Invalid rest operator's argument"); + } } - parseForIn(node, init, awaitAt) { - const type = this.match(types._in) ? "ForInStatement" : "ForOfStatement"; - - if (awaitAt > -1) { - this.eatContextual("of"); - } else { - this.next(); + checkCommaAfterRest() { + if (this.match(types.comma)) { + this.raiseRestNotLast(this.state.start); } + } - if (type === "ForOfStatement") { - node.await = awaitAt > -1; + checkCommaAfterRestFromSpread() { + if (this.state.commaAfterSpreadAt > -1) { + this.raiseRestNotLast(this.state.commaAfterSpreadAt); } + } - node.left = init; - node.right = this.parseExpression(); - this.expect(types.parenR); - node.body = this.withTopicForbiddingContext(() => this.parseStatement("for")); - this.state.labels.pop(); - return this.finishNode(node, type); + raiseRestNotLast(pos) { + this.raise(pos, `Rest element must be last element`); } - parseVar(node, isFor, kind) { - const declarations = node.declarations = []; - const isTypescript = this.hasPlugin("typescript"); - node.kind = kind; +} - for (;;) { - const decl = this.startNode(); - this.parseVarId(decl, kind); +const unwrapParenthesizedExpression = node => { + return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node; +}; - if (this.eat(types.eq)) { - decl.init = this.parseMaybeAssign(isFor); - } else { - if (kind === "const" && !(this.match(types._in) || this.isContextual("of"))) { - if (!isTypescript) { - this.unexpected(); - } - } else if (decl.id.type !== "Identifier" && !(isFor && (this.match(types._in) || this.isContextual("of")))) { - this.raise(this.state.lastTokEnd, "Complex binding patterns require an initialization value"); - } +class ExpressionParser extends LValParser { + checkPropClash(prop, propHash) { + if (prop.type === "SpreadElement" || prop.computed || prop.kind || prop.shorthand) { + return; + } - decl.init = null; + const key = prop.key; + const name = key.type === "Identifier" ? key.name : String(key.value); + + if (name === "__proto__") { + if (propHash.proto) { + this.raise(key.start, "Redefinition of __proto__ property"); } - declarations.push(this.finishNode(decl, "VariableDeclarator")); - if (!this.eat(types.comma)) break; + propHash.proto = true; } - - return node; } - parseVarId(decl, kind) { - if ((kind === "const" || kind === "let") && this.isContextual("let")) { - this.unexpected(null, "let is disallowed as a lexically bound name"); + getExpression() { + this.scope.enter(SCOPE_PROGRAM); + this.nextToken(); + const expr = this.parseExpression(); + + if (!this.match(types.eof)) { + this.unexpected(); } - decl.id = this.parseBindingAtom(); - this.checkLVal(decl.id, true, undefined, "variable declaration"); + expr.comments = this.state.comments; + return expr; } - parseFunction(node, isStatement, allowExpressionBody = false, isAsync = false, optionalId = false) { - const oldInFunc = this.state.inFunction; - const oldInMethod = this.state.inMethod; - const oldInAsync = this.state.inAsync; - const oldInGenerator = this.state.inGenerator; - const oldInClassProperty = this.state.inClassProperty; - const oldYieldPos = this.state.yieldPos; - const oldAwaitPos = this.state.awaitPos; - this.state.inFunction = true; - this.state.inMethod = false; - this.state.inClassProperty = false; - this.state.yieldPos = 0; - this.state.awaitPos = 0; - this.initFunction(node, isAsync); - node.generator = this.eat(types.star); - - if (isStatement && !optionalId && !this.match(types.name)) { - this.unexpected(); - } + parseExpression(noIn, refShorthandDefaultPos) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + const expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos); - if (!isStatement) { - this.state.inAsync = isAsync; - this.state.inGenerator = node.generator; - } + if (this.match(types.comma)) { + const node = this.startNodeAt(startPos, startLoc); + node.expressions = [expr]; - if (this.match(types.name)) { - node.id = this.parseIdentifier(); - } + while (this.eat(types.comma)) { + node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos)); + } - if (isStatement) { - this.state.inAsync = isAsync; - this.state.inGenerator = node.generator; + this.toReferencedList(node.expressions); + return this.finishNode(node, "SequenceExpression"); } - this.parseFunctionParams(node); - this.withTopicForbiddingContext(() => { - this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression", allowExpressionBody); - }); - this.state.inFunction = oldInFunc; - this.state.inMethod = oldInMethod; - this.state.inAsync = oldInAsync; - this.state.inGenerator = oldInGenerator; - this.state.inClassProperty = oldInClassProperty; - this.state.yieldPos = oldYieldPos; - this.state.awaitPos = oldAwaitPos; - return node; + return expr; } - parseFunctionParams(node, allowModifiers) { - const oldInParameters = this.state.inParameters; - this.state.inParameters = true; - this.expect(types.parenL); - node.params = this.parseBindingList(types.parenR, false, allowModifiers); - this.state.inParameters = oldInParameters; - this.checkYieldAwaitInDefaultParams(); - } + parseMaybeAssign(noIn, refShorthandDefaultPos, afterLeftParse, refNeedsArrowPos) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; - parseClass(node, isStatement, optionalId) { - this.next(); - this.takeDecorators(node); - const oldStrict = this.state.strict; - this.state.strict = true; - this.parseClassId(node, isStatement, optionalId); - this.parseClassSuper(node); - this.parseClassBody(node); - this.state.strict = oldStrict; - return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); - } + if (this.isContextual("yield")) { + if (this.scope.inGenerator) { + let left = this.parseYield(noIn); - isClassProperty() { - return this.match(types.eq) || this.match(types.semi) || this.match(types.braceR); - } + if (afterLeftParse) { + left = afterLeftParse.call(this, left, startPos, startLoc); + } - isClassMethod() { - return this.match(types.parenL); - } + return left; + } else { + this.state.exprAllowed = false; + } + } - isNonstaticConstructor(method) { - return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor"); - } + const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; + this.state.commaAfterSpreadAt = -1; + let failOnShorthandAssign; - parseClassBody(node) { - this.state.classLevel++; - const state = { - hadConstructor: false - }; - let decorators = []; - const classBody = this.startNode(); - classBody.body = []; - this.expect(types.braceL); - this.withTopicForbiddingContext(() => { - while (!this.eat(types.braceR)) { - if (this.eat(types.semi)) { - if (decorators.length > 0) { - this.raise(this.state.lastTokEnd, "Decorators must not be followed by a semicolon"); - } + if (refShorthandDefaultPos) { + failOnShorthandAssign = false; + } else { + refShorthandDefaultPos = { + start: 0 + }; + failOnShorthandAssign = true; + } + + if (this.match(types.parenL) || this.match(types.name)) { + this.state.potentialArrowAt = this.state.start; + } + + let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos); - continue; - } + if (afterLeftParse) { + left = afterLeftParse.call(this, left, startPos, startLoc); + } - if (this.match(types.at)) { - decorators.push(this.parseDecorator()); - continue; - } + if (this.state.type.isAssign) { + const node = this.startNodeAt(startPos, startLoc); + const operator = this.state.value; + node.operator = operator; - const member = this.startNode(); + if (operator === "??=") { + this.expectPlugin("nullishCoalescingOperator"); + this.expectPlugin("logicalAssignment"); + } - if (decorators.length) { - member.decorators = decorators; - this.resetStartLocationFromNode(member, decorators[0]); - decorators = []; - } + if (operator === "||=" || operator === "&&=") { + this.expectPlugin("logicalAssignment"); + } - this.parseClassMember(classBody, member, state); + node.left = this.match(types.eq) ? this.toAssignable(left, undefined, "assignment expression") : left; + refShorthandDefaultPos.start = 0; + this.checkLVal(left, undefined, undefined, "assignment expression"); + const maybePattern = unwrapParenthesizedExpression(left); + let patternErrorMsg; - if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) { - this.raise(member.start, "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?"); - } + if (maybePattern.type === "ObjectPattern") { + patternErrorMsg = "`({a}) = 0` use `({a} = 0)`"; + } else if (maybePattern.type === "ArrayPattern") { + patternErrorMsg = "`([a]) = 0` use `([a] = 0)`"; } - }); - if (decorators.length) { - this.raise(this.state.start, "You have trailing decorators with no method"); + if (patternErrorMsg && (left.extra && left.extra.parenthesized || left.type === "ParenthesizedExpression")) { + this.raise(maybePattern.start, `You're trying to assign to a parenthesized expression, eg. instead of ${patternErrorMsg}`); + } + + if (patternErrorMsg) this.checkCommaAfterRestFromSpread(); + this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; + this.next(); + node.right = this.parseMaybeAssign(noIn); + return this.finishNode(node, "AssignmentExpression"); + } else if (failOnShorthandAssign && refShorthandDefaultPos.start) { + this.unexpected(refShorthandDefaultPos.start); } - node.body = this.finishNode(classBody, "ClassBody"); - this.state.classLevel--; + this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; + return left; } - parseClassMember(classBody, member, state) { - let isStatic = false; - const containsEsc = this.state.containsEsc; - - if (this.match(types.name) && this.state.value === "static") { - const key = this.parseIdentifier(true); - - if (this.isClassMethod()) { - const method = member; - method.kind = "method"; - method.computed = false; - method.key = key; - method.static = false; - this.pushClassMethod(classBody, method, false, false, false); - return; - } else if (this.isClassProperty()) { - const prop = member; - prop.computed = false; - prop.key = key; - prop.static = false; - classBody.body.push(this.parseClassProperty(prop)); - return; - } else if (containsEsc) { - throw this.unexpected(); - } + parseMaybeConditional(noIn, refShorthandDefaultPos, refNeedsArrowPos) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + const potentialArrowAt = this.state.potentialArrowAt; + const expr = this.parseExprOps(noIn, refShorthandDefaultPos); - isStatic = true; + if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) { + return expr; } - this.parseClassMemberWithIsStatic(classBody, member, state, isStatic); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr; + return this.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos); } - parseClassMemberWithIsStatic(classBody, member, state, isStatic) { - const publicMethod = member; - const privateMethod = member; - const publicProp = member; - const privateProp = member; - const method = publicMethod; - const publicMember = publicMethod; - member.static = isStatic; + parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) { + if (this.eat(types.question)) { + const node = this.startNodeAt(startPos, startLoc); + node.test = expr; + node.consequent = this.parseMaybeAssign(); + this.expect(types.colon); + node.alternate = this.parseMaybeAssign(noIn); + return this.finishNode(node, "ConditionalExpression"); + } - if (this.eat(types.star)) { - method.kind = "method"; - this.parseClassPropertyName(method); + return expr; + } - if (method.key.type === "PrivateName") { - this.pushClassPrivateMethod(classBody, privateMethod, true, false); - return; - } + parseExprOps(noIn, refShorthandDefaultPos) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + const potentialArrowAt = this.state.potentialArrowAt; + const expr = this.parseMaybeUnary(refShorthandDefaultPos); - if (this.isNonstaticConstructor(publicMethod)) { - this.raise(publicMethod.key.start, "Constructor can't be a generator"); - } + if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) { + return expr; + } - this.pushClassMethod(classBody, publicMethod, true, false, false); - return; + if (refShorthandDefaultPos && refShorthandDefaultPos.start) { + return expr; } - const key = this.parseClassPropertyName(member); - const isPrivate = key.type === "PrivateName"; - const isSimple = key.type === "Identifier"; - this.parsePostMemberNameModifiers(publicMember); + return this.parseExprOp(expr, startPos, startLoc, -1, noIn); + } - if (this.isClassMethod()) { - method.kind = "method"; + parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) { + const prec = this.state.type.binop; - if (isPrivate) { - this.pushClassPrivateMethod(classBody, privateMethod, false, false); - return; - } + if (prec != null && (!noIn || !this.match(types._in))) { + if (prec > minPrec) { + const node = this.startNodeAt(leftStartPos, leftStartLoc); + const operator = this.state.value; + node.left = left; + node.operator = operator; - const isConstructor = this.isNonstaticConstructor(publicMethod); + if (operator === "**" && left.type === "UnaryExpression" && (this.options.createParenthesizedExpressions || !(left.extra && left.extra.parenthesized))) { + this.raise(left.argument.start, "Illegal expression. Wrap left hand side or entire exponentiation in parentheses."); + } - if (isConstructor) { - publicMethod.kind = "constructor"; + const op = this.state.type; - if (publicMethod.decorators) { - this.raise(publicMethod.start, "You can't attach decorators to a class constructor"); + if (op === types.pipeline) { + this.expectPlugin("pipelineOperator"); + this.state.inPipeline = true; + this.checkPipelineAtInfixOperator(left, leftStartPos); + } else if (op === types.nullishCoalescing) { + this.expectPlugin("nullishCoalescingOperator"); } - if (state.hadConstructor && !this.hasPlugin("typescript")) { - this.raise(key.start, "Duplicate constructor in the same class"); + this.next(); + + if (op === types.pipeline && this.getPluginOption("pipelineOperator", "proposal") === "minimal") { + if (this.match(types.name) && this.state.value === "await" && this.scope.inAsync) { + throw this.raise(this.state.start, `Unexpected "await" after pipeline body; await must have parentheses in minimal proposal`); + } } - state.hadConstructor = true; + node.right = this.parseExprOpRightExpr(op, prec, noIn); + this.finishNode(node, op === types.logicalOR || op === types.logicalAND || op === types.nullishCoalescing ? "LogicalExpression" : "BinaryExpression"); + return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); } + } - this.pushClassMethod(classBody, publicMethod, false, false, isConstructor); - } else if (this.isClassProperty()) { - if (isPrivate) { - this.pushClassPrivateProperty(classBody, privateProp); - } else { - this.pushClassProperty(classBody, publicProp); - } - } else if (isSimple && key.name === "async" && !this.isLineTerminator()) { - const isGenerator = this.eat(types.star); - method.kind = "method"; - this.parseClassPropertyName(method); + return left; + } - if (method.key.type === "PrivateName") { - this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true); - } else { - if (this.isNonstaticConstructor(publicMethod)) { - this.raise(publicMethod.key.start, "Constructor can't be an async function"); + parseExprOpRightExpr(op, prec, noIn) { + switch (op) { + case types.pipeline: + if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + return this.withTopicPermittingContext(() => { + return this.parseSmartPipelineBody(this.parseExprOpBaseRightExpr(op, prec, noIn), startPos, startLoc); + }); } - this.pushClassMethod(classBody, publicMethod, isGenerator, true, false); - } - } else if (isSimple && (key.name === "get" || key.name === "set") && !(this.match(types.star) && this.isLineTerminator())) { - method.kind = key.name; - this.parseClassPropertyName(publicMethod); + default: + return this.parseExprOpBaseRightExpr(op, prec, noIn); + } + } - if (method.key.type === "PrivateName") { - this.pushClassPrivateMethod(classBody, privateMethod, false, false); - } else { - if (this.isNonstaticConstructor(publicMethod)) { - this.raise(publicMethod.key.start, "Constructor can't have get/set modifier"); - } + parseExprOpBaseRightExpr(op, prec, noIn) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + return this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, op.rightAssociative ? prec - 1 : prec, noIn); + } + + parseMaybeUnary(refShorthandDefaultPos) { + if (this.isContextual("await") && (this.scope.inAsync || !this.scope.inFunction && this.options.allowAwaitOutsideFunction)) { + return this.parseAwait(); + } else if (this.state.type.prefix) { + const node = this.startNode(); + const update = this.match(types.incDec); + node.operator = this.state.value; + node.prefix = true; - this.pushClassMethod(classBody, publicMethod, false, false, false); + if (node.operator === "throw") { + this.expectPlugin("throwExpressions"); } - this.checkGetterSetterParams(publicMethod); - } else if (this.isLineTerminator()) { - if (isPrivate) { - this.pushClassPrivateProperty(classBody, privateProp); - } else { - this.pushClassProperty(classBody, publicProp); + this.next(); + node.argument = this.parseMaybeUnary(); + + if (refShorthandDefaultPos && refShorthandDefaultPos.start) { + this.unexpected(refShorthandDefaultPos.start); } - } else { - this.unexpected(); - } - } - parseClassPropertyName(member) { - const key = this.parsePropertyName(member); + if (update) { + this.checkLVal(node.argument, undefined, undefined, "prefix operation"); + } else if (this.state.strict && node.operator === "delete") { + const arg = node.argument; - if (!member.computed && member.static && (key.name === "prototype" || key.value === "prototype")) { - this.raise(key.start, "Classes may not have static property named prototype"); - } + if (arg.type === "Identifier") { + this.raise(node.start, "Deleting local variable in strict mode"); + } else if (arg.type === "MemberExpression" && arg.property.type === "PrivateName") { + this.raise(node.start, "Deleting a private field is not allowed"); + } + } - if (key.type === "PrivateName" && key.id.name === "constructor") { - this.raise(key.start, "Classes may not have a private field named '#constructor'"); + return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); } - return key; - } + const startPos = this.state.start; + const startLoc = this.state.startLoc; + let expr = this.parseExprSubscripts(refShorthandDefaultPos); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr; - pushClassProperty(classBody, prop) { - if (this.isNonstaticConstructor(prop)) { - this.raise(prop.key.start, "Classes may not have a non-static field named 'constructor'"); + while (this.state.type.postfix && !this.canInsertSemicolon()) { + const node = this.startNodeAt(startPos, startLoc); + node.operator = this.state.value; + node.prefix = false; + node.argument = expr; + this.checkLVal(expr, undefined, undefined, "postfix operation"); + this.next(); + expr = this.finishNode(node, "UpdateExpression"); } - classBody.body.push(this.parseClassProperty(prop)); + return expr; } - pushClassPrivateProperty(classBody, prop) { - this.expectPlugin("classPrivateProperties", prop.key.start); - classBody.body.push(this.parseClassPrivateProperty(prop)); - } + parseExprSubscripts(refShorthandDefaultPos) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + const potentialArrowAt = this.state.potentialArrowAt; + const expr = this.parseExprAtom(refShorthandDefaultPos); - pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) { - classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, "ClassMethod")); - } + if (expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt) { + return expr; + } - pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { - this.expectPlugin("classPrivateMethods", method.key.start); - classBody.body.push(this.parseMethod(method, isGenerator, isAsync, false, "ClassPrivateMethod")); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) { + return expr; + } + + return this.parseSubscripts(expr, startPos, startLoc); } - parsePostMemberNameModifiers(methodOrProp) {} + parseSubscripts(base, startPos, startLoc, noCalls) { + const maybeAsyncArrow = this.atPossibleAsync(base); + const state = { + optionalChainMember: false, + stop: false + }; - parseAccessModifier() { - return undefined; - } + do { + base = this.parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow); + } while (!state.stop); - parseClassPrivateProperty(node) { - const oldInMethod = this.state.inMethod; - this.state.inMethod = false; - this.state.inClassProperty = true; - node.value = this.eat(types.eq) ? this.parseMaybeAssign() : null; - this.semicolon(); - this.state.inClassProperty = false; - this.state.inMethod = oldInMethod; - return this.finishNode(node, "ClassPrivateProperty"); + return base; } - parseClassProperty(node) { - if (!node.typeAnnotation) { - this.expectPlugin("classProperties"); - } + parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow) { + if (!noCalls && this.eat(types.doubleColon)) { + const node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.callee = this.parseNoCallExpr(); + state.stop = true; + return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls); + } else if (this.match(types.questionDot)) { + this.expectPlugin("optionalChaining"); + state.optionalChainMember = true; - const oldInMethod = this.state.inMethod; - this.state.inMethod = false; - this.state.inClassProperty = true; + if (noCalls && this.lookahead().type === types.parenL) { + state.stop = true; + return base; + } - if (this.match(types.eq)) { - this.expectPlugin("classProperties"); this.next(); - node.value = this.parseMaybeAssign(); - } else { - node.value = null; - } - - this.semicolon(); - this.state.inClassProperty = false; - this.state.inMethod = oldInMethod; - return this.finishNode(node, "ClassProperty"); - } + const node = this.startNodeAt(startPos, startLoc); - parseClassId(node, isStatement, optionalId) { - if (this.match(types.name)) { - node.id = this.parseIdentifier(); - } else { - if (optionalId || !isStatement) { - node.id = null; + if (this.eat(types.bracketL)) { + node.object = base; + node.property = this.parseExpression(); + node.computed = true; + node.optional = true; + this.expect(types.bracketR); + return this.finishNode(node, "OptionalMemberExpression"); + } else if (this.eat(types.parenL)) { + node.callee = base; + node.arguments = this.parseCallExpressionArguments(types.parenR, false); + node.optional = true; + return this.finishNode(node, "OptionalCallExpression"); } else { - this.unexpected(null, "A class name is required"); + node.object = base; + node.property = this.parseIdentifier(true); + node.computed = false; + node.optional = true; + return this.finishNode(node, "OptionalMemberExpression"); } - } - } + } else if (this.eat(types.dot)) { + const node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.property = this.parseMaybePrivateName(); + node.computed = false; - parseClassSuper(node) { - node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null; - } + if (state.optionalChainMember) { + node.optional = false; + return this.finishNode(node, "OptionalMemberExpression"); + } - parseExport(node) { - const hasDefault = this.maybeParseExportDefaultSpecifier(node); - const parseAfterDefault = !hasDefault || this.eat(types.comma); - const hasStar = parseAfterDefault && this.eatExportStar(node); - const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node); - const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(types.comma)); - const isFromRequired = hasDefault || hasStar; + return this.finishNode(node, "MemberExpression"); + } else if (this.eat(types.bracketL)) { + const node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.property = this.parseExpression(); + node.computed = true; + this.expect(types.bracketR); - if (hasStar && !hasNamespace) { - if (hasDefault) this.unexpected(); - this.parseExportFrom(node, true); - return this.finishNode(node, "ExportAllDeclaration"); - } + if (state.optionalChainMember) { + node.optional = false; + return this.finishNode(node, "OptionalMemberExpression"); + } - const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node); + return this.finishNode(node, "MemberExpression"); + } else if (!noCalls && this.match(types.parenL)) { + const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.maybeInArrowParameters = true; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + this.next(); + let node = this.startNodeAt(startPos, startLoc); + node.callee = base; + const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; + this.state.commaAfterSpreadAt = -1; + node.arguments = this.parseCallExpressionArguments(types.parenR, maybeAsyncArrow, base.type === "Import", base.type !== "Super"); - if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers || hasNamespace && parseAfterNamespace && !hasSpecifiers) { - throw this.unexpected(null, types.braceL); - } + if (!state.optionalChainMember) { + this.finishCallExpression(node); + } else { + this.finishOptionalCallExpression(node); + } - let hasDeclaration; + if (maybeAsyncArrow && this.shouldParseAsyncArrow()) { + state.stop = true; + this.checkCommaAfterRestFromSpread(); + node = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); + this.checkYieldAwaitInDefaultParams(); + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; + } else { + this.toReferencedListDeep(node.arguments); + this.state.yieldPos = oldYieldPos || this.state.yieldPos; + this.state.awaitPos = oldAwaitPos || this.state.awaitPos; + } - if (isFromRequired || hasSpecifiers) { - hasDeclaration = false; - this.parseExportFrom(node, isFromRequired); + this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; + return node; + } else if (this.match(types.backQuote)) { + return this.parseTaggedTemplateExpression(startPos, startLoc, base, state); } else { - hasDeclaration = this.maybeParseExportDeclaration(node); + state.stop = true; + return base; } + } - if (isFromRequired || hasSpecifiers || hasDeclaration) { - this.checkExport(node, true); - return this.finishNode(node, "ExportNamedDeclaration"); - } + parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments) { + const node = this.startNodeAt(startPos, startLoc); + node.tag = base; + node.quasi = this.parseTemplate(true); + if (typeArguments) node.typeParameters = typeArguments; - if (this.eat(types._default)) { - node.declaration = this.parseExportDefaultExpression(); - this.checkExport(node, true, true); - return this.finishNode(node, "ExportDefaultDeclaration"); + if (state.optionalChainMember) { + this.raise(startPos, "Tagged Template Literals are not allowed in optionalChain"); } - throw this.unexpected(null, types.braceL); + return this.finishNode(node, "TaggedTemplateExpression"); } - eatExportStar(node) { - return this.eat(types.star); + atPossibleAsync(base) { + return base.type === "Identifier" && base.name === "async" && this.state.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async"; } - maybeParseExportDefaultSpecifier(node) { - if (this.isExportDefaultSpecifier()) { - this.expectPlugin("exportDefaultFrom"); - const specifier = this.startNode(); - specifier.exported = this.parseIdentifier(true); - node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; - return true; - } + finishCallExpression(node) { + if (node.callee.type === "Import") { + if (node.arguments.length !== 1) { + this.raise(node.start, "import() requires exactly one argument"); + } - return false; - } + const importArg = node.arguments[0]; - maybeParseExportNamespaceSpecifier(node) { - if (this.isContextual("as")) { - if (!node.specifiers) node.specifiers = []; - this.expectPlugin("exportNamespaceFrom"); - const specifier = this.startNodeAt(this.state.lastTokStart, this.state.lastTokStartLoc); - this.next(); - specifier.exported = this.parseIdentifier(true); - node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier")); - return true; + if (importArg && importArg.type === "SpreadElement") { + this.raise(importArg.start, "... is not allowed in import()"); + } } - return false; + return this.finishNode(node, "CallExpression"); } - maybeParseExportNamedSpecifiers(node) { - if (this.match(types.braceL)) { - if (!node.specifiers) node.specifiers = []; - node.specifiers.push(...this.parseExportSpecifiers()); - node.source = null; - node.declaration = null; - return true; - } - - return false; - } + finishOptionalCallExpression(node) { + if (node.callee.type === "Import") { + if (node.arguments.length !== 1) { + this.raise(node.start, "import() requires exactly one argument"); + } - maybeParseExportDeclaration(node) { - if (this.shouldParseExportDeclaration()) { - if (this.isContextual("async")) { - const next = this.lookahead(); + const importArg = node.arguments[0]; - if (next.type !== types._function) { - this.unexpected(next.start, `Unexpected token, expected "function"`); - } + if (importArg && importArg.type === "SpreadElement") { + this.raise(importArg.start, "... is not allowed in import()"); } - - node.specifiers = []; - node.source = null; - node.declaration = this.parseExportDeclaration(node); - return true; } - return false; + return this.finishNode(node, "OptionalCallExpression"); } - isAsyncFunction() { - if (!this.isContextual("async")) return false; - const { - input, - pos, - length - } = this.state; - skipWhiteSpace.lastIndex = pos; - const skip = skipWhiteSpace.exec(input); - if (!skip || !skip.length) return false; - const next = pos + skip[0].length; - return !lineBreak.test(input.slice(pos, next)) && input.slice(next, next + 8) === "function" && (next + 8 === length || !isIdentifierChar(input.charCodeAt(next + 8))); - } + parseCallExpressionArguments(close, possibleAsyncArrow, dynamicImport, allowPlaceholder) { + const elts = []; + let innerParenStart; + let first = true; - parseExportDefaultExpression() { - const expr = this.startNode(); - const isAsync = this.isAsyncFunction(); + while (!this.eat(close)) { + if (first) { + first = false; + } else { + this.expect(types.comma); - if (this.eat(types._function) || isAsync) { - if (isAsync) { - this.eatContextual("async"); - this.expect(types._function); + if (this.eat(close)) { + if (dynamicImport) { + this.raise(this.state.lastTokStart, "Trailing comma is disallowed inside import(...) arguments"); + } + + break; + } } - return this.parseFunction(expr, true, false, isAsync, true); - } else if (this.match(types._class)) { - return this.parseClass(expr, true, true); - } else if (this.match(types.at)) { - if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) { - this.unexpected(this.state.start, "Decorators must be placed *before* the 'export' keyword." + " You can set the 'decoratorsBeforeExport' option to false to use" + " the 'export @decorator class {}' syntax"); + if (this.match(types.parenL) && !innerParenStart) { + innerParenStart = this.state.start; } - this.parseDecorators(false); - return this.parseClass(expr, true, true); - } else if (this.match(types._const) || this.match(types._var) || this.isLet()) { - return this.raise(this.state.start, "Only expressions, functions or classes are allowed as the `default` export."); - } else { - const res = this.parseMaybeAssign(); - this.semicolon(); - return res; + elts.push(this.parseExprListItem(false, possibleAsyncArrow ? { + start: 0 + } : undefined, possibleAsyncArrow ? { + start: 0 + } : undefined, allowPlaceholder)); } - } - parseExportDeclaration(node) { - return this.parseStatement(null); - } - - isExportDefaultSpecifier() { - if (this.match(types.name)) { - return this.state.value !== "async" && this.state.value !== "let"; + if (possibleAsyncArrow && innerParenStart && this.shouldParseAsyncArrow()) { + this.unexpected(); } - if (!this.match(types._default)) { - return false; - } + return elts; + } - const lookahead = this.lookahead(); - return lookahead.type === types.comma || lookahead.type === types.name && lookahead.value === "from"; + shouldParseAsyncArrow() { + return this.match(types.arrow) && !this.canInsertSemicolon(); } - parseExportFrom(node, expect) { - if (this.eatContextual("from")) { - node.source = this.parseImportSource(); - this.checkExport(node); - } else { - if (expect) { - this.unexpected(); - } else { - node.source = null; - } - } + parseAsyncArrowFromCallExpression(node, call) { + this.expect(types.arrow); + this.parseArrowExpression(node, call.arguments, true); + return node; + } - this.semicolon(); + parseNoCallExpr() { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true); } - shouldParseExportDeclaration() { - if (this.match(types.at)) { - this.expectOnePlugin(["decorators", "decorators-legacy"]); + parseExprAtom(refShorthandDefaultPos) { + if (this.state.type === types.slash) this.readRegexp(); + const canBeArrow = this.state.potentialArrowAt === this.state.start; + let node; - if (this.hasPlugin("decorators")) { - if (this.getPluginOption("decorators", "decoratorsBeforeExport")) { - this.unexpected(this.state.start, "Decorators must be placed *before* the 'export' keyword." + " You can set the 'decoratorsBeforeExport' option to false to use" + " the 'export @decorator class {}' syntax"); - } else { - return true; + switch (this.state.type) { + case types._super: + if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) { + this.raise(this.state.start, "super is only allowed in object methods and classes"); } - } - } - return this.state.type.keyword === "var" || this.state.type.keyword === "const" || this.state.type.keyword === "function" || this.state.type.keyword === "class" || this.isLet() || this.isAsyncFunction(); - } + node = this.startNode(); + this.next(); - checkExport(node, checkNames, isDefault) { - if (checkNames) { - if (isDefault) { - this.checkDuplicateExports(node, "default"); - } else if (node.specifiers && node.specifiers.length) { - for (let _i2 = 0, _node$specifiers = node.specifiers; _i2 < _node$specifiers.length; _i2++) { - const specifier = _node$specifiers[_i2]; - this.checkDuplicateExports(specifier, specifier.exported.name); + if (this.match(types.parenL) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) { + this.raise(node.start, "super() is only valid inside a class constructor of a subclass. " + "Maybe a typo in the method name ('constructor') or not extending another class?"); } - } else if (node.declaration) { - if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") { - const id = node.declaration.id; - if (!id) throw new Error("Assertion failure"); - this.checkDuplicateExports(node, id.name); - } else if (node.declaration.type === "VariableDeclaration") { - for (let _i3 = 0, _node$declaration$dec = node.declaration.declarations; _i3 < _node$declaration$dec.length; _i3++) { - const declaration = _node$declaration$dec[_i3]; - this.checkDeclaration(declaration.id); + + if (!this.match(types.parenL) && !this.match(types.bracketL) && !this.match(types.dot)) { + this.unexpected(); + } + + return this.finishNode(node, "Super"); + + case types._import: + node = this.startNode(); + this.next(); + + if (this.match(types.dot)) { + return this.parseImportMetaProperty(node); + } + + this.expectPlugin("dynamicImport", node.start); + + if (!this.match(types.parenL)) { + this.unexpected(null, types.parenL); + } + + return this.finishNode(node, "Import"); + + case types._this: + node = this.startNode(); + this.next(); + return this.finishNode(node, "ThisExpression"); + + case types.name: + { + node = this.startNode(); + const containsEsc = this.state.containsEsc; + const id = this.parseIdentifier(); + + if (!containsEsc && id.name === "async" && this.match(types._function) && !this.canInsertSemicolon()) { + this.next(); + return this.parseFunction(node, undefined, true); + } else if (canBeArrow && !containsEsc && id.name === "async" && this.match(types.name) && !this.canInsertSemicolon()) { + const params = [this.parseIdentifier()]; + this.expect(types.arrow); + this.parseArrowExpression(node, params, true); + return node; + } + + if (canBeArrow && this.match(types.arrow) && !this.canInsertSemicolon()) { + this.next(); + this.parseArrowExpression(node, [id], false); + return node; } + + return id; } - } - } - const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1]; + case types._do: + { + this.expectPlugin("doExpressions"); + const node = this.startNode(); + this.next(); + const oldLabels = this.state.labels; + this.state.labels = []; + node.body = this.parseBlock(); + this.state.labels = oldLabels; + return this.finishNode(node, "DoExpression"); + } - if (currentContextDecorators.length) { - const isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression"); + case types.regexp: + { + const value = this.state.value; + node = this.parseLiteral(value.value, "RegExpLiteral"); + node.pattern = value.pattern; + node.flags = value.flags; + return node; + } - if (!node.declaration || !isClass) { - throw this.raise(node.start, "You can only use decorators on an export when exporting a class"); - } + case types.num: + return this.parseLiteral(this.state.value, "NumericLiteral"); - this.takeDecorators(node.declaration); - } - } + case types.bigint: + return this.parseLiteral(this.state.value, "BigIntLiteral"); - checkDeclaration(node) { - if (node.type === "Identifier") { - this.checkDuplicateExports(node, node.name); - } else if (node.type === "ObjectPattern") { - for (let _i4 = 0, _node$properties = node.properties; _i4 < _node$properties.length; _i4++) { - const prop = _node$properties[_i4]; - this.checkDeclaration(prop); - } - } else if (node.type === "ArrayPattern") { - for (let _i5 = 0, _node$elements = node.elements; _i5 < _node$elements.length; _i5++) { - const elem = _node$elements[_i5]; + case types.string: + return this.parseLiteral(this.state.value, "StringLiteral"); - if (elem) { - this.checkDeclaration(elem); + case types._null: + node = this.startNode(); + this.next(); + return this.finishNode(node, "NullLiteral"); + + case types._true: + case types._false: + return this.parseBooleanLiteral(); + + case types.parenL: + return this.parseParenAndDistinguishExpression(canBeArrow); + + case types.bracketL: + node = this.startNode(); + this.next(); + node.elements = this.parseExprList(types.bracketR, true, refShorthandDefaultPos); + + if (!this.state.maybeInArrowParameters) { + this.toReferencedList(node.elements); } - } - } else if (node.type === "ObjectProperty") { - this.checkDeclaration(node.value); - } else if (node.type === "RestElement") { - this.checkDeclaration(node.argument); - } else if (node.type === "AssignmentPattern") { - this.checkDeclaration(node.left); - } - } - checkDuplicateExports(node, name) { - if (this.state.exportedIdentifiers.indexOf(name) > -1) { - throw this.raise(node.start, name === "default" ? "Only one default export allowed per module." : `\`${name}\` has already been exported. Exported identifiers must be unique.`); - } + return this.finishNode(node, "ArrayExpression"); + + case types.braceL: + return this.parseObj(false, refShorthandDefaultPos); + + case types._function: + return this.parseFunctionExpression(); - this.state.exportedIdentifiers.push(name); - } + case types.at: + this.parseDecorators(); - parseExportSpecifiers() { - const nodes = []; - let first = true; - let needsFrom; - this.expect(types.braceL); + case types._class: + node = this.startNode(); + this.takeDecorators(node); + return this.parseClass(node, false); - while (!this.eat(types.braceR)) { - if (first) { - first = false; - } else { - this.expect(types.comma); - if (this.eat(types.braceR)) break; - } + case types._new: + return this.parseNew(); - const isDefault = this.match(types._default); - if (isDefault && !needsFrom) needsFrom = true; - const node = this.startNode(); - node.local = this.parseIdentifier(isDefault); - node.exported = this.eatContextual("as") ? this.parseIdentifier(true) : node.local.__clone(); - nodes.push(this.finishNode(node, "ExportSpecifier")); - } + case types.backQuote: + return this.parseTemplate(false); - if (needsFrom && !this.isContextual("from")) { - this.unexpected(); - } + case types.doubleColon: + { + node = this.startNode(); + this.next(); + node.object = null; + const callee = node.callee = this.parseNoCallExpr(); - return nodes; - } + if (callee.type === "MemberExpression") { + return this.finishNode(node, "BindExpression"); + } else { + throw this.raise(callee.start, "Binding should be performed on object property."); + } + } - parseImport(node) { - node.specifiers = []; + case types.hash: + { + if (this.state.inPipeline) { + node = this.startNode(); - if (!this.match(types.string)) { - const hasDefault = this.maybeParseDefaultImportSpecifier(node); - const parseNext = !hasDefault || this.eat(types.comma); - const hasStar = parseNext && this.maybeParseStarImportSpecifier(node); - if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node); - this.expectContextual("from"); - } + if (this.getPluginOption("pipelineOperator", "proposal") !== "smart") { + this.raise(node.start, "Primary Topic Reference found but pipelineOperator not passed 'smart' for 'proposal' option."); + } - node.source = this.parseImportSource(); - this.semicolon(); - return this.finishNode(node, "ImportDeclaration"); - } + this.next(); - parseImportSource() { - if (!this.match(types.string)) this.unexpected(); - return this.parseExprAtom(); - } + if (this.primaryTopicReferenceIsAllowedInCurrentTopicContext()) { + this.registerTopicReference(); + return this.finishNode(node, "PipelinePrimaryTopicReference"); + } else { + throw this.raise(node.start, `Topic reference was used in a lexical context without topic binding`); + } + } + } - shouldParseDefaultImport(node) { - return this.match(types.name); + default: + throw this.unexpected(); + } } - parseImportSpecifierLocal(node, specifier, type, contextDescription) { - specifier.local = this.parseIdentifier(); - this.checkLVal(specifier.local, true, undefined, contextDescription); - node.specifiers.push(this.finishNode(specifier, type)); + parseBooleanLiteral() { + const node = this.startNode(); + node.value = this.match(types._true); + this.next(); + return this.finishNode(node, "BooleanLiteral"); } - maybeParseDefaultImportSpecifier(node) { - if (this.shouldParseDefaultImport(node)) { - this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier", "default import specifier"); - return true; - } + parseMaybePrivateName() { + const isPrivate = this.match(types.hash); - return false; + if (isPrivate) { + this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]); + const node = this.startNode(); + this.next(); + this.assertNoSpace("Unexpected space between # and identifier"); + node.id = this.parseIdentifier(true); + return this.finishNode(node, "PrivateName"); + } else { + return this.parseIdentifier(true); + } } - maybeParseStarImportSpecifier(node) { - if (this.match(types.star)) { - const specifier = this.startNode(); - this.next(); - this.expectContextual("as"); - this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier", "import namespace specifier"); - return true; + parseFunctionExpression() { + const node = this.startNode(); + let meta = this.startNode(); + this.next(); + meta = this.createIdentifier(meta, "function"); + + if (this.scope.inGenerator && this.eat(types.dot)) { + return this.parseMetaProperty(node, meta, "sent"); } - return false; + return this.parseFunction(node); } - parseNamedImportSpecifiers(node) { - let first = true; - this.expect(types.braceL); - - while (!this.eat(types.braceR)) { - if (first) { - first = false; - } else { - if (this.eat(types.colon)) { - this.unexpected(null, "ES2015 named imports do not destructure. " + "Use another statement for destructuring after the import."); - } + parseMetaProperty(node, meta, propertyName) { + node.meta = meta; - this.expect(types.comma); - if (this.eat(types.braceR)) break; + if (meta.name === "function" && propertyName === "sent") { + if (this.isContextual(propertyName)) { + this.expectPlugin("functionSent"); + } else if (!this.hasPlugin("functionSent")) { + this.unexpected(); } - - this.parseImportSpecifier(node); } - } - parseImportSpecifier(node) { - const specifier = this.startNode(); - specifier.imported = this.parseIdentifier(true); + const containsEsc = this.state.containsEsc; + node.property = this.parseIdentifier(true); - if (this.eatContextual("as")) { - specifier.local = this.parseIdentifier(); - } else { - this.checkReservedWord(specifier.imported.name, specifier.start, true, true); - specifier.local = specifier.imported.__clone(); + if (node.property.name !== propertyName || containsEsc) { + this.raise(node.property.start, `The only valid meta property for ${meta.name} is ${meta.name}.${propertyName}`); } - this.checkLVal(specifier.local, true, undefined, "import specifier"); - node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); + return this.finishNode(node, "MetaProperty"); } -} - -class Parser extends StatementParser { - constructor(options, input) { - options = getOptions(options); - super(options, input); - this.options = options; - this.inModule = this.options.sourceType === "module"; - this.plugins = pluginsMap(this.options.plugins); - this.filename = options.sourceFilename; - } + parseImportMetaProperty(node) { + const id = this.createIdentifier(this.startNodeAtNode(node), "import"); + this.expect(types.dot); - parse() { - const file = this.startNode(); - const program = this.startNode(); - this.nextToken(); - return this.parseTopLevel(file, program); - } + if (this.isContextual("meta")) { + this.expectPlugin("importMeta"); + } else if (!this.hasPlugin("importMeta")) { + this.raise(id.start, `Dynamic imports require a parameter: import('a.js')`); + } -} + if (!this.inModule) { + this.raise(id.start, `import.meta may appear only with 'sourceType: "module"'`, { + code: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED" + }); + } -function pluginsMap(plugins) { - const pluginMap = new Map(); + this.sawUnambiguousESM = true; + return this.parseMetaProperty(node, id, "meta"); + } - for (let _i = 0; _i < plugins.length; _i++) { - const plugin = plugins[_i]; - const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}]; - if (!pluginMap.has(name)) pluginMap.set(name, options || {}); + parseLiteral(value, type, startPos, startLoc) { + startPos = startPos || this.state.start; + startLoc = startLoc || this.state.startLoc; + const node = this.startNodeAt(startPos, startLoc); + this.addExtra(node, "rawValue", value); + this.addExtra(node, "raw", this.input.slice(startPos, this.state.end)); + node.value = value; + this.next(); + return this.finishNode(node, type); } - return pluginMap; -} + parseParenAndDistinguishExpression(canBeArrow) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + let val; + this.expect(types.parenL); + const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.maybeInArrowParameters = true; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + const innerStartPos = this.state.start; + const innerStartLoc = this.state.startLoc; + const exprList = []; + const refShorthandDefaultPos = { + start: 0 + }; + const refNeedsArrowPos = { + start: 0 + }; + let first = true; + let spreadStart; + let optionalCommaStart; -function nonNull(x) { - if (x == null) { - throw new Error(`Unexpected ${x} value.`); - } + while (!this.match(types.parenR)) { + if (first) { + first = false; + } else { + this.expect(types.comma, refNeedsArrowPos.start || null); - return x; -} + if (this.match(types.parenR)) { + optionalCommaStart = this.state.start; + break; + } + } + + if (this.match(types.ellipsis)) { + const spreadNodeStartPos = this.state.start; + const spreadNodeStartLoc = this.state.startLoc; + spreadStart = this.state.start; + exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartPos, spreadNodeStartLoc)); + this.checkCommaAfterRest(); + break; + } else { + exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos)); + } + } -function assert(x) { - if (!x) { - throw new Error("Assert fail"); - } -} + const innerEndPos = this.state.start; + const innerEndLoc = this.state.startLoc; + this.expect(types.parenR); + this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + let arrowNode = this.startNodeAt(startPos, startLoc); -function keywordTypeFromName(value) { - switch (value) { - case "any": - return "TSAnyKeyword"; + if (canBeArrow && this.shouldParseArrow() && (arrowNode = this.parseArrow(arrowNode))) { + this.checkYieldAwaitInDefaultParams(); + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; - case "boolean": - return "TSBooleanKeyword"; + for (let _i = 0; _i < exprList.length; _i++) { + const param = exprList[_i]; - case "bigint": - return "TSBigIntKeyword"; + if (param.extra && param.extra.parenthesized) { + this.unexpected(param.extra.parenStart); + } + } - case "never": - return "TSNeverKeyword"; + this.parseArrowExpression(arrowNode, exprList, false); + return arrowNode; + } - case "number": - return "TSNumberKeyword"; + this.state.yieldPos = oldYieldPos || this.state.yieldPos; + this.state.awaitPos = oldAwaitPos || this.state.awaitPos; - case "object": - return "TSObjectKeyword"; + if (!exprList.length) { + this.unexpected(this.state.lastTokStart); + } - case "string": - return "TSStringKeyword"; + if (optionalCommaStart) this.unexpected(optionalCommaStart); + if (spreadStart) this.unexpected(spreadStart); - case "symbol": - return "TSSymbolKeyword"; + if (refShorthandDefaultPos.start) { + this.unexpected(refShorthandDefaultPos.start); + } - case "undefined": - return "TSUndefinedKeyword"; + if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start); + this.toReferencedListDeep(exprList, true); - case "unknown": - return "TSUnknownKeyword"; + if (exprList.length > 1) { + val = this.startNodeAt(innerStartPos, innerStartLoc); + val.expressions = exprList; + this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); + } else { + val = exprList[0]; + } - default: - return undefined; - } -} + if (!this.options.createParenthesizedExpressions) { + this.addExtra(val, "parenthesized", true); + this.addExtra(val, "parenStart", startPos); + return val; + } -var typescript = (superClass => class extends superClass { - tsIsIdentifier() { - return this.match(types.name); + const parenExpression = this.startNodeAt(startPos, startLoc); + parenExpression.expression = val; + this.finishNode(parenExpression, "ParenthesizedExpression"); + return parenExpression; } - tsNextTokenCanFollowModifier() { - this.next(); - return !this.hasPrecedingLineBreak() && !this.match(types.parenL) && !this.match(types.parenR) && !this.match(types.colon) && !this.match(types.eq) && !this.match(types.question) && !this.match(types.bang); + shouldParseArrow() { + return !this.canInsertSemicolon(); } - tsParseModifier(allowedModifiers) { - if (!this.match(types.name)) { - return undefined; + parseArrow(node) { + if (this.eat(types.arrow)) { + return node; } + } - const modifier = this.state.value; + parseParenItem(node, startPos, startLoc) { + return node; + } - if (allowedModifiers.indexOf(modifier) !== -1 && this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) { - return modifier; - } + parseNew() { + const node = this.startNode(); + const meta = this.parseIdentifier(true); - return undefined; - } + if (this.eat(types.dot)) { + const metaProp = this.parseMetaProperty(node, meta, "target"); - tsIsListTerminator(kind) { - switch (kind) { - case "EnumMembers": - case "TypeMembers": - return this.match(types.braceR); + if (!this.scope.inNonArrowFunction && !this.state.inClassProperty) { + let error = "new.target can only be used in functions"; - case "HeritageClauseElement": - return this.match(types.braceL); + if (this.hasPlugin("classProperties")) { + error += " or class properties"; + } - case "TupleElementTypes": - return this.match(types.bracketR); + this.raise(metaProp.start, error); + } - case "TypeParametersOrArguments": - return this.isRelational(">"); + return metaProp; } - throw new Error("Unreachable"); - } - - tsParseList(kind, parseElement) { - const result = []; + node.callee = this.parseNoCallExpr(); - while (!this.tsIsListTerminator(kind)) { - result.push(parseElement()); + if (node.callee.type === "Import") { + this.raise(node.callee.start, "Cannot use new with import(...)"); + } else if (node.callee.type === "OptionalMemberExpression" || node.callee.type === "OptionalCallExpression") { + this.raise(this.state.lastTokEnd, "constructors in/after an Optional Chain are not allowed"); + } else if (this.eat(types.questionDot)) { + this.raise(this.state.start, "constructors in/after an Optional Chain are not allowed"); } - return result; - } - - tsParseDelimitedList(kind, parseElement) { - return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true)); + this.parseNewArguments(node); + return this.finishNode(node, "NewExpression"); } - tsTryParseDelimitedList(kind, parseElement) { - return this.tsParseDelimitedListWorker(kind, parseElement, false); + parseNewArguments(node) { + if (this.eat(types.parenL)) { + const args = this.parseExprList(types.parenR); + this.toReferencedList(args); + node.arguments = args; + } else { + node.arguments = []; + } } - tsParseDelimitedListWorker(kind, parseElement, expectSuccess) { - const result = []; + parseTemplateElement(isTagged) { + const elem = this.startNode(); - while (true) { - if (this.tsIsListTerminator(kind)) { - break; + if (this.state.value === null) { + if (!isTagged) { + this.raise(this.state.invalidTemplateEscapePosition || 0, "Invalid escape sequence in template"); + } else { + this.state.invalidTemplateEscapePosition = null; } + } - const element = parseElement(); + elem.value = { + raw: this.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"), + cooked: this.state.value + }; + this.next(); + elem.tail = this.match(types.backQuote); + return this.finishNode(elem, "TemplateElement"); + } - if (element == null) { - return undefined; - } + parseTemplate(isTagged) { + const node = this.startNode(); + this.next(); + node.expressions = []; + let curElt = this.parseTemplateElement(isTagged); + node.quasis = [curElt]; - result.push(element); + while (!curElt.tail) { + this.expect(types.dollarBraceL); + node.expressions.push(this.parseExpression()); + this.expect(types.braceR); + node.quasis.push(curElt = this.parseTemplateElement(isTagged)); + } - if (this.eat(types.comma)) { - continue; - } + this.next(); + return this.finishNode(node, "TemplateLiteral"); + } - if (this.tsIsListTerminator(kind)) { - break; - } + parseObj(isPattern, refShorthandDefaultPos) { + const propHash = Object.create(null); + let first = true; + const node = this.startNode(); + node.properties = []; + this.next(); - if (expectSuccess) { + while (!this.eat(types.braceR)) { + if (first) { + first = false; + } else { this.expect(types.comma); + if (this.eat(types.braceR)) break; } - return undefined; - } - - return result; - } + const prop = this.parseObjectMember(isPattern, refShorthandDefaultPos); + if (!isPattern) this.checkPropClash(prop, propHash); - tsParseBracketedList(kind, parseElement, bracket, skipFirstToken) { - if (!skipFirstToken) { - if (bracket) { - this.expect(types.bracketL); - } else { - this.expectRelational("<"); + if (prop.shorthand) { + this.addExtra(prop, "shorthand", true); } - } - - const result = this.tsParseDelimitedList(kind, parseElement); - if (bracket) { - this.expect(types.bracketR); - } else { - this.expectRelational(">"); + node.properties.push(prop); } - return result; + return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); } - tsParseImportType() { - const node = this.startNode(); - this.expect(types._import); - this.expect(types.parenL); + isAsyncProp(prop) { + return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" && (this.match(types.name) || this.match(types.num) || this.match(types.string) || this.match(types.bracketL) || this.state.type.keyword || this.match(types.star)) && !this.hasPrecedingLineBreak(); + } - if (!this.match(types.string)) { - throw this.unexpected(null, "Argument in a type import must be a string literal"); + parseObjectMember(isPattern, refShorthandDefaultPos) { + let decorators = []; + + if (this.match(types.at)) { + if (this.hasPlugin("decorators")) { + this.raise(this.state.start, "Stage 2 decorators disallow object literal property decorators"); + } else { + while (this.match(types.at)) { + decorators.push(this.parseDecorator()); + } + } } - node.argument = this.parseLiteral(this.state.value, "StringLiteral"); - this.expect(types.parenR); + const prop = this.startNode(); + let isGenerator = false; + let isAsync = false; + let startPos; + let startLoc; - if (this.eat(types.dot)) { - node.qualifier = this.tsParseEntityName(true); - } + if (this.match(types.ellipsis)) { + if (decorators.length) this.unexpected(); - if (this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); + if (isPattern) { + this.next(); + prop.argument = this.parseIdentifier(); + this.checkCommaAfterRest(); + return this.finishNode(prop, "RestElement"); + } + + return this.parseSpread(); } - return this.finishNode(node, "TSImportType"); - } + if (decorators.length) { + prop.decorators = decorators; + decorators = []; + } - tsParseEntityName(allowReservedWords) { - let entity = this.parseIdentifier(); + prop.method = false; - while (this.eat(types.dot)) { - const node = this.startNodeAtNode(entity); - node.left = entity; - node.right = this.parseIdentifier(allowReservedWords); - entity = this.finishNode(node, "TSQualifiedName"); + if (isPattern || refShorthandDefaultPos) { + startPos = this.state.start; + startLoc = this.state.startLoc; } - return entity; - } + if (!isPattern) { + isGenerator = this.eat(types.star); + } - tsParseTypeReference() { - const node = this.startNode(); - node.typeName = this.tsParseEntityName(false); + const containsEsc = this.state.containsEsc; + this.parsePropertyName(prop); - if (!this.hasPrecedingLineBreak() && this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); + if (!isPattern && !containsEsc && !isGenerator && this.isAsyncProp(prop)) { + isAsync = true; + isGenerator = this.eat(types.star); + this.parsePropertyName(prop); + } else { + isAsync = false; } - return this.finishNode(node, "TSTypeReference"); + this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc); + return prop; } - tsParseThisTypePredicate(lhs) { - this.next(); - const node = this.startNodeAtNode(lhs); - node.parameterName = lhs; - node.typeAnnotation = this.tsParseTypeAnnotation(false); - return this.finishNode(node, "TSTypePredicate"); + isGetterOrSetterMethod(prop, isPattern) { + return !isPattern && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.match(types.string) || this.match(types.num) || this.match(types.bracketL) || this.match(types.name) || !!this.state.type.keyword); } - tsParseThisTypeNode() { - const node = this.startNode(); - this.next(); - return this.finishNode(node, "TSThisType"); + getGetterSetterExpectedParamCount(method) { + return method.kind === "get" ? 0 : 1; } - tsParseTypeQuery() { - const node = this.startNode(); - this.expect(types._typeof); + checkGetterSetterParams(method) { + const paramCount = this.getGetterSetterExpectedParamCount(method); + const start = method.start; - if (this.match(types._import)) { - node.exprName = this.tsParseImportType(); - } else { - node.exprName = this.tsParseEntityName(true); + if (method.params.length !== paramCount) { + if (method.kind === "get") { + this.raise(start, "getter must not have any formal parameters"); + } else { + this.raise(start, "setter must have exactly one formal parameter"); + } } - return this.finishNode(node, "TSTypeQuery"); + if (method.kind === "set" && method.params[method.params.length - 1].type === "RestElement") { + this.raise(start, "setter function argument must not be a rest parameter"); + } } - tsParseTypeParameter() { - const node = this.startNode(); - node.name = this.parseIdentifierName(node.start); - node.constraint = this.tsEatThenParseType(types._extends); - node.default = this.tsEatThenParseType(types.eq); - return this.finishNode(node, "TSTypeParameter"); - } + parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) { + if (isAsync || isGenerator || this.match(types.parenL)) { + if (isPattern) this.unexpected(); + prop.kind = "method"; + prop.method = true; + return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod"); + } - tsTryParseTypeParameters() { - if (this.isRelational("<")) { - return this.tsParseTypeParameters(); + if (!containsEsc && this.isGetterOrSetterMethod(prop, isPattern)) { + if (isGenerator || isAsync) this.unexpected(); + prop.kind = prop.key.name; + this.parsePropertyName(prop); + this.parseMethod(prop, false, false, false, false, "ObjectMethod"); + this.checkGetterSetterParams(prop); + return prop; } } - tsParseTypeParameters() { - const node = this.startNode(); + parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) { + prop.shorthand = false; - if (this.isRelational("<") || this.match(types.jsxTagStart)) { - this.next(); - } else { - this.unexpected(); + if (this.eat(types.colon)) { + prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos); + return this.finishNode(prop, "ObjectProperty"); } - node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true); - return this.finishNode(node, "TSTypeParameterDeclaration"); - } + if (!prop.computed && prop.key.type === "Identifier") { + this.checkReservedWord(prop.key.name, prop.key.start, true, true); - tsFillSignature(returnToken, signature) { - const returnTokenRequired = returnToken === types.arrow; - signature.typeParameters = this.tsTryParseTypeParameters(); - this.expect(types.parenL); - signature.parameters = this.tsParseBindingListForSignature(); + if (isPattern) { + prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); + } else if (this.match(types.eq) && refShorthandDefaultPos) { + if (!refShorthandDefaultPos.start) { + refShorthandDefaultPos.start = this.state.start; + } - if (returnTokenRequired) { - signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); - } else if (this.match(returnToken)) { - signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); + prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); + } else { + prop.value = prop.key.__clone(); + } + + prop.shorthand = true; + return this.finishNode(prop, "ObjectProperty"); } } - tsParseBindingListForSignature() { - return this.parseBindingList(types.parenR).map(pattern => { - if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") { - throw this.unexpected(pattern.start, `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${pattern.type}`); - } - - return pattern; - }); + parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc) { + const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) || this.parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos); + if (!node) this.unexpected(); + return node; } - tsParseTypeMemberSemicolon() { - if (!this.eat(types.comma)) { - this.semicolon(); + parsePropertyName(prop) { + if (this.eat(types.bracketL)) { + prop.computed = true; + prop.key = this.parseMaybeAssign(); + this.expect(types.bracketR); + } else { + const oldInPropertyName = this.state.inPropertyName; + this.state.inPropertyName = true; + prop.key = this.match(types.num) || this.match(types.string) ? this.parseExprAtom() : this.parseMaybePrivateName(); + + if (prop.key.type !== "PrivateName") { + prop.computed = false; + } + + this.state.inPropertyName = oldInPropertyName; } + + return prop.key; } - tsParseSignatureMember(kind) { - const node = this.startNode(); + initFunction(node, isAsync) { + node.id = null; + node.generator = false; + node.async = !!isAsync; + } - if (kind === "TSConstructSignatureDeclaration") { - this.expect(types._new); - } + parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) { + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + this.initFunction(node, isAsync); + node.generator = !!isGenerator; + const allowModifiers = isConstructor; + this.scope.enter(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (inClassScope ? SCOPE_CLASS : 0) | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0)); + this.parseFunctionParams(node, allowModifiers); + this.checkYieldAwaitInDefaultParams(); + this.parseFunctionBodyAndFinish(node, type, true); + this.scope.exit(); + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; + return node; + } - this.tsFillSignature(types.colon, node); - this.tsParseTypeMemberSemicolon(); - return this.finishNode(node, kind); + parseArrowExpression(node, params, isAsync) { + this.scope.enter(functionFlags(isAsync, false) | SCOPE_ARROW); + this.initFunction(node, isAsync); + const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.maybeInArrowParameters = false; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + if (params) this.setArrowFunctionParameters(node, params); + this.parseFunctionBody(node, true); + this.scope.exit(); + this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; + return this.finishNode(node, "ArrowFunctionExpression"); } - tsIsUnambiguouslyIndexSignature() { - this.next(); - return this.eat(types.name) && this.match(types.colon); + setArrowFunctionParameters(node, params) { + node.params = this.toAssignableList(params, true, "arrow function parameters"); } - tsTryParseIndexSignature(node) { - if (!(this.match(types.bracketL) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) { - return undefined; + isStrictBody(node) { + const isBlockStatement = node.body.type === "BlockStatement"; + + if (isBlockStatement && node.body.directives.length) { + for (let _i2 = 0, _node$body$directives = node.body.directives; _i2 < _node$body$directives.length; _i2++) { + const directive = _node$body$directives[_i2]; + + if (directive.value.value === "use strict") { + return true; + } + } } - this.expect(types.bracketL); - const id = this.parseIdentifier(); - id.typeAnnotation = this.tsParseTypeAnnotation(); - this.finishNode(id, "Identifier"); - this.expect(types.bracketR); - node.parameters = [id]; - const type = this.tsTryParseTypeAnnotation(); - if (type) node.typeAnnotation = type; - this.tsParseTypeMemberSemicolon(); - return this.finishNode(node, "TSIndexSignature"); + return false; } - tsParsePropertyOrMethodSignature(node, readonly) { - this.parsePropertyName(node); - if (this.eat(types.question)) node.optional = true; - const nodeAny = node; + parseFunctionBodyAndFinish(node, type, isMethod = false) { + this.parseFunctionBody(node, false, isMethod); + this.finishNode(node, type); + } - if (!readonly && (this.match(types.parenL) || this.isRelational("<"))) { - const method = nodeAny; - this.tsFillSignature(types.colon, method); - this.tsParseTypeMemberSemicolon(); - return this.finishNode(method, "TSMethodSignature"); + parseFunctionBody(node, allowExpression, isMethod = false) { + const isExpression = allowExpression && !this.match(types.braceL); + const oldStrict = this.state.strict; + let useStrict = false; + const oldInParameters = this.state.inParameters; + this.state.inParameters = false; + + if (isExpression) { + node.body = this.parseMaybeAssign(); + this.checkParams(node, false, allowExpression); } else { - const property = nodeAny; - if (readonly) property.readonly = true; - const type = this.tsTryParseTypeAnnotation(); - if (type) property.typeAnnotation = type; - this.tsParseTypeMemberSemicolon(); - return this.finishNode(property, "TSPropertySignature"); - } - } + const nonSimple = !this.isSimpleParamList(node.params); - tsParseTypeMember() { - if (this.match(types.parenL) || this.isRelational("<")) { - return this.tsParseSignatureMember("TSCallSignatureDeclaration"); - } + if (!oldStrict || nonSimple) { + useStrict = this.strictDirective(this.state.end); - if (this.match(types._new) && this.tsLookAhead(this.tsIsStartOfConstructSignature.bind(this))) { - return this.tsParseSignatureMember("TSConstructSignatureDeclaration"); - } + if (useStrict && nonSimple) { + const errorPos = (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.end : node.start; + this.raise(errorPos, "Illegal 'use strict' directive in function with non-simple parameter list"); + } + } - const node = this.startNode(); - const readonly = !!this.tsParseModifier(["readonly"]); - const idx = this.tsTryParseIndexSignature(node); + const oldLabels = this.state.labels; + this.state.labels = []; + if (useStrict) this.state.strict = true; + this.checkParams(node, !oldStrict && !useStrict && !allowExpression && !isMethod && !nonSimple, allowExpression); + node.body = this.parseBlock(true, false); + this.state.labels = oldLabels; + } - if (idx) { - if (readonly) node.readonly = true; - return idx; + this.state.inParameters = oldInParameters; + + if (this.state.strict && node.id) { + this.checkLVal(node.id, BIND_OUTSIDE, undefined, "function name"); } - return this.tsParsePropertyOrMethodSignature(node, readonly); + this.state.strict = oldStrict; } - tsIsStartOfConstructSignature() { - this.next(); - return this.match(types.parenL) || this.isRelational("<"); - } + isSimpleParamList(params) { + for (let i = 0, len = params.length; i < len; i++) { + if (params[i].type !== "Identifier") return false; + } - tsParseTypeLiteral() { - const node = this.startNode(); - node.members = this.tsParseObjectTypeMembers(); - return this.finishNode(node, "TSTypeLiteral"); + return true; } - tsParseObjectTypeMembers() { - this.expect(types.braceL); - const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this)); - this.expect(types.braceR); - return members; + checkParams(node, allowDuplicates, isArrowFunction) { + const nameHash = Object.create(null); + + for (let i = 0; i < node.params.length; i++) { + this.checkLVal(node.params[i], BIND_VAR, allowDuplicates ? null : nameHash, "function paramter list"); + } } - tsIsStartOfMappedType() { - this.next(); + parseExprList(close, allowEmpty, refShorthandDefaultPos) { + const elts = []; + let first = true; - if (this.eat(types.plusMin)) { - return this.isContextual("readonly"); - } + while (!this.eat(close)) { + if (first) { + first = false; + } else { + this.expect(types.comma); + if (this.eat(close)) break; + } - if (this.isContextual("readonly")) { - this.next(); + elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos)); } - if (!this.match(types.bracketL)) { - return false; - } + return elts; + } - this.next(); + parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos, allowPlaceholder) { + let elt; - if (!this.tsIsIdentifier()) { - return false; + if (allowEmpty && this.match(types.comma)) { + elt = null; + } else if (this.match(types.ellipsis)) { + const spreadNodeStartPos = this.state.start; + const spreadNodeStartLoc = this.state.startLoc; + elt = this.parseParenItem(this.parseSpread(refShorthandDefaultPos, refNeedsArrowPos), spreadNodeStartPos, spreadNodeStartLoc); + } else if (this.match(types.question)) { + this.expectPlugin("partialApplication"); + + if (!allowPlaceholder) { + this.raise(this.state.start, "Unexpected argument placeholder"); + } + + const node = this.startNode(); + this.next(); + elt = this.finishNode(node, "ArgumentPlaceholder"); + } else { + elt = this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos); } - this.next(); - return this.match(types._in); + return elt; } - tsParseMappedTypeParameter() { + parseIdentifier(liberal) { const node = this.startNode(); - node.name = this.parseIdentifierName(node.start); - node.constraint = this.tsExpectThenParseType(types._in); - return this.finishNode(node, "TSTypeParameter"); + const name = this.parseIdentifierName(node.start, liberal); + return this.createIdentifier(node, name); } - tsParseMappedType() { - const node = this.startNode(); - this.expect(types.braceL); + createIdentifier(node, name) { + node.name = name; + node.loc.identifierName = name; + return this.finishNode(node, "Identifier"); + } - if (this.match(types.plusMin)) { - node.readonly = this.state.value; - this.next(); - this.expectContextual("readonly"); - } else if (this.eatContextual("readonly")) { - node.readonly = true; - } + parseIdentifierName(pos, liberal) { + let name; - this.expect(types.bracketL); - node.typeParameter = this.tsParseMappedTypeParameter(); - this.expect(types.bracketR); + if (this.match(types.name)) { + name = this.state.value; + } else if (this.state.type.keyword) { + name = this.state.type.keyword; - if (this.match(types.plusMin)) { - node.optional = this.state.value; - this.next(); - this.expect(types.question); - } else if (this.eat(types.question)) { - node.optional = true; + if ((name === "class" || name === "function") && (this.state.lastTokEnd !== this.state.lastTokStart + 1 || this.input.charCodeAt(this.state.lastTokStart) !== 46)) { + this.state.context.pop(); + } + } else { + throw this.unexpected(); } - node.typeAnnotation = this.tsTryParseType(); - this.semicolon(); - this.expect(types.braceR); - return this.finishNode(node, "TSMappedType"); - } + if (!liberal) { + this.checkReservedWord(name, this.state.start, !!this.state.type.keyword, false); + } - tsParseTupleType() { - const node = this.startNode(); - node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false); - let seenOptionalElement = false; - node.elementTypes.forEach(elementNode => { - if (elementNode.type === "TSOptionalType") { - seenOptionalElement = true; - } else if (seenOptionalElement && elementNode.type !== "TSRestType") { - this.raise(elementNode.start, "A required element cannot follow an optional element."); - } - }); - return this.finishNode(node, "TSTupleType"); + this.next(); + return name; } - tsParseTupleElementType() { - if (this.match(types.ellipsis)) { - const restNode = this.startNode(); - this.next(); - restNode.typeAnnotation = this.tsParseType(); - this.checkCommaAfterRest(types.bracketR, "type"); - return this.finishNode(restNode, "TSRestType"); + checkReservedWord(word, startLoc, checkKeywords, isBinding) { + if (this.scope.inGenerator && word === "yield") { + this.raise(startLoc, "Can not use 'yield' as identifier inside a generator"); } - const type = this.tsParseType(); + if (this.scope.inAsync && word === "await") { + this.raise(startLoc, "Can not use 'await' as identifier inside an async function"); + } - if (this.eat(types.question)) { - const optionalTypeNode = this.startNodeAtNode(type); - optionalTypeNode.typeAnnotation = type; - return this.finishNode(optionalTypeNode, "TSOptionalType"); + if (this.state.inClassProperty && word === "arguments") { + this.raise(startLoc, "'arguments' is not allowed in class field initializer"); } - return type; - } + if (checkKeywords && isKeyword(word)) { + this.raise(startLoc, `Unexpected keyword '${word}'`); + } - tsParseParenthesizedType() { - const node = this.startNode(); - this.expect(types.parenL); - node.typeAnnotation = this.tsParseType(); - this.expect(types.parenR); - return this.finishNode(node, "TSParenthesizedType"); + const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord; + + if (reservedTest(word, this.inModule)) { + if (!this.scope.inAsync && word === "await") { + this.raise(startLoc, "Can not use keyword 'await' outside an async function"); + } + + this.raise(startLoc, `Unexpected reserved word '${word}'`); + } } - tsParseFunctionOrConstructorType(type) { + parseAwait() { + if (!this.state.awaitPos) { + this.state.awaitPos = this.state.start; + } + const node = this.startNode(); + this.next(); - if (type === "TSConstructorType") { - this.expect(types._new); + if (this.state.inParameters) { + this.raise(node.start, "await is not allowed in async function parameters"); } - this.tsFillSignature(types.arrow, node); - return this.finishNode(node, type); + if (this.match(types.star)) { + this.raise(node.start, "await* has been removed from the async functions proposal. Use Promise.all() instead."); + } + + node.argument = this.parseMaybeUnary(); + return this.finishNode(node, "AwaitExpression"); } - tsParseLiteralTypeNode() { + parseYield(noIn) { + if (!this.state.yieldPos) { + this.state.yieldPos = this.state.start; + } + const node = this.startNode(); - node.literal = (() => { - switch (this.state.type) { - case types.num: - return this.parseLiteral(this.state.value, "NumericLiteral"); + if (this.state.inParameters) { + this.raise(node.start, "yield is not allowed in generator parameters"); + } - case types.string: - return this.parseLiteral(this.state.value, "StringLiteral"); + this.next(); - case types._true: - case types._false: - return this.parseBooleanLiteral(); + if (this.match(types.semi) || !this.match(types.star) && !this.state.type.startsExpr || this.canInsertSemicolon()) { + node.delegate = false; + node.argument = null; + } else { + node.delegate = this.eat(types.star); + node.argument = this.parseMaybeAssign(noIn); + } - default: - throw this.unexpected(); - } - })(); + return this.finishNode(node, "YieldExpression"); + } - return this.finishNode(node, "TSLiteralType"); + checkPipelineAtInfixOperator(left, leftStartPos) { + if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { + if (left.type === "SequenceExpression") { + throw this.raise(leftStartPos, `Pipeline head should not be a comma-separated sequence expression`); + } + } } - tsParseNonArrayType() { - switch (this.state.type) { - case types.name: - case types._void: - case types._null: - { - const type = this.match(types._void) ? "TSVoidKeyword" : this.match(types._null) ? "TSNullKeyword" : keywordTypeFromName(this.state.value); + parseSmartPipelineBody(childExpression, startPos, startLoc) { + const pipelineStyle = this.checkSmartPipelineBodyStyle(childExpression); + this.checkSmartPipelineBodyEarlyErrors(childExpression, pipelineStyle, startPos); + return this.parseSmartPipelineBodyInStyle(childExpression, pipelineStyle, startPos, startLoc); + } - if (type !== undefined && this.lookahead().type !== types.dot) { - const node = this.startNode(); - this.next(); - return this.finishNode(node, type); - } + checkSmartPipelineBodyEarlyErrors(childExpression, pipelineStyle, startPos) { + if (this.match(types.arrow)) { + throw this.raise(this.state.start, `Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized`); + } else if (pipelineStyle === "PipelineTopicExpression" && childExpression.type === "SequenceExpression") { + throw this.raise(startPos, `Pipeline body may not be a comma-separated sequence expression`); + } + } - return this.tsParseTypeReference(); - } + parseSmartPipelineBodyInStyle(childExpression, pipelineStyle, startPos, startLoc) { + const bodyNode = this.startNodeAt(startPos, startLoc); - case types.string: - case types.num: - case types._true: - case types._false: - return this.tsParseLiteralTypeNode(); + switch (pipelineStyle) { + case "PipelineBareFunction": + bodyNode.callee = childExpression; + break; - case types.plusMin: - if (this.state.value === "-") { - const node = this.startNode(); - this.next(); + case "PipelineBareConstructor": + bodyNode.callee = childExpression.callee; + break; - if (!this.match(types.num)) { - throw this.unexpected(); - } + case "PipelineBareAwaitedFunction": + bodyNode.callee = childExpression.argument; + break; - node.literal = this.parseLiteral(-this.state.value, "NumericLiteral", node.start, node.loc.start); - return this.finishNode(node, "TSLiteralType"); + case "PipelineTopicExpression": + if (!this.topicReferenceWasUsedInCurrentTopicContext()) { + throw this.raise(startPos, `Pipeline is in topic style but does not use topic reference`); } + bodyNode.expression = childExpression; break; - case types._this: - { - const thisKeyword = this.tsParseThisTypeNode(); - - if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { - return this.tsParseThisTypePredicate(thisKeyword); - } else { - return thisKeyword; - } - } + default: + throw this.raise(startPos, `Unknown pipeline style ${pipelineStyle}`); + } - case types._typeof: - return this.tsParseTypeQuery(); + return this.finishNode(bodyNode, pipelineStyle); + } - case types._import: - return this.tsParseImportType(); + checkSmartPipelineBodyStyle(expression) { + switch (expression.type) { + default: + return this.isSimpleReference(expression) ? "PipelineBareFunction" : "PipelineTopicExpression"; + } + } - case types.braceL: - return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral(); + isSimpleReference(expression) { + switch (expression.type) { + case "MemberExpression": + return !expression.computed && this.isSimpleReference(expression.object); - case types.bracketL: - return this.tsParseTupleType(); + case "Identifier": + return true; - case types.parenL: - return this.tsParseParenthesizedType(); + default: + return false; } - - throw this.unexpected(); } - tsParseArrayTypeOrHigher() { - let type = this.tsParseNonArrayType(); + withTopicPermittingContext(callback) { + const outerContextTopicState = this.state.topicContext; + this.state.topicContext = { + maxNumOfResolvableTopics: 1, + maxTopicIndex: null + }; - while (!this.hasPrecedingLineBreak() && this.eat(types.bracketL)) { - if (this.match(types.bracketR)) { - const node = this.startNodeAtNode(type); - node.elementType = type; - this.expect(types.bracketR); - type = this.finishNode(node, "TSArrayType"); - } else { - const node = this.startNodeAtNode(type); - node.objectType = type; - node.indexType = this.tsParseType(); - this.expect(types.bracketR); - type = this.finishNode(node, "TSIndexedAccessType"); - } + try { + return callback(); + } finally { + this.state.topicContext = outerContextTopicState; } + } - return type; + withTopicForbiddingContext(callback) { + const outerContextTopicState = this.state.topicContext; + this.state.topicContext = { + maxNumOfResolvableTopics: 0, + maxTopicIndex: null + }; + + try { + return callback(); + } finally { + this.state.topicContext = outerContextTopicState; + } } - tsParseTypeOperator(operator) { - const node = this.startNode(); - this.expectContextual(operator); - node.operator = operator; - node.typeAnnotation = this.tsParseTypeOperatorOrHigher(); - return this.finishNode(node, "TSTypeOperator"); + registerTopicReference() { + this.state.topicContext.maxTopicIndex = 0; } - tsParseInferType() { - const node = this.startNode(); - this.expectContextual("infer"); - const typeParameter = this.startNode(); - typeParameter.name = this.parseIdentifierName(typeParameter.start); - node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter"); - return this.finishNode(node, "TSInferType"); + primaryTopicReferenceIsAllowedInCurrentTopicContext() { + return this.state.topicContext.maxNumOfResolvableTopics >= 1; } - tsParseTypeOperatorOrHigher() { - const operator = ["keyof", "unique"].find(kw => this.isContextual(kw)); - return operator ? this.tsParseTypeOperator(operator) : this.isContextual("infer") ? this.tsParseInferType() : this.tsParseArrayTypeOrHigher(); + topicReferenceWasUsedInCurrentTopicContext() { + return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0; } - tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) { - this.eat(operator); - let type = parseConstituentType(); +} - if (this.match(operator)) { - const types$$1 = [type]; +const loopLabel = { + kind: "loop" +}, + switchLabel = { + kind: "switch" +}; +const FUNC_NO_FLAGS = 0b000, + FUNC_STATEMENT = 0b001, + FUNC_HANGING_STATEMENT = 0b010, + FUNC_NULLABLE_ID = 0b100; +class StatementParser extends ExpressionParser { + parseTopLevel(file, program) { + program.sourceType = this.options.sourceType; + program.interpreter = this.parseInterpreterDirective(); + this.parseBlockBody(program, true, true, types.eof); - while (this.eat(operator)) { - types$$1.push(parseConstituentType()); + if (this.inModule && this.scope.undefinedExports.size > 0) { + for (let _i = 0, _Array$from = Array.from(this.scope.undefinedExports); _i < _Array$from.length; _i++) { + const [name] = _Array$from[_i]; + const pos = this.scope.undefinedExports.get(name); + this.raise(pos, `Export '${name}' is not defined`); } - - const node = this.startNodeAtNode(type); - node.types = types$$1; - type = this.finishNode(node, kind); } - return type; - } - - tsParseIntersectionTypeOrHigher() { - return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), types.bitwiseAND); + file.program = this.finishNode(program, "Program"); + file.comments = this.state.comments; + if (this.options.tokens) file.tokens = this.state.tokens; + return this.finishNode(file, "File"); } - tsParseUnionTypeOrHigher() { - return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), types.bitwiseOR); + stmtToDirective(stmt) { + const expr = stmt.expression; + const directiveLiteral = this.startNodeAt(expr.start, expr.loc.start); + const directive = this.startNodeAt(stmt.start, stmt.loc.start); + const raw = this.input.slice(expr.start, expr.end); + const val = directiveLiteral.value = raw.slice(1, -1); + this.addExtra(directiveLiteral, "raw", raw); + this.addExtra(directiveLiteral, "rawValue", val); + directive.value = this.finishNodeAt(directiveLiteral, "DirectiveLiteral", expr.end, expr.loc.end); + return this.finishNodeAt(directive, "Directive", stmt.end, stmt.loc.end); } - tsIsStartOfFunctionType() { - if (this.isRelational("<")) { - return true; + parseInterpreterDirective() { + if (!this.match(types.interpreterDirective)) { + return null; } - return this.match(types.parenL) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this)); + const node = this.startNode(); + node.value = this.state.value; + this.next(); + return this.finishNode(node, "InterpreterDirective"); } - tsSkipParameterStart() { - if (this.match(types.name) || this.match(types._this)) { - this.next(); - return true; + isLet(context) { + if (!this.isContextual("let")) { + return false; } - if (this.match(types.braceL)) { - let braceStackCounter = 1; - this.next(); + skipWhiteSpace.lastIndex = this.state.pos; + const skip = skipWhiteSpace.exec(this.input); + const next = this.state.pos + skip[0].length; + const nextCh = this.input.charCodeAt(next); + if (nextCh === 91) return true; + if (context) return false; + if (nextCh === 123) return true; - while (braceStackCounter > 0) { - if (this.match(types.braceL)) { - ++braceStackCounter; - } else if (this.match(types.braceR)) { - --braceStackCounter; - } + if (isIdentifierStart(nextCh)) { + let pos = next + 1; - this.next(); + while (isIdentifierChar(this.input.charCodeAt(pos))) { + ++pos; } - return true; + const ident = this.input.slice(next, pos); + if (!keywordRelationalOperator.test(ident)) return true; } - if (this.match(types.bracketL)) { - let braceStackCounter = 1; - this.next(); - - while (braceStackCounter > 0) { - if (this.match(types.bracketL)) { - ++braceStackCounter; - } else if (this.match(types.bracketR)) { - --braceStackCounter; - } - - this.next(); - } + return false; + } - return true; + parseStatement(context, topLevel) { + if (this.match(types.at)) { + this.parseDecorators(true); } - return false; + return this.parseStatementContent(context, topLevel); } - tsIsUnambiguouslyStartOfFunctionType() { - this.next(); + parseStatementContent(context, topLevel) { + let starttype = this.state.type; + const node = this.startNode(); + let kind; - if (this.match(types.parenR) || this.match(types.ellipsis)) { - return true; + if (this.isLet(context)) { + starttype = types._var; + kind = "let"; } - if (this.tsSkipParameterStart()) { - if (this.match(types.colon) || this.match(types.comma) || this.match(types.question) || this.match(types.eq)) { - return true; - } + switch (starttype) { + case types._break: + case types._continue: + return this.parseBreakContinueStatement(node, starttype.keyword); + + case types._debugger: + return this.parseDebuggerStatement(node); + + case types._do: + return this.parseDoStatement(node); + + case types._for: + return this.parseForStatement(node); + + case types._function: + if (this.lookahead().type === types.dot) break; + + if (context) { + if (this.state.strict) { + this.raise(this.state.start, "In strict mode code, functions can only be declared at top level or inside a block"); + } else if (context !== "if" && context !== "label") { + this.raise(this.state.start, "In non-strict mode code, functions can only be declared at top level, " + "inside a block, or as the body of an if statement"); + } + } + + return this.parseFunctionStatement(node, false, !context); + + case types._class: + if (context) this.unexpected(); + return this.parseClass(node, true); + + case types._if: + return this.parseIfStatement(node); + + case types._return: + return this.parseReturnStatement(node); + + case types._switch: + return this.parseSwitchStatement(node); + + case types._throw: + return this.parseThrowStatement(node); + + case types._try: + return this.parseTryStatement(node); - if (this.match(types.parenR)) { - this.next(); + case types._const: + case types._var: + kind = kind || this.state.value; - if (this.match(types.arrow)) { - return true; + if (context && kind !== "var") { + this.unexpected(this.state.start, "Lexical declaration cannot appear in a single-statement context"); } - } - } - return false; - } + return this.parseVarStatement(node, kind); - tsParseTypeOrTypePredicateAnnotation(returnToken) { - return this.tsInType(() => { - const t = this.startNode(); - this.expect(returnToken); - const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); + case types._while: + return this.parseWhileStatement(node); - if (!typePredicateVariable) { - return this.tsParseTypeAnnotation(false, t); - } + case types._with: + return this.parseWithStatement(node); - const type = this.tsParseTypeAnnotation(false); - const node = this.startNodeAtNode(typePredicateVariable); - node.parameterName = typePredicateVariable; - node.typeAnnotation = type; - t.typeAnnotation = this.finishNode(node, "TSTypePredicate"); - return this.finishNode(t, "TSTypeAnnotation"); - }); - } + case types.braceL: + return this.parseBlock(); - tsTryParseTypeOrTypePredicateAnnotation() { - return this.match(types.colon) ? this.tsParseTypeOrTypePredicateAnnotation(types.colon) : undefined; - } + case types.semi: + return this.parseEmptyStatement(node); - tsTryParseTypeAnnotation() { - return this.match(types.colon) ? this.tsParseTypeAnnotation() : undefined; - } + case types._export: + case types._import: + { + const nextToken = this.lookahead(); - tsTryParseType() { - return this.tsEatThenParseType(types.colon); - } + if (nextToken.type === types.parenL || nextToken.type === types.dot) { + break; + } - tsParseTypePredicatePrefix() { - const id = this.parseIdentifier(); + if (!this.options.allowImportExportEverywhere && !topLevel) { + this.raise(this.state.start, "'import' and 'export' may only appear at the top level"); + } - if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { - this.next(); - return id; - } - } + this.next(); + let result; - tsParseTypeAnnotation(eatColon = true, t = this.startNode()) { - this.tsInType(() => { - if (eatColon) this.expect(types.colon); - t.typeAnnotation = this.tsParseType(); - }); - return this.finishNode(t, "TSTypeAnnotation"); - } + if (starttype === types._import) { + result = this.parseImport(node); - tsParseType() { - assert(this.state.inType); - const type = this.tsParseNonConditionalType(); + if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) { + this.sawUnambiguousESM = true; + } + } else { + result = this.parseExport(node); - if (this.hasPrecedingLineBreak() || !this.eat(types._extends)) { - return type; - } + if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") { + this.sawUnambiguousESM = true; + } + } - const node = this.startNodeAtNode(type); - node.checkType = type; - node.extendsType = this.tsParseNonConditionalType(); - this.expect(types.question); - node.trueType = this.tsParseType(); - this.expect(types.colon); - node.falseType = this.tsParseType(); - return this.finishNode(node, "TSConditionalType"); - } + this.assertModuleNodeAllowed(node); + return result; + } - tsParseNonConditionalType() { - if (this.tsIsStartOfFunctionType()) { - return this.tsParseFunctionOrConstructorType("TSFunctionType"); - } + default: + { + if (this.isAsyncFunction()) { + if (context) { + this.unexpected(null, "Async functions can only be declared at the top level or inside a block"); + } - if (this.match(types._new)) { - return this.tsParseFunctionOrConstructorType("TSConstructorType"); + this.next(); + return this.parseFunctionStatement(node, true, !context); + } + } } - return this.tsParseUnionTypeOrHigher(); - } - - tsParseTypeAssertion() { - const node = this.startNode(); - this.next(); - node.typeAnnotation = this.tsInType(() => this.tsParseType()); - this.expectRelational(">"); - node.expression = this.parseMaybeUnary(); - return this.finishNode(node, "TSTypeAssertion"); - } - - tsParseHeritageClause(descriptor) { - const originalStart = this.state.start; - const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", this.tsParseExpressionWithTypeArguments.bind(this)); + const maybeName = this.state.value; + const expr = this.parseExpression(); - if (!delimitedList.length) { - this.raise(originalStart, `'${descriptor}' list cannot be empty.`); + if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon)) { + return this.parseLabeledStatement(node, maybeName, expr, context); + } else { + return this.parseExpressionStatement(node, expr); } - - return delimitedList; } - tsParseExpressionWithTypeArguments() { - const node = this.startNode(); - node.expression = this.tsParseEntityName(false); - - if (this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); + assertModuleNodeAllowed(node) { + if (!this.options.allowImportExportEverywhere && !this.inModule) { + this.raise(node.start, `'import' and 'export' may appear only with 'sourceType: "module"'`, { + code: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED" + }); } - - return this.finishNode(node, "TSExpressionWithTypeArguments"); } - tsParseInterfaceDeclaration(node) { - node.id = this.parseIdentifier(); - node.typeParameters = this.tsTryParseTypeParameters(); + takeDecorators(node) { + const decorators = this.state.decoratorStack[this.state.decoratorStack.length - 1]; - if (this.eat(types._extends)) { - node.extends = this.tsParseHeritageClause("extends"); + if (decorators.length) { + node.decorators = decorators; + this.resetStartLocationFromNode(node, decorators[0]); + this.state.decoratorStack[this.state.decoratorStack.length - 1] = []; } - - const body = this.startNode(); - body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this)); - node.body = this.finishNode(body, "TSInterfaceBody"); - return this.finishNode(node, "TSInterfaceDeclaration"); } - tsParseTypeAliasDeclaration(node) { - node.id = this.parseIdentifier(); - node.typeParameters = this.tsTryParseTypeParameters(); - node.typeAnnotation = this.tsExpectThenParseType(types.eq); - this.semicolon(); - return this.finishNode(node, "TSTypeAliasDeclaration"); + canHaveLeadingDecorator() { + return this.match(types._class); } - tsInNoContext(cb) { - const oldContext = this.state.context; - this.state.context = [oldContext[0]]; + parseDecorators(allowExport) { + const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1]; - try { - return cb(); - } finally { - this.state.context = oldContext; + while (this.match(types.at)) { + const decorator = this.parseDecorator(); + currentContextDecorators.push(decorator); } - } - tsInType(cb) { - const oldInType = this.state.inType; - this.state.inType = true; + if (this.match(types._export)) { + if (!allowExport) { + this.unexpected(); + } - try { - return cb(); - } finally { - this.state.inType = oldInType; + if (this.hasPlugin("decorators") && !this.getPluginOption("decorators", "decoratorsBeforeExport")) { + this.raise(this.state.start, "Using the export keyword between a decorator and a class is not allowed. " + "Please use `export @dec class` instead."); + } + } else if (!this.canHaveLeadingDecorator()) { + this.raise(this.state.start, "Leading decorators must be attached to a class declaration"); } } - tsEatThenParseType(token) { - return !this.match(token) ? undefined : this.tsNextThenParseType(); - } - - tsExpectThenParseType(token) { - return this.tsDoThenParseType(() => this.expect(token)); - } + parseDecorator() { + this.expectOnePlugin(["decorators-legacy", "decorators"]); + const node = this.startNode(); + this.next(); - tsNextThenParseType() { - return this.tsDoThenParseType(() => this.next()); - } + if (this.hasPlugin("decorators")) { + this.state.decoratorStack.push([]); + const startPos = this.state.start; + const startLoc = this.state.startLoc; + let expr; - tsDoThenParseType(cb) { - return this.tsInType(() => { - cb(); - return this.tsParseType(); - }); - } + if (this.eat(types.parenL)) { + expr = this.parseExpression(); + this.expect(types.parenR); + } else { + expr = this.parseIdentifier(false); - tsParseEnumMember() { - const node = this.startNode(); - node.id = this.match(types.string) ? this.parseLiteral(this.state.value, "StringLiteral") : this.parseIdentifier(true); + while (this.eat(types.dot)) { + const node = this.startNodeAt(startPos, startLoc); + node.object = expr; + node.property = this.parseIdentifier(true); + node.computed = false; + expr = this.finishNode(node, "MemberExpression"); + } + } - if (this.eat(types.eq)) { - node.initializer = this.parseMaybeAssign(); + node.expression = this.parseMaybeDecoratorArguments(expr); + this.state.decoratorStack.pop(); + } else { + node.expression = this.parseMaybeAssign(); } - return this.finishNode(node, "TSEnumMember"); + return this.finishNode(node, "Decorator"); } - tsParseEnumDeclaration(node, isConst) { - if (isConst) node.const = true; - node.id = this.parseIdentifier(); - this.expect(types.braceL); - node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this)); - this.expect(types.braceR); - return this.finishNode(node, "TSEnumDeclaration"); - } + parseMaybeDecoratorArguments(expr) { + if (this.eat(types.parenL)) { + const node = this.startNodeAtNode(expr); + node.callee = expr; + node.arguments = this.parseCallExpressionArguments(types.parenR, false); + this.toReferencedList(node.arguments); + return this.finishNode(node, "CallExpression"); + } - tsParseModuleBlock() { - const node = this.startNode(); - this.expect(types.braceL); - this.parseBlockOrModuleBlockBody(node.body = [], undefined, true, types.braceR); - return this.finishNode(node, "TSModuleBlock"); + return expr; } - tsParseModuleOrNamespaceDeclaration(node) { - node.id = this.parseIdentifier(); + parseBreakContinueStatement(node, keyword) { + const isBreak = keyword === "break"; + this.next(); - if (this.eat(types.dot)) { - const inner = this.startNode(); - this.tsParseModuleOrNamespaceDeclaration(inner); - node.body = inner; + if (this.isLineTerminator()) { + node.label = null; } else { - node.body = this.tsParseModuleBlock(); + node.label = this.parseIdentifier(); + this.semicolon(); } - return this.finishNode(node, "TSModuleDeclaration"); + this.verifyBreakContinue(node, keyword); + return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); } - tsParseAmbientExternalModuleDeclaration(node) { - if (this.isContextual("global")) { - node.global = true; - node.id = this.parseIdentifier(); - } else if (this.match(types.string)) { - node.id = this.parseExprAtom(); - } else { - this.unexpected(); - } + verifyBreakContinue(node, keyword) { + const isBreak = keyword === "break"; + let i; - if (this.match(types.braceL)) { - node.body = this.tsParseModuleBlock(); - } else { - this.semicolon(); + for (i = 0; i < this.state.labels.length; ++i) { + const lab = this.state.labels[i]; + + if (node.label == null || lab.name === node.label.name) { + if (lab.kind != null && (isBreak || lab.kind === "loop")) break; + if (node.label && isBreak) break; + } } - return this.finishNode(node, "TSModuleDeclaration"); + if (i === this.state.labels.length) { + this.raise(node.start, "Unsyntactic " + keyword); + } } - tsParseImportEqualsDeclaration(node, isExport) { - node.isExport = isExport || false; - node.id = this.parseIdentifier(); - this.expect(types.eq); - node.moduleReference = this.tsParseModuleReference(); + parseDebuggerStatement(node) { + this.next(); this.semicolon(); - return this.finishNode(node, "TSImportEqualsDeclaration"); + return this.finishNode(node, "DebuggerStatement"); } - tsIsExternalModuleReference() { - return this.isContextual("require") && this.lookahead().type === types.parenL; + parseHeaderExpression() { + this.expect(types.parenL); + const val = this.parseExpression(); + this.expect(types.parenR); + return val; } - tsParseModuleReference() { - return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false); + parseDoStatement(node) { + this.next(); + this.state.labels.push(loopLabel); + node.body = this.withTopicForbiddingContext(() => this.parseStatement("do")); + this.state.labels.pop(); + this.expect(types._while); + node.test = this.parseHeaderExpression(); + this.eat(types.semi); + return this.finishNode(node, "DoWhileStatement"); } - tsParseExternalModuleReference() { - const node = this.startNode(); - this.expectContextual("require"); - this.expect(types.parenL); + parseForStatement(node) { + this.next(); + this.state.labels.push(loopLabel); + let awaitAt = -1; - if (!this.match(types.string)) { - throw this.unexpected(); + if ((this.scope.inAsync || !this.scope.inFunction && this.options.allowAwaitOutsideFunction) && this.eatContextual("await")) { + awaitAt = this.state.lastTokStart; } - node.expression = this.parseLiteral(this.state.value, "StringLiteral"); - this.expect(types.parenR); - return this.finishNode(node, "TSExternalModuleReference"); - } - - tsLookAhead(f) { - const state = this.state.clone(); - const res = f(); - this.state = state; - return res; - } - - tsTryParseAndCatch(f) { - const state = this.state.clone(); + this.scope.enter(SCOPE_OTHER); + this.expect(types.parenL); - try { - return f(); - } catch (e) { - if (e instanceof SyntaxError) { - this.state = state; - return undefined; + if (this.match(types.semi)) { + if (awaitAt > -1) { + this.unexpected(awaitAt); } - throw e; + return this.parseFor(node, null); } - } - tsTryParse(f) { - const state = this.state.clone(); - const result = f(); + const isLet = this.isLet(); - if (result !== undefined && result !== false) { - return result; - } else { - this.state = state; - return undefined; - } - } + if (this.match(types._var) || this.match(types._const) || isLet) { + const init = this.startNode(); + const kind = isLet ? "let" : this.state.value; + this.next(); + this.parseVar(init, true, kind); + this.finishNode(init, "VariableDeclaration"); - nodeWithSamePosition(original, type) { - const node = this.startNodeAtNode(original); - node.type = type; - node.end = original.end; - node.loc.end = original.loc.end; + if ((this.match(types._in) || this.isContextual("of")) && init.declarations.length === 1) { + return this.parseForIn(node, init, awaitAt); + } - if (original.leadingComments) { - node.leadingComments = original.leadingComments; - } + if (awaitAt > -1) { + this.unexpected(awaitAt); + } - if (original.trailingComments) { - node.trailingComments = original.trailingComments; + return this.parseFor(node, init); } - if (original.innerComments) node.innerComments = original.innerComments; - return node; - } + const refShorthandDefaultPos = { + start: 0 + }; + const init = this.parseExpression(true, refShorthandDefaultPos); - tsTryParseDeclare(nany) { - if (this.isLineTerminator()) { - return; + if (this.match(types._in) || this.isContextual("of")) { + const description = this.isContextual("of") ? "for-of statement" : "for-in statement"; + this.toAssignable(init, undefined, description); + this.checkLVal(init, undefined, undefined, description); + return this.parseForIn(node, init, awaitAt); + } else if (refShorthandDefaultPos.start) { + this.unexpected(refShorthandDefaultPos.start); } - let starttype = this.state.type; - let kind; - - if (this.isContextual("let")) { - starttype = types._var; - kind = "let"; + if (awaitAt > -1) { + this.unexpected(awaitAt); } - switch (starttype) { - case types._function: - this.next(); - return this.parseFunction(nany, true); + return this.parseFor(node, init); + } - case types._class: - return this.parseClass(nany, true, false); + parseFunctionStatement(node, isAsync, declarationPosition) { + this.next(); + return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), isAsync); + } - case types._const: - if (this.match(types._const) && this.isLookaheadContextual("enum")) { - this.expect(types._const); - this.expectContextual("enum"); - return this.tsParseEnumDeclaration(nany, true); - } + parseIfStatement(node) { + this.next(); + node.test = this.parseHeaderExpression(); + node.consequent = this.parseStatement("if"); + node.alternate = this.eat(types._else) ? this.parseStatement("if") : null; + return this.finishNode(node, "IfStatement"); + } - case types._var: - kind = kind || this.state.value; - return this.parseVarStatement(nany, kind); + parseReturnStatement(node) { + if (!this.scope.inFunction && !this.options.allowReturnOutsideFunction) { + this.raise(this.state.start, "'return' outside of function"); + } - case types.name: - { - const value = this.state.value; + this.next(); - if (value === "global") { - return this.tsParseAmbientExternalModuleDeclaration(nany); - } else { - return this.tsParseDeclaration(nany, value, true); - } - } + if (this.isLineTerminator()) { + node.argument = null; + } else { + node.argument = this.parseExpression(); + this.semicolon(); } - } - tsTryParseExportDeclaration() { - return this.tsParseDeclaration(this.startNode(), this.state.value, true); + return this.finishNode(node, "ReturnStatement"); } - tsParseExpressionStatement(node, expr) { - switch (expr.name) { - case "declare": - { - const declaration = this.tsTryParseDeclare(node); + parseSwitchStatement(node) { + this.next(); + node.discriminant = this.parseHeaderExpression(); + const cases = node.cases = []; + this.expect(types.braceL); + this.state.labels.push(switchLabel); + this.scope.enter(SCOPE_OTHER); + let cur; - if (declaration) { - declaration.declare = true; - return declaration; + for (let sawDefault; !this.match(types.braceR);) { + if (this.match(types._case) || this.match(types._default)) { + const isCase = this.match(types._case); + if (cur) this.finishNode(cur, "SwitchCase"); + cases.push(cur = this.startNode()); + cur.consequent = []; + this.next(); + + if (isCase) { + cur.test = this.parseExpression(); + } else { + if (sawDefault) { + this.raise(this.state.lastTokStart, "Multiple default clauses"); } - break; + sawDefault = true; + cur.test = null; } - case "global": - if (this.match(types.braceL)) { - const mod = node; - mod.global = true; - mod.id = expr; - mod.body = this.tsParseModuleBlock(); - return this.finishNode(mod, "TSModuleDeclaration"); + this.expect(types.colon); + } else { + if (cur) { + cur.consequent.push(this.parseStatement(null)); + } else { + this.unexpected(); } + } + } - break; + this.scope.exit(); + if (cur) this.finishNode(cur, "SwitchCase"); + this.next(); + this.state.labels.pop(); + return this.finishNode(node, "SwitchStatement"); + } - default: - return this.tsParseDeclaration(node, expr.name, false); + parseThrowStatement(node) { + this.next(); + + if (lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))) { + this.raise(this.state.lastTokEnd, "Illegal newline after throw"); } + + node.argument = this.parseExpression(); + this.semicolon(); + return this.finishNode(node, "ThrowStatement"); } - tsParseDeclaration(node, value, next) { - switch (value) { - case "abstract": - if (this.tsCheckLineTerminatorAndMatch(types._class, next)) { - const cls = node; - cls.abstract = true; + parseTryStatement(node) { + this.next(); + node.block = this.parseBlock(); + node.handler = null; - if (next) { - this.next(); + if (this.match(types._catch)) { + const clause = this.startNode(); + this.next(); - if (!this.match(types._class)) { - this.unexpected(null, types._class); - } - } + if (this.match(types.parenL)) { + this.expect(types.parenL); + clause.param = this.parseBindingAtom(); + const simple = clause.param.type === "Identifier"; + this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0); + this.checkLVal(clause.param, BIND_LEXICAL, null, "catch clause"); + this.expect(types.parenR); + } else { + clause.param = null; + this.scope.enter(SCOPE_OTHER); + } - return this.parseClass(cls, true, false); - } + clause.body = this.withTopicForbiddingContext(() => this.parseBlock(false, false)); + this.scope.exit(); + node.handler = this.finishNode(clause, "CatchClause"); + } - break; + node.finalizer = this.eat(types._finally) ? this.parseBlock() : null; - case "enum": - if (next || this.match(types.name)) { - if (next) this.next(); - return this.tsParseEnumDeclaration(node, false); - } + if (!node.handler && !node.finalizer) { + this.raise(node.start, "Missing catch or finally clause"); + } - break; + return this.finishNode(node, "TryStatement"); + } - case "interface": - if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - if (next) this.next(); - return this.tsParseInterfaceDeclaration(node); - } + parseVarStatement(node, kind) { + this.next(); + this.parseVar(node, false, kind); + this.semicolon(); + return this.finishNode(node, "VariableDeclaration"); + } - break; + parseWhileStatement(node) { + this.next(); + node.test = this.parseHeaderExpression(); + this.state.labels.push(loopLabel); + node.body = this.withTopicForbiddingContext(() => this.parseStatement("while")); + this.state.labels.pop(); + return this.finishNode(node, "WhileStatement"); + } - case "module": - if (next) this.next(); + parseWithStatement(node) { + if (this.state.strict) { + this.raise(this.state.start, "'with' in strict mode"); + } - if (this.match(types.string)) { - return this.tsParseAmbientExternalModuleDeclaration(node); - } else if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - return this.tsParseModuleOrNamespaceDeclaration(node); - } + this.next(); + node.object = this.parseHeaderExpression(); + node.body = this.withTopicForbiddingContext(() => this.parseStatement("with")); + return this.finishNode(node, "WithStatement"); + } - break; + parseEmptyStatement(node) { + this.next(); + return this.finishNode(node, "EmptyStatement"); + } - case "namespace": - if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - if (next) this.next(); - return this.tsParseModuleOrNamespaceDeclaration(node); - } + parseLabeledStatement(node, maybeName, expr, context) { + for (let _i2 = 0, _this$state$labels = this.state.labels; _i2 < _this$state$labels.length; _i2++) { + const label = _this$state$labels[_i2]; - break; + if (label.name === maybeName) { + this.raise(expr.start, `Label '${maybeName}' is already declared`); + } + } - case "type": - if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - if (next) this.next(); - return this.tsParseTypeAliasDeclaration(node); - } + const kind = this.state.type.isLoop ? "loop" : this.match(types._switch) ? "switch" : null; + + for (let i = this.state.labels.length - 1; i >= 0; i--) { + const label = this.state.labels[i]; + if (label.statementStart === node.start) { + label.statementStart = this.state.start; + label.kind = kind; + } else { break; + } } + + this.state.labels.push({ + name: maybeName, + kind: kind, + statementStart: this.state.start + }); + node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label"); + this.state.labels.pop(); + node.label = expr; + return this.finishNode(node, "LabeledStatement"); } - tsCheckLineTerminatorAndMatch(tokenType, next) { - return (next || this.match(tokenType)) && !this.isLineTerminator(); + parseExpressionStatement(node, expr) { + node.expression = expr; + this.semicolon(); + return this.finishNode(node, "ExpressionStatement"); } - tsTryParseGenericAsyncArrowFunction(startPos, startLoc) { - const res = this.tsTryParseAndCatch(() => { - const node = this.startNodeAt(startPos, startLoc); - node.typeParameters = this.tsParseTypeParameters(); - super.parseFunctionParams(node); - node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); - this.expect(types.arrow); - return node; - }); + parseBlock(allowDirectives = false, createNewLexicalScope = true) { + const node = this.startNode(); + this.expect(types.braceL); - if (!res) { - return undefined; + if (createNewLexicalScope) { + this.scope.enter(SCOPE_OTHER); + } + + this.parseBlockBody(node, allowDirectives, false, types.braceR); + + if (createNewLexicalScope) { + this.scope.exit(); } - const oldInAsync = this.state.inAsync; - const oldInGenerator = this.state.inGenerator; - this.state.inAsync = true; - this.state.inGenerator = false; - res.id = null; - res.generator = false; - res.expression = true; - res.async = true; - this.parseFunctionBody(res, true); - this.state.inAsync = oldInAsync; - this.state.inGenerator = oldInGenerator; - return this.finishNode(res, "ArrowFunctionExpression"); + return this.finishNode(node, "BlockStatement"); } - tsParseTypeArguments() { - const node = this.startNode(); - node.params = this.tsInType(() => this.tsInNoContext(() => { - this.expectRelational("<"); - return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this)); - })); - this.state.exprAllowed = false; - this.expectRelational(">"); - return this.finishNode(node, "TSTypeParameterInstantiation"); + isValidDirective(stmt) { + return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized; } - tsIsDeclarationStart() { - if (this.match(types.name)) { - switch (this.state.value) { - case "abstract": - case "declare": - case "enum": - case "interface": - case "module": - case "namespace": - case "type": - return true; + parseBlockBody(node, allowDirectives, topLevel, end) { + const body = node.body = []; + const directives = node.directives = []; + this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end); + } + + parseBlockOrModuleBlockBody(body, directives, topLevel, end) { + let parsedNonDirective = false; + let oldStrict; + let octalPosition; + + while (!this.eat(end)) { + if (!parsedNonDirective && this.state.containsOctal && !octalPosition) { + octalPosition = this.state.octalPosition; + } + + const stmt = this.parseStatement(null, topLevel); + + if (directives && !parsedNonDirective && this.isValidDirective(stmt)) { + const directive = this.stmtToDirective(stmt); + directives.push(directive); + + if (oldStrict === undefined && directive.value.value === "use strict") { + oldStrict = this.state.strict; + this.setStrict(true); + + if (octalPosition) { + this.raise(octalPosition, "Octal literal in strict mode"); + } + } + + continue; } + + parsedNonDirective = true; + body.push(stmt); } - return false; + if (oldStrict === false) { + this.setStrict(false); + } } - isExportDefaultSpecifier() { - if (this.tsIsDeclarationStart()) return false; - return super.isExportDefaultSpecifier(); + parseFor(node, init) { + node.init = init; + this.expect(types.semi); + node.test = this.match(types.semi) ? null : this.parseExpression(); + this.expect(types.semi); + node.update = this.match(types.parenR) ? null : this.parseExpression(); + this.expect(types.parenR); + node.body = this.withTopicForbiddingContext(() => this.parseStatement("for")); + this.scope.exit(); + this.state.labels.pop(); + return this.finishNode(node, "ForStatement"); } - parseAssignableListItem(allowModifiers, decorators) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - let accessibility; - let readonly = false; + parseForIn(node, init, awaitAt) { + const isForIn = this.match(types._in); + this.next(); - if (allowModifiers) { - accessibility = this.parseAccessModifier(); - readonly = !!this.tsParseModifier(["readonly"]); + if (isForIn) { + if (awaitAt > -1) this.unexpected(awaitAt); + } else { + node.await = awaitAt > -1; } - const left = this.parseMaybeDefault(); - this.parseAssignableListItemTypes(left); - const elt = this.parseMaybeDefault(left.start, left.loc.start, left); + if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) { + this.raise(init.start, `${isForIn ? "for-in" : "for-of"} loop variable declaration may not have an initializer`); + } else if (init.type === "AssignmentPattern") { + this.raise(init.start, "Invalid left-hand side in for-loop"); + } - if (accessibility || readonly) { - const pp = this.startNodeAt(startPos, startLoc); + node.left = init; + node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign(); + this.expect(types.parenR); + node.body = this.withTopicForbiddingContext(() => this.parseStatement("for")); + this.scope.exit(); + this.state.labels.pop(); + return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement"); + } - if (decorators.length) { - pp.decorators = decorators; - } + parseVar(node, isFor, kind) { + const declarations = node.declarations = []; + const isTypescript = this.hasPlugin("typescript"); + node.kind = kind; - if (accessibility) pp.accessibility = accessibility; - if (readonly) pp.readonly = readonly; + for (;;) { + const decl = this.startNode(); + this.parseVarId(decl, kind); - if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { - throw this.raise(pp.start, "A parameter property may not be declared using a binding pattern."); + if (this.eat(types.eq)) { + decl.init = this.parseMaybeAssign(isFor); + } else { + if (kind === "const" && !(this.match(types._in) || this.isContextual("of"))) { + if (!isTypescript) { + this.unexpected(); + } + } else if (decl.id.type !== "Identifier" && !(isFor && (this.match(types._in) || this.isContextual("of")))) { + this.raise(this.state.lastTokEnd, "Complex binding patterns require an initialization value"); + } + + decl.init = null; } - pp.parameter = elt; - return this.finishNode(pp, "TSParameterProperty"); + declarations.push(this.finishNode(decl, "VariableDeclarator")); + if (!this.eat(types.comma)) break; } - if (decorators.length) { - left.decorators = decorators; + return node; + } + + parseVarId(decl, kind) { + if ((kind === "const" || kind === "let") && this.isContextual("let")) { + this.unexpected(null, "let is disallowed as a lexically bound name"); } - return elt; + decl.id = this.parseBindingAtom(); + this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, undefined, "variable declaration"); } - parseFunctionBodyAndFinish(node, type, allowExpressionBody) { - if (!allowExpressionBody && this.match(types.colon)) { - node.returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon); + parseFunction(node, statement = FUNC_NO_FLAGS, isAsync = false) { + const isStatement = statement & FUNC_STATEMENT; + const isHangingStatement = statement & FUNC_HANGING_STATEMENT; + const requireId = !!isStatement && !(statement & FUNC_NULLABLE_ID); + this.initFunction(node, isAsync); + + if (this.match(types.star) && isHangingStatement) { + this.unexpected(this.state.start, "Generators can only be declared at the top level or inside a block"); } - const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" ? "TSDeclareMethod" : undefined; + node.generator = this.eat(types.star); - if (bodilessType && !this.match(types.braceL) && this.isLineTerminator()) { - this.finishNode(node, bodilessType); - return; + if (isStatement) { + node.id = this.parseFunctionId(requireId); } - super.parseFunctionBodyAndFinish(node, type, allowExpressionBody); - } + const oldInClassProperty = this.state.inClassProperty; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.inClassProperty = false; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + this.scope.enter(functionFlags(node.async, node.generator)); - parseSubscript(base, startPos, startLoc, noCalls, state) { - if (!this.hasPrecedingLineBreak() && this.match(types.bang)) { - this.state.exprAllowed = false; - this.next(); - const nonNullExpression = this.startNodeAt(startPos, startLoc); - nonNullExpression.expression = base; - return this.finishNode(nonNullExpression, "TSNonNullExpression"); + if (!isStatement) { + node.id = this.parseFunctionId(); } - if (this.isRelational("<")) { - const result = this.tsTryParseAndCatch(() => { - if (!noCalls && this.atPossibleAsync(base)) { - const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc); - - if (asyncArrowFn) { - return asyncArrowFn; - } - } + this.parseFunctionParams(node); + this.withTopicForbiddingContext(() => { + this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); + }); + this.scope.exit(); - const node = this.startNodeAt(startPos, startLoc); - node.callee = base; - const typeArguments = this.tsParseTypeArguments(); + if (isStatement && !isHangingStatement) { + this.checkFunctionStatementId(node); + } - if (typeArguments) { - if (!noCalls && this.eat(types.parenL)) { - node.arguments = this.parseCallExpressionArguments(types.parenR, false); - node.typeParameters = typeArguments; - return this.finishCallExpression(node); - } else if (this.match(types.backQuote)) { - return this.parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments); - } - } + this.state.inClassProperty = oldInClassProperty; + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; + return node; + } - this.unexpected(); - }); - if (result) return result; - } + parseFunctionId(requireId) { + return requireId || this.match(types.name) ? this.parseIdentifier() : null; + } - return super.parseSubscript(base, startPos, startLoc, noCalls, state); + parseFunctionParams(node, allowModifiers) { + const oldInParameters = this.state.inParameters; + this.state.inParameters = true; + this.expect(types.parenL); + node.params = this.parseBindingList(types.parenR, false, allowModifiers); + this.state.inParameters = oldInParameters; + this.checkYieldAwaitInDefaultParams(); } - parseNewArguments(node) { - if (this.isRelational("<")) { - const typeParameters = this.tsTryParseAndCatch(() => { - const args = this.tsParseTypeArguments(); - if (!this.match(types.parenL)) this.unexpected(); - return args; - }); + checkFunctionStatementId(node) { + if (!node.id) return; + this.checkLVal(node.id, this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION, null, "function name"); + } - if (typeParameters) { - node.typeParameters = typeParameters; - } - } + parseClass(node, isStatement, optionalId) { + this.next(); + this.takeDecorators(node); + const oldStrict = this.state.strict; + this.state.strict = true; + this.parseClassId(node, isStatement, optionalId); + this.parseClassSuper(node); + node.body = this.parseClassBody(!!node.superClass); + this.state.strict = oldStrict; + return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); + } - super.parseNewArguments(node); + isClassProperty() { + return this.match(types.eq) || this.match(types.semi) || this.match(types.braceR); } - parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) { - if (nonNull(types._in.binop) > minPrec && !this.hasPrecedingLineBreak() && this.isContextual("as")) { - const node = this.startNodeAt(leftStartPos, leftStartLoc); - node.expression = left; - node.typeAnnotation = this.tsNextThenParseType(); - this.finishNode(node, "TSAsExpression"); - return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); - } + isClassMethod() { + return this.match(types.parenL); + } - return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn); + isNonstaticConstructor(method) { + return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor"); } - checkReservedWord(word, startLoc, checkKeywords, isBinding) {} + parseClassBody(constructorAllowsSuper) { + this.state.classLevel++; + const state = { + hadConstructor: false + }; + let decorators = []; + const classBody = this.startNode(); + classBody.body = []; + this.expect(types.braceL); + this.withTopicForbiddingContext(() => { + while (!this.eat(types.braceR)) { + if (this.eat(types.semi)) { + if (decorators.length > 0) { + this.raise(this.state.lastTokEnd, "Decorators must not be followed by a semicolon"); + } - checkDuplicateExports() {} + continue; + } - parseImport(node) { - if (this.match(types.name) && this.lookahead().type === types.eq) { - return this.tsParseImportEqualsDeclaration(node); - } + if (this.match(types.at)) { + decorators.push(this.parseDecorator()); + continue; + } - return super.parseImport(node); - } + const member = this.startNode(); - parseExport(node) { - if (this.match(types._import)) { - this.expect(types._import); - return this.tsParseImportEqualsDeclaration(node, true); - } else if (this.eat(types.eq)) { - const assign = node; - assign.expression = this.parseExpression(); - this.semicolon(); - return this.finishNode(assign, "TSExportAssignment"); - } else if (this.eatContextual("as")) { - const decl = node; - this.expectContextual("namespace"); - decl.id = this.parseIdentifier(); - this.semicolon(); - return this.finishNode(decl, "TSNamespaceExportDeclaration"); - } else { - return super.parseExport(node); + if (decorators.length) { + member.decorators = decorators; + this.resetStartLocationFromNode(member, decorators[0]); + decorators = []; + } + + this.parseClassMember(classBody, member, state, constructorAllowsSuper); + + if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) { + this.raise(member.start, "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?"); + } + } + }); + + if (decorators.length) { + this.raise(this.state.start, "You have trailing decorators with no method"); } - } - isAbstractClass() { - return this.isContextual("abstract") && this.lookahead().type === types._class; + this.state.classLevel--; + return this.finishNode(classBody, "ClassBody"); } - parseExportDefaultExpression() { - if (this.isAbstractClass()) { - const cls = this.startNode(); - this.next(); - this.parseClass(cls, true, true); - cls.abstract = true; - return cls; - } + parseClassMember(classBody, member, state, constructorAllowsSuper) { + let isStatic = false; + const containsEsc = this.state.containsEsc; - if (this.state.value === "interface") { - const result = this.tsParseDeclaration(this.startNode(), this.state.value, true); - if (result) return result; + if (this.match(types.name) && this.state.value === "static") { + const key = this.parseIdentifier(true); + + if (this.isClassMethod()) { + const method = member; + method.kind = "method"; + method.computed = false; + method.key = key; + method.static = false; + this.pushClassMethod(classBody, method, false, false, false, false); + return; + } else if (this.isClassProperty()) { + const prop = member; + prop.computed = false; + prop.key = key; + prop.static = false; + classBody.body.push(this.parseClassProperty(prop)); + return; + } else if (containsEsc) { + throw this.unexpected(); + } + + isStatic = true; } - return super.parseExportDefaultExpression(); + this.parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper); } - parseStatementContent(context, topLevel) { - if (this.state.type === types._const) { - const ahead = this.lookahead(); + parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper) { + const publicMethod = member; + const privateMethod = member; + const publicProp = member; + const privateProp = member; + const method = publicMethod; + const publicMember = publicMethod; + member.static = isStatic; - if (ahead.type === types.name && ahead.value === "enum") { - const node = this.startNode(); - this.expect(types._const); - this.expectContextual("enum"); - return this.tsParseEnumDeclaration(node, true); + if (this.eat(types.star)) { + method.kind = "method"; + this.parseClassPropertyName(method); + + if (method.key.type === "PrivateName") { + this.pushClassPrivateMethod(classBody, privateMethod, true, false); + return; + } + + if (this.isNonstaticConstructor(publicMethod)) { + this.raise(publicMethod.key.start, "Constructor can't be a generator"); } + + this.pushClassMethod(classBody, publicMethod, true, false, false, false); + return; } - return super.parseStatementContent(context, topLevel); - } + const containsEsc = this.state.containsEsc; + const key = this.parseClassPropertyName(member); + const isPrivate = key.type === "PrivateName"; + const isSimple = key.type === "Identifier"; + this.parsePostMemberNameModifiers(publicMember); - parseAccessModifier() { - return this.tsParseModifier(["public", "protected", "private"]); - } + if (this.isClassMethod()) { + method.kind = "method"; - parseClassMember(classBody, member, state) { - const accessibility = this.parseAccessModifier(); - if (accessibility) member.accessibility = accessibility; - super.parseClassMember(classBody, member, state); - } + if (isPrivate) { + this.pushClassPrivateMethod(classBody, privateMethod, false, false); + return; + } - parseClassMemberWithIsStatic(classBody, member, state, isStatic) { - const methodOrProp = member; - const prop = member; - const propOrIdx = member; - let abstract = false, - readonly = false; - const mod = this.tsParseModifier(["abstract", "readonly"]); + const isConstructor = this.isNonstaticConstructor(publicMethod); + let allowsDirectSuper = false; - switch (mod) { - case "readonly": - readonly = true; - abstract = !!this.tsParseModifier(["abstract"]); - break; + if (isConstructor) { + publicMethod.kind = "constructor"; - case "abstract": - abstract = true; - readonly = !!this.tsParseModifier(["readonly"]); - break; - } + if (publicMethod.decorators) { + this.raise(publicMethod.start, "You can't attach decorators to a class constructor"); + } - if (abstract) methodOrProp.abstract = true; - if (readonly) propOrIdx.readonly = true; + if (state.hadConstructor && !this.hasPlugin("typescript")) { + this.raise(key.start, "Duplicate constructor in the same class"); + } - if (!abstract && !isStatic && !methodOrProp.accessibility) { - const idx = this.tsTryParseIndexSignature(member); + state.hadConstructor = true; + allowsDirectSuper = constructorAllowsSuper; + } - if (idx) { - classBody.body.push(idx); - return; + this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper); + } else if (this.isClassProperty()) { + if (isPrivate) { + this.pushClassPrivateProperty(classBody, privateProp); + } else { + this.pushClassProperty(classBody, publicProp); } - } + } else if (isSimple && key.name === "async" && !containsEsc && !this.isLineTerminator()) { + const isGenerator = this.eat(types.star); + method.kind = "method"; + this.parseClassPropertyName(method); - if (readonly) { - methodOrProp.static = isStatic; - this.parseClassPropertyName(prop); - this.parsePostMemberNameModifiers(methodOrProp); - this.pushClassProperty(classBody, prop); - return; - } + if (method.key.type === "PrivateName") { + this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true); + } else { + if (this.isNonstaticConstructor(publicMethod)) { + this.raise(publicMethod.key.start, "Constructor can't be an async function"); + } - super.parseClassMemberWithIsStatic(classBody, member, state, isStatic); - } + this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false); + } + } else if (isSimple && (key.name === "get" || key.name === "set") && !containsEsc && !(this.match(types.star) && this.isLineTerminator())) { + method.kind = key.name; + this.parseClassPropertyName(publicMethod); - parsePostMemberNameModifiers(methodOrProp) { - const optional = this.eat(types.question); - if (optional) methodOrProp.optional = true; - } + if (method.key.type === "PrivateName") { + this.pushClassPrivateMethod(classBody, privateMethod, false, false); + } else { + if (this.isNonstaticConstructor(publicMethod)) { + this.raise(publicMethod.key.start, "Constructor can't have get/set modifier"); + } - parseExpressionStatement(node, expr) { - const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined; - return decl || super.parseExpressionStatement(node, expr); - } + this.pushClassMethod(classBody, publicMethod, false, false, false, false); + } - shouldParseExportDeclaration() { - if (this.tsIsDeclarationStart()) return true; - return super.shouldParseExportDeclaration(); + this.checkGetterSetterParams(publicMethod); + } else if (this.isLineTerminator()) { + if (isPrivate) { + this.pushClassPrivateProperty(classBody, privateProp); + } else { + this.pushClassProperty(classBody, publicProp); + } + } else { + this.unexpected(); + } } - parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) { - if (!refNeedsArrowPos || !this.match(types.question)) { - return super.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos); + parseClassPropertyName(member) { + const key = this.parsePropertyName(member); + + if (!member.computed && member.static && (key.name === "prototype" || key.value === "prototype")) { + this.raise(key.start, "Classes may not have static property named prototype"); } - const state = this.state.clone(); + if (key.type === "PrivateName" && key.id.name === "constructor") { + this.raise(key.start, "Classes may not have a private field named '#constructor'"); + } - try { - return super.parseConditional(expr, noIn, startPos, startLoc); - } catch (err) { - if (!(err instanceof SyntaxError)) { - throw err; - } + return key; + } - this.state = state; - refNeedsArrowPos.start = err.pos || this.state.start; - return expr; + pushClassProperty(classBody, prop) { + if (this.isNonstaticConstructor(prop)) { + this.raise(prop.key.start, "Classes may not have a non-static field named 'constructor'"); } + + classBody.body.push(this.parseClassProperty(prop)); } - parseParenItem(node, startPos, startLoc) { - node = super.parseParenItem(node, startPos, startLoc); + pushClassPrivateProperty(classBody, prop) { + this.expectPlugin("classPrivateProperties", prop.key.start); + classBody.body.push(this.parseClassPrivateProperty(prop)); + } - if (this.eat(types.question)) { - node.optional = true; - } + pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { + classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true)); + } - if (this.match(types.colon)) { - const typeCastNode = this.startNodeAt(startPos, startLoc); - typeCastNode.expression = node; - typeCastNode.typeAnnotation = this.tsParseTypeAnnotation(); - return this.finishNode(typeCastNode, "TSTypeCastExpression"); - } + pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { + this.expectPlugin("classPrivateMethods", method.key.start); + classBody.body.push(this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true)); + } + + parsePostMemberNameModifiers(methodOrProp) {} - return this.finishNode(node, node.type); + parseAccessModifier() { + return undefined; } - parseExportDeclaration(node) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - const isDeclare = this.eatContextual("declare"); - let declaration; + parseClassPrivateProperty(node) { + this.state.inClassProperty = true; + this.scope.enter(SCOPE_CLASS | SCOPE_SUPER); + node.value = this.eat(types.eq) ? this.parseMaybeAssign() : null; + this.semicolon(); + this.state.inClassProperty = false; + this.scope.exit(); + return this.finishNode(node, "ClassPrivateProperty"); + } - if (this.match(types.name)) { - declaration = this.tsTryParseExportDeclaration(); + parseClassProperty(node) { + if (!node.typeAnnotation) { + this.expectPlugin("classProperties"); } - if (!declaration) { - declaration = super.parseExportDeclaration(node); - } + this.state.inClassProperty = true; + this.scope.enter(SCOPE_CLASS | SCOPE_SUPER); - if (declaration && isDeclare) { - this.resetStartLocation(declaration, startPos, startLoc); - declaration.declare = true; + if (this.match(types.eq)) { + this.expectPlugin("classProperties"); + this.next(); + node.value = this.parseMaybeAssign(); + } else { + node.value = null; } - return declaration; + this.semicolon(); + this.state.inClassProperty = false; + this.scope.exit(); + return this.finishNode(node, "ClassProperty"); } parseClassId(node, isStatement, optionalId) { - if ((!isStatement || optionalId) && this.isContextual("implements")) { - return; + if (this.match(types.name)) { + node.id = this.parseIdentifier(); + + if (isStatement) { + this.checkLVal(node.id, BIND_CLASS, undefined, "class name"); + } + } else { + if (optionalId || !isStatement) { + node.id = null; + } else { + this.unexpected(null, "A class name is required"); + } } + } - super.parseClassId(...arguments); - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) node.typeParameters = typeParameters; + parseClassSuper(node) { + node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null; } - parseClassProperty(node) { - if (!node.optional && this.eat(types.bang)) { - node.definite = true; + parseExport(node) { + const hasDefault = this.maybeParseExportDefaultSpecifier(node); + const parseAfterDefault = !hasDefault || this.eat(types.comma); + const hasStar = parseAfterDefault && this.eatExportStar(node); + const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node); + const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(types.comma)); + const isFromRequired = hasDefault || hasStar; + + if (hasStar && !hasNamespace) { + if (hasDefault) this.unexpected(); + this.parseExportFrom(node, true); + return this.finishNode(node, "ExportAllDeclaration"); } - const type = this.tsTryParseTypeAnnotation(); - if (type) node.typeAnnotation = type; - return super.parseClassProperty(node); - } + const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node); - pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) method.typeParameters = typeParameters; - super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor); - } + if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers || hasNamespace && parseAfterNamespace && !hasSpecifiers) { + throw this.unexpected(null, types.braceL); + } - pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) method.typeParameters = typeParameters; - super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); - } + let hasDeclaration; - parseClassSuper(node) { - super.parseClassSuper(node); + if (isFromRequired || hasSpecifiers) { + hasDeclaration = false; + this.parseExportFrom(node, isFromRequired); + } else { + hasDeclaration = this.maybeParseExportDeclaration(node); + } - if (node.superClass && this.isRelational("<")) { - node.superTypeParameters = this.tsParseTypeArguments(); + if (isFromRequired || hasSpecifiers || hasDeclaration) { + this.checkExport(node, true, false, !!node.source); + return this.finishNode(node, "ExportNamedDeclaration"); } - if (this.eatContextual("implements")) { - node.implements = this.tsParseHeritageClause("implements"); + if (this.eat(types._default)) { + node.declaration = this.parseExportDefaultExpression(); + this.checkExport(node, true, true); + return this.finishNode(node, "ExportDefaultDeclaration"); } - } - parseObjPropValue(prop, ...args) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) prop.typeParameters = typeParameters; - super.parseObjPropValue(prop, ...args); + throw this.unexpected(null, types.braceL); } - parseFunctionParams(node, allowModifiers) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) node.typeParameters = typeParameters; - super.parseFunctionParams(node, allowModifiers); + eatExportStar(node) { + return this.eat(types.star); } - parseVarId(decl, kind) { - super.parseVarId(decl, kind); - - if (decl.id.type === "Identifier" && this.eat(types.bang)) { - decl.definite = true; + maybeParseExportDefaultSpecifier(node) { + if (this.isExportDefaultSpecifier()) { + this.expectPlugin("exportDefaultFrom"); + const specifier = this.startNode(); + specifier.exported = this.parseIdentifier(true); + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + return true; } - const type = this.tsTryParseTypeAnnotation(); + return false; + } - if (type) { - decl.id.typeAnnotation = type; - this.finishNode(decl.id, decl.id.type); + maybeParseExportNamespaceSpecifier(node) { + if (this.isContextual("as")) { + if (!node.specifiers) node.specifiers = []; + this.expectPlugin("exportNamespaceFrom"); + const specifier = this.startNodeAt(this.state.lastTokStart, this.state.lastTokStartLoc); + this.next(); + specifier.exported = this.parseIdentifier(true); + node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier")); + return true; } + + return false; } - parseAsyncArrowFromCallExpression(node, call) { - if (this.match(types.colon)) { - node.returnType = this.tsParseTypeAnnotation(); + maybeParseExportNamedSpecifiers(node) { + if (this.match(types.braceL)) { + if (!node.specifiers) node.specifiers = []; + node.specifiers.push(...this.parseExportSpecifiers()); + node.source = null; + node.declaration = null; + return true; } - return super.parseAsyncArrowFromCallExpression(node, call); + return false; } - parseMaybeAssign(...args) { - let jsxError; - - if (this.match(types.jsxTagStart)) { - const context = this.curContext(); - assert(context === types$1.j_oTag); - assert(this.state.context[this.state.context.length - 2] === types$1.j_expr); - const state = this.state.clone(); + maybeParseExportDeclaration(node) { + if (this.shouldParseExportDeclaration()) { + if (this.isContextual("async")) { + const next = this.lookahead(); - try { - return super.parseMaybeAssign(...args); - } catch (err) { - if (!(err instanceof SyntaxError)) { - throw err; + if (next.type !== types._function) { + this.unexpected(next.start, `Unexpected token, expected "function"`); } - - this.state = state; - assert(this.curContext() === types$1.j_oTag); - this.state.context.pop(); - assert(this.curContext() === types$1.j_expr); - this.state.context.pop(); - jsxError = err; } - } - if (jsxError === undefined && !this.isRelational("<")) { - return super.parseMaybeAssign(...args); + node.specifiers = []; + node.source = null; + node.declaration = this.parseExportDeclaration(node); + return true; } - let arrowExpression; - let typeParameters; - const state = this.state.clone(); + return false; + } - try { - typeParameters = this.tsParseTypeParameters(); - arrowExpression = super.parseMaybeAssign(...args); + isAsyncFunction() { + if (!this.isContextual("async")) return false; + const { + pos + } = this.state; + skipWhiteSpace.lastIndex = pos; + const skip = skipWhiteSpace.exec(this.input); + if (!skip || !skip.length) return false; + const next = pos + skip[0].length; + return !lineBreak.test(this.input.slice(pos, next)) && this.input.slice(next, next + 8) === "function" && (next + 8 === this.length || !isIdentifierChar(this.input.charCodeAt(next + 8))); + } - if (arrowExpression.type !== "ArrowFunctionExpression") { - this.unexpected(); - } - } catch (err) { - if (!(err instanceof SyntaxError)) { - throw err; + parseExportDefaultExpression() { + const expr = this.startNode(); + const isAsync = this.isAsyncFunction(); + + if (this.match(types._function) || isAsync) { + this.next(); + + if (isAsync) { + this.next(); } - if (jsxError) { - throw jsxError; + return this.parseFunction(expr, FUNC_STATEMENT | FUNC_NULLABLE_ID, isAsync); + } else if (this.match(types._class)) { + return this.parseClass(expr, true, true); + } else if (this.match(types.at)) { + if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport")) { + this.unexpected(this.state.start, "Decorators must be placed *before* the 'export' keyword." + " You can set the 'decoratorsBeforeExport' option to false to use" + " the 'export @decorator class {}' syntax"); } - assert(!this.hasPlugin("jsx")); - this.state = state; - return super.parseMaybeAssign(...args); + this.parseDecorators(false); + return this.parseClass(expr, true, true); + } else if (this.match(types._const) || this.match(types._var) || this.isLet()) { + return this.raise(this.state.start, "Only expressions, functions or classes are allowed as the `default` export."); + } else { + const res = this.parseMaybeAssign(); + this.semicolon(); + return res; } + } - if (typeParameters && typeParameters.params.length !== 0) { - this.resetStartLocationFromNode(arrowExpression, typeParameters); + parseExportDeclaration(node) { + return this.parseStatement(null); + } + + isExportDefaultSpecifier() { + if (this.match(types.name)) { + return this.state.value !== "async" && this.state.value !== "let"; } - arrowExpression.typeParameters = typeParameters; - return arrowExpression; + if (!this.match(types._default)) { + return false; + } + + const lookahead = this.lookahead(); + return lookahead.type === types.comma || lookahead.type === types.name && lookahead.value === "from"; } - parseMaybeUnary(refShorthandDefaultPos) { - if (!this.hasPlugin("jsx") && this.isRelational("<")) { - return this.tsParseTypeAssertion(); + parseExportFrom(node, expect) { + if (this.eatContextual("from")) { + node.source = this.parseImportSource(); + this.checkExport(node); } else { - return super.parseMaybeUnary(refShorthandDefaultPos); + if (expect) { + this.unexpected(); + } else { + node.source = null; + } } + + this.semicolon(); } - parseArrow(node) { - if (this.match(types.colon)) { - const state = this.state.clone(); + shouldParseExportDeclaration() { + if (this.match(types.at)) { + this.expectOnePlugin(["decorators", "decorators-legacy"]); - try { - const returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon); - if (this.canInsertSemicolon()) this.unexpected(); - if (!this.match(types.arrow)) this.unexpected(); - node.returnType = returnType; - } catch (err) { - if (err instanceof SyntaxError) { - this.state = state; + if (this.hasPlugin("decorators")) { + if (this.getPluginOption("decorators", "decoratorsBeforeExport")) { + this.unexpected(this.state.start, "Decorators must be placed *before* the 'export' keyword." + " You can set the 'decoratorsBeforeExport' option to false to use" + " the 'export @decorator class {}' syntax"); } else { - throw err; + return true; } } } - return super.parseArrow(node); + return this.state.type.keyword === "var" || this.state.type.keyword === "const" || this.state.type.keyword === "function" || this.state.type.keyword === "class" || this.isLet() || this.isAsyncFunction(); } - parseAssignableListItemTypes(param) { - if (this.eat(types.question)) { - if (param.type !== "Identifier") { - throw this.raise(param.start, "A binding pattern parameter cannot be optional in an implementation signature."); - } - - param.optional = true; - } - - const type = this.tsTryParseTypeAnnotation(); - if (type) param.typeAnnotation = type; - return this.finishNode(param, param.type); - } + checkExport(node, checkNames, isDefault, isFrom) { + if (checkNames) { + if (isDefault) { + this.checkDuplicateExports(node, "default"); + } else if (node.specifiers && node.specifiers.length) { + for (let _i3 = 0, _node$specifiers = node.specifiers; _i3 < _node$specifiers.length; _i3++) { + const specifier = _node$specifiers[_i3]; + this.checkDuplicateExports(specifier, specifier.exported.name); - toAssignable(node, isBinding, contextDescription) { - switch (node.type) { - case "TSTypeCastExpression": - return super.toAssignable(this.typeCastToParameter(node), isBinding, contextDescription); + if (!isFrom && specifier.local) { + this.checkReservedWord(specifier.local.name, specifier.local.start, true, false); + this.scope.checkLocalExport(specifier.local); + } + } + } else if (node.declaration) { + if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") { + const id = node.declaration.id; + if (!id) throw new Error("Assertion failure"); + this.checkDuplicateExports(node, id.name); + } else if (node.declaration.type === "VariableDeclaration") { + for (let _i4 = 0, _node$declaration$dec = node.declaration.declarations; _i4 < _node$declaration$dec.length; _i4++) { + const declaration = _node$declaration$dec[_i4]; + this.checkDeclaration(declaration.id); + } + } + } + } - case "TSParameterProperty": - return super.toAssignable(node, isBinding, contextDescription); + const currentContextDecorators = this.state.decoratorStack[this.state.decoratorStack.length - 1]; - case "TSAsExpression": - case "TSNonNullExpression": - case "TSTypeAssertion": - node.expression = this.toAssignable(node.expression, isBinding, contextDescription); - return node; + if (currentContextDecorators.length) { + const isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression"); - default: - return super.toAssignable(node, isBinding, contextDescription); + if (!node.declaration || !isClass) { + throw this.raise(node.start, "You can only use decorators on an export when exporting a class"); + } + + this.takeDecorators(node.declaration); } } - checkLVal(expr, isBinding, checkClashes, contextDescription) { - switch (expr.type) { - case "TSTypeCastExpression": - return; - - case "TSParameterProperty": - this.checkLVal(expr.parameter, isBinding, checkClashes, "parameter property"); - return; - - case "TSAsExpression": - case "TSNonNullExpression": - case "TSTypeAssertion": - this.checkLVal(expr.expression, isBinding, checkClashes, contextDescription); - return; + checkDeclaration(node) { + if (node.type === "Identifier") { + this.checkDuplicateExports(node, node.name); + } else if (node.type === "ObjectPattern") { + for (let _i5 = 0, _node$properties = node.properties; _i5 < _node$properties.length; _i5++) { + const prop = _node$properties[_i5]; + this.checkDeclaration(prop); + } + } else if (node.type === "ArrayPattern") { + for (let _i6 = 0, _node$elements = node.elements; _i6 < _node$elements.length; _i6++) { + const elem = _node$elements[_i6]; - default: - super.checkLVal(expr, isBinding, checkClashes, contextDescription); - return; + if (elem) { + this.checkDeclaration(elem); + } + } + } else if (node.type === "ObjectProperty") { + this.checkDeclaration(node.value); + } else if (node.type === "RestElement") { + this.checkDeclaration(node.argument); + } else if (node.type === "AssignmentPattern") { + this.checkDeclaration(node.left); } } - parseBindingAtom() { - switch (this.state.type) { - case types._this: - return this.parseIdentifier(true); - - default: - return super.parseBindingAtom(); + checkDuplicateExports(node, name) { + if (this.state.exportedIdentifiers.indexOf(name) > -1) { + throw this.raise(node.start, name === "default" ? "Only one default export allowed per module." : `\`${name}\` has already been exported. Exported identifiers must be unique.`); } + + this.state.exportedIdentifiers.push(name); } - parseMaybeDecoratorArguments(expr) { - if (this.isRelational("<")) { - const typeArguments = this.tsParseTypeArguments(); + parseExportSpecifiers() { + const nodes = []; + let first = true; + this.expect(types.braceL); - if (this.match(types.parenL)) { - const call = super.parseMaybeDecoratorArguments(expr); - call.typeParameters = typeArguments; - return call; + while (!this.eat(types.braceR)) { + if (first) { + first = false; + } else { + this.expect(types.comma); + if (this.eat(types.braceR)) break; } - this.unexpected(this.state.start, types.parenL); + const node = this.startNode(); + node.local = this.parseIdentifier(true); + node.exported = this.eatContextual("as") ? this.parseIdentifier(true) : node.local.__clone(); + nodes.push(this.finishNode(node, "ExportSpecifier")); } - return super.parseMaybeDecoratorArguments(expr); - } - - isClassMethod() { - return this.isRelational("<") || super.isClassMethod(); - } - - isClassProperty() { - return this.match(types.bang) || this.match(types.colon) || super.isClassProperty(); + return nodes; } - parseMaybeDefault(...args) { - const node = super.parseMaybeDefault(...args); + parseImport(node) { + node.specifiers = []; - if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) { - this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, " + "e.g. instead of `age = 25: number` use `age: number = 25`"); + if (!this.match(types.string)) { + const hasDefault = this.maybeParseDefaultImportSpecifier(node); + const parseNext = !hasDefault || this.eat(types.comma); + const hasStar = parseNext && this.maybeParseStarImportSpecifier(node); + if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node); + this.expectContextual("from"); } - return node; + node.source = this.parseImportSource(); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); } - getTokenFromCode(code) { - if (this.state.inType && (code === 62 || code === 60)) { - return this.finishOp(types.relational, 1); - } else { - return super.getTokenFromCode(code); - } + parseImportSource() { + if (!this.match(types.string)) this.unexpected(); + return this.parseExprAtom(); } - toAssignableList(exprList, isBinding, contextDescription) { - for (let i = 0; i < exprList.length; i++) { - const expr = exprList[i]; - - if (expr && expr.type === "TSTypeCastExpression") { - exprList[i] = this.typeCastToParameter(expr); - } - } - - return super.toAssignableList(exprList, isBinding, contextDescription); + shouldParseDefaultImport(node) { + return this.match(types.name); } - typeCastToParameter(node) { - node.expression.typeAnnotation = node.typeAnnotation; - return this.finishNodeAt(node.expression, node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end); + parseImportSpecifierLocal(node, specifier, type, contextDescription) { + specifier.local = this.parseIdentifier(); + this.checkLVal(specifier.local, BIND_LEXICAL, undefined, contextDescription); + node.specifiers.push(this.finishNode(specifier, type)); } - toReferencedList(exprList, isInParens) { - for (let i = 0; i < exprList.length; i++) { - const expr = exprList[i]; - - if (expr && expr._exprListItem && expr.type === "TsTypeCastExpression") { - this.raise(expr.start, "Did not expect a type annotation here."); - } + maybeParseDefaultImportSpecifier(node) { + if (this.shouldParseDefaultImport(node)) { + this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier", "default import specifier"); + return true; } - return exprList; + return false; } - shouldParseArrow() { - return this.match(types.colon) || super.shouldParseArrow(); - } + maybeParseStarImportSpecifier(node) { + if (this.match(types.star)) { + const specifier = this.startNode(); + this.next(); + this.expectContextual("as"); + this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier", "import namespace specifier"); + return true; + } - shouldParseAsyncArrow() { - return this.match(types.colon) || super.shouldParseAsyncArrow(); + return false; } - canHaveLeadingDecorator() { - return super.canHaveLeadingDecorator() || this.isAbstractClass(); - } + parseNamedImportSpecifiers(node) { + let first = true; + this.expect(types.braceL); - jsxParseOpeningElementAfterName(node) { - const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArguments()); - if (typeArguments) node.typeParameters = typeArguments; - return super.jsxParseOpeningElementAfterName(node); - } + while (!this.eat(types.braceR)) { + if (first) { + first = false; + } else { + if (this.eat(types.colon)) { + this.unexpected(null, "ES2015 named imports do not destructure. " + "Use another statement for destructuring after the import."); + } -}); + this.expect(types.comma); + if (this.eat(types.braceR)) break; + } -function hasPlugin(plugins, name) { - return plugins.some(plugin => { - if (Array.isArray(plugin)) { - return plugin[0] === name; - } else { - return plugin === name; + this.parseImportSpecifier(node); } - }); -} -function getPluginOption(plugins, name, option) { - const plugin = plugins.find(plugin => { - if (Array.isArray(plugin)) { - return plugin[0] === name; + } + + parseImportSpecifier(node) { + const specifier = this.startNode(); + specifier.imported = this.parseIdentifier(true); + + if (this.eatContextual("as")) { + specifier.local = this.parseIdentifier(); } else { - return plugin === name; + this.checkReservedWord(specifier.imported.name, specifier.start, true, true); + specifier.local = specifier.imported.__clone(); } - }); - if (plugin && Array.isArray(plugin)) { - return plugin[1][option]; + this.checkLVal(specifier.local, BIND_LEXICAL, undefined, "import specifier"); + node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); } - return null; } -const PIPELINE_PROPOSALS = ["minimal", "smart"]; -function validatePlugins(plugins) { - if (hasPlugin(plugins, "decorators")) { - if (hasPlugin(plugins, "decorators-legacy")) { - throw new Error("Cannot use the decorators and decorators-legacy plugin together"); - } - const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport"); +class Parser extends StatementParser { + constructor(options, input) { + options = getOptions(options); + super(options, input); + const ScopeHandler = this.getScopeHandler(); + this.options = options; + this.inModule = this.options.sourceType === "module"; + this.scope = new ScopeHandler(this.raise.bind(this), this.inModule); + this.plugins = pluginsMap(this.options.plugins); + this.filename = options.sourceFilename; + } - if (decoratorsBeforeExport == null) { - throw new Error("The 'decorators' plugin requires a 'decoratorsBeforeExport' option," + " whose value must be a boolean. If you are migrating from" + " Babylon/Babel 6 or want to use the old decorators proposal, you" + " should use the 'decorators-legacy' plugin instead of 'decorators'."); - } else if (typeof decoratorsBeforeExport !== "boolean") { - throw new Error("'decoratorsBeforeExport' must be a boolean."); - } + getScopeHandler() { + return ScopeHandler; } - if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) { - throw new Error("Cannot combine flow and typescript plugins."); + parse() { + this.scope.enter(SCOPE_PROGRAM); + const file = this.startNode(); + const program = this.startNode(); + this.nextToken(); + return this.parseTopLevel(file, program); } - if (hasPlugin(plugins, "pipelineOperator") && !PIPELINE_PROPOSALS.includes(getPluginOption(plugins, "pipelineOperator", "proposal"))) { - throw new Error("'pipelineOperator' requires 'proposal' option whose value should be one of: " + PIPELINE_PROPOSALS.map(p => `'${p}'`).join(", ")); +} + +function pluginsMap(plugins) { + const pluginMap = new Map(); + + for (let _i = 0; _i < plugins.length; _i++) { + const plugin = plugins[_i]; + const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}]; + if (!pluginMap.has(name)) pluginMap.set(name, options || {}); } + + return pluginMap; } -const mixinPluginNames = ["estree", "jsx", "flow", "typescript"]; -const mixinPlugins = { - estree, - jsx, - flow, - typescript -}; function parse(input, options) { if (options && options.sourceType === "unambiguous") { @@ -10669,6 +11278,7 @@ function parseExpression(input, options) { return parser.getExpression(); } + function getParser(options, input) { let cls = Parser; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/parser/package.json b/tools/node_modules/babel-eslint/node_modules/@babel/parser/package.json index 34e38f3908..2c4ad12717 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/parser/package.json +++ b/tools/node_modules/babel-eslint/node_modules/@babel/parser/package.json @@ -11,9 +11,9 @@ "description": "A JavaScript parser", "devDependencies": { "@babel/code-frame": "^7.0.0", - "@babel/helper-fixtures": "^7.2.0", - "charcodes": "0.1.0", - "unicode-11.0.0": "^0.7.8" + "@babel/helper-fixtures": "^7.4.4", + "charcodes": "^0.2.0", + "unicode-12.0.0": "^0.7.9" }, "engines": { "node": ">=6.0.0" @@ -23,7 +23,7 @@ "lib", "typings" ], - "gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741", + "gitHead": "33ab4f166117e2380de3955a0842985f578b01b8", "homepage": "https://babeljs.io/", "keywords": [ "babel", @@ -44,5 +44,5 @@ "url": "https://github.com/babel/babel/tree/master/packages/babel-parser" }, "types": "typings/babel-parser.d.ts", - "version": "7.3.4" + "version": "7.4.5" } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/template/LICENSE b/tools/node_modules/babel-eslint/node_modules/@babel/template/LICENSE index a06ec0e70f..f31575ec77 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/template/LICENSE +++ b/tools/node_modules/babel-eslint/node_modules/@babel/template/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2018 Sebastian McKenzie and other contributors +Copyright (c) 2014-present Sebastian McKenzie and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/literal.js b/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/literal.js index 9d39a7cb86..0b8f904582 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/literal.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/literal.js @@ -54,7 +54,8 @@ function buildLiteralData(formatter, tpl, opts) { parser: opts.parser, placeholderWhitelist: new Set(result.names.concat(opts.placeholderWhitelist ? Array.from(opts.placeholderWhitelist) : [])), placeholderPattern: opts.placeholderPattern, - preserveComments: opts.preserveComments + preserveComments: opts.preserveComments, + syntacticPlaceholders: opts.syntacticPlaceholders }); } while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name))); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/options.js b/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/options.js index c0208b2296..35ed733388 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/options.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/options.js @@ -13,13 +13,15 @@ function merge(a, b) { const { placeholderWhitelist = a.placeholderWhitelist, placeholderPattern = a.placeholderPattern, - preserveComments = a.preserveComments + preserveComments = a.preserveComments, + syntacticPlaceholders = a.syntacticPlaceholders } = b; return { parser: Object.assign({}, a.parser, b.parser), placeholderWhitelist, placeholderPattern, - preserveComments + preserveComments, + syntacticPlaceholders }; } @@ -32,9 +34,10 @@ function validate(opts) { { placeholderWhitelist, placeholderPattern, - preserveComments + preserveComments, + syntacticPlaceholders } = _ref, - parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments"]); + parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"]); if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) { throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined"); @@ -48,11 +51,20 @@ function validate(opts) { throw new Error("'.preserveComments' must be a boolean, null, or undefined"); } + if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") { + throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined"); + } + + if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) { + throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'"); + } + return { parser, placeholderWhitelist: placeholderWhitelist || undefined, placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern, - preserveComments: preserveComments == null ? false : preserveComments + preserveComments: preserveComments == null ? false : preserveComments, + syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders }; } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/parse.js b/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/parse.js index 336edcf661..3173349559 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/parse.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/template/lib/parse.js @@ -43,40 +43,65 @@ function parseAndBuildMetadata(formatter, code, opts) { const ast = parseWithCodeFrame(code, opts.parser); const { placeholderWhitelist, - placeholderPattern = PATTERN, - preserveComments + placeholderPattern, + preserveComments, + syntacticPlaceholders } = opts; t().removePropertiesDeep(ast, { preserveComments }); formatter.validate(ast); - const placeholders = []; - const placeholderNames = new Set(); + const syntactic = { + placeholders: [], + placeholderNames: new Set() + }; + const legacy = { + placeholders: [], + placeholderNames: new Set() + }; + const isLegacyRef = { + value: undefined + }; t().traverse(ast, placeholderVisitorHandler, { - placeholders, - placeholderNames, + syntactic, + legacy, + isLegacyRef, placeholderWhitelist, - placeholderPattern + placeholderPattern, + syntacticPlaceholders }); - return { - ast, - placeholders, - placeholderNames - }; + return Object.assign({ + ast + }, isLegacyRef.value ? legacy : syntactic); } function placeholderVisitorHandler(node, ancestors, state) { let name; - if (t().isIdentifier(node) || t().isJSXIdentifier(node)) { + if (t().isPlaceholder(node)) { + if (state.syntacticPlaceholders === false) { + throw new Error("%%foo%%-style placeholders can't be used when " + "'.syntacticPlaceholders' is false."); + } else { + name = node.name.name; + state.isLegacyRef.value = false; + } + } else if (state.isLegacyRef.value === false || state.syntacticPlaceholders) { + return; + } else if (t().isIdentifier(node) || t().isJSXIdentifier(node)) { name = node.name; + state.isLegacyRef.value = true; } else if (t().isStringLiteral(node)) { name = node.value; + state.isLegacyRef.value = true; } else { return; } - if ((!state.placeholderPattern || !state.placeholderPattern.test(name)) && (!state.placeholderWhitelist || !state.placeholderWhitelist.has(name))) { + if (!state.isLegacyRef.value && (state.placeholderPattern != null || state.placeholderWhitelist != null)) { + throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'"); + } + + if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && (!state.placeholderWhitelist || !state.placeholderWhitelist.has(name))) { return; } @@ -87,24 +112,32 @@ function placeholderVisitorHandler(node, ancestors, state) { } = ancestors[ancestors.length - 1]; let type; - if (t().isStringLiteral(node)) { + if (t().isStringLiteral(node) || t().isPlaceholder(node, { + expectedNode: "StringLiteral" + })) { type = "string"; } else if (t().isNewExpression(parent) && key === "arguments" || t().isCallExpression(parent) && key === "arguments" || t().isFunction(parent) && key === "params") { type = "param"; - } else if (t().isExpressionStatement(parent)) { + } else if (t().isExpressionStatement(parent) && !t().isPlaceholder(node)) { type = "statement"; ancestors = ancestors.slice(0, -1); + } else if (t().isStatement(node) && t().isPlaceholder(node)) { + type = "statement"; } else { type = "other"; } - state.placeholders.push({ + const { + placeholders, + placeholderNames + } = state.isLegacyRef.value ? state.legacy : state.syntactic; + placeholders.push({ name, type, resolve: ast => resolveAncestors(ast, ancestors), - isDuplicate: state.placeholderNames.has(name) + isDuplicate: placeholderNames.has(name) }); - state.placeholderNames.add(name); + placeholderNames.add(name); } function resolveAncestors(ast, ancestors) { @@ -139,7 +172,9 @@ function parseWithCodeFrame(code, parserOpts) { allowReturnOutsideFunction: true, allowSuperOutsideMethod: true, sourceType: "module" - }, parserOpts); + }, parserOpts, { + plugins: (parserOpts.plugins || []).concat("placeholders") + }); try { return (0, _parser().parse)(code, parserOpts); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/template/package.json b/tools/node_modules/babel-eslint/node_modules/@babel/template/package.json index 6090da2691..54bdfd6423 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/template/package.json +++ b/tools/node_modules/babel-eslint/node_modules/@babel/template/package.json @@ -6,11 +6,12 @@ "bundleDependencies": false, "dependencies": { "@babel/code-frame": "^7.0.0", - "@babel/parser": "^7.2.2", - "@babel/types": "^7.2.2" + "@babel/parser": "^7.4.4", + "@babel/types": "^7.4.4" }, "deprecated": false, "description": "Generate an AST from a string template.", + "gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba", "homepage": "https://babeljs.io/", "license": "MIT", "main": "lib/index.js", @@ -22,5 +23,5 @@ "type": "git", "url": "https://github.com/babel/babel/tree/master/packages/babel-template" }, - "version": "7.2.2" + "version": "7.4.4" } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/context.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/context.js index 53516aa845..eacfc4e9b2 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/context.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/context.js @@ -53,7 +53,7 @@ function _call(fns) { const ret = fn.call(this.state, this, this.state); if (ret && typeof ret === "object" && typeof ret.then === "function") { - throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support.` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); + throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); } if (ret) { @@ -169,7 +169,7 @@ function _resyncKey() { } } } else { - for (const key in this.container) { + for (const key of Object.keys(this.container)) { if (this.container[key] === this.node) { return this.setKey(key); } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/index.js index 840d71802f..906087f10d 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/index.js @@ -76,7 +76,7 @@ class NodePath { this.parent = parent; this.hub = hub; this.contexts = []; - this.data = {}; + this.data = Object.create(null); this.shouldSkip = false; this.shouldStop = false; this.removed = false; @@ -149,7 +149,7 @@ class NodePath { getData(key, def) { let val = this.data[key]; - if (!val && def) val = this.data[key] = def; + if (val === undefined && def !== undefined) val = this.data[key] = def; return val; } @@ -208,7 +208,7 @@ for (const type of t().TYPES) { }; } -for (const type in virtualTypes) { +for (const type of Object.keys(virtualTypes)) { if (type[0] === "_") continue; if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type); const virtualType = virtualTypes[type]; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js index 58023a1c48..5890b93827 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/inference/inferers.js @@ -12,6 +12,7 @@ exports.BinaryExpression = BinaryExpression; exports.LogicalExpression = LogicalExpression; exports.ConditionalExpression = ConditionalExpression; exports.SequenceExpression = SequenceExpression; +exports.ParenthesizedExpression = ParenthesizedExpression; exports.AssignmentExpression = AssignmentExpression; exports.UpdateExpression = UpdateExpression; exports.StringLiteral = StringLiteral; @@ -128,6 +129,10 @@ function SequenceExpression() { return this.get("expressions").pop().getTypeAnnotation(); } +function ParenthesizedExpression() { + return this.get("expression").getTypeAnnotation(); +} + function AssignmentExpression() { return this.get("right").getTypeAnnotation(); } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/hoister.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/hoister.js index a14921c464..544d78827b 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/hoister.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/hoister.js @@ -54,7 +54,7 @@ class PathHoister { } isCompatibleScope(scope) { - for (const key in this.bindings) { + for (const key of Object.keys(this.bindings)) { const binding = this.bindings[key]; if (!scope.bindingIdentifierEquals(key, binding.identifier)) { @@ -92,7 +92,7 @@ class PathHoister { } if (targetScope.path.isProgram() || targetScope.path.isFunction()) { - for (const name in this.bindings) { + for (const name of Object.keys(this.bindings)) { if (!targetScope.hasOwnBinding(name)) continue; const binding = this.bindings[name]; @@ -154,7 +154,7 @@ class PathHoister { } hasOwnParamBindings(scope) { - for (const name in this.bindings) { + for (const name of Object.keys(this.bindings)) { if (!scope.hasOwnBinding(name)) continue; const binding = this.bindings[name]; if (binding.kind === "param" && binding.constant) return true; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/virtual-types.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/virtual-types.js index af321caa83..2ac7cf044c 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/virtual-types.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/lib/virtual-types.js @@ -20,10 +20,12 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; const ReferencedIdentifier = { types: ["Identifier", "JSXIdentifier"], - checkPath({ - node, - parent - }, opts) { + checkPath(path, opts) { + const { + node, + parent + } = path; + if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) { if (t().isJSXIdentifier(node, opts)) { if (t().react.isCompatTag(node.name)) return false; @@ -32,7 +34,7 @@ const ReferencedIdentifier = { } } - return t().isReferenced(node, parent); + return t().isReferenced(node, parent, path.parentPath.parent); } }; @@ -52,11 +54,13 @@ exports.ReferencedMemberExpression = ReferencedMemberExpression; const BindingIdentifier = { types: ["Identifier"], - checkPath({ - node, - parent - }) { - return t().isIdentifier(node) && t().isBinding(node, parent); + checkPath(path) { + const { + node, + parent + } = path; + const grandparent = path.parentPath.parent; + return t().isIdentifier(node) && t().isBinding(node, parent, grandparent); } }; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/replacement.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/replacement.js index 373861f6c4..36e6c9fdd2 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/replacement.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/path/replacement.js @@ -57,7 +57,7 @@ const hoistVariablesVisitor = { if (path.node.kind !== "var") return; const bindings = path.getBindingIdentifiers(); - for (const key in bindings) { + for (const key of Object.keys(bindings)) { path.scope.push({ id: bindings[key] }); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/scope/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/scope/index.js index 9d24068b98..b27f22678a 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/scope/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/scope/index.js @@ -152,9 +152,7 @@ const collectorVisitor = { if (binding) binding.reference(path); } else if (t().isVariableDeclaration(declar)) { for (const decl of declar.declarations) { - const ids = t().getBindingIdentifiers(decl); - - for (const name in ids) { + for (const name of Object.keys(t().getBindingIdentifiers(decl))) { const binding = scope.getBinding(name); if (binding) binding.reference(path); } @@ -371,7 +369,7 @@ class Scope { do { console.log("#", scope.block.type); - for (const name in scope.bindings) { + for (const name of Object.keys(scope.bindings)) { const binding = scope.bindings[name]; console.log(" -", name, { constant: binding.constant, @@ -472,7 +470,7 @@ class Scope { registerConstantViolation(path) { const ids = path.getBindingIdentifiers(); - for (const name in ids) { + for (const name of Object.keys(ids)) { const binding = this.getBinding(name); if (binding) binding.reassign(path); } @@ -492,9 +490,9 @@ class Scope { } const parent = this.getProgramParent(); - const ids = path.getBindingIdentifiers(true); + const ids = path.getOuterBindingIdentifiers(true); - for (const name in ids) { + for (const name of Object.keys(ids)) { for (const id of ids[name]) { const local = this.getOwnBinding(name); @@ -687,7 +685,7 @@ class Scope { const ids = path.getBindingIdentifiers(); let programParent; - for (const name in ids) { + for (const name of Object.keys(ids)) { if (path.scope.getBinding(name)) continue; programParent = programParent || path.scope.getProgramParent(); programParent.addGlobal(ids[name]); @@ -800,7 +798,7 @@ class Scope { let scope = this; do { - for (const name in scope.bindings) { + for (const name of Object.keys(scope.bindings)) { const binding = scope.bindings[name]; if (binding.kind === kind) ids[name] = binding; } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/visitors.js b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/visitors.js index 963c5da73a..7483fe1735 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/visitors.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/lib/visitors.js @@ -37,7 +37,7 @@ function explode(visitor) { if (visitor._exploded) return visitor; visitor._exploded = true; - for (const nodeType in visitor) { + for (const nodeType of Object.keys(visitor)) { if (shouldIgnoreKey(nodeType)) continue; const parts = nodeType.split("|"); if (parts.length === 1) continue; @@ -60,7 +60,7 @@ function explode(visitor) { if (!wrapper) continue; const fns = visitor[nodeType]; - for (const type in fns) { + for (const type of Object.keys(fns)) { fns[type] = wrapCheck(wrapper, fns[type]); } @@ -79,7 +79,7 @@ function explode(visitor) { } } - for (const nodeType in visitor) { + for (const nodeType of Object.keys(visitor)) { if (shouldIgnoreKey(nodeType)) continue; const fns = visitor[nodeType]; let aliases = t().FLIPPED_ALIAS_KEYS[nodeType]; @@ -104,7 +104,7 @@ function explode(visitor) { } } - for (const nodeType in visitor) { + for (const nodeType of Object.keys(visitor)) { if (shouldIgnoreKey(nodeType)) continue; ensureCallbackArrays(visitor[nodeType]); } @@ -119,7 +119,7 @@ function verify(visitor) { throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?"); } - for (const nodeType in visitor) { + for (const nodeType of Object.keys(visitor)) { if (nodeType === "enter" || nodeType === "exit") { validateVisitorMethods(nodeType, visitor[nodeType]); } @@ -133,7 +133,7 @@ function verify(visitor) { const visitors = visitor[nodeType]; if (typeof visitors === "object") { - for (const visitorKey in visitors) { + for (const visitorKey of Object.keys(visitors)) { if (visitorKey === "enter" || visitorKey === "exit") { validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]); } else { @@ -164,7 +164,7 @@ function merge(visitors, states = [], wrapper) { const state = states[i]; explode(visitor); - for (const type in visitor) { + for (const type of Object.keys(visitor)) { let visitorType = visitor[type]; if (state || wrapper) { @@ -182,7 +182,7 @@ function merge(visitors, states = [], wrapper) { function wrapWithStateOrWrapper(oldVisitor, state, wrapper) { const newVisitor = {}; - for (const key in oldVisitor) { + for (const key of Object.keys(oldVisitor)) { let fns = oldVisitor[key]; if (!Array.isArray(fns)) continue; fns = fns.map(function (fn) { @@ -207,7 +207,7 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) { } function ensureEntranceObjects(obj) { - for (const key in obj) { + for (const key of Object.keys(obj)) { if (shouldIgnoreKey(key)) continue; const fns = obj[key]; @@ -248,7 +248,7 @@ function shouldIgnoreKey(key) { } function mergePair(dest, src) { - for (const key in src) { + for (const key of Object.keys(src)) { dest[key] = [].concat(dest[key] || [], src[key]); } } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/package.json b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/package.json index bea5eb0a91..9eff77c00e 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/traverse/package.json +++ b/tools/node_modules/babel-eslint/node_modules/@babel/traverse/package.json @@ -6,11 +6,11 @@ "bundleDependencies": false, "dependencies": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.3.4", + "@babel/generator": "^7.4.4", "@babel/helper-function-name": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.0.0", - "@babel/parser": "^7.3.4", - "@babel/types": "^7.3.4", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.4.5", + "@babel/types": "^7.4.4", "debug": "^4.1.0", "globals": "^11.1.0", "lodash": "^4.17.11" @@ -20,7 +20,7 @@ "devDependencies": { "@babel/helper-plugin-test-runner": "^7.0.0" }, - "gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741", + "gitHead": "33ab4f166117e2380de3955a0842985f578b01b8", "homepage": "https://babeljs.io/", "license": "MIT", "main": "lib/index.js", @@ -32,5 +32,5 @@ "type": "git", "url": "https://github.com/babel/babel/tree/master/packages/babel-traverse" }, - "version": "7.3.4" + "version": "7.4.5" } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/asserts/generated/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/asserts/generated/index.js index 5b5659a155..a9f59b08ad 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/asserts/generated/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/asserts/generated/index.js @@ -42,6 +42,7 @@ exports.assertObjectProperty = assertObjectProperty; exports.assertRestElement = assertRestElement; exports.assertReturnStatement = assertReturnStatement; exports.assertSequenceExpression = assertSequenceExpression; +exports.assertParenthesizedExpression = assertParenthesizedExpression; exports.assertSwitchCase = assertSwitchCase; exports.assertSwitchStatement = assertSwitchStatement; exports.assertThisExpression = assertThisExpression; @@ -146,7 +147,8 @@ exports.assertJSXFragment = assertJSXFragment; exports.assertJSXOpeningFragment = assertJSXOpeningFragment; exports.assertJSXClosingFragment = assertJSXClosingFragment; exports.assertNoop = assertNoop; -exports.assertParenthesizedExpression = assertParenthesizedExpression; +exports.assertPlaceholder = assertPlaceholder; +exports.assertArgumentPlaceholder = assertArgumentPlaceholder; exports.assertAwaitExpression = assertAwaitExpression; exports.assertBindExpression = assertBindExpression; exports.assertClassProperty = assertClassProperty; @@ -437,6 +439,10 @@ function assertSequenceExpression(node, opts = {}) { assert("SequenceExpression", node, opts); } +function assertParenthesizedExpression(node, opts = {}) { + assert("ParenthesizedExpression", node, opts); +} + function assertSwitchCase(node, opts = {}) { assert("SwitchCase", node, opts); } @@ -853,8 +859,12 @@ function assertNoop(node, opts = {}) { assert("Noop", node, opts); } -function assertParenthesizedExpression(node, opts = {}) { - assert("ParenthesizedExpression", node, opts); +function assertPlaceholder(node, opts = {}) { + assert("Placeholder", node, opts); +} + +function assertArgumentPlaceholder(node, opts = {}) { + assert("ArgumentPlaceholder", node, opts); } function assertAwaitExpression(node, opts = {}) { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/builder.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/builder.js index 50d1b2a95f..b42fac2f15 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/builder.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/builder.js @@ -42,7 +42,7 @@ function builder(type, ...args) { i++; }); - for (const key in node) { + for (const key of Object.keys(node)) { (0, _validate.default)(node, key, node[key]); } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/generated/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/generated/index.js index e77a2dd345..06d0127d12 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/generated/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/builders/generated/index.js @@ -42,6 +42,7 @@ exports.objectProperty = exports.ObjectProperty = ObjectProperty; exports.restElement = exports.RestElement = RestElement; exports.returnStatement = exports.ReturnStatement = ReturnStatement; exports.sequenceExpression = exports.SequenceExpression = SequenceExpression; +exports.parenthesizedExpression = exports.ParenthesizedExpression = ParenthesizedExpression; exports.switchCase = exports.SwitchCase = SwitchCase; exports.switchStatement = exports.SwitchStatement = SwitchStatement; exports.thisExpression = exports.ThisExpression = ThisExpression; @@ -146,7 +147,8 @@ exports.jSXFragment = exports.jsxFragment = exports.JSXFragment = JSXFragment; exports.jSXOpeningFragment = exports.jsxOpeningFragment = exports.JSXOpeningFragment = JSXOpeningFragment; exports.jSXClosingFragment = exports.jsxClosingFragment = exports.JSXClosingFragment = JSXClosingFragment; exports.noop = exports.Noop = Noop; -exports.parenthesizedExpression = exports.ParenthesizedExpression = ParenthesizedExpression; +exports.placeholder = exports.Placeholder = Placeholder; +exports.argumentPlaceholder = exports.ArgumentPlaceholder = ArgumentPlaceholder; exports.awaitExpression = exports.AwaitExpression = AwaitExpression; exports.bindExpression = exports.BindExpression = BindExpression; exports.classProperty = exports.ClassProperty = ClassProperty; @@ -389,6 +391,10 @@ function SequenceExpression(...args) { return (0, _builder.default)("SequenceExpression", ...args); } +function ParenthesizedExpression(...args) { + return (0, _builder.default)("ParenthesizedExpression", ...args); +} + function SwitchCase(...args) { return (0, _builder.default)("SwitchCase", ...args); } @@ -805,8 +811,12 @@ function Noop(...args) { return (0, _builder.default)("Noop", ...args); } -function ParenthesizedExpression(...args) { - return (0, _builder.default)("ParenthesizedExpression", ...args); +function Placeholder(...args) { + return (0, _builder.default)("Placeholder", ...args); +} + +function ArgumentPlaceholder(...args) { + return (0, _builder.default)("ArgumentPlaceholder", ...args); } function AwaitExpression(...args) { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/clone/cloneNode.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/clone/cloneNode.js index bcccddcf47..ce9cb8c1f3 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/clone/cloneNode.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/clone/cloneNode.js @@ -63,7 +63,7 @@ function cloneNode(node, deep = true) { } if (has(node, "innerComments")) { - newNode.innerComments = node.innerCmments; + newNode.innerComments = node.innerComments; } if (has(node, "trailingComments")) { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js index 2d05485b80..fadd0f04be 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js @@ -32,7 +32,7 @@ function gatherSequenceExpressions(nodes, scope, declars) { for (const declar of node.declarations) { const bindings = (0, _getBindingIdentifiers.default)(declar); - for (const key in bindings) { + for (const key of Object.keys(bindings)) { declars.push({ kind: node.kind, id: (0, _cloneNode.default)(bindings[key]) diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/valueToNode.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/valueToNode.js index a7456ebfb0..9e19dbfa76 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/valueToNode.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/converters/valueToNode.js @@ -85,7 +85,7 @@ function valueToNode(value) { if ((0, _isPlainObject().default)(value)) { const props = []; - for (const key in value) { + for (const key of Object.keys(value)) { let nodeKey; if ((0, _isValidIdentifier.default)(key)) { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/core.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/core.js index b2bcbd9c2f..d759890cf5 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/core.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/core.js @@ -114,7 +114,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de validate: (0, _utils.assertNodeType)("Expression") }, arguments: { - validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName"))) + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName", "ArgumentPlaceholder"))) }, optional: { validate: (0, _utils.assertOneOf)(true, false), @@ -572,6 +572,15 @@ exports.patternLikeCommon = patternLikeCommon; }, aliases: ["Expression"] }); +(0, _utils.default)("ParenthesizedExpression", { + visitor: ["expression"], + aliases: ["Expression", "ExpressionWrapper"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } +}); (0, _utils.default)("SwitchCase", { visitor: ["test", "consequent"], fields: { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/experimental.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/experimental.js index e31b9fb7b9..3332a60073 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/experimental.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/experimental.js @@ -6,6 +6,7 @@ var _es = require("./es2015"); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } +(0, _utils.default)("ArgumentPlaceholder", {}); (0, _utils.default)("AwaitExpression", { builder: ["argument"], visitor: ["argument"], diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/index.js index ddb9e5101f..7f28569f50 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/index.js @@ -39,6 +39,24 @@ Object.defineProperty(exports, "DEPRECATED_KEYS", { return _utils.DEPRECATED_KEYS; } }); +Object.defineProperty(exports, "PLACEHOLDERS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS; + } +}); +Object.defineProperty(exports, "PLACEHOLDERS_ALIAS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS_ALIAS; + } +}); +Object.defineProperty(exports, "PLACEHOLDERS_FLIPPED_ALIAS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS_FLIPPED_ALIAS; + } +}); exports.TYPES = void 0; function _toFastProperties() { @@ -67,6 +85,8 @@ require("./typescript"); var _utils = require("./utils"); +var _placeholders = require("./placeholders"); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } (0, _toFastProperties().default)(_utils.VISITOR_KEYS); @@ -75,5 +95,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de (0, _toFastProperties().default)(_utils.NODE_FIELDS); (0, _toFastProperties().default)(_utils.BUILDER_KEYS); (0, _toFastProperties().default)(_utils.DEPRECATED_KEYS); +(0, _toFastProperties().default)(_placeholders.PLACEHOLDERS_ALIAS); +(0, _toFastProperties().default)(_placeholders.PLACEHOLDERS_FLIPPED_ALIAS); const TYPES = Object.keys(_utils.VISITOR_KEYS).concat(Object.keys(_utils.FLIPPED_ALIAS_KEYS)).concat(Object.keys(_utils.DEPRECATED_KEYS)); exports.TYPES = TYPES; \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/misc.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/misc.js index 714f297944..ecc4db67ff 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/misc.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/misc.js @@ -2,17 +2,22 @@ var _utils = _interopRequireWildcard(require("./utils")); +var _placeholders = require("./placeholders"); + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } (0, _utils.default)("Noop", { visitor: [] }); -(0, _utils.default)("ParenthesizedExpression", { - visitor: ["expression"], - aliases: ["Expression", "ExpressionWrapper"], +(0, _utils.default)("Placeholder", { + visitor: [], + builder: ["expectedNode", "name"], fields: { - expression: { - validate: (0, _utils.assertNodeType)("Expression") + name: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + expectedNode: { + validate: (0, _utils.assertOneOf)(..._placeholders.PLACEHOLDERS) } } }); \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/placeholders.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/placeholders.js new file mode 100644 index 0000000000..0edf7b2e80 --- /dev/null +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/placeholders.js @@ -0,0 +1,33 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.PLACEHOLDERS_FLIPPED_ALIAS = exports.PLACEHOLDERS_ALIAS = exports.PLACEHOLDERS = void 0; + +var _utils = require("./utils"); + +const PLACEHOLDERS = ["Identifier", "StringLiteral", "Expression", "Statement", "Declaration", "BlockStatement", "ClassBody", "Pattern"]; +exports.PLACEHOLDERS = PLACEHOLDERS; +const PLACEHOLDERS_ALIAS = { + Declaration: ["Statement"], + Pattern: ["PatternLike", "LVal"] +}; +exports.PLACEHOLDERS_ALIAS = PLACEHOLDERS_ALIAS; + +for (const type of PLACEHOLDERS) { + const alias = _utils.ALIAS_KEYS[type]; + if (alias && alias.length) PLACEHOLDERS_ALIAS[type] = alias; +} + +const PLACEHOLDERS_FLIPPED_ALIAS = {}; +exports.PLACEHOLDERS_FLIPPED_ALIAS = PLACEHOLDERS_FLIPPED_ALIAS; +Object.keys(PLACEHOLDERS_ALIAS).forEach(type => { + PLACEHOLDERS_ALIAS[type].forEach(alias => { + if (!Object.hasOwnProperty.call(PLACEHOLDERS_FLIPPED_ALIAS, alias)) { + PLACEHOLDERS_FLIPPED_ALIAS[alias] = []; + } + + PLACEHOLDERS_FLIPPED_ALIAS[alias].push(type); + }); +}); \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/typescript.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/typescript.js index 0e5f905512..6760567a53 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/typescript.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/typescript.js @@ -110,7 +110,7 @@ for (const type of tsKeywordTypes) { }); const fnOrCtr = { aliases: ["TSType"], - visitor: ["typeParameters", "typeAnnotation"], + visitor: ["typeParameters", "parameters", "typeAnnotation"], fields: signatureDeclarationCommon }; (0, _utils.default)("TSFunctionType", fnOrCtr); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/utils.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/utils.js index c8fee08c52..f049ccc173 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/utils.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/definitions/utils.js @@ -192,7 +192,7 @@ function defineType(type, opts = {}) { fields[key] = fields[key] || {}; } - for (const key in fields) { + for (const key of Object.keys(fields)) { const field = fields[key]; if (builder.indexOf(key) === -1) { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js index 8d9df04d7b..f5bb66b0aa 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js @@ -47,6 +47,7 @@ var _exportNames = { isLet: true, isNode: true, isNodesEquivalent: true, + isPlaceholderType: true, isReferenced: true, isScope: true, isSpecifierDefault: true, @@ -310,6 +311,12 @@ Object.defineProperty(exports, "isNodesEquivalent", { return _isNodesEquivalent.default; } }); +Object.defineProperty(exports, "isPlaceholderType", { + enumerable: true, + get: function () { + return _isPlaceholderType.default; + } +}); Object.defineProperty(exports, "isReferenced", { enumerable: true, get: function () { @@ -527,6 +534,8 @@ var _isNode = _interopRequireDefault(require("./validators/isNode")); var _isNodesEquivalent = _interopRequireDefault(require("./validators/isNodesEquivalent")); +var _isPlaceholderType = _interopRequireDefault(require("./validators/isPlaceholderType")); + var _isReferenced = _interopRequireDefault(require("./validators/isReferenced")); var _isScope = _interopRequireDefault(require("./validators/isScope")); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js.flow b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js.flow index f3e3e39df9..b717fab48d 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js.flow +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/index.js.flow @@ -85,7 +85,7 @@ declare class BabelNodeBreakStatement extends BabelNode { declare class BabelNodeCallExpression extends BabelNode { type: "CallExpression"; callee: BabelNodeExpression; - arguments: Array; + arguments: Array; optional?: true | false; typeArguments?: BabelNodeTypeParameterInstantiation; typeParameters?: BabelNodeTSTypeParameterInstantiation; @@ -237,7 +237,7 @@ declare class BabelNodeMemberExpression extends BabelNode { declare class BabelNodeNewExpression extends BabelNode { type: "NewExpression"; callee: BabelNodeExpression; - arguments: Array; + arguments: Array; optional?: true | false; typeArguments?: BabelNodeTypeParameterInstantiation; typeParameters?: BabelNodeTSTypeParameterInstantiation; @@ -297,6 +297,11 @@ declare class BabelNodeSequenceExpression extends BabelNode { expressions: Array; } +declare class BabelNodeParenthesizedExpression extends BabelNode { + type: "ParenthesizedExpression"; + expression: BabelNodeExpression; +} + declare class BabelNodeSwitchCase extends BabelNode { type: "SwitchCase"; test?: BabelNodeExpression; @@ -932,9 +937,14 @@ declare class BabelNodeNoop extends BabelNode { type: "Noop"; } -declare class BabelNodeParenthesizedExpression extends BabelNode { - type: "ParenthesizedExpression"; - expression: BabelNodeExpression; +declare class BabelNodePlaceholder extends BabelNode { + type: "Placeholder"; + expectedNode: "Identifier" | "StringLiteral" | "Expression" | "Statement" | "Declaration" | "BlockStatement" | "ClassBody" | "Pattern"; + name: BabelNodeIdentifier; +} + +declare class BabelNodeArgumentPlaceholder extends BabelNode { + type: "ArgumentPlaceholder"; } declare class BabelNodeAwaitExpression extends BabelNode { @@ -1095,14 +1105,14 @@ declare class BabelNodeTSQualifiedName extends BabelNode { declare class BabelNodeTSCallSignatureDeclaration extends BabelNode { type: "TSCallSignatureDeclaration"; typeParameters?: BabelNodeTSTypeParameterDeclaration; - parameters?: Array; + parameters: Array; typeAnnotation?: BabelNodeTSTypeAnnotation; } declare class BabelNodeTSConstructSignatureDeclaration extends BabelNode { type: "TSConstructSignatureDeclaration"; typeParameters?: BabelNodeTSTypeParameterDeclaration; - parameters?: Array; + parameters: Array; typeAnnotation?: BabelNodeTSTypeAnnotation; } @@ -1120,7 +1130,7 @@ declare class BabelNodeTSMethodSignature extends BabelNode { type: "TSMethodSignature"; key: BabelNodeExpression; typeParameters?: BabelNodeTSTypeParameterDeclaration; - parameters?: Array; + parameters: Array; typeAnnotation?: BabelNodeTSTypeAnnotation; computed?: boolean; optional?: boolean; @@ -1184,15 +1194,15 @@ declare class BabelNodeTSThisType extends BabelNode { declare class BabelNodeTSFunctionType extends BabelNode { type: "TSFunctionType"; typeParameters?: BabelNodeTSTypeParameterDeclaration; + parameters: Array; typeAnnotation?: BabelNodeTSTypeAnnotation; - parameters?: Array; } declare class BabelNodeTSConstructorType extends BabelNode { type: "TSConstructorType"; typeParameters?: BabelNodeTSTypeParameterDeclaration; + parameters: Array; typeAnnotation?: BabelNodeTSTypeAnnotation; - parameters?: Array; } declare class BabelNodeTSTypeReference extends BabelNode { @@ -1411,7 +1421,7 @@ declare class BabelNodeTSTypeParameter extends BabelNode { name?: string; } -type BabelNodeExpression = BabelNodeArrayExpression | BabelNodeAssignmentExpression | BabelNodeBinaryExpression | BabelNodeCallExpression | BabelNodeConditionalExpression | BabelNodeFunctionExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeLogicalExpression | BabelNodeMemberExpression | BabelNodeNewExpression | BabelNodeObjectExpression | BabelNodeSequenceExpression | BabelNodeThisExpression | BabelNodeUnaryExpression | BabelNodeUpdateExpression | BabelNodeArrowFunctionExpression | BabelNodeClassExpression | BabelNodeMetaProperty | BabelNodeSuper | BabelNodeTaggedTemplateExpression | BabelNodeTemplateLiteral | BabelNodeYieldExpression | BabelNodeTypeCastExpression | BabelNodeJSXElement | BabelNodeJSXFragment | BabelNodeParenthesizedExpression | BabelNodeAwaitExpression | BabelNodeBindExpression | BabelNodeOptionalMemberExpression | BabelNodePipelinePrimaryTopicReference | BabelNodeOptionalCallExpression | BabelNodeImport | BabelNodeDoExpression | BabelNodeBigIntLiteral | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression; +type BabelNodeExpression = BabelNodeArrayExpression | BabelNodeAssignmentExpression | BabelNodeBinaryExpression | BabelNodeCallExpression | BabelNodeConditionalExpression | BabelNodeFunctionExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeLogicalExpression | BabelNodeMemberExpression | BabelNodeNewExpression | BabelNodeObjectExpression | BabelNodeSequenceExpression | BabelNodeParenthesizedExpression | BabelNodeThisExpression | BabelNodeUnaryExpression | BabelNodeUpdateExpression | BabelNodeArrowFunctionExpression | BabelNodeClassExpression | BabelNodeMetaProperty | BabelNodeSuper | BabelNodeTaggedTemplateExpression | BabelNodeTemplateLiteral | BabelNodeYieldExpression | BabelNodeTypeCastExpression | BabelNodeJSXElement | BabelNodeJSXFragment | BabelNodeAwaitExpression | BabelNodeBindExpression | BabelNodeOptionalMemberExpression | BabelNodePipelinePrimaryTopicReference | BabelNodeOptionalCallExpression | BabelNodeImport | BabelNodeDoExpression | BabelNodeBigIntLiteral | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression; type BabelNodeBinary = BabelNodeBinaryExpression | BabelNodeLogicalExpression; type BabelNodeScopable = BabelNodeBlockStatement | BabelNodeCatchClause | BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeProgram | BabelNodeObjectMethod | BabelNodeSwitchStatement | BabelNodeWhileStatement | BabelNodeArrowFunctionExpression | BabelNodeClassDeclaration | BabelNodeClassExpression | BabelNodeForOfStatement | BabelNodeClassMethod | BabelNodeClassPrivateMethod; type BabelNodeBlockParent = BabelNodeBlockStatement | BabelNodeCatchClause | BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeProgram | BabelNodeObjectMethod | BabelNodeSwitchStatement | BabelNodeWhileStatement | BabelNodeArrowFunctionExpression | BabelNodeForOfStatement | BabelNodeClassMethod | BabelNodeClassPrivateMethod; @@ -1422,7 +1432,7 @@ type BabelNodeCompletionStatement = BabelNodeBreakStatement | BabelNodeContinueS type BabelNodeConditional = BabelNodeConditionalExpression | BabelNodeIfStatement; type BabelNodeLoop = BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeWhileStatement | BabelNodeForOfStatement; type BabelNodeWhile = BabelNodeDoWhileStatement | BabelNodeWhileStatement; -type BabelNodeExpressionWrapper = BabelNodeExpressionStatement | BabelNodeTypeCastExpression | BabelNodeParenthesizedExpression; +type BabelNodeExpressionWrapper = BabelNodeExpressionStatement | BabelNodeParenthesizedExpression | BabelNodeTypeCastExpression; type BabelNodeFor = BabelNodeForInStatement | BabelNodeForStatement | BabelNodeForOfStatement; type BabelNodeForXStatement = BabelNodeForInStatement | BabelNodeForOfStatement; type BabelNodeFunction = BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeObjectMethod | BabelNodeArrowFunctionExpression | BabelNodeClassMethod | BabelNodeClassPrivateMethod; @@ -1463,7 +1473,7 @@ declare module "@babel/types" { declare function directiveLiteral(value: string): BabelNodeDirectiveLiteral; declare function blockStatement(body: Array, directives?: Array): BabelNodeBlockStatement; declare function breakStatement(label?: BabelNodeIdentifier): BabelNodeBreakStatement; - declare function callExpression(callee: BabelNodeExpression, _arguments: Array, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeCallExpression; + declare function callExpression(callee: BabelNodeExpression, _arguments: Array, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeCallExpression; declare function catchClause(param?: BabelNodeIdentifier, body: BabelNodeBlockStatement): BabelNodeCatchClause; declare function conditionalExpression(test: BabelNodeExpression, consequent: BabelNodeExpression, alternate: BabelNodeExpression): BabelNodeConditionalExpression; declare function continueStatement(label?: BabelNodeIdentifier): BabelNodeContinueStatement; @@ -1486,7 +1496,7 @@ declare module "@babel/types" { declare function regExpLiteral(pattern: string, flags?: string): BabelNodeRegExpLiteral; declare function logicalExpression(operator: "||" | "&&" | "??", left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression; declare function memberExpression(object: BabelNodeExpression, property: any, computed?: boolean, optional?: true | false): BabelNodeMemberExpression; - declare function newExpression(callee: BabelNodeExpression, _arguments: Array, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeNewExpression; + declare function newExpression(callee: BabelNodeExpression, _arguments: Array, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeNewExpression; declare function program(body: Array, directives?: Array, sourceType?: "script" | "module", interpreter?: BabelNodeInterpreterDirective, sourceFile?: string): BabelNodeProgram; declare function objectExpression(properties: Array): BabelNodeObjectExpression; declare function objectMethod(kind?: "method" | "get" | "set", key: any, params: Array, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: Array, generator?: boolean, returnType?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop, typeParameters?: BabelNodeTypeParameterDeclaration | BabelNodeTSTypeParameterDeclaration | BabelNodeNoop): BabelNodeObjectMethod; @@ -1494,6 +1504,7 @@ declare module "@babel/types" { declare function restElement(argument: BabelNodeLVal, decorators?: Array, typeAnnotation?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop): BabelNodeRestElement; declare function returnStatement(argument?: BabelNodeExpression): BabelNodeReturnStatement; declare function sequenceExpression(expressions: Array): BabelNodeSequenceExpression; + declare function parenthesizedExpression(expression: BabelNodeExpression): BabelNodeParenthesizedExpression; declare function switchCase(test?: BabelNodeExpression, consequent: Array): BabelNodeSwitchCase; declare function switchStatement(discriminant: BabelNodeExpression, cases: Array): BabelNodeSwitchStatement; declare function thisExpression(): BabelNodeThisExpression; @@ -1597,7 +1608,8 @@ declare module "@babel/types" { declare function jsxOpeningFragment(): BabelNodeJSXOpeningFragment; declare function jsxClosingFragment(): BabelNodeJSXClosingFragment; declare function noop(): BabelNodeNoop; - declare function parenthesizedExpression(expression: BabelNodeExpression): BabelNodeParenthesizedExpression; + declare function placeholder(expectedNode: "Identifier" | "StringLiteral" | "Expression" | "Statement" | "Declaration" | "BlockStatement" | "ClassBody" | "Pattern", name: BabelNodeIdentifier): BabelNodePlaceholder; + declare function argumentPlaceholder(): BabelNodeArgumentPlaceholder; declare function awaitExpression(argument: BabelNodeExpression): BabelNodeAwaitExpression; declare function bindExpression(object: any, callee: any): BabelNodeBindExpression; declare function classProperty(key: BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeExpression, value?: BabelNodeExpression, typeAnnotation?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop, decorators?: Array, computed?: boolean, abstract?: boolean, accessibility?: "public" | "private" | "protected", definite?: boolean, optional?: boolean, readonly?: boolean, _static?: boolean): BabelNodeClassProperty; @@ -1618,10 +1630,10 @@ declare module "@babel/types" { declare function tsDeclareFunction(id?: BabelNodeIdentifier, typeParameters?: BabelNodeTSTypeParameterDeclaration | BabelNodeNoop, params: Array, returnType?: BabelNodeTSTypeAnnotation | BabelNodeNoop, async?: boolean, declare?: boolean, generator?: boolean): BabelNodeTSDeclareFunction; declare function tsDeclareMethod(decorators?: Array, key: BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration | BabelNodeNoop, params: Array, returnType?: BabelNodeTSTypeAnnotation | BabelNodeNoop, abstract?: boolean, access?: "public" | "private" | "protected", accessibility?: "public" | "private" | "protected", async?: boolean, computed?: boolean, generator?: boolean, kind?: "get" | "set" | "method" | "constructor", optional?: boolean, _static?: boolean): BabelNodeTSDeclareMethod; declare function tsQualifiedName(left: BabelNodeTSEntityName, right: BabelNodeIdentifier): BabelNodeTSQualifiedName; - declare function tsCallSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSCallSignatureDeclaration; - declare function tsConstructSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructSignatureDeclaration; + declare function tsCallSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSCallSignatureDeclaration; + declare function tsConstructSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructSignatureDeclaration; declare function tsPropertySignature(key: BabelNodeExpression, typeAnnotation?: BabelNodeTSTypeAnnotation, initializer?: BabelNodeExpression, computed?: boolean, optional?: boolean, readonly?: boolean): BabelNodeTSPropertySignature; - declare function tsMethodSignature(key: BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array, typeAnnotation?: BabelNodeTSTypeAnnotation, computed?: boolean, optional?: boolean): BabelNodeTSMethodSignature; + declare function tsMethodSignature(key: BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array, typeAnnotation?: BabelNodeTSTypeAnnotation, computed?: boolean, optional?: boolean): BabelNodeTSMethodSignature; declare function tsIndexSignature(parameters: Array, typeAnnotation?: BabelNodeTSTypeAnnotation, readonly?: boolean): BabelNodeTSIndexSignature; declare function tsAnyKeyword(): BabelNodeTSAnyKeyword; declare function tsUnknownKeyword(): BabelNodeTSUnknownKeyword; @@ -1635,8 +1647,8 @@ declare module "@babel/types" { declare function tsNullKeyword(): BabelNodeTSNullKeyword; declare function tsNeverKeyword(): BabelNodeTSNeverKeyword; declare function tsThisType(): BabelNodeTSThisType; - declare function tsFunctionType(typeParameters?: BabelNodeTSTypeParameterDeclaration, typeAnnotation?: BabelNodeTSTypeAnnotation, parameters?: Array): BabelNodeTSFunctionType; - declare function tsConstructorType(typeParameters?: BabelNodeTSTypeParameterDeclaration, typeAnnotation?: BabelNodeTSTypeAnnotation, parameters?: Array): BabelNodeTSConstructorType; + declare function tsFunctionType(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSFunctionType; + declare function tsConstructorType(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructorType; declare function tsTypeReference(typeName: BabelNodeTSEntityName, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeTSTypeReference; declare function tsTypePredicate(parameterName: BabelNodeIdentifier | BabelNodeTSThisType, typeAnnotation: BabelNodeTSTypeAnnotation): BabelNodeTSTypePredicate; declare function tsTypeQuery(exprName: BabelNodeTSEntityName | BabelNodeTSImportType): BabelNodeTSTypeQuery; @@ -1713,6 +1725,7 @@ declare module "@babel/types" { declare function isRestElement(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeRestElement) declare function isReturnStatement(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeReturnStatement) declare function isSequenceExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeSequenceExpression) + declare function isParenthesizedExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeParenthesizedExpression) declare function isSwitchCase(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeSwitchCase) declare function isSwitchStatement(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeSwitchStatement) declare function isThisExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeThisExpression) @@ -1817,7 +1830,8 @@ declare module "@babel/types" { declare function isJSXOpeningFragment(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXOpeningFragment) declare function isJSXClosingFragment(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXClosingFragment) declare function isNoop(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeNoop) - declare function isParenthesizedExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeParenthesizedExpression) + declare function isPlaceholder(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodePlaceholder) + declare function isArgumentPlaceholder(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeArgumentPlaceholder) declare function isAwaitExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeAwaitExpression) declare function isBindExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeBindExpression) declare function isClassProperty(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeClassProperty) diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js index 089179e257..5802683995 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js @@ -62,11 +62,11 @@ function removeTypeDuplicates(nodes) { types.push(node); } - for (const type in bases) { + for (const type of Object.keys(bases)) { types.push(bases[type]); } - for (const name in generics) { + for (const name of Object.keys(generics)) { types.push(generics[name]); } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/inherits.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/inherits.js index 452811d376..64d72fcf2f 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/inherits.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/inherits.js @@ -20,7 +20,7 @@ function inherits(child, parent) { } } - for (const key in parent) { + for (const key of Object.keys(parent)) { if (key[0] === "_" && key !== "__clone") child[key] = parent[key]; } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/removeProperties.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/removeProperties.js index 9135981688..f9cf8e6065 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/removeProperties.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/modifications/removeProperties.js @@ -18,7 +18,7 @@ function removeProperties(node, opts = {}) { if (node[key] != null) node[key] = undefined; } - for (const key in node) { + for (const key of Object.keys(node)) { if (key[0] === "_" && node[key] != null) node[key] = undefined; } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/generated/index.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/generated/index.js index 93edeab2de..e94b2fbbb0 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/generated/index.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/generated/index.js @@ -42,6 +42,7 @@ exports.isObjectProperty = isObjectProperty; exports.isRestElement = isRestElement; exports.isReturnStatement = isReturnStatement; exports.isSequenceExpression = isSequenceExpression; +exports.isParenthesizedExpression = isParenthesizedExpression; exports.isSwitchCase = isSwitchCase; exports.isSwitchStatement = isSwitchStatement; exports.isThisExpression = isThisExpression; @@ -146,7 +147,8 @@ exports.isJSXFragment = isJSXFragment; exports.isJSXOpeningFragment = isJSXOpeningFragment; exports.isJSXClosingFragment = isJSXClosingFragment; exports.isNoop = isNoop; -exports.isParenthesizedExpression = isParenthesizedExpression; +exports.isPlaceholder = isPlaceholder; +exports.isArgumentPlaceholder = isArgumentPlaceholder; exports.isAwaitExpression = isAwaitExpression; exports.isBindExpression = isBindExpression; exports.isClassProperty = isClassProperty; @@ -860,6 +862,21 @@ function isSequenceExpression(node, opts) { return false; } +function isParenthesizedExpression(node, opts) { + if (!node) return false; + const nodeType = node.type; + + if (nodeType === "ParenthesizedExpression") { + if (typeof opts === "undefined") { + return true; + } else { + return (0, _shallowEqual.default)(node, opts); + } + } + + return false; +} + function isSwitchCase(node, opts) { if (!node) return false; const nodeType = node.type; @@ -2420,11 +2437,26 @@ function isNoop(node, opts) { return false; } -function isParenthesizedExpression(node, opts) { +function isPlaceholder(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "ParenthesizedExpression") { + if (nodeType === "Placeholder") { + if (typeof opts === "undefined") { + return true; + } else { + return (0, _shallowEqual.default)(node, opts); + } + } + + return false; +} + +function isArgumentPlaceholder(node, opts) { + if (!node) return false; + const nodeType = node.type; + + if (nodeType === "ArgumentPlaceholder") { if (typeof opts === "undefined") { return true; } else { @@ -3594,7 +3626,7 @@ function isExpression(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Expression" || "ArrayExpression" === nodeType || "AssignmentExpression" === nodeType || "BinaryExpression" === nodeType || "CallExpression" === nodeType || "ConditionalExpression" === nodeType || "FunctionExpression" === nodeType || "Identifier" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ThisExpression" === nodeType || "UnaryExpression" === nodeType || "UpdateExpression" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassExpression" === nodeType || "MetaProperty" === nodeType || "Super" === nodeType || "TaggedTemplateExpression" === nodeType || "TemplateLiteral" === nodeType || "YieldExpression" === nodeType || "TypeCastExpression" === nodeType || "JSXElement" === nodeType || "JSXFragment" === nodeType || "ParenthesizedExpression" === nodeType || "AwaitExpression" === nodeType || "BindExpression" === nodeType || "OptionalMemberExpression" === nodeType || "PipelinePrimaryTopicReference" === nodeType || "OptionalCallExpression" === nodeType || "Import" === nodeType || "DoExpression" === nodeType || "BigIntLiteral" === nodeType || "TSAsExpression" === nodeType || "TSTypeAssertion" === nodeType || "TSNonNullExpression" === nodeType) { + if (nodeType === "Expression" || "ArrayExpression" === nodeType || "AssignmentExpression" === nodeType || "BinaryExpression" === nodeType || "CallExpression" === nodeType || "ConditionalExpression" === nodeType || "FunctionExpression" === nodeType || "Identifier" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ParenthesizedExpression" === nodeType || "ThisExpression" === nodeType || "UnaryExpression" === nodeType || "UpdateExpression" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassExpression" === nodeType || "MetaProperty" === nodeType || "Super" === nodeType || "TaggedTemplateExpression" === nodeType || "TemplateLiteral" === nodeType || "YieldExpression" === nodeType || "TypeCastExpression" === nodeType || "JSXElement" === nodeType || "JSXFragment" === nodeType || "AwaitExpression" === nodeType || "BindExpression" === nodeType || "OptionalMemberExpression" === nodeType || "PipelinePrimaryTopicReference" === nodeType || "OptionalCallExpression" === nodeType || "Import" === nodeType || "DoExpression" === nodeType || "BigIntLiteral" === nodeType || "TSAsExpression" === nodeType || "TSTypeAssertion" === nodeType || "TSNonNullExpression" === nodeType || nodeType === "Placeholder" && ("Expression" === node.expectedNode || "Identifier" === node.expectedNode || "StringLiteral" === node.expectedNode)) { if (typeof opts === "undefined") { return true; } else { @@ -3624,7 +3656,7 @@ function isScopable(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Scopable" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType) { + if (nodeType === "Scopable" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType || nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3639,7 +3671,7 @@ function isBlockParent(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "BlockParent" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType) { + if (nodeType === "BlockParent" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType || nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3654,7 +3686,7 @@ function isBlock(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Block" || "BlockStatement" === nodeType || "Program" === nodeType) { + if (nodeType === "Block" || "BlockStatement" === nodeType || "Program" === nodeType || nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3669,7 +3701,7 @@ function isStatement(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Statement" || "BlockStatement" === nodeType || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || "DebuggerStatement" === nodeType || "DoWhileStatement" === nodeType || "EmptyStatement" === nodeType || "ExpressionStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "IfStatement" === nodeType || "LabeledStatement" === nodeType || "ReturnStatement" === nodeType || "SwitchStatement" === nodeType || "ThrowStatement" === nodeType || "TryStatement" === nodeType || "VariableDeclaration" === nodeType || "WhileStatement" === nodeType || "WithStatement" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ForOfStatement" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || "TSImportEqualsDeclaration" === nodeType || "TSExportAssignment" === nodeType || "TSNamespaceExportDeclaration" === nodeType) { + if (nodeType === "Statement" || "BlockStatement" === nodeType || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || "DebuggerStatement" === nodeType || "DoWhileStatement" === nodeType || "EmptyStatement" === nodeType || "ExpressionStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "IfStatement" === nodeType || "LabeledStatement" === nodeType || "ReturnStatement" === nodeType || "SwitchStatement" === nodeType || "ThrowStatement" === nodeType || "TryStatement" === nodeType || "VariableDeclaration" === nodeType || "WhileStatement" === nodeType || "WithStatement" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ForOfStatement" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || "TSImportEqualsDeclaration" === nodeType || "TSExportAssignment" === nodeType || "TSNamespaceExportDeclaration" === nodeType || nodeType === "Placeholder" && ("Statement" === node.expectedNode || "Declaration" === node.expectedNode || "BlockStatement" === node.expectedNode)) { if (typeof opts === "undefined") { return true; } else { @@ -3759,7 +3791,7 @@ function isExpressionWrapper(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "ExpressionWrapper" || "ExpressionStatement" === nodeType || "TypeCastExpression" === nodeType || "ParenthesizedExpression" === nodeType) { + if (nodeType === "ExpressionWrapper" || "ExpressionStatement" === nodeType || "ParenthesizedExpression" === nodeType || "TypeCastExpression" === nodeType) { if (typeof opts === "undefined") { return true; } else { @@ -3834,7 +3866,7 @@ function isPureish(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Pureish" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "BigIntLiteral" === nodeType) { + if (nodeType === "Pureish" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "BigIntLiteral" === nodeType || nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3849,7 +3881,7 @@ function isDeclaration(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Declaration" || "FunctionDeclaration" === nodeType || "VariableDeclaration" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType) { + if (nodeType === "Declaration" || "FunctionDeclaration" === nodeType || "VariableDeclaration" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || nodeType === "Placeholder" && "Declaration" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3864,7 +3896,7 @@ function isPatternLike(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "PatternLike" || "Identifier" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType) { + if (nodeType === "PatternLike" || "Identifier" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || nodeType === "Placeholder" && ("Pattern" === node.expectedNode || "Identifier" === node.expectedNode)) { if (typeof opts === "undefined") { return true; } else { @@ -3879,7 +3911,7 @@ function isLVal(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "LVal" || "Identifier" === nodeType || "MemberExpression" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || "TSParameterProperty" === nodeType) { + if (nodeType === "LVal" || "Identifier" === nodeType || "MemberExpression" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || "TSParameterProperty" === nodeType || nodeType === "Placeholder" && ("Pattern" === node.expectedNode || "Identifier" === node.expectedNode)) { if (typeof opts === "undefined") { return true; } else { @@ -3894,7 +3926,7 @@ function isTSEntityName(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "TSEntityName" || "Identifier" === nodeType || "TSQualifiedName" === nodeType) { + if (nodeType === "TSEntityName" || "Identifier" === nodeType || "TSQualifiedName" === nodeType || nodeType === "Placeholder" && "Identifier" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3909,7 +3941,7 @@ function isLiteral(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Literal" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "TemplateLiteral" === nodeType || "BigIntLiteral" === nodeType) { + if (nodeType === "Literal" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "TemplateLiteral" === nodeType || "BigIntLiteral" === nodeType || nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -3924,7 +3956,7 @@ function isImmutable(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Immutable" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "JSXAttribute" === nodeType || "JSXClosingElement" === nodeType || "JSXElement" === nodeType || "JSXExpressionContainer" === nodeType || "JSXSpreadChild" === nodeType || "JSXOpeningElement" === nodeType || "JSXText" === nodeType || "JSXFragment" === nodeType || "JSXOpeningFragment" === nodeType || "JSXClosingFragment" === nodeType || "BigIntLiteral" === nodeType) { + if (nodeType === "Immutable" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "JSXAttribute" === nodeType || "JSXClosingElement" === nodeType || "JSXElement" === nodeType || "JSXExpressionContainer" === nodeType || "JSXSpreadChild" === nodeType || "JSXOpeningElement" === nodeType || "JSXText" === nodeType || "JSXFragment" === nodeType || "JSXOpeningFragment" === nodeType || "JSXClosingFragment" === nodeType || "BigIntLiteral" === nodeType || nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { @@ -4014,7 +4046,7 @@ function isPattern(node, opts) { if (!node) return false; const nodeType = node.type; - if (nodeType === "Pattern" || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType) { + if (nodeType === "Pattern" || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || nodeType === "Placeholder" && "Pattern" === node.expectedNode) { if (typeof opts === "undefined") { return true; } else { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/is.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/is.js index 5aa809d25e..a68c108861 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/is.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/is.js @@ -9,12 +9,23 @@ var _shallowEqual = _interopRequireDefault(require("../utils/shallowEqual")); var _isType = _interopRequireDefault(require("./isType")); +var _isPlaceholderType = _interopRequireDefault(require("./isPlaceholderType")); + +var _definitions = require("../definitions"); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function is(type, node, opts) { if (!node) return false; const matches = (0, _isType.default)(node.type, type); - if (!matches) return false; + + if (!matches) { + if (!opts && node.type === "Placeholder" && type in _definitions.FLIPPED_ALIAS_KEYS) { + return (0, _isPlaceholderType.default)(node.expectedNode, type); + } + + return false; + } if (typeof opts === "undefined") { return true; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isBinding.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isBinding.js index 24d781bf04..e18ad19760 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isBinding.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isBinding.js @@ -9,7 +9,11 @@ var _getBindingIdentifiers = _interopRequireDefault(require("../retrievers/getBi function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -function isBinding(node, parent) { +function isBinding(node, parent, grandparent) { + if (grandparent && node.type === "Identifier" && parent.type === "ObjectProperty" && grandparent.type === "ObjectExpression") { + return false; + } + const keys = _getBindingIdentifiers.default.keys[parent.type]; if (keys) { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isNodesEquivalent.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isNodesEquivalent.js index 01c5c1848a..0c3b8ac437 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isNodesEquivalent.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isNodesEquivalent.js @@ -24,6 +24,12 @@ function isNodesEquivalent(a, b) { return false; } + if (a[field] == null && b[field] == null) { + continue; + } else if (a[field] == null || b[field] == null) { + return false; + } + if (Array.isArray(a[field])) { if (!Array.isArray(b[field])) { return false; @@ -43,7 +49,7 @@ function isNodesEquivalent(a, b) { } if (typeof a[field] === "object" && (!visitorKeys || !visitorKeys.includes(field))) { - for (const key in a[field]) { + for (const key of Object.keys(a[field])) { if (a[field][key] !== b[field][key]) { return false; } diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isPlaceholderType.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isPlaceholderType.js new file mode 100644 index 0000000000..e8271de0b1 --- /dev/null +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isPlaceholderType.js @@ -0,0 +1,21 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = isPlaceholderType; + +var _definitions = require("../definitions"); + +function isPlaceholderType(placeholderType, targetType) { + if (placeholderType === targetType) return true; + const aliases = _definitions.PLACEHOLDERS_ALIAS[placeholderType]; + + if (aliases) { + for (const alias of aliases) { + if (targetType === alias) return true; + } + } + + return false; +} \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isReferenced.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isReferenced.js index 26c047efb4..46598dd1c8 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isReferenced.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/lib/validators/isReferenced.js @@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = isReferenced; -function isReferenced(node, parent) { +function isReferenced(node, parent, grandparent) { switch (parent.type) { case "MemberExpression": case "JSXMemberExpression": @@ -29,6 +29,9 @@ function isReferenced(node, parent) { return parent.local === node; + case "PrivateName": + return false; + case "ObjectProperty": case "ClassProperty": case "ClassPrivateProperty": @@ -39,7 +42,11 @@ function isReferenced(node, parent) { return !!parent.computed; } - return parent.value === node; + if (parent.value === node) { + return !grandparent || grandparent.type !== "ObjectPattern"; + } + + return true; case "ClassDeclaration": case "ClassExpression": @@ -89,6 +96,16 @@ function isReferenced(node, parent) { case "ObjectTypeProperty": return parent.key !== node; + + case "TSEnumMember": + return parent.id !== node; + + case "TSPropertySignature": + if (parent.key === node) { + return !!parent.computed; + } + + return true; } return true; diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/package.json b/tools/node_modules/babel-eslint/node_modules/@babel/types/package.json index b365bb91f1..72e411f75f 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/package.json +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/package.json @@ -12,10 +12,10 @@ "deprecated": false, "description": "Babel Types is a Lodash-esque utility library for AST nodes", "devDependencies": { - "@babel/generator": "^7.3.4", - "@babel/parser": "^7.3.4" + "@babel/generator": "^7.4.4", + "@babel/parser": "^7.4.4" }, - "gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741", + "gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba", "homepage": "https://babeljs.io/", "license": "MIT", "main": "lib/index.js", @@ -25,5 +25,5 @@ "url": "https://github.com/babel/babel/tree/master/packages/babel-types" }, "types": "lib/index.d.ts", - "version": "7.3.4" + "version": "7.4.4" } \ No newline at end of file diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generateTypeHelpers.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generateTypeHelpers.js index 794b214adf..bf0b036c18 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generateTypeHelpers.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generateTypeHelpers.js @@ -1,39 +1,29 @@ "use strict"; -const fs = require("fs"); const path = require("path"); const chalk = require("chalk"); const generateBuilders = require("./generators/generateBuilders"); const generateValidators = require("./generators/generateValidators"); const generateAsserts = require("./generators/generateAsserts"); const generateConstants = require("./generators/generateConstants"); -const format = require("./utils/formatCode"); +const format = require("../../../scripts/utils/formatCode"); +const writeFile = require("../../../scripts/utils/writeFileAndMkDir"); const baseDir = path.join(__dirname, "../src"); -function writeFile(content, location) { - const file = path.join(baseDir, location); - - try { - fs.mkdirSync(path.dirname(file)); - } catch (error) { - if (error.code !== "EEXIST") { - throw error; - } - } - - fs.writeFileSync(file, format(content, file)); -} - console.log("Generating @babel/types dynamic functions"); -writeFile(generateBuilders(), "builders/generated/index.js"); +const buildersFile = path.join(baseDir, "builders/generated/index.js"); +writeFile(buildersFile, format(generateBuilders(), buildersFile)); console.log(` ${chalk.green("✔")} Generated builders`); -writeFile(generateValidators(), "validators/generated/index.js"); +const validatorsFile = path.join(baseDir, "validators/generated/index.js"); +writeFile(validatorsFile, format(generateValidators(), validatorsFile)); console.log(` ${chalk.green("✔")} Generated validators`); -writeFile(generateAsserts(), "asserts/generated/index.js"); +const assertsFile = path.join(baseDir, "asserts/generated/index.js"); +writeFile(assertsFile, format(generateAsserts(), assertsFile)); console.log(` ${chalk.green("✔")} Generated asserts`); -writeFile(generateConstants(), "constants/generated/index.js"); +const constantsFile = path.join(baseDir, "constants/generated/index.js"); +writeFile(constantsFile, format(generateConstants(), constantsFile)); console.log(` ${chalk.green("✔")} Generated constants`); diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generators/generateValidators.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generators/generateValidators.js index 1e1ed321be..1455f99e5b 100644 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generators/generateValidators.js +++ b/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/generators/generateValidators.js @@ -1,14 +1,37 @@ "use strict"; const definitions = require("../../lib/definitions"); +const has = Function.call.bind(Object.prototype.hasOwnProperty); + +function joinComparisons(leftArr, right) { + return ( + leftArr.map(JSON.stringify).join(` === ${right} || `) + ` === ${right}` + ); +} + function addIsHelper(type, aliasKeys, deprecated) { const targetType = JSON.stringify(type); let aliasSource = ""; if (aliasKeys) { - aliasSource = - " || " + - aliasKeys.map(JSON.stringify).join(" === nodeType || ") + - " === nodeType"; + aliasSource = " || " + joinComparisons(aliasKeys, "nodeType"); + } + + let placeholderSource = ""; + const placeholderTypes = []; + if ( + definitions.PLACEHOLDERS.includes(type) && + has(definitions.FLIPPED_ALIAS_KEYS, type) + ) { + placeholderTypes.push(type); + } + if (has(definitions.PLACEHOLDERS_FLIPPED_ALIAS, type)) { + placeholderTypes.push(...definitions.PLACEHOLDERS_FLIPPED_ALIAS[type]); + } + if (placeholderTypes.length > 0) { + placeholderSource = + ' || nodeType === "Placeholder" && (' + + joinComparisons(placeholderTypes, "node.expectedNode") + + ")"; } return `export function is${type}(node: ?Object, opts?: Object): boolean { @@ -16,7 +39,7 @@ function addIsHelper(type, aliasKeys, deprecated) { if (!node) return false; const nodeType = node.type; - if (nodeType === ${targetType}${aliasSource}) { + if (nodeType === ${targetType}${aliasSource}${placeholderSource}) { if (typeof opts === "undefined") { return true; } else { diff --git a/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/utils/formatCode.js b/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/utils/formatCode.js deleted file mode 100644 index 1ed327bd82..0000000000 --- a/tools/node_modules/babel-eslint/node_modules/@babel/types/scripts/utils/formatCode.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -const prettier = require("prettier"); - -module.exports = function formatCode(code, filename) { - filename = filename || __filename; - const prettierConfig = prettier.resolveConfig.sync(filename); - prettierConfig.filepath = filename; - prettierConfig.parser = "babylon"; - - return prettier.format(code, prettierConfig); -}; diff --git a/tools/node_modules/babel-eslint/node_modules/globals/globals.json b/tools/node_modules/babel-eslint/node_modules/globals/globals.json index 65a4c7ec78..6f5ac02f1e 100644 --- a/tools/node_modules/babel-eslint/node_modules/globals/globals.json +++ b/tools/node_modules/babel-eslint/node_modules/globals/globals.json @@ -21,6 +21,7 @@ "Float32Array": false, "Float64Array": false, "Function": false, + "globalThis": false, "hasOwnProperty": false, "Infinity": false, "Int16Array": false, diff --git a/tools/node_modules/babel-eslint/node_modules/globals/package.json b/tools/node_modules/babel-eslint/node_modules/globals/package.json index aa91e2f18e..ae094f3054 100644 --- a/tools/node_modules/babel-eslint/node_modules/globals/package.json +++ b/tools/node_modules/babel-eslint/node_modules/globals/package.json @@ -41,7 +41,7 @@ "scripts": { "test": "xo && ava" }, - "version": "11.11.0", + "version": "11.12.0", "xo": { "ignores": [ "get-browser-globals.js" -- cgit v1.2.3