diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-05-13 23:47:07 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-06-11 15:59:19 +0200 |
commit | a121f815109178e5ea49bdb7fc914efa8b741b56 (patch) | |
tree | 295351e6964561dcf67d7fe84e1ab934eb95edfb /tools/node_modules | |
parent | cddff701f89d91c2ea4580a035b30b4f8cb81828 (diff) | |
download | android-node-v8-a121f815109178e5ea49bdb7fc914efa8b741b56.tar.gz android-node-v8-a121f815109178e5ea49bdb7fc914efa8b741b56.tar.bz2 android-node-v8-a121f815109178e5ea49bdb7fc914efa8b741b56.zip |
tools: update babel-eslint
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 <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Diffstat (limited to 'tools/node_modules')
53 files changed, 3724 insertions, 2831 deletions
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 <sebmck@gmail.com> +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,6 +3655,2464 @@ var jsx = (superClass => class extends superClass { }); +class Scope { + constructor(flags) { + this.var = []; + this.lexical = []; + this.functions = []; + this.flags = flags; + } + +} +class ScopeHandler { + constructor(raise, inModule) { + this.scopeStack = []; + this.undefinedExports = new Map(); + this.raise = raise; + this.inModule = inModule; + } + + get inFunction() { + return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0; + } + + get inGenerator() { + return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0; + } + + get inAsync() { + return (this.currentVarScope().flags & SCOPE_ASYNC) > 0; + } + + get allowSuper() { + return (this.currentThisScope().flags & SCOPE_SUPER) > 0; + } + + get allowDirectSuper() { + return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0; + } + + get inNonArrowFunction() { + return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0; + } + + get treatFunctionsAsVar() { + return this.treatFunctionsAsVarInScope(this.currentScope()); + } + + createScope(flags) { + return new Scope(flags); + } + + enter(flags) { + this.scopeStack.push(this.createScope(flags)); + } + + exit() { + this.scopeStack.pop(); + } + + treatFunctionsAsVarInScope(scope) { + return !!(scope.flags & SCOPE_FUNCTION || !this.inModule && scope.flags & SCOPE_PROGRAM); + } + + declareName(name, bindingType, pos) { + let scope = this.currentScope(); + + 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 { + scope.lexical.push(name); + } + + 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 (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); + } + } + + 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`); + } + } + + isRedeclaredInScope(scope, name, bindingType) { + if (!(bindingType & BIND_KIND_VALUE)) return false; + + if (bindingType & BIND_SCOPE_LEXICAL) { + return scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1; + } + + if (bindingType & BIND_SCOPE_FUNCTION) { + return scope.lexical.indexOf(name) > -1 || !this.treatFunctionsAsVarInScope(scope) && scope.var.indexOf(name) > -1; + } + + return scope.lexical.indexOf(name) > -1 && !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical[0] === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.indexOf(name) > -1; + } + + 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); + } + } + + 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; + } + } + } + + 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; + } + } + } + +} + +class TypeScriptScope extends Scope { + constructor(...args) { + super(...args); + this.types = []; + this.enums = []; + this.constEnums = []; + this.classes = []; + this.exportOnlyBindings = []; + } + +} + +class TypeScriptScopeHandler extends ScopeHandler { + createScope(flags) { + return new TypeScriptScope(flags); + } + + declareName(name, bindingType, pos) { + const scope = this.currentScope(); + + if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) { + this.maybeExportDefined(scope, name); + scope.exportOnlyBindings.push(name); + return; + } + + super.declareName(...arguments); + + if (bindingType & BIND_KIND_TYPE) { + if (!(bindingType & BIND_KIND_VALUE)) { + this.checkRedeclarationInScope(scope, name, bindingType, pos); + this.maybeExportDefined(scope, name); + } + + scope.types.push(name); + } + + 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; + } + + return true; + } + + 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 (bindingType & BIND_KIND_TYPE && scope.types.indexOf(name) > -1) { + return true; + } + + return super.isRedeclaredInScope(...arguments); + } + + checkLocalExport(id) { + if (this.scopeStack[0].types.indexOf(id.name) === -1 && this.scopeStack[0].exportOnlyBindings.indexOf(id.name) === -1) { + super.checkLocalExport(id); + } + } + +} + +function nonNull(x) { + if (x == null) { + throw new Error(`Unexpected ${x} value.`); + } + + return x; +} + +function assert(x) { + if (!x) { + throw new Error("Assert fail"); + } +} + +function keywordTypeFromName(value) { + switch (value) { + case "any": + return "TSAnyKeyword"; + + case "boolean": + return "TSBooleanKeyword"; + + case "bigint": + return "TSBigIntKeyword"; + + case "never": + return "TSNeverKeyword"; + + case "number": + return "TSNumberKeyword"; + + case "object": + return "TSObjectKeyword"; + + case "string": + return "TSStringKeyword"; + + case "symbol": + return "TSSymbolKeyword"; + + case "undefined": + return "TSUndefinedKeyword"; + + case "unknown": + return "TSUnknownKeyword"; + + default: + return undefined; + } +} + +var typescript = (superClass => class extends superClass { + getScopeHandler() { + return TypeScriptScopeHandler; + } + + tsIsIdentifier() { + return this.match(types.name); + } + + 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); + } + + tsParseModifier(allowedModifiers) { + if (!this.match(types.name)) { + return undefined; + } + + const modifier = this.state.value; + + if (allowedModifiers.indexOf(modifier) !== -1 && this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) { + return modifier; + } + + return undefined; + } + + tsIsListTerminator(kind) { + switch (kind) { + case "EnumMembers": + case "TypeMembers": + return this.match(types.braceR); + + case "HeritageClauseElement": + return this.match(types.braceL); + + case "TupleElementTypes": + return this.match(types.bracketR); + + case "TypeParametersOrArguments": + return this.isRelational(">"); + } + + throw new Error("Unreachable"); + } + + tsParseList(kind, parseElement) { + const result = []; + + while (!this.tsIsListTerminator(kind)) { + result.push(parseElement()); + } + + return result; + } + + tsParseDelimitedList(kind, parseElement) { + return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true)); + } + + tsTryParseDelimitedList(kind, parseElement) { + return this.tsParseDelimitedListWorker(kind, parseElement, false); + } + + tsParseDelimitedListWorker(kind, parseElement, expectSuccess) { + const result = []; + + while (true) { + if (this.tsIsListTerminator(kind)) { + break; + } + + const element = parseElement(); + + if (element == null) { + return undefined; + } + + result.push(element); + + if (this.eat(types.comma)) { + continue; + } + + if (this.tsIsListTerminator(kind)) { + break; + } + + if (expectSuccess) { + this.expect(types.comma); + } + + return undefined; + } + + return result; + } + + tsParseBracketedList(kind, parseElement, bracket, skipFirstToken) { + if (!skipFirstToken) { + if (bracket) { + this.expect(types.bracketL); + } else { + this.expectRelational("<"); + } + } + + const result = this.tsParseDelimitedList(kind, parseElement); + + if (bracket) { + this.expect(types.bracketR); + } else { + this.expectRelational(">"); + } + + return result; + } + + tsParseImportType() { + const node = this.startNode(); + this.expect(types._import); + this.expect(types.parenL); + + if (!this.match(types.string)) { + throw this.unexpected(null, "Argument in a type import must be a string literal"); + } + + node.argument = this.parseExprAtom(); + this.expect(types.parenR); + + if (this.eat(types.dot)) { + node.qualifier = this.tsParseEntityName(true); + } + + if (this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); + } + + return this.finishNode(node, "TSImportType"); + } + + tsParseEntityName(allowReservedWords) { + let entity = this.parseIdentifier(); + + while (this.eat(types.dot)) { + const node = this.startNodeAtNode(entity); + node.left = entity; + node.right = this.parseIdentifier(allowReservedWords); + entity = this.finishNode(node, "TSQualifiedName"); + } + + return entity; + } + + tsParseTypeReference() { + const node = this.startNode(); + node.typeName = this.tsParseEntityName(false); + + if (!this.hasPrecedingLineBreak() && this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); + } + + return this.finishNode(node, "TSTypeReference"); + } + + tsParseThisTypePredicate(lhs) { + this.next(); + const node = this.startNodeAtNode(lhs); + node.parameterName = lhs; + node.typeAnnotation = this.tsParseTypeAnnotation(false); + return this.finishNode(node, "TSTypePredicate"); + } + + tsParseThisTypeNode() { + const node = this.startNode(); + this.next(); + return this.finishNode(node, "TSThisType"); + } + + tsParseTypeQuery() { + const node = this.startNode(); + this.expect(types._typeof); + + if (this.match(types._import)) { + node.exprName = this.tsParseImportType(); + } else { + node.exprName = this.tsParseEntityName(true); + } + + return this.finishNode(node, "TSTypeQuery"); + } + + 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"); + } + + tsTryParseTypeParameters() { + if (this.isRelational("<")) { + return this.tsParseTypeParameters(); + } + } + + tsParseTypeParameters() { + const node = this.startNode(); + + if (this.isRelational("<") || this.match(types.jsxTagStart)) { + this.next(); + } else { + this.unexpected(); + } + + node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true); + return this.finishNode(node, "TSTypeParameterDeclaration"); + } + + tsTryNextParseConstantContext() { + if (this.lookahead().type === types._const) { + this.next(); + return this.tsParseTypeReference(); + } + + return null; + } + + tsFillSignature(returnToken, signature) { + const returnTokenRequired = returnToken === types.arrow; + signature.typeParameters = this.tsTryParseTypeParameters(); + this.expect(types.parenL); + signature.parameters = this.tsParseBindingListForSignature(); + + if (returnTokenRequired) { + signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); + } else if (this.match(returnToken)) { + signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); + } + } + + 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; + }); + } + + tsParseTypeMemberSemicolon() { + if (!this.eat(types.comma)) { + this.semicolon(); + } + } + + tsParseSignatureMember(kind, node) { + this.tsFillSignature(types.colon, node); + this.tsParseTypeMemberSemicolon(); + return this.finishNode(node, kind); + } + + tsIsUnambiguouslyIndexSignature() { + this.next(); + return this.eat(types.name) && this.match(types.colon); + } + + tsTryParseIndexSignature(node) { + if (!(this.match(types.bracketL) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) { + return undefined; + } + + 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"); + } + + tsParsePropertyOrMethodSignature(node, readonly) { + if (this.eat(types.question)) node.optional = true; + const nodeAny = node; + + if (!readonly && (this.match(types.parenL) || this.isRelational("<"))) { + const method = nodeAny; + this.tsFillSignature(types.colon, method); + this.tsParseTypeMemberSemicolon(); + return this.finishNode(method, "TSMethodSignature"); + } 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"); + } + } + + tsParseTypeMember() { + const node = this.startNode(); + + if (this.match(types.parenL) || this.isRelational("<")) { + return this.tsParseSignatureMember("TSCallSignatureDeclaration", node); + } + + if (this.match(types._new)) { + const id = this.startNode(); + this.next(); + + if (this.match(types.parenL) || this.isRelational("<")) { + return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node); + } else { + node.key = this.createIdentifier(id, "new"); + return this.tsParsePropertyOrMethodSignature(node, false); + } + } + + const readonly = !!this.tsParseModifier(["readonly"]); + const idx = this.tsTryParseIndexSignature(node); + + if (idx) { + if (readonly) node.readonly = true; + return idx; + } + + this.parsePropertyName(node); + return this.tsParsePropertyOrMethodSignature(node, readonly); + } + + tsParseTypeLiteral() { + const node = this.startNode(); + node.members = this.tsParseObjectTypeMembers(); + return this.finishNode(node, "TSTypeLiteral"); + } + + tsParseObjectTypeMembers() { + this.expect(types.braceL); + const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this)); + this.expect(types.braceR); + return members; + } + + tsIsStartOfMappedType() { + this.next(); + + if (this.eat(types.plusMin)) { + return this.isContextual("readonly"); + } + + if (this.isContextual("readonly")) { + this.next(); + } + + if (!this.match(types.bracketL)) { + return false; + } + + this.next(); + + if (!this.tsIsIdentifier()) { + return false; + } + + this.next(); + return this.match(types._in); + } + + tsParseMappedTypeParameter() { + const node = this.startNode(); + node.name = this.parseIdentifierName(node.start); + node.constraint = this.tsExpectThenParseType(types._in); + return this.finishNode(node, "TSTypeParameter"); + } + + tsParseMappedType() { + const node = this.startNode(); + this.expect(types.braceL); + + if (this.match(types.plusMin)) { + node.readonly = this.state.value; + this.next(); + this.expectContextual("readonly"); + } else if (this.eatContextual("readonly")) { + node.readonly = true; + } + + this.expect(types.bracketL); + node.typeParameter = this.tsParseMappedTypeParameter(); + this.expect(types.bracketR); + + 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; + } + + node.typeAnnotation = this.tsTryParseType(); + this.semicolon(); + this.expect(types.braceR); + return this.finishNode(node, "TSMappedType"); + } + + 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"); + } + + tsParseTupleElementType() { + if (this.match(types.ellipsis)) { + const restNode = this.startNode(); + this.next(); + restNode.typeAnnotation = this.tsParseType(); + this.checkCommaAfterRest(); + return this.finishNode(restNode, "TSRestType"); + } + + const type = this.tsParseType(); + + if (this.eat(types.question)) { + const optionalTypeNode = this.startNodeAtNode(type); + optionalTypeNode.typeAnnotation = type; + return this.finishNode(optionalTypeNode, "TSOptionalType"); + } + + return type; + } + + tsParseParenthesizedType() { + const node = this.startNode(); + this.expect(types.parenL); + node.typeAnnotation = this.tsParseType(); + this.expect(types.parenR); + return this.finishNode(node, "TSParenthesizedType"); + } + + tsParseFunctionOrConstructorType(type) { + const node = this.startNode(); + + if (type === "TSConstructorType") { + this.expect(types._new); + } + + this.tsFillSignature(types.arrow, node); + return this.finishNode(node, type); + } + + tsParseLiteralTypeNode() { + const node = this.startNode(); + + node.literal = (() => { + switch (this.state.type) { + case types.num: + case types.string: + case types._true: + case types._false: + return this.parseExprAtom(); + + default: + throw this.unexpected(); + } + })(); + + return this.finishNode(node, "TSLiteralType"); + } + + tsParseTemplateLiteralType() { + const node = this.startNode(); + const templateNode = this.parseTemplate(false); + + if (templateNode.expressions.length > 0) { + throw this.raise(templateNode.expressions[0].start, "Template literal types cannot have any substitution"); + } + + node.literal = templateNode; + return this.finishNode(node, "TSLiteralType"); + } + + 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 (type !== undefined && this.lookahead().type !== types.dot) { + const node = this.startNode(); + this.next(); + return this.finishNode(node, type); + } + + return this.tsParseTypeReference(); + } + + case types.string: + case types.num: + case types._true: + case types._false: + return this.tsParseLiteralTypeNode(); + + case types.plusMin: + if (this.state.value === "-") { + const node = this.startNode(); + + if (this.lookahead().type !== types.num) { + throw this.unexpected(); + } + + node.literal = this.parseMaybeUnary(); + return this.finishNode(node, "TSLiteralType"); + } + + break; + + case types._this: + { + const thisKeyword = this.tsParseThisTypeNode(); + + if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { + return this.tsParseThisTypePredicate(thisKeyword); + } else { + return thisKeyword; + } + } + + case types._typeof: + return this.tsParseTypeQuery(); + + case types._import: + return this.tsParseImportType(); + + case types.braceL: + return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral(); + + case types.bracketL: + return this.tsParseTupleType(); + + case types.parenL: + return this.tsParseParenthesizedType(); + + case types.backQuote: + return this.tsParseTemplateLiteralType(); + } + + throw this.unexpected(); + } + + tsParseArrayTypeOrHigher() { + let type = this.tsParseNonArrayType(); + + 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"); + } + } + + return type; + } + + tsParseTypeOperator(operator) { + const node = this.startNode(); + this.expectContextual(operator); + node.operator = operator; + node.typeAnnotation = this.tsParseTypeOperatorOrHigher(); + + if (operator === "readonly") { + this.tsCheckTypeAnnotationForReadOnly(node); + } + + return this.finishNode(node, "TSTypeOperator"); + } + + tsCheckTypeAnnotationForReadOnly(node) { + switch (node.typeAnnotation.type) { + case "TSTupleType": + case "TSArrayType": + return; + + default: + this.raise(node.start, "'readonly' type modifier is only permitted on array and tuple literal types."); + } + } + + 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"); + } + + tsParseTypeOperatorOrHigher() { + const operator = ["keyof", "unique", "readonly"].find(kw => this.isContextual(kw)); + return operator ? this.tsParseTypeOperator(operator) : this.isContextual("infer") ? this.tsParseInferType() : this.tsParseArrayTypeOrHigher(); + } + + tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) { + this.eat(operator); + let type = parseConstituentType(); + + if (this.match(operator)) { + const types = [type]; + + while (this.eat(operator)) { + types.push(parseConstituentType()); + } + + const node = this.startNodeAtNode(type); + node.types = types; + type = this.finishNode(node, kind); + } + + return type; + } + + tsParseIntersectionTypeOrHigher() { + return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), types.bitwiseAND); + } + + tsParseUnionTypeOrHigher() { + return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), types.bitwiseOR); + } + + tsIsStartOfFunctionType() { + if (this.isRelational("<")) { + return true; + } + + return this.match(types.parenL) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this)); + } + + tsSkipParameterStart() { + if (this.match(types.name) || this.match(types._this)) { + this.next(); + return true; + } + + if (this.match(types.braceL)) { + let braceStackCounter = 1; + this.next(); + + while (braceStackCounter > 0) { + if (this.match(types.braceL)) { + ++braceStackCounter; + } else if (this.match(types.braceR)) { + --braceStackCounter; + } + + this.next(); + } + + 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 true; + } + + return false; + } + + tsIsUnambiguouslyStartOfFunctionType() { + this.next(); + + if (this.match(types.parenR) || this.match(types.ellipsis)) { + return true; + } + + if (this.tsSkipParameterStart()) { + if (this.match(types.colon) || this.match(types.comma) || this.match(types.question) || this.match(types.eq)) { + return true; + } + + if (this.match(types.parenR)) { + this.next(); + + if (this.match(types.arrow)) { + return true; + } + } + } + + return false; + } + + tsParseTypeOrTypePredicateAnnotation(returnToken) { + return this.tsInType(() => { + const t = this.startNode(); + this.expect(returnToken); + const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); + + 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"); + }); + } + + tsTryParseTypeOrTypePredicateAnnotation() { + return this.match(types.colon) ? this.tsParseTypeOrTypePredicateAnnotation(types.colon) : undefined; + } + + tsTryParseTypeAnnotation() { + return this.match(types.colon) ? this.tsParseTypeAnnotation() : undefined; + } + + tsTryParseType() { + return this.tsEatThenParseType(types.colon); + } + + tsParseTypePredicatePrefix() { + const id = this.parseIdentifier(); + + if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { + this.next(); + return id; + } + } + + tsParseTypeAnnotation(eatColon = true, t = this.startNode()) { + this.tsInType(() => { + if (eatColon) this.expect(types.colon); + t.typeAnnotation = this.tsParseType(); + }); + return this.finishNode(t, "TSTypeAnnotation"); + } + + tsParseType() { + assert(this.state.inType); + const type = this.tsParseNonConditionalType(); + + if (this.hasPrecedingLineBreak() || !this.eat(types._extends)) { + return type; + } + + 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"); + } + + tsParseNonConditionalType() { + if (this.tsIsStartOfFunctionType()) { + return this.tsParseFunctionOrConstructorType("TSFunctionType"); + } + + if (this.match(types._new)) { + return this.tsParseFunctionOrConstructorType("TSConstructorType"); + } + + return this.tsParseUnionTypeOrHigher(); + } + + tsParseTypeAssertion() { + const node = this.startNode(); + + const _const = this.tsTryNextParseConstantContext(); + + node.typeAnnotation = _const || this.tsNextThenParseType(); + 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)); + + if (!delimitedList.length) { + this.raise(originalStart, `'${descriptor}' list cannot be empty.`); + } + + return delimitedList; + } + + tsParseExpressionWithTypeArguments() { + const node = this.startNode(); + node.expression = this.tsParseEntityName(false); + + if (this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); + } + + return this.finishNode(node, "TSExpressionWithTypeArguments"); + } + + tsParseInterfaceDeclaration(node) { + node.id = this.parseIdentifier(); + this.checkLVal(node.id, BIND_TS_INTERFACE, undefined, "typescript interface declaration"); + node.typeParameters = this.tsTryParseTypeParameters(); + + if (this.eat(types._extends)) { + node.extends = this.tsParseHeritageClause("extends"); + } + + 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(); + 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"); + } + + tsInNoContext(cb) { + const oldContext = this.state.context; + this.state.context = [oldContext[0]]; + + try { + return cb(); + } finally { + this.state.context = oldContext; + } + } + + tsInType(cb) { + const oldInType = this.state.inType; + this.state.inType = true; + + try { + return cb(); + } finally { + this.state.inType = oldInType; + } + } + + tsEatThenParseType(token) { + return !this.match(token) ? undefined : this.tsNextThenParseType(); + } + + tsExpectThenParseType(token) { + return this.tsDoThenParseType(() => this.expect(token)); + } + + tsNextThenParseType() { + return this.tsDoThenParseType(() => this.next()); + } + + tsDoThenParseType(cb) { + return this.tsInType(() => { + cb(); + return this.tsParseType(); + }); + } + + tsParseEnumMember() { + const node = this.startNode(); + node.id = this.match(types.string) ? this.parseExprAtom() : this.parseIdentifier(true); + + if (this.eat(types.eq)) { + node.initializer = this.parseMaybeAssign(); + } + + return this.finishNode(node, "TSEnumMember"); + } + + 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"); + } + + 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"); + } + + tsParseModuleOrNamespaceDeclaration(node, nested = false) { + node.id = this.parseIdentifier(); + + if (!nested) { + this.checkLVal(node.id, BIND_TS_NAMESPACE, null, "module or namespace declaration"); + } + + if (this.eat(types.dot)) { + const inner = this.startNode(); + this.tsParseModuleOrNamespaceDeclaration(inner, true); + node.body = inner; + } else { + node.body = this.tsParseModuleBlock(); + } + + return this.finishNode(node, "TSModuleDeclaration"); + } + + 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 (this.match(types.braceL)) { + node.body = this.tsParseModuleBlock(); + } else { + 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"); + } + + tsIsExternalModuleReference() { + return this.isContextual("require") && this.lookahead().type === types.parenL; + } + + tsParseModuleReference() { + return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false); + } + + tsParseExternalModuleReference() { + const node = this.startNode(); + this.expectContextual("require"); + this.expect(types.parenL); + + if (!this.match(types.string)) { + throw this.unexpected(); + } + + node.expression = this.parseExprAtom(); + 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(); + + try { + return f(); + } catch (e) { + if (e instanceof SyntaxError) { + this.state = state; + return undefined; + } + + throw e; + } + } + + tsTryParse(f) { + const state = this.state.clone(); + const result = f(); + + if (result !== undefined && result !== false) { + return result; + } else { + this.state = state; + return undefined; + } + } + + nodeWithSamePosition(original, type) { + const node = this.startNodeAtNode(original); + node.type = type; + node.end = original.end; + node.loc.end = original.loc.end; + + if (original.leadingComments) { + node.leadingComments = original.leadingComments; + } + + if (original.trailingComments) { + node.trailingComments = original.trailingComments; + } + + if (original.innerComments) node.innerComments = original.innerComments; + return node; + } + + tsTryParseDeclare(nany) { + if (this.isLineTerminator()) { + return; + } + + let starttype = this.state.type; + let kind; + + if (this.isContextual("let")) { + starttype = types._var; + kind = "let"; + } + + switch (starttype) { + case types._function: + return this.parseFunctionStatement(nany, false, true); + + case types._class: + return this.parseClass(nany, true, false); + + case types._const: + if (this.match(types._const) && this.isLookaheadContextual("enum")) { + this.expect(types._const); + this.expectContextual("enum"); + return this.tsParseEnumDeclaration(nany, true); + } + + case types._var: + kind = kind || this.state.value; + return this.parseVarStatement(nany, kind); + + case types.name: + { + const value = this.state.value; + + if (value === "global") { + return this.tsParseAmbientExternalModuleDeclaration(nany); + } else { + return this.tsParseDeclaration(nany, value, true); + } + } + } + } + + tsTryParseExportDeclaration() { + return this.tsParseDeclaration(this.startNode(), this.state.value, true); + } + + tsParseExpressionStatement(node, expr) { + switch (expr.name) { + case "declare": + { + const declaration = this.tsTryParseDeclare(node); + + if (declaration) { + declaration.declare = true; + return declaration; + } + + break; + } + + 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"); + } + + break; + + default: + return this.tsParseDeclaration(node, expr.name, false); + } + } + + tsParseDeclaration(node, value, next) { + switch (value) { + case "abstract": + if (this.tsCheckLineTerminatorAndMatch(types._class, next)) { + const cls = node; + cls.abstract = true; + + if (next) { + this.next(); + + if (!this.match(types._class)) { + this.unexpected(null, types._class); + } + } + + return this.parseClass(cls, true, false); + } + + break; + + case "enum": + if (next || this.match(types.name)) { + if (next) this.next(); + return this.tsParseEnumDeclaration(node, false); + } + + break; + + case "interface": + if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + if (next) this.next(); + return this.tsParseInterfaceDeclaration(node); + } + + break; + + case "module": + if (next) this.next(); + + if (this.match(types.string)) { + return this.tsParseAmbientExternalModuleDeclaration(node); + } else if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + return this.tsParseModuleOrNamespaceDeclaration(node); + } + + break; + + case "namespace": + if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + if (next) this.next(); + return this.tsParseModuleOrNamespaceDeclaration(node); + } + + break; + + case "type": + if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { + if (next) this.next(); + return this.tsParseTypeAliasDeclaration(node); + } + + break; + } + } + + tsCheckLineTerminatorAndMatch(tokenType, next) { + return (next || this.match(tokenType)) && !this.isLineTerminator(); + } + + tsTryParseGenericAsyncArrowFunction(startPos, startLoc) { + if (!this.isRelational("<")) { + return undefined; + } + + 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 (!res) { + return undefined; + } + + return this.parseArrowExpression(res, null, true); + } + + 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"); + } + + 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 false; + } + + isExportDefaultSpecifier() { + if (this.tsIsDeclarationStart()) return false; + return super.isExportDefaultSpecifier(); + } + + parseAssignableListItem(allowModifiers, decorators) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + let accessibility; + let readonly = false; + + if (allowModifiers) { + accessibility = this.parseAccessModifier(); + readonly = !!this.tsParseModifier(["readonly"]); + } + + const left = this.parseMaybeDefault(); + this.parseAssignableListItemTypes(left); + const elt = this.parseMaybeDefault(left.start, left.loc.start, left); + + if (accessibility || readonly) { + const pp = this.startNodeAt(startPos, startLoc); + + if (decorators.length) { + pp.decorators = decorators; + } + + if (accessibility) pp.accessibility = accessibility; + if (readonly) pp.readonly = readonly; + + if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { + throw this.raise(pp.start, "A parameter property may not be declared using a binding pattern."); + } + + pp.parameter = elt; + return this.finishNode(pp, "TSParameterProperty"); + } + + if (decorators.length) { + left.decorators = decorators; + } + + return elt; + } + + 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); + } + + checkFunctionStatementId(node) { + if (!node.body && node.id) { + this.checkLVal(node.id, BIND_TS_FN_TYPE, null, "function name"); + } else { + super.checkFunctionStatementId(...arguments); + } + } + + 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 (this.isRelational("<")) { + const result = this.tsTryParseAndCatch(() => { + if (!noCalls && this.atPossibleAsync(base)) { + const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc); + + if (asyncArrowFn) { + return asyncArrowFn; + } + } + + const node = this.startNodeAt(startPos, startLoc); + node.callee = base; + const typeArguments = this.tsParseTypeArguments(); + + 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.unexpected(); + }); + if (result) return result; + } + + return super.parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow); + } + + parseNewArguments(node) { + if (this.isRelational("<")) { + const typeParameters = this.tsTryParseAndCatch(() => { + const args = this.tsParseTypeArguments(); + if (!this.match(types.parenL)) this.unexpected(); + return args; + }); + + if (typeParameters) { + node.typeParameters = typeParameters; + } + } + + super.parseNewArguments(node); + } + + 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 { + node.typeAnnotation = this.tsNextThenParseType(); + } + + this.finishNode(node, "TSAsExpression"); + return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); + } + + return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn); + } + + checkReservedWord(word, startLoc, checkKeywords, isBinding) {} + + checkDuplicateExports() {} + + parseImport(node) { + if (this.match(types.name) && this.lookahead().type === types.eq) { + return this.tsParseImportEqualsDeclaration(node); + } + + return super.parseImport(node); + } + + 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); + } + } + + isAbstractClass() { + return this.isContextual("abstract") && this.lookahead().type === types._class; + } + + parseExportDefaultExpression() { + if (this.isAbstractClass()) { + const cls = this.startNode(); + this.next(); + this.parseClass(cls, true, true); + cls.abstract = true; + return cls; + } + + if (this.state.value === "interface") { + const result = this.tsParseDeclaration(this.startNode(), this.state.value, true); + if (result) return result; + } + + return super.parseExportDefaultExpression(); + } + + parseStatementContent(context, topLevel) { + if (this.state.type === types._const) { + const ahead = this.lookahead(); + + if (ahead.type === types.name && ahead.value === "enum") { + const node = this.startNode(); + this.expect(types._const); + this.expectContextual("enum"); + return this.tsParseEnumDeclaration(node, true); + } + } + + return super.parseStatementContent(context, topLevel); + } + + parseAccessModifier() { + return this.tsParseModifier(["public", "protected", "private"]); + } + + parseClassMember(classBody, member, state, constructorAllowsSuper) { + const accessibility = this.parseAccessModifier(); + if (accessibility) member.accessibility = accessibility; + super.parseClassMember(classBody, member, state, constructorAllowsSuper); + } + + 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"]); + + switch (mod) { + case "readonly": + readonly = true; + abstract = !!this.tsParseModifier(["abstract"]); + break; + + case "abstract": + abstract = true; + readonly = !!this.tsParseModifier(["readonly"]); + break; + } + + if (abstract) methodOrProp.abstract = true; + if (readonly) propOrIdx.readonly = true; + + if (!abstract && !isStatic && !methodOrProp.accessibility) { + const idx = this.tsTryParseIndexSignature(member); + + if (idx) { + classBody.body.push(idx); + return; + } + } + + if (readonly) { + methodOrProp.static = isStatic; + this.parseClassPropertyName(prop); + this.parsePostMemberNameModifiers(methodOrProp); + this.pushClassProperty(classBody, prop); + return; + } + + super.parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper); + } + + parsePostMemberNameModifiers(methodOrProp) { + const optional = this.eat(types.question); + if (optional) methodOrProp.optional = true; + } + + parseExpressionStatement(node, expr) { + const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined; + return decl || super.parseExpressionStatement(node, expr); + } + + shouldParseExportDeclaration() { + if (this.tsIsDeclarationStart()) return true; + return super.shouldParseExportDeclaration(); + } + + parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) { + if (!refNeedsArrowPos || !this.match(types.question)) { + return super.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos); + } + + const state = this.state.clone(); + + try { + return super.parseConditional(expr, noIn, startPos, startLoc); + } catch (err) { + if (!(err instanceof SyntaxError)) { + throw err; + } + + this.state = state; + refNeedsArrowPos.start = err.pos || this.state.start; + return expr; + } + } + + parseParenItem(node, startPos, startLoc) { + node = super.parseParenItem(node, startPos, startLoc); + + if (this.eat(types.question)) { + node.optional = true; + this.resetEndLocation(node); + } + + 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; + } + + parseExportDeclaration(node) { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + const isDeclare = this.eatContextual("declare"); + let declaration; + + if (this.match(types.name)) { + declaration = this.tsTryParseExportDeclaration(); + } + + if (!declaration) { + declaration = super.parseExportDeclaration(node); + } + + if (declaration && isDeclare) { + this.resetStartLocation(declaration, startPos, startLoc); + declaration.declare = true; + } + + return declaration; + } + + parseClassId(node, isStatement, optionalId) { + if ((!isStatement || optionalId) && this.isContextual("implements")) { + return; + } + + super.parseClassId(...arguments); + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) node.typeParameters = typeParameters; + } + + parseClassProperty(node) { + if (!node.optional && this.eat(types.bang)) { + node.definite = true; + } + + const type = this.tsTryParseTypeAnnotation(); + if (type) node.typeAnnotation = type; + return super.parseClassProperty(node); + } + + pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) method.typeParameters = typeParameters; + super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper); + } + + pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) method.typeParameters = typeParameters; + super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); + } + + parseClassSuper(node) { + super.parseClassSuper(node); + + if (node.superClass && this.isRelational("<")) { + node.superTypeParameters = this.tsParseTypeArguments(); + } + + if (this.eatContextual("implements")) { + node.implements = this.tsParseHeritageClause("implements"); + } + } + + parseObjPropValue(prop, ...args) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) prop.typeParameters = typeParameters; + super.parseObjPropValue(prop, ...args); + } + + parseFunctionParams(node, allowModifiers) { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) node.typeParameters = typeParameters; + super.parseFunctionParams(node, allowModifiers); + } + + parseVarId(decl, kind) { + super.parseVarId(decl, kind); + + if (decl.id.type === "Identifier" && this.eat(types.bang)) { + decl.definite = true; + } + + const type = this.tsTryParseTypeAnnotation(); + + if (type) { + decl.id.typeAnnotation = type; + this.resetEndLocation(decl.id); + } + } + + parseAsyncArrowFromCallExpression(node, call) { + if (this.match(types.colon)) { + node.returnType = this.tsParseTypeAnnotation(); + } + + return super.parseAsyncArrowFromCallExpression(node, call); + } + + 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(); + + try { + return super.parseMaybeAssign(...args); + } catch (err) { + if (!(err instanceof SyntaxError)) { + throw err; + } + + 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); + } + + let arrowExpression; + let typeParameters; + const state = this.state.clone(); + + try { + typeParameters = this.tsParseTypeParameters(); + arrowExpression = super.parseMaybeAssign(...args); + + if (arrowExpression.type !== "ArrowFunctionExpression" || arrowExpression.extra && arrowExpression.extra.parenthesized) { + this.unexpected(); + } + } catch (err) { + if (!(err instanceof SyntaxError)) { + throw err; + } + + if (jsxError) { + throw jsxError; + } + + assert(!this.hasPlugin("jsx")); + this.state = state; + return super.parseMaybeAssign(...args); + } + + if (typeParameters && typeParameters.params.length !== 0) { + this.resetStartLocationFromNode(arrowExpression, typeParameters); + } + + arrowExpression.typeParameters = typeParameters; + return arrowExpression; + } + + parseMaybeUnary(refShorthandDefaultPos) { + if (!this.hasPlugin("jsx") && this.isRelational("<")) { + return this.tsParseTypeAssertion(); + } else { + return super.parseMaybeUnary(refShorthandDefaultPos); + } + } + + parseArrow(node) { + if (this.match(types.colon)) { + const state = this.state.clone(); + + try { + const returnType = this.tsParseTypeOrTypePredicateAnnotation(types.colon); + + 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 super.parseArrow(node); + } + + 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; + this.resetEndLocation(param); + return param; + } + + toAssignable(node, isBinding, contextDescription) { + switch (node.type) { + case "TSTypeCastExpression": + return super.toAssignable(this.typeCastToParameter(node), isBinding, contextDescription); + + case "TSParameterProperty": + return super.toAssignable(node, isBinding, contextDescription); + + case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": + node.expression = this.toAssignable(node.expression, isBinding, contextDescription); + return node; + + default: + return super.toAssignable(node, isBinding, contextDescription); + } + } + + checkLVal(expr, bindingType = BIND_NONE, checkClashes, contextDescription) { + switch (expr.type) { + case "TSTypeCastExpression": + return; + + case "TSParameterProperty": + this.checkLVal(expr.parameter, bindingType, checkClashes, "parameter property"); + return; + + case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": + this.checkLVal(expr.expression, bindingType, checkClashes, contextDescription); + return; + + default: + super.checkLVal(expr, bindingType, checkClashes, contextDescription); + return; + } + } + + parseBindingAtom() { + switch (this.state.type) { + case types._this: + return this.parseIdentifier(true); + + default: + return super.parseBindingAtom(); + } + } + + parseMaybeDecoratorArguments(expr) { + if (this.isRelational("<")) { + const typeArguments = this.tsParseTypeArguments(); + + if (this.match(types.parenL)) { + const call = super.parseMaybeDecoratorArguments(expr); + call.typeParameters = typeArguments; + return call; + } + + this.unexpected(this.state.start, types.parenL); + } + + return super.parseMaybeDecoratorArguments(expr); + } + + isClassMethod() { + return this.isRelational("<") || super.isClassMethod(); + } + + isClassProperty() { + return this.match(types.bang) || this.match(types.colon) || super.isClassProperty(); + } + + parseMaybeDefault(...args) { + const node = super.parseMaybeDefault(...args); + + 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`"); + } + + return node; + } + + getTokenFromCode(code) { + if (this.state.inType && (code === 62 || code === 60)) { + return this.finishOp(types.relational, 1); + } else { + return super.getTokenFromCode(code); + } + } + + toAssignableList(exprList, isBinding, contextDescription) { + for (let i = 0; i < exprList.length; i++) { + const expr = exprList[i]; + if (!expr) continue; + + switch (expr.type) { + case "TSTypeCastExpression": + exprList[i] = this.typeCastToParameter(expr); + break; + + case "TSAsExpression": + case "TSTypeAssertion": + this.raise(expr.start, "Unexpected type cast in parameter position."); + break; + } + } + + return super.toAssignableList(exprList, isBinding, contextDescription); + } + + typeCastToParameter(node) { + node.expression.typeAnnotation = node.typeAnnotation; + this.resetEndLocation(node.expression, node.typeAnnotation.end, node.typeAnnotation.loc.end); + return node.expression; + } + + 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."); + } + } + + return exprList; + } + + shouldParseArrow() { + return this.match(types.colon) || super.shouldParseArrow(); + } + + shouldParseAsyncArrow() { + return this.match(types.colon) || super.shouldParseAsyncArrow(); + } + + canHaveLeadingDecorator() { + return super.canHaveLeadingDecorator() || this.isAbstractClass(); + } + + jsxParseOpeningElementAfterName(node) { + if (this.isRelational("<")) { + const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArguments()); + if (typeArguments) node.typeParameters = typeArguments; + } + + return super.jsxParseOpeningElementAfterName(node); + } + + 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; + } + +}); + +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); + } + } + + finishPlaceholder(node, expectedNode) { + const isFinished = !!(node.expectedNode && node.type === "Placeholder"); + node.expectedNode = expectedNode; + return isFinished ? node : this.finishNode(node, "Placeholder"); + } + + getTokenFromCode(code) { + if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) { + return this.finishOp(types.placeholder, 2); + } + + return super.getTokenFromCode(...arguments); + } + + parseExprAtom() { + return this.parsePlaceholder("Expression") || super.parseExprAtom(...arguments); + } + + parseIdentifier() { + return this.parsePlaceholder("Identifier") || super.parseIdentifier(...arguments); + } + + checkReservedWord(word) { + if (word !== undefined) super.checkReservedWord(...arguments); + } + + parseBindingAtom() { + return this.parsePlaceholder("Pattern") || super.parseBindingAtom(...arguments); + } + + checkLVal(expr) { + if (expr.type !== "Placeholder") super.checkLVal(...arguments); + } + + toAssignable(node) { + if (node && node.type === "Placeholder" && node.expectedNode === "Expression") { + node.expectedNode = "Pattern"; + return node; + } + + return super.toAssignable(...arguments); + } + + verifyBreakContinue(node) { + if (node.label && node.label.type === "Placeholder") return; + super.verifyBreakContinue(...arguments); + } + + parseExpressionStatement(node, expr) { + if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) { + return super.parseExpressionStatement(...arguments); + } + + 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"); + } + + parseBlock() { + return this.parsePlaceholder("BlockStatement") || super.parseBlock(...arguments); + } + + parseFunctionId() { + return this.parsePlaceholder("Identifier") || super.parseFunctionId(...arguments); + } + + parseClass(node, isStatement, optionalId) { + const type = isStatement ? "ClassDeclaration" : "ClassExpression"; + this.next(); + this.takeDecorators(node); + const placeholder = this.parsePlaceholder("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"); + } + } else { + this.parseClassId(node, isStatement, optionalId); + } + + this.parseClassSuper(node); + node.body = this.parsePlaceholder("ClassBody") || this.parseClassBody(!!node.superClass); + return this.finishNode(node, type); + } + + parseExport(node) { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseExport(...arguments); + + if (!this.isContextual("from") && !this.match(types.comma)) { + node.specifiers = []; + node.source = null; + node.declaration = this.finishPlaceholder(placeholder, "Declaration"); + return this.finishNode(node, "ExportNamedDeclaration"); + } + + this.expectPlugin("exportDefaultFrom"); + const specifier = this.startNode(); + specifier.exported = placeholder; + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + return super.parseExport(node); + } + + maybeParseExportDefaultSpecifier(node) { + if (node.specifiers && node.specifiers.length > 0) { + return true; + } + + return super.maybeParseExportDefaultSpecifier(...arguments); + } + + checkExport(node) { + const { + specifiers + } = node; + + if (specifiers && specifiers.length) { + node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder"); + } + + super.checkExport(node); + node.specifiers = specifiers; + } + + parseImport(node) { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseImport(...arguments); + node.specifiers = []; + + if (!this.isContextual("from") && !this.match(types.comma)) { + node.source = this.finishPlaceholder(placeholder, "StringLiteral"); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); + } + + const specifier = this.startNodeAtNode(placeholder); + specifier.local = placeholder; + this.finishNode(specifier, "ImportDefaultSpecifier"); + node.specifiers.push(specifier); + + if (this.eat(types.comma)) { + const hasStarImport = this.maybeParseStarImportSpecifier(node); + if (!hasStarImport) this.parseNamedImportSpecifiers(node); + } + + this.expectContextual("from"); + node.source = this.parseImportSource(); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); + } + + parseImportSource() { + return this.parsePlaceholder("StringLiteral") || super.parseImportSource(...arguments); + } + +}); + +function hasPlugin(plugins, name) { + return plugins.some(plugin => { + if (Array.isArray(plugin)) { + return plugin[0] === name; + } else { + return plugin === name; + } + }); +} +function getPluginOption(plugins, name, option) { + const plugin = plugins.find(plugin => { + if (Array.isArray(plugin)) { + return plugin[0] === name; + } else { + return plugin === name; + } + }); + + if (plugin && Array.isArray(plugin)) { + return plugin[1][option]; + } + + 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"); + + 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 (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) { + throw new Error("Cannot combine flow and typescript plugins."); + } + + 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); + const defaultOptions = { sourceType: "script", sourceFilename: undefined, @@ -3619,12 +6124,14 @@ const defaultOptions = { plugins: [], strictMode: null, ranges: false, - tokens: false + tokens: false, + createParenthesizedExpressions: false }; function getOptions(opts) { const options = {}; - for (const key in defaultOptions) { + 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]; } @@ -3822,11 +6329,17 @@ class CommentsParser extends BaseParser { } 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; + } + raise(pos, message, { missingPluginNames, code } = {}) { - const loc = getLineInfo(this.state.input, pos); + const loc = this.getLocationForPosition(pos); message += ` (${loc.line}:${loc.column})`; const err = new SyntaxError(message); err.pos = pos; @@ -3851,12 +6364,8 @@ class State { 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; @@ -3898,10 +6407,8 @@ class State { this.invalidTemplateEscapePosition = null; } - init(options, input) { + init(options) { 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(); } @@ -3918,7 +6425,7 @@ class State { const key = keys[i]; let val = this[key]; - if ((!skipArrays || key === "context") && Array.isArray(val)) { + if (!skipArrays && Array.isArray(val)) { val = val.slice(); } @@ -3933,7 +6440,6 @@ class State { 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], @@ -3958,7 +6464,9 @@ class Tokenizer extends LocationParser { constructor(options, input) { super(); this.state = new State(); - this.state.init(options, input); + this.state.init(options); + this.input = input; + this.length = input.length; this.isLookahead = false; } @@ -4004,7 +6512,7 @@ class Tokenizer extends LocationParser { this.state.pos = this.state.start; while (this.state.pos < this.state.lineStart) { - this.state.lineStart = this.state.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; + this.state.lineStart = this.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; --this.state.curLine; } @@ -4023,7 +6531,7 @@ class Tokenizer extends LocationParser { this.state.start = this.state.pos; this.state.startLoc = this.state.curPosition(); - if (this.state.pos >= this.state.length) { + if (this.state.pos >= this.length) { this.finishToken(types.eof); return; } @@ -4031,7 +6539,7 @@ class Tokenizer extends LocationParser { if (curContext.override) { curContext.override(this); } else { - this.getTokenFromCode(this.state.input.codePointAt(this.state.pos)); + this.getTokenFromCode(this.input.codePointAt(this.state.pos)); } } @@ -4043,48 +6551,47 @@ class Tokenizer extends LocationParser { end: end, loc: new SourceLocation(startLoc, endLoc) }; - - if (!this.isLookahead) { - if (this.options.tokens) this.state.tokens.push(comment); - this.state.comments.push(comment); - this.addComment(comment); - } + if (this.options.tokens) this.state.tokens.push(comment); + this.state.comments.push(comment); + this.addComment(comment); } skipBlockComment() { const startLoc = this.state.curPosition(); const start = this.state.pos; - 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 + 2; lineBreakG.lastIndex = start; let match; - while ((match = lineBreakG.exec(this.state.input)) && match.index < this.state.pos) { + while ((match = lineBreakG.exec(this.input)) && match.index < this.state.pos) { ++this.state.curLine; this.state.lineStart = match.index + match[0].length; } - this.pushComment(true, this.state.input.slice(start + 2, end), start, this.state.pos, startLoc, this.state.curPosition()); + 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.state.input.charCodeAt(this.state.pos += startSkip); + let ch = this.input.charCodeAt(this.state.pos += startSkip); - 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); + 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); } } - this.pushComment(false, this.state.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition()); + if (this.isLookahead) return; + this.pushComment(false, this.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition()); } skipSpace() { - loop: while (this.state.pos < this.state.length) { - const ch = this.state.input.charCodeAt(this.state.pos); + loop: while (this.state.pos < this.length) { + const ch = this.input.charCodeAt(this.state.pos); switch (ch) { case 32: @@ -4094,7 +6601,7 @@ class Tokenizer extends LocationParser { break; case 13: - if (this.state.input.charCodeAt(this.state.pos + 1) === 10) { + if (this.input.charCodeAt(this.state.pos + 1) === 10) { ++this.state.pos; } @@ -4107,7 +6614,7 @@ class Tokenizer extends LocationParser { break; case 47: - switch (this.state.input.charCodeAt(this.state.pos + 1)) { + switch (this.input.charCodeAt(this.state.pos + 1)) { case 42: this.skipBlockComment(); break; @@ -4139,7 +6646,7 @@ class Tokenizer extends LocationParser { const prevType = this.state.type; this.state.type = type; this.state.value = val; - this.updateContext(prevType); + if (!this.isLookahead) this.updateContext(prevType); } readToken_numberSign() { @@ -4148,7 +6655,7 @@ class Tokenizer extends LocationParser { } const nextPos = this.state.pos + 1; - const next = this.state.input.charCodeAt(nextPos); + const next = this.input.charCodeAt(nextPos); if (next >= 48 && next <= 57) { this.raise(this.state.pos, "Unexpected digit after hash token"); @@ -4166,14 +6673,14 @@ class Tokenizer extends LocationParser { } readToken_dot() { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (next >= 48 && next <= 57) { this.readNumber(true); return; } - const next2 = this.state.input.charCodeAt(this.state.pos + 2); + const next2 = this.input.charCodeAt(this.state.pos + 2); if (next === 46 && next2 === 46) { this.state.pos += 3; @@ -4191,7 +6698,7 @@ class Tokenizer extends LocationParser { return; } - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (next === 61) { this.finishOp(types.assign, 2); @@ -4201,17 +6708,17 @@ class Tokenizer extends LocationParser { } readToken_interpreter() { - if (this.state.pos !== 0 || this.state.length < 2) return false; + if (this.state.pos !== 0 || this.length < 2) return false; const start = this.state.pos; this.state.pos += 1; - let ch = this.state.input.charCodeAt(this.state.pos); + 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.state.length) { - ch = this.state.input.charCodeAt(this.state.pos); + while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.length) { + ch = this.input.charCodeAt(this.state.pos); } - const value = this.state.input.slice(start + 2, this.state.pos); + const value = this.input.slice(start + 2, this.state.pos); this.finishToken(types.interpreterDirective, value); return true; } @@ -4219,12 +6726,12 @@ class Tokenizer extends LocationParser { 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); + let next = this.input.charCodeAt(this.state.pos + 1); const exprAllowed = this.state.exprAllowed; if (code === 42 && next === 42) { width++; - next = this.state.input.charCodeAt(this.state.pos + 2); + next = this.input.charCodeAt(this.state.pos + 2); type = types.exponent; } @@ -4237,10 +6744,10 @@ class Tokenizer extends LocationParser { } readToken_pipe_amp(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (next === code) { - if (this.state.input.charCodeAt(this.state.pos + 2) === 61) { + if (this.input.charCodeAt(this.state.pos + 2) === 61) { this.finishOp(types.assign, 3); } else { this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2); @@ -4265,7 +6772,7 @@ class Tokenizer extends LocationParser { } readToken_caret() { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (next === 61) { this.finishOp(types.assign, 2); @@ -4275,10 +6782,10 @@ class Tokenizer extends LocationParser { } readToken_plus_min(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.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))) { + 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(); @@ -4297,13 +6804,13 @@ class Tokenizer extends LocationParser { } readToken_lt_gt(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); let size = 1; if (next === code) { - size = code === 62 && this.state.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2; + size = code === 62 && this.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2; - if (this.state.input.charCodeAt(this.state.pos + size) === 61) { + if (this.input.charCodeAt(this.state.pos + size) === 61) { this.finishOp(types.assign, size + 1); return; } @@ -4312,7 +6819,7 @@ class Tokenizer extends LocationParser { return; } - 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) { + 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(); @@ -4327,10 +6834,10 @@ class Tokenizer extends LocationParser { } readToken_eq_excl(code) { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (next === 61) { - this.finishOp(types.equality, this.state.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2); + this.finishOp(types.equality, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2); return; } @@ -4344,8 +6851,8 @@ class Tokenizer extends LocationParser { } readToken_question() { - const next = this.state.input.charCodeAt(this.state.pos + 1); - const next2 = this.state.input.charCodeAt(this.state.pos + 2); + 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) { @@ -4409,7 +6916,7 @@ class Tokenizer extends LocationParser { return; case 58: - if (this.hasPlugin("functionBind") && this.state.input.charCodeAt(this.state.pos + 1) === 58) { + if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) { this.finishOp(types.doubleColon, 2); } else { ++this.state.pos; @@ -4429,7 +6936,7 @@ class Tokenizer extends LocationParser { case 48: { - const next = this.state.input.charCodeAt(this.state.pos + 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (next === 120 || next === 88) { this.readRadixNumber(16); @@ -4526,7 +7033,7 @@ class Tokenizer extends LocationParser { } finishOp(type, size) { - const str = this.state.input.slice(this.state.pos, this.state.pos + size); + const str = this.input.slice(this.state.pos, this.state.pos + size); this.state.pos += size; this.finishToken(type, str); } @@ -4536,11 +7043,11 @@ class Tokenizer extends LocationParser { let escaped, inClass; for (;;) { - if (this.state.pos >= this.state.length) { + if (this.state.pos >= this.length) { this.raise(start, "Unterminated regular expression"); } - const ch = this.state.input.charAt(this.state.pos); + const ch = this.input.charAt(this.state.pos); if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); @@ -4563,13 +7070,13 @@ class Tokenizer extends LocationParser { ++this.state.pos; } - const content = this.state.input.slice(start, this.state.pos); + const content = this.input.slice(start, this.state.pos); ++this.state.pos; let mods = ""; - while (this.state.pos < this.state.length) { - const char = this.state.input[this.state.pos]; - const charCode = this.state.input.codePointAt(this.state.pos); + while (this.state.pos < this.length) { + const char = this.input[this.state.pos]; + const charCode = this.input.codePointAt(this.state.pos); if (VALID_REGEX_FLAGS.has(char)) { if (mods.indexOf(char) > -1) { @@ -4598,12 +7105,12 @@ class Tokenizer extends LocationParser { let total = 0; for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { - const code = this.state.input.charCodeAt(this.state.pos); + const code = this.input.charCodeAt(this.state.pos); let val; if (this.hasPlugin("numericSeparator")) { - const prev = this.state.input.charCodeAt(this.state.pos - 1); - const next = this.state.input.charCodeAt(this.state.pos + 1); + const prev = this.input.charCodeAt(this.state.pos - 1); + const next = this.input.charCodeAt(this.state.pos + 1); if (code === 95) { if (allowedSiblings.indexOf(next) === -1) { @@ -4652,18 +7159,18 @@ class Tokenizer extends LocationParser { } if (this.hasPlugin("bigInt")) { - if (this.state.input.charCodeAt(this.state.pos) === 110) { + if (this.input.charCodeAt(this.state.pos) === 110) { ++this.state.pos; isBigInt = true; } } - if (isIdentifierStart(this.state.input.codePointAt(this.state.pos))) { + if (isIdentifierStart(this.input.codePointAt(this.state.pos))) { this.raise(this.state.pos, "Identifier directly after number"); } if (isBigInt) { - const str = this.state.input.slice(start, this.state.pos).replace(/[_n]/g, ""); + const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, ""); this.finishToken(types.bigint, str); return; } @@ -4680,29 +7187,29 @@ class Tokenizer extends LocationParser { this.raise(start, "Invalid number"); } - let octal = this.state.pos - start >= 2 && this.state.input.charCodeAt(start) === 48; + 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.state.input.slice(start, this.state.pos))) { + if (/[89]/.test(this.input.slice(start, this.state.pos))) { octal = false; } } - let next = this.state.input.charCodeAt(this.state.pos); + let next = this.input.charCodeAt(this.state.pos); if (next === 46 && !octal) { ++this.state.pos; this.readInt(10); isFloat = true; - next = this.state.input.charCodeAt(this.state.pos); + next = this.input.charCodeAt(this.state.pos); } if ((next === 69 || next === 101) && !octal) { - next = this.state.input.charCodeAt(++this.state.pos); + next = this.input.charCodeAt(++this.state.pos); if (next === 43 || next === 45) { ++this.state.pos; @@ -4710,7 +7217,7 @@ class Tokenizer extends LocationParser { if (this.readInt(10) === null) this.raise(start, "Invalid number"); isFloat = true; - next = this.state.input.charCodeAt(this.state.pos); + next = this.input.charCodeAt(this.state.pos); } if (this.hasPlugin("bigInt")) { @@ -4721,11 +7228,11 @@ class Tokenizer extends LocationParser { } } - if (isIdentifierStart(this.state.input.codePointAt(this.state.pos))) { + if (isIdentifierStart(this.input.codePointAt(this.state.pos))) { this.raise(this.state.pos, "Identifier directly after number"); } - const str = this.state.input.slice(start, this.state.pos).replace(/[_n]/g, ""); + const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, ""); if (isBigInt) { this.finishToken(types.bigint, str); @@ -4737,12 +7244,12 @@ class Tokenizer extends LocationParser { } readCodePoint(throwOnInvalid) { - const ch = this.state.input.charCodeAt(this.state.pos); + const ch = this.input.charCodeAt(this.state.pos); let code; if (ch === 123) { const codePos = ++this.state.pos; - code = this.readHexChar(this.state.input.indexOf("}", this.state.pos) - this.state.pos, throwOnInvalid); + code = this.readHexChar(this.input.indexOf("}", this.state.pos) - this.state.pos, throwOnInvalid); ++this.state.pos; if (code === null) { @@ -4767,15 +7274,15 @@ class Tokenizer extends LocationParser { 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 === 92) { - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); out += this.readEscapedChar(false); chunkStart = this.state.pos; } else if (ch === 8232 || ch === 8233) { @@ -4788,7 +7295,7 @@ class Tokenizer extends LocationParser { } } - out += this.state.input.slice(chunkStart, this.state.pos++); + out += this.input.slice(chunkStart, this.state.pos++); this.finishToken(types.string, out); } @@ -4798,13 +7305,13 @@ class Tokenizer extends LocationParser { containsInvalid = false; for (;;) { - if (this.state.pos >= this.state.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated template"); } - const ch = this.state.input.charCodeAt(this.state.pos); + const ch = this.input.charCodeAt(this.state.pos); - if (ch === 96 || ch === 36 && this.state.input.charCodeAt(this.state.pos + 1) === 123) { + 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; @@ -4817,13 +7324,13 @@ class Tokenizer extends LocationParser { } } - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); this.finishToken(types.template, containsInvalid ? null : out); return; } if (ch === 92) { - out += this.state.input.slice(chunkStart, this.state.pos); + out += this.input.slice(chunkStart, this.state.pos); const escaped = this.readEscapedChar(true); if (escaped === null) { @@ -4834,12 +7341,12 @@ class Tokenizer extends LocationParser { 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); ++this.state.pos; switch (ch) { case 13: - if (this.state.input.charCodeAt(this.state.pos) === 10) { + if (this.input.charCodeAt(this.state.pos) === 10) { ++this.state.pos; } @@ -4863,7 +7370,7 @@ class Tokenizer extends LocationParser { readEscapedChar(inTemplate) { const throwOnInvalid = !inTemplate; - const ch = this.state.input.charCodeAt(++this.state.pos); + const ch = this.input.charCodeAt(++this.state.pos); ++this.state.pos; switch (ch) { @@ -4898,7 +7405,7 @@ class Tokenizer extends LocationParser { return "\f"; case 13: - if (this.state.input.charCodeAt(this.state.pos) === 10) { + if (this.input.charCodeAt(this.state.pos) === 10) { ++this.state.pos; } @@ -4913,7 +7420,7 @@ class Tokenizer extends LocationParser { 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 octalStr = this.input.substr(this.state.pos - 1, 3).match(/^[0-7]+/)[0]; let octal = parseInt(octalStr, 8); if (octal > 255) { @@ -4921,7 +7428,10 @@ class Tokenizer extends LocationParser { octal = parseInt(octalStr, 8); } - if (octal > 0) { + 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; @@ -4933,7 +7443,6 @@ class Tokenizer extends LocationParser { } } - this.state.pos += octalStr.length - 1; return String.fromCharCode(octal); } @@ -4963,8 +7472,8 @@ class Tokenizer extends LocationParser { 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); + while (this.state.pos < this.length) { + const ch = this.input.codePointAt(this.state.pos); if (isIdentifierChar(ch)) { this.state.pos += ch <= 0xffff ? 1 : 2; @@ -4972,11 +7481,11 @@ class Tokenizer extends LocationParser { ++this.state.pos; } else if (ch === 92) { this.state.containsEsc = true; - word += this.state.input.slice(chunkStart, this.state.pos); + word += this.input.slice(chunkStart, this.state.pos); const escStart = this.state.pos; const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar; - if (this.state.input.charCodeAt(++this.state.pos) !== 117) { + if (this.input.charCodeAt(++this.state.pos) !== 117) { this.raise(this.state.pos, "Expecting Unicode escape sequence \\uXXXX"); } @@ -4994,7 +7503,7 @@ class Tokenizer extends LocationParser { } } - return word + this.state.input.slice(chunkStart, this.state.pos); + return word + this.input.slice(chunkStart, this.state.pos); } isIterator(word) { @@ -5003,7 +7512,7 @@ class Tokenizer extends LocationParser { readWord() { const word = this.readWord1(); - const type = keywords[word] || types.name; + const type = keywords.get(word) || types.name; if (type.keyword && this.state.containsEsc) { this.raise(this.state.pos, `Escape sequence in keyword ${word}`); @@ -5028,7 +7537,7 @@ class Tokenizer extends LocationParser { } if (prevType === types._return || prevType === types.name && this.state.exprAllowed) { - return lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start)); + return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)); } if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) { @@ -5065,6 +7574,7 @@ class Tokenizer extends LocationParser { } +const literal = /^('|")((?:\\?.)*?)\1/; class UtilParser extends Tokenizer { addExtra(node, key, val) { if (!node) return; @@ -5120,7 +7630,7 @@ class UtilParser extends Tokenizer { } hasPrecedingLineBreak() { - return lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start)); + return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)); } isLineTerminator() { @@ -5135,6 +7645,12 @@ class UtilParser extends Tokenizer { this.eat(type) || this.unexpected(pos, type); } + assertNoSpace(message = "Unexpected space.") { + if (this.state.start > this.state.lastTokEnd) { + this.raise(this.state.lastTokEnd, message); + } + } + unexpected(pos, messageOrType = "Unexpected token") { if (typeof messageOrType !== "string") { messageOrType = `Unexpected token, expected "${messageOrType.label}"`; @@ -5171,6 +7687,25 @@ class UtilParser extends Tokenizer { } } + 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; + + if (this.input[start] === ";") { + start++; + } + } + + return false; + } + } class Node { @@ -5218,6 +7753,7 @@ class NodeUtils extends UtilParser { } finishNodeAt(node, type, pos, loc) { + node.type = type; node.end = pos; node.loc.end = loc; @@ -5232,6 +7768,12 @@ class NodeUtils extends UtilParser { if (this.options.ranges) node.range[0] = start; } + 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; + } + resetStartLocationFromNode(node, locationNode) { this.resetStartLocation(node, locationNode.start, locationNode.loc.start); } @@ -5287,6 +7829,10 @@ class LValParser extends NodeUtils { break; + case "ParenthesizedExpression": + node.expression = this.toAssignable(node.expression, isBinding, contextDescription); + break; + case "MemberExpression": if (!isBinding) break; @@ -5306,7 +7852,7 @@ class LValParser extends NodeUtils { 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"); + this.raiseRestNotLast(prop.start); } else { this.toAssignable(prop, isBinding, "object destructuring pattern"); } @@ -5340,7 +7886,7 @@ class LValParser extends NodeUtils { this.toAssignable(elt, isBinding, contextDescription); if (elt.type === "RestElement") { - this.raiseRestNotLast(elt.start, "element"); + this.raiseRestNotLast(elt.start); } } } @@ -5378,7 +7924,7 @@ class LValParser extends NodeUtils { return this.finishNode(node, "SpreadElement"); } - parseRest() { + parseRestBinding() { const node = this.startNode(); this.next(); node.argument = this.parseBindingAtom(); @@ -5387,9 +7933,6 @@ class LValParser extends NodeUtils { parseBindingAtom() { switch (this.state.type) { - case types.name: - return this.parseIdentifier(); - case types.bracketL: { const node = this.startNode(); @@ -5400,10 +7943,9 @@ class LValParser extends NodeUtils { case types.braceL: return this.parseObj(true); - - default: - throw this.unexpected(); } + + return this.parseIdentifier(); } parseBindingList(close, allowEmpty, allowModifiers) { @@ -5422,8 +7964,8 @@ class LValParser extends NodeUtils { } 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"); + elts.push(this.parseAssignableListItemTypes(this.parseRestBinding())); + this.checkCommaAfterRest(); this.expect(close); break; } else { @@ -5471,34 +8013,41 @@ class LValParser extends NodeUtils { return this.finishNode(node, "AssignmentPattern"); } - checkLVal(expr, isBinding, checkClashes, contextDescription) { + 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, `${isBinding ? "Binding" : "Assigning to"} '${expr.name}' in strict mode`); + this.raise(expr.start, `${bindingType === BIND_NONE ? "Assigning to" : "Binding"} '${expr.name}' in strict mode`); } if (checkClashes) { const key = `_${expr.name}`; if (checkClashes[key]) { - this.raise(expr.start, "Argument name clash in strict mode"); + this.raise(expr.start, "Argument name clash"); } else { checkClashes[key] = true; } } + if (!(bindingType & BIND_NONE)) { + this.scope.declareName(expr.name, bindingType, expr.start); + } + break; case "MemberExpression": - if (isBinding) this.raise(expr.start, "Binding member expression"); + if (bindingType !== BIND_NONE) { + 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"); + this.checkLVal(prop, bindingType, checkClashes, "object destructuring pattern"); } break; @@ -5508,23 +8057,27 @@ class LValParser extends NodeUtils { const elem = _expr$elements[_i3]; if (elem) { - this.checkLVal(elem, isBinding, checkClashes, "array destructuring pattern"); + this.checkLVal(elem, bindingType, checkClashes, "array destructuring pattern"); } } break; case "AssignmentPattern": - this.checkLVal(expr.left, isBinding, checkClashes, "assignment pattern"); + this.checkLVal(expr.left, bindingType, checkClashes, "assignment pattern"); break; case "RestElement": - this.checkLVal(expr.argument, isBinding, checkClashes, "rest element"); + this.checkLVal(expr.argument, bindingType, checkClashes, "rest element"); + break; + + case "ParenthesizedExpression": + this.checkLVal(expr.expression, bindingType, checkClashes, "parenthesized expression"); break; default: { - const message = (isBinding ? "Binding invalid" : "Invalid") + " left-hand side" + (contextDescription ? " in " + contextDescription : "expression"); + const message = (bindingType === BIND_NONE ? "Invalid" : "Binding invalid") + " left-hand side" + (contextDescription ? " in " + contextDescription : "expression"); this.raise(expr.start, message); } } @@ -5536,35 +8089,34 @@ class LValParser extends NodeUtils { } } - checkCommaAfterRest(close, kind) { + checkCommaAfterRest() { if (this.match(types.comma)) { - if (this.lookahead().type === close) { - this.raiseCommaAfterRest(this.state.start, kind); - } else { - this.raiseRestNotLast(this.state.start, kind); - } + this.raiseRestNotLast(this.state.start); } } - checkCommaAfterRestFromSpread(kind) { + checkCommaAfterRestFromSpread() { if (this.state.commaAfterSpreadAt > -1) { - this.raiseCommaAfterRest(this.state.commaAfterSpreadAt, kind); + this.raiseRestNotLast(this.state.commaAfterSpreadAt); } } - raiseCommaAfterRest(pos, kind) { - this.raise(pos, `A trailing comma is not permitted after the rest ${kind}`); - } - - raiseRestNotLast(pos, kind) { - this.raise(pos, `The rest ${kind} must be the last ${kind}`); + raiseRestNotLast(pos) { + this.raise(pos, `Rest element must be last element`); } } +const unwrapParenthesizedExpression = node => { + return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node; +}; + class ExpressionParser extends LValParser { checkPropClash(prop, propHash) { - if (prop.computed || prop.kind) return; + if (prop.type === "SpreadElement" || prop.computed || prop.kind || prop.shorthand) { + return; + } + const key = prop.key; const name = key.type === "Identifier" ? key.name : String(key.value); @@ -5578,6 +8130,7 @@ class ExpressionParser extends LValParser { } getExpression() { + this.scope.enter(SCOPE_PROGRAM); this.nextToken(); const expr = this.parseExpression(); @@ -5614,7 +8167,7 @@ class ExpressionParser extends LValParser { const startLoc = this.state.startLoc; if (this.isContextual("yield")) { - if (this.state.inGenerator) { + if (this.scope.inGenerator) { let left = this.parseYield(noIn); if (afterLeftParse) { @@ -5667,22 +8220,20 @@ class ExpressionParser extends LValParser { 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; - let elementName; - if (left.type === "ObjectPattern") { + if (maybePattern.type === "ObjectPattern") { patternErrorMsg = "`({a}) = 0` use `({a} = 0)`"; - elementName = "property"; - } else if (left.type === "ArrayPattern") { + } else if (maybePattern.type === "ArrayPattern") { patternErrorMsg = "`([a]) = 0` use `([a] = 0)`"; - elementName = "element"; } - if (patternErrorMsg && left.extra && left.extra.parenthesized) { - this.raise(left.start, `You're trying to assign to a parenthesized expression, eg. instead of ${patternErrorMsg}`); + 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 (elementName) this.checkCommaAfterRestFromSpread(elementName); + if (patternErrorMsg) this.checkCommaAfterRestFromSpread(); this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; this.next(); node.right = this.parseMaybeAssign(noIn); @@ -5749,7 +8300,7 @@ class ExpressionParser extends LValParser { node.left = left; node.operator = operator; - if (operator === "**" && left.type === "UnaryExpression" && !(left.extra && left.extra.parenthesized)) { + 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."); } @@ -5766,7 +8317,7 @@ class ExpressionParser extends LValParser { this.next(); if (op === types.pipeline && this.getPluginOption("pipelineOperator", "proposal") === "minimal") { - if (this.match(types.name) && this.state.value === "await" && this.state.inAsync) { + 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`); } } @@ -5803,7 +8354,7 @@ class ExpressionParser extends LValParser { } parseMaybeUnary(refShorthandDefaultPos) { - if (this.isContextual("await") && (this.state.inAsync || !this.state.inFunction && this.options.allowAwaitOutsideFunction)) { + 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(); @@ -5873,19 +8424,20 @@ class ExpressionParser extends LValParser { } parseSubscripts(base, startPos, startLoc, noCalls) { + const maybeAsyncArrow = this.atPossibleAsync(base); const state = { optionalChainMember: false, stop: false }; do { - base = this.parseSubscript(base, startPos, startLoc, noCalls, state); + base = this.parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow); } while (!state.stop); return base; } - parseSubscript(base, startPos, startLoc, noCalls, state) { + parseSubscript(base, startPos, startLoc, noCalls, state, maybeAsyncArrow) { if (!noCalls && this.eat(types.doubleColon)) { const node = this.startNodeAt(startPos, startLoc); node.object = base; @@ -5912,9 +8464,8 @@ class ExpressionParser extends LValParser { 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.arguments = this.parseCallExpressionArguments(types.parenR, false); node.optional = true; return this.finishNode(node, "OptionalCallExpression"); } else { @@ -5956,13 +8507,12 @@ class ExpressionParser extends LValParser { 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"); + node.arguments = this.parseCallExpressionArguments(types.parenR, maybeAsyncArrow, base.type === "Import", base.type !== "Super"); if (!state.optionalChainMember) { this.finishCallExpression(node); @@ -5970,9 +8520,9 @@ class ExpressionParser extends LValParser { this.finishOptionalCallExpression(node); } - if (possibleAsync && this.shouldParseAsyncArrow()) { + if (maybeAsyncArrow && this.shouldParseAsyncArrow()) { state.stop = true; - this.checkCommaAfterRestFromSpread("parameter"); + this.checkCommaAfterRestFromSpread(); node = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); this.checkYieldAwaitInDefaultParams(); this.state.yieldPos = oldYieldPos; @@ -6008,7 +8558,7 @@ class ExpressionParser extends LValParser { } atPossibleAsync(base) { - return !this.state.containsEsc && this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon(); + return base.type === "Identifier" && base.name === "async" && this.state.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async"; } finishCallExpression(node) { @@ -6043,7 +8593,7 @@ class ExpressionParser extends LValParser { return this.finishNode(node, "OptionalCallExpression"); } - parseCallExpressionArguments(close, possibleAsyncArrow, dynamicImport) { + parseCallExpressionArguments(close, possibleAsyncArrow, dynamicImport, allowPlaceholder) { const elts = []; let innerParenStart; let first = true; @@ -6071,7 +8621,7 @@ class ExpressionParser extends LValParser { start: 0 } : undefined, possibleAsyncArrow ? { start: 0 - } : undefined)); + } : undefined, allowPlaceholder)); } if (possibleAsyncArrow && innerParenStart && this.shouldParseAsyncArrow()) { @@ -6082,7 +8632,7 @@ class ExpressionParser extends LValParser { } shouldParseAsyncArrow() { - return this.match(types.arrow); + return this.match(types.arrow) && !this.canInsertSemicolon(); } parseAsyncArrowFromCallExpression(node, call) { @@ -6104,32 +8654,33 @@ class ExpressionParser extends LValParser { switch (this.state.type) { case types._super: - if (!this.state.inMethod && !this.state.inClassProperty && !this.options.allowSuperOutsideMethod) { + if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) { this.raise(this.state.start, "super is only allowed in object methods and classes"); } node = this.startNode(); this.next(); - if (!this.match(types.parenL) && !this.match(types.bracketL) && !this.match(types.dot)) { - this.unexpected(); + 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?"); } - 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'."); + if (!this.match(types.parenL) && !this.match(types.bracketL) && !this.match(types.dot)) { + this.unexpected(); } return this.finishNode(node, "Super"); case types._import: - if (this.lookahead().type === types.dot) { - return this.parseImportMetaProperty(); - } - - this.expectPlugin("dynamicImport"); 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); } @@ -6149,14 +8700,11 @@ class ExpressionParser extends LValParser { 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; + 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); - this.state.inAsync = oldInAsync; return node; } @@ -6174,12 +8722,9 @@ class ExpressionParser extends LValParser { 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; + node.body = this.parseBlock(); this.state.labels = oldLabels; return this.finishNode(node, "DoExpression"); } @@ -6297,15 +8842,8 @@ class ExpressionParser extends LValParser { 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; - - if (spacesBetweenHashAndIdentifier != 0) { - this.raise(columnIdentifierStart, "Unexpected space between # and identifier"); - } - + this.assertNoSpace("Unexpected space between # and identifier"); node.id = this.parseIdentifier(true); return this.finishNode(node, "PrivateName"); } else { @@ -6319,11 +8857,11 @@ class ExpressionParser extends LValParser { this.next(); meta = this.createIdentifier(meta, "function"); - if (this.state.inGenerator && this.eat(types.dot)) { + if (this.scope.inGenerator && this.eat(types.dot)) { return this.parseMetaProperty(node, meta, "sent"); } - return this.parseFunction(node, false); + return this.parseFunction(node); } parseMetaProperty(node, meta, propertyName) { @@ -6347,17 +8885,14 @@ class ExpressionParser extends LValParser { return this.finishNode(node, "MetaProperty"); } - parseImportMetaProperty() { - const node = this.startNode(); - const id = this.parseIdentifier(true); + parseImportMetaProperty(node) { + const id = this.createIdentifier(this.startNodeAtNode(node), "import"); this.expect(types.dot); - 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("meta")) { + this.expectPlugin("importMeta"); + } else if (!this.hasPlugin("importMeta")) { + this.raise(id.start, `Dynamic imports require a parameter: import('a.js')`); } if (!this.inModule) { @@ -6375,19 +8910,12 @@ class ExpressionParser extends LValParser { 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)); + this.addExtra(node, "raw", this.input.slice(startPos, this.state.end)); node.value = value; this.next(); return this.finishNode(node, type); } - parseParenExpression() { - this.expect(types.parenL); - const val = this.parseExpression(); - this.expect(types.parenR); - return val; - } - parseParenAndDistinguishExpression(canBeArrow) { const startPos = this.state.start; const startLoc = this.state.startLoc; @@ -6428,8 +8956,8 @@ class ExpressionParser extends LValParser { 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"); + exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartPos, spreadNodeStartLoc)); + this.checkCommaAfterRest(); break; } else { exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos)); @@ -6484,9 +9012,16 @@ class ExpressionParser extends LValParser { val = exprList[0]; } - this.addExtra(val, "parenthesized", true); - this.addExtra(val, "parenStart", startPos); - return val; + if (!this.options.createParenthesizedExpressions) { + this.addExtra(val, "parenthesized", true); + this.addExtra(val, "parenStart", startPos); + return val; + } + + const parenExpression = this.startNodeAt(startPos, startLoc); + parenExpression.expression = val; + this.finishNode(parenExpression, "ParenthesizedExpression"); + return parenExpression; } shouldParseArrow() { @@ -6510,7 +9045,7 @@ class ExpressionParser extends LValParser { if (this.eat(types.dot)) { const metaProp = this.parseMetaProperty(node, meta, "target"); - if (!this.state.inFunction && !this.state.inClassProperty) { + if (!this.scope.inNonArrowFunction && !this.state.inClassProperty) { let error = "new.target can only be used in functions"; if (this.hasPlugin("classProperties")) { @@ -6559,7 +9094,7 @@ class ExpressionParser extends LValParser { } elem.value = { - raw: this.state.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"), + raw: this.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"), cooked: this.state.value }; this.next(); @@ -6586,7 +9121,6 @@ class ExpressionParser extends LValParser { } parseObj(isPattern, refShorthandDefaultPos) { - let decorators = []; const propHash = Object.create(null); let first = true; const node = this.startNode(); @@ -6601,95 +9135,96 @@ class ExpressionParser extends LValParser { if (this.eat(types.braceR)) break; } - 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()); - } - } - } - - let prop = this.startNode(), - isGenerator = false, - isAsync = false, - startPos, - startLoc; + const prop = this.parseObjectMember(isPattern, refShorthandDefaultPos); + if (!isPattern) this.checkPropClash(prop, propHash); - if (decorators.length) { - prop.decorators = decorators; - decorators = []; + if (prop.shorthand) { + this.addExtra(prop, "shorthand", true); } - 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; - } + node.properties.push(prop); + } - continue; - } + return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); + } - prop.method = false; + 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 (isPattern || refShorthandDefaultPos) { - startPos = this.state.start; - startLoc = this.state.startLoc; - } + parseObjectMember(isPattern, refShorthandDefaultPos) { + let decorators = []; - if (!isPattern) { - isGenerator = this.eat(types.star); + 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()); + } } + } - const containsEsc = this.state.containsEsc; + const prop = this.startNode(); + let isGenerator = false; + let isAsync = false; + let startPos; + let startLoc; - if (!isPattern && this.isContextual("async")) { - if (isGenerator) this.unexpected(); - const asyncId = this.parseIdentifier(); + if (this.match(types.ellipsis)) { + if (decorators.length) this.unexpected(); - 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); - } - } else { - this.parsePropertyName(prop); + if (isPattern) { + this.next(); + prop.argument = this.parseIdentifier(); + this.checkCommaAfterRest(); + return this.finishNode(prop, "RestElement"); } - this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc); - this.checkPropClash(prop, propHash); + return this.parseSpread(); + } + + if (decorators.length) { + prop.decorators = decorators; + decorators = []; + } - if (prop.shorthand) { - this.addExtra(prop, "shorthand", true); - } + prop.method = false; - node.properties.push(prop); + if (isPattern || refShorthandDefaultPos) { + startPos = this.state.start; + startLoc = this.state.startLoc; } - if (decorators.length) { - this.raise(this.state.start, "You have trailing decorators with no property"); + if (!isPattern) { + isGenerator = this.eat(types.star); } - return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); + const containsEsc = this.state.containsEsc; + this.parsePropertyName(prop); + + if (!isPattern && !containsEsc && !isGenerator && this.isAsyncProp(prop)) { + isAsync = true; + isGenerator = this.eat(types.star); + this.parsePropertyName(prop); + } else { + isAsync = false; + } + + this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos, containsEsc); + return prop; } 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); } + getGetterSetterExpectedParamCount(method) { + return method.kind === "get" ? 0 : 1; + } + checkGetterSetterParams(method) { - const paramCount = method.kind === "get" ? 0 : 1; + const paramCount = this.getGetterSetterExpectedParamCount(method); const start = method.start; if (method.params.length !== paramCount) { @@ -6700,7 +9235,7 @@ class ExpressionParser extends LValParser { } } - if (method.kind === "set" && method.params[0].type === "RestElement") { + if (method.kind === "set" && method.params[method.params.length - 1].type === "RestElement") { this.raise(start, "setter function argument must not be a rest parameter"); } } @@ -6710,14 +9245,14 @@ class ExpressionParser extends LValParser { if (isPattern) this.unexpected(); prop.kind = "method"; prop.method = true; - return this.parseMethod(prop, isGenerator, isAsync, false, "ObjectMethod"); + return this.parseMethod(prop, isGenerator, isAsync, false, 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.parseMethod(prop, false, false, false, false, "ObjectMethod"); this.checkGetterSetterParams(prop); return prop; } @@ -6783,53 +9318,36 @@ class ExpressionParser extends LValParser { node.async = !!isAsync; } - 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; + parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) { 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.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); - this.state.inFunction = oldInFunc; - this.state.inMethod = oldInMethod; - this.state.inAsync = oldInAsync; - this.state.inGenerator = oldInGenerator; + this.parseFunctionBodyAndFinish(node, type, true); + this.scope.exit(); this.state.yieldPos = oldYieldPos; this.state.awaitPos = oldAwaitPos; return node; } parseArrowExpression(node, params, isAsync) { + this.scope.enter(functionFlags(isAsync, false) | SCOPE_ARROW); 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.scope.exit(); this.state.maybeInArrowParameters = oldMaybeInArrowParameters; this.state.yieldPos = oldYieldPos; this.state.awaitPos = oldAwaitPos; @@ -6856,57 +9374,64 @@ class ExpressionParser extends LValParser { return false; } - parseFunctionBodyAndFinish(node, type, allowExpressionBody) { - this.parseFunctionBody(node, allowExpressionBody); + parseFunctionBodyAndFinish(node, type, isMethod = false) { + this.parseFunctionBody(node, false, isMethod); this.finishNode(node, type); } - parseFunctionBody(node, allowExpression) { + 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 oldInFunc = this.state.inFunction; + const nonSimple = !this.isSimpleParamList(node.params); + + if (!oldStrict || nonSimple) { + useStrict = this.strictDirective(this.state.end); + + 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 oldLabels = this.state.labels; - this.state.inFunction = true; this.state.labels = []; - node.body = this.parseBlock(true); - this.state.inFunction = oldInFunc; + 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; } - this.checkFunctionNameAndParams(node, allowExpression); this.state.inParameters = oldInParameters; - } - 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; + if (this.state.strict && node.id) { + this.checkLVal(node.id, BIND_OUTSIDE, undefined, "function name"); + } - if (checkLVal) { - const nameHash = Object.create(null); + this.state.strict = oldStrict; + } - if (node.id) { - this.checkLVal(node.id, true, undefined, "function name"); - } + isSimpleParamList(params) { + for (let i = 0, len = params.length; i < len; i++) { + if (params[i].type !== "Identifier") return false; + } - for (let _i3 = 0, _node$params = node.params; _i3 < _node$params.length; _i3++) { - const param = _node$params[_i3]; + return true; + } - if (isStrict && param.type !== "Identifier") { - this.raise(param.start, "Non-simple parameter in strict mode"); - } + checkParams(node, allowDuplicates, isArrowFunction) { + const nameHash = Object.create(null); - this.checkLVal(param, true, nameHash, "function parameter list"); - } + for (let i = 0; i < node.params.length; i++) { + this.checkLVal(node.params[i], BIND_VAR, allowDuplicates ? null : nameHash, "function paramter list"); } - - this.state.strict = oldStrict; } parseExprList(close, allowEmpty, refShorthandDefaultPos) { @@ -6927,7 +9452,7 @@ class ExpressionParser extends LValParser { return elts; } - parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos) { + parseExprListItem(allowEmpty, refShorthandDefaultPos, refNeedsArrowPos, allowPlaceholder) { let elt; if (allowEmpty && this.match(types.comma)) { @@ -6936,6 +9461,16 @@ class ExpressionParser extends LValParser { 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); } @@ -6963,7 +9498,7 @@ class ExpressionParser extends LValParser { } else if (this.state.type.keyword) { name = this.state.type.keyword; - if ((name === "class" || name === "function") && (this.state.lastTokEnd !== this.state.lastTokStart + 1 || this.state.input.charCodeAt(this.state.lastTokStart) !== 46)) { + if ((name === "class" || name === "function") && (this.state.lastTokEnd !== this.state.lastTokStart + 1 || this.input.charCodeAt(this.state.lastTokStart) !== 46)) { this.state.context.pop(); } } else { @@ -6979,17 +9514,15 @@ class ExpressionParser extends LValParser { } checkReservedWord(word, startLoc, checkKeywords, isBinding) { - const state = this.state; - - if (state.inGenerator && word === "yield") { + if (this.scope.inGenerator && word === "yield") { this.raise(startLoc, "Can not use 'yield' as identifier inside a generator"); } - if (state.inAsync && word === "await") { + if (this.scope.inAsync && word === "await") { this.raise(startLoc, "Can not use 'await' as identifier inside an async function"); } - if (state.inClassProperty && word === "arguments") { + if (this.state.inClassProperty && word === "arguments") { this.raise(startLoc, "'arguments' is not allowed in class field initializer"); } @@ -6997,10 +9530,10 @@ class ExpressionParser extends LValParser { this.raise(startLoc, `Unexpected keyword '${word}'`); } - const reservedTest = !state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord; + const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord; if (reservedTest(word, this.inModule)) { - if (!state.inAsync && word === "await") { + if (!this.scope.inAsync && word === "await") { this.raise(startLoc, "Can not use keyword 'await' outside an async function"); } @@ -7167,18 +9700,30 @@ class ExpressionParser extends LValParser { } -const empty = []; const loopLabel = { kind: "loop" -}; -const switchLabel = { +}, + 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); + + 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`); + } + } + file.program = this.finishNode(program, "Program"); file.comments = this.state.comments; if (this.options.tokens) file.tokens = this.state.tokens; @@ -7189,7 +9734,7 @@ class StatementParser extends ExpressionParser { 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 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); @@ -7214,9 +9759,9 @@ class StatementParser extends ExpressionParser { } skipWhiteSpace.lastIndex = this.state.pos; - const skip = skipWhiteSpace.exec(this.state.input); + const skip = skipWhiteSpace.exec(this.input); const next = this.state.pos + skip[0].length; - const nextCh = this.state.input.charCodeAt(next); + const nextCh = this.input.charCodeAt(next); if (nextCh === 91) return true; if (context) return false; if (nextCh === 123) return true; @@ -7224,11 +9769,11 @@ class StatementParser extends ExpressionParser { if (isIdentifierStart(nextCh)) { let pos = next + 1; - while (isIdentifierChar(this.state.input.charCodeAt(pos))) { + while (isIdentifierChar(this.input.charCodeAt(pos))) { ++pos; } - const ident = this.state.input.slice(next, pos); + const ident = this.input.slice(next, pos); if (!keywordRelationalOperator.test(ident)) return true; } @@ -7268,22 +9813,18 @@ class StatementParser extends ExpressionParser { return this.parseForStatement(node); case types._function: - { - if (this.lookahead().type === types.dot) break; - - if (context && (this.state.strict || context !== "if" && context !== "label")) { - this.raise(this.state.start, "Function declaration not allowed in this context"); - } - - const result = this.parseFunctionStatement(node); + if (this.lookahead().type === types.dot) break; - if (context && result.generator) { - this.unexpected(node.start); + 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 result; } + return this.parseFunctionStatement(node, false, !context); + case types._class: if (context) this.unexpected(); return this.parseClass(node, true); @@ -7306,7 +9847,11 @@ class StatementParser extends ExpressionParser { case types._const: case types._var: kind = kind || this.state.value; - if (context && kind !== "var") this.unexpected(); + + if (context && kind !== "var") { + this.unexpected(this.state.start, "Lexical declaration cannot appear in a single-statement context"); + } + return this.parseVarStatement(node, kind); case types._while: @@ -7355,23 +9900,17 @@ class StatementParser extends ExpressionParser { return result; } - case types.name: - if (this.isContextual("async")) { - const state = this.state.clone(); - this.next(); - - if (this.match(types._function) && !this.canInsertSemicolon()) { + default: + { + if (this.isAsyncFunction()) { if (context) { - this.raise(this.state.lastTokStart, "Function declaration not allowed in this context"); + this.unexpected(null, "Async functions can only be declared at the top level or inside a block"); } this.next(); - return this.parseFunction(node, true, false, true); - } else { - this.state = state; + return this.parseFunctionStatement(node, true, !context); } } - } const maybeName = this.state.value; @@ -7480,13 +10019,17 @@ class StatementParser extends ExpressionParser { if (this.isLineTerminator()) { node.label = null; - } else if (!this.match(types.name)) { - this.unexpected(); } else { node.label = this.parseIdentifier(); this.semicolon(); } + this.verifyBreakContinue(node, keyword); + return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); + } + + verifyBreakContinue(node, keyword) { + const isBreak = keyword === "break"; let i; for (i = 0; i < this.state.labels.length; ++i) { @@ -7501,8 +10044,6 @@ class StatementParser extends ExpressionParser { if (i === this.state.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); } - - return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); } parseDebuggerStatement(node) { @@ -7511,13 +10052,20 @@ class StatementParser extends ExpressionParser { return this.finishNode(node, "DebuggerStatement"); } + parseHeaderExpression() { + this.expect(types.parenL); + const val = this.parseExpression(); + this.expect(types.parenR); + return val; + } + 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(); + node.test = this.parseHeaderExpression(); this.eat(types.semi); return this.finishNode(node, "DoWhileStatement"); } @@ -7527,10 +10075,11 @@ class StatementParser extends ExpressionParser { this.state.labels.push(loopLabel); let awaitAt = -1; - if ((this.state.inAsync || !this.state.inFunction && this.options.allowAwaitOutsideFunction) && this.eatContextual("await")) { + if ((this.scope.inAsync || !this.scope.inFunction && this.options.allowAwaitOutsideFunction) && this.eatContextual("await")) { awaitAt = this.state.lastTokStart; } + this.scope.enter(SCOPE_OTHER); this.expect(types.parenL); if (this.match(types.semi)) { @@ -7550,17 +10099,8 @@ class StatementParser extends ExpressionParser { this.parseVar(init, true, kind); this.finishNode(init, "VariableDeclaration"); - 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"); - - 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); - } - } + if ((this.match(types._in) || this.isContextual("of")) && init.declarations.length === 1) { + return this.parseForIn(node, init, awaitAt); } if (awaitAt > -1) { @@ -7591,21 +10131,21 @@ class StatementParser extends ExpressionParser { return this.parseFor(node, init); } - parseFunctionStatement(node) { + parseFunctionStatement(node, isAsync, declarationPosition) { this.next(); - return this.parseFunction(node, true); + return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), isAsync); } parseIfStatement(node) { this.next(); - node.test = this.parseParenExpression(); + node.test = this.parseHeaderExpression(); node.consequent = this.parseStatement("if"); node.alternate = this.eat(types._else) ? this.parseStatement("if") : null; return this.finishNode(node, "IfStatement"); } parseReturnStatement(node) { - if (!this.state.inFunction && !this.options.allowReturnOutsideFunction) { + if (!this.scope.inFunction && !this.options.allowReturnOutsideFunction) { this.raise(this.state.start, "'return' outside of function"); } @@ -7623,10 +10163,11 @@ class StatementParser extends ExpressionParser { parseSwitchStatement(node) { this.next(); - node.discriminant = this.parseParenExpression(); + node.discriminant = this.parseHeaderExpression(); const cases = node.cases = []; this.expect(types.braceL); this.state.labels.push(switchLabel); + this.scope.enter(SCOPE_OTHER); let cur; for (let sawDefault; !this.match(types.braceR);) { @@ -7658,6 +10199,7 @@ class StatementParser extends ExpressionParser { } } + this.scope.exit(); if (cur) this.finishNode(cur, "SwitchCase"); this.next(); this.state.labels.pop(); @@ -7667,7 +10209,7 @@ class StatementParser extends ExpressionParser { parseThrowStatement(node) { this.next(); - if (lineBreak.test(this.state.input.slice(this.state.lastTokEnd, this.state.start))) { + if (lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))) { this.raise(this.state.lastTokEnd, "Illegal newline after throw"); } @@ -7688,18 +10230,20 @@ class StatementParser extends ExpressionParser { 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"); + 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); } - clause.body = this.withTopicForbiddingContext(() => this.parseBlock(false)); + clause.body = this.withTopicForbiddingContext(() => this.parseBlock(false, false)); + this.scope.exit(); node.handler = this.finishNode(clause, "CatchClause"); } - node.guardedHandlers = empty; node.finalizer = this.eat(types._finally) ? this.parseBlock() : null; if (!node.handler && !node.finalizer) { @@ -7718,7 +10262,7 @@ class StatementParser extends ExpressionParser { parseWhileStatement(node) { this.next(); - node.test = this.parseParenExpression(); + node.test = this.parseHeaderExpression(); this.state.labels.push(loopLabel); node.body = this.withTopicForbiddingContext(() => this.parseStatement("while")); this.state.labels.pop(); @@ -7731,7 +10275,7 @@ class StatementParser extends ExpressionParser { } this.next(); - node.object = this.parseParenExpression(); + node.object = this.parseHeaderExpression(); node.body = this.withTopicForbiddingContext(() => this.parseStatement("with")); return this.finishNode(node, "WithStatement"); } @@ -7742,8 +10286,8 @@ class StatementParser extends ExpressionParser { } 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]; + for (let _i2 = 0, _this$state$labels = this.state.labels; _i2 < _this$state$labels.length; _i2++) { + const label = _this$state$labels[_i2]; if (label.name === maybeName) { this.raise(expr.start, `Label '${maybeName}' is already declared`); @@ -7780,10 +10324,20 @@ class StatementParser extends ExpressionParser { return this.finishNode(node, "ExpressionStatement"); } - parseBlock(allowDirectives) { + parseBlock(allowDirectives = false, createNewLexicalScope = true) { const node = this.startNode(); this.expect(types.braceL); + + if (createNewLexicalScope) { + this.scope.enter(SCOPE_OTHER); + } + this.parseBlockBody(node, allowDirectives, false, types.braceR); + + if (createNewLexicalScope) { + this.scope.exit(); + } + return this.finishNode(node, "BlockStatement"); } @@ -7842,29 +10396,34 @@ class StatementParser extends ExpressionParser { 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"); } parseForIn(node, init, awaitAt) { - const type = this.match(types._in) ? "ForInStatement" : "ForOfStatement"; + const isForIn = this.match(types._in); + this.next(); - if (awaitAt > -1) { - this.eatContextual("of"); + if (isForIn) { + if (awaitAt > -1) this.unexpected(awaitAt); } else { - this.next(); + node.await = awaitAt > -1; } - if (type === "ForOfStatement") { - node.await = awaitAt > -1; + 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"); } node.left = init; - node.right = this.parseExpression(); + 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, type); + return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement"); } parseVar(node, isFor, kind) { @@ -7903,57 +10462,57 @@ class StatementParser extends ExpressionParser { } decl.id = this.parseBindingAtom(); - this.checkLVal(decl.id, true, undefined, "variable declaration"); + this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, undefined, "variable declaration"); } - 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; + 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"); + } + + node.generator = this.eat(types.star); + + if (isStatement) { + node.id = this.parseFunctionId(requireId); + } + 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(); - } + this.scope.enter(functionFlags(node.async, node.generator)); if (!isStatement) { - this.state.inAsync = isAsync; - this.state.inGenerator = node.generator; - } - - if (this.match(types.name)) { - node.id = this.parseIdentifier(); - } - - if (isStatement) { - this.state.inAsync = isAsync; - this.state.inGenerator = node.generator; + node.id = this.parseFunctionId(); } this.parseFunctionParams(node); this.withTopicForbiddingContext(() => { - this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression", allowExpressionBody); + this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); }); - this.state.inFunction = oldInFunc; - this.state.inMethod = oldInMethod; - this.state.inAsync = oldInAsync; - this.state.inGenerator = oldInGenerator; + this.scope.exit(); + + if (isStatement && !isHangingStatement) { + this.checkFunctionStatementId(node); + } + this.state.inClassProperty = oldInClassProperty; this.state.yieldPos = oldYieldPos; this.state.awaitPos = oldAwaitPos; return node; } + parseFunctionId(requireId) { + return requireId || this.match(types.name) ? this.parseIdentifier() : null; + } + parseFunctionParams(node, allowModifiers) { const oldInParameters = this.state.inParameters; this.state.inParameters = true; @@ -7963,6 +10522,11 @@ class StatementParser extends ExpressionParser { this.checkYieldAwaitInDefaultParams(); } + 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"); + } + parseClass(node, isStatement, optionalId) { this.next(); this.takeDecorators(node); @@ -7970,7 +10534,7 @@ class StatementParser extends ExpressionParser { this.state.strict = true; this.parseClassId(node, isStatement, optionalId); this.parseClassSuper(node); - this.parseClassBody(node); + node.body = this.parseClassBody(!!node.superClass); this.state.strict = oldStrict; return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); } @@ -7987,7 +10551,7 @@ class StatementParser extends ExpressionParser { return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor"); } - parseClassBody(node) { + parseClassBody(constructorAllowsSuper) { this.state.classLevel++; const state = { hadConstructor: false @@ -8019,7 +10583,7 @@ class StatementParser extends ExpressionParser { decorators = []; } - this.parseClassMember(classBody, member, state); + 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 { ... }'?"); @@ -8031,11 +10595,11 @@ class StatementParser extends ExpressionParser { this.raise(this.state.start, "You have trailing decorators with no method"); } - node.body = this.finishNode(classBody, "ClassBody"); this.state.classLevel--; + return this.finishNode(classBody, "ClassBody"); } - parseClassMember(classBody, member, state) { + parseClassMember(classBody, member, state, constructorAllowsSuper) { let isStatic = false; const containsEsc = this.state.containsEsc; @@ -8048,7 +10612,7 @@ class StatementParser extends ExpressionParser { method.computed = false; method.key = key; method.static = false; - this.pushClassMethod(classBody, method, false, false, false); + this.pushClassMethod(classBody, method, false, false, false, false); return; } else if (this.isClassProperty()) { const prop = member; @@ -8064,10 +10628,10 @@ class StatementParser extends ExpressionParser { isStatic = true; } - this.parseClassMemberWithIsStatic(classBody, member, state, isStatic); + this.parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper); } - parseClassMemberWithIsStatic(classBody, member, state, isStatic) { + parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper) { const publicMethod = member; const privateMethod = member; const publicProp = member; @@ -8089,10 +10653,11 @@ class StatementParser extends ExpressionParser { this.raise(publicMethod.key.start, "Constructor can't be a generator"); } - this.pushClassMethod(classBody, publicMethod, true, false, false); + this.pushClassMethod(classBody, publicMethod, true, false, false, false); return; } + const containsEsc = this.state.containsEsc; const key = this.parseClassPropertyName(member); const isPrivate = key.type === "PrivateName"; const isSimple = key.type === "Identifier"; @@ -8107,6 +10672,7 @@ class StatementParser extends ExpressionParser { } const isConstructor = this.isNonstaticConstructor(publicMethod); + let allowsDirectSuper = false; if (isConstructor) { publicMethod.kind = "constructor"; @@ -8120,16 +10686,17 @@ class StatementParser extends ExpressionParser { } state.hadConstructor = true; + allowsDirectSuper = constructorAllowsSuper; } - this.pushClassMethod(classBody, publicMethod, false, false, isConstructor); + 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" && !this.isLineTerminator()) { + } else if (isSimple && key.name === "async" && !containsEsc && !this.isLineTerminator()) { const isGenerator = this.eat(types.star); method.kind = "method"; this.parseClassPropertyName(method); @@ -8141,9 +10708,9 @@ class StatementParser extends ExpressionParser { this.raise(publicMethod.key.start, "Constructor can't be an async function"); } - this.pushClassMethod(classBody, publicMethod, isGenerator, true, false); + this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false); } - } else if (isSimple && (key.name === "get" || key.name === "set") && !(this.match(types.star) && this.isLineTerminator())) { + } else if (isSimple && (key.name === "get" || key.name === "set") && !containsEsc && !(this.match(types.star) && this.isLineTerminator())) { method.kind = key.name; this.parseClassPropertyName(publicMethod); @@ -8154,7 +10721,7 @@ class StatementParser extends ExpressionParser { this.raise(publicMethod.key.start, "Constructor can't have get/set modifier"); } - this.pushClassMethod(classBody, publicMethod, false, false, false); + this.pushClassMethod(classBody, publicMethod, false, false, false, false); } this.checkGetterSetterParams(publicMethod); @@ -8196,13 +10763,13 @@ class StatementParser extends ExpressionParser { classBody.body.push(this.parseClassPrivateProperty(prop)); } - pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) { - classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, "ClassMethod")); + pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { + classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true)); } pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { this.expectPlugin("classPrivateMethods", method.key.start); - classBody.body.push(this.parseMethod(method, isGenerator, isAsync, false, "ClassPrivateMethod")); + classBody.body.push(this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true)); } parsePostMemberNameModifiers(methodOrProp) {} @@ -8212,13 +10779,12 @@ class StatementParser extends ExpressionParser { } parseClassPrivateProperty(node) { - const oldInMethod = this.state.inMethod; - this.state.inMethod = false; 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.state.inMethod = oldInMethod; + this.scope.exit(); return this.finishNode(node, "ClassPrivateProperty"); } @@ -8227,9 +10793,8 @@ class StatementParser extends ExpressionParser { this.expectPlugin("classProperties"); } - const oldInMethod = this.state.inMethod; - this.state.inMethod = false; this.state.inClassProperty = true; + this.scope.enter(SCOPE_CLASS | SCOPE_SUPER); if (this.match(types.eq)) { this.expectPlugin("classProperties"); @@ -8241,13 +10806,17 @@ class StatementParser extends ExpressionParser { this.semicolon(); this.state.inClassProperty = false; - this.state.inMethod = oldInMethod; + this.scope.exit(); return this.finishNode(node, "ClassProperty"); } parseClassId(node, isStatement, optionalId) { 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; @@ -8291,7 +10860,7 @@ class StatementParser extends ExpressionParser { } if (isFromRequired || hasSpecifiers || hasDeclaration) { - this.checkExport(node, true); + this.checkExport(node, true, false, !!node.source); return this.finishNode(node, "ExportNamedDeclaration"); } @@ -8368,28 +10937,27 @@ class StatementParser extends ExpressionParser { isAsyncFunction() { if (!this.isContextual("async")) return false; const { - input, - pos, - length + pos } = this.state; skipWhiteSpace.lastIndex = pos; - const skip = skipWhiteSpace.exec(input); + const skip = skipWhiteSpace.exec(this.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))); + 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))); } parseExportDefaultExpression() { const expr = this.startNode(); const isAsync = this.isAsyncFunction(); - if (this.eat(types._function) || isAsync) { + if (this.match(types._function) || isAsync) { + this.next(); + if (isAsync) { - this.eatContextual("async"); - this.expect(types._function); + this.next(); } - return this.parseFunction(expr, true, false, isAsync, true); + 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)) { @@ -8456,14 +11024,19 @@ class StatementParser extends ExpressionParser { 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(); } - checkExport(node, checkNames, isDefault) { + checkExport(node, checkNames, isDefault, isFrom) { 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]; + for (let _i3 = 0, _node$specifiers = node.specifiers; _i3 < _node$specifiers.length; _i3++) { + const specifier = _node$specifiers[_i3]; this.checkDuplicateExports(specifier, specifier.exported.name); + + 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") { @@ -8471,8 +11044,8 @@ class StatementParser extends ExpressionParser { 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]; + 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); } } @@ -8496,13 +11069,13 @@ class StatementParser extends ExpressionParser { 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]; + 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 _i5 = 0, _node$elements = node.elements; _i5 < _node$elements.length; _i5++) { - const elem = _node$elements[_i5]; + for (let _i6 = 0, _node$elements = node.elements; _i6 < _node$elements.length; _i6++) { + const elem = _node$elements[_i6]; if (elem) { this.checkDeclaration(elem); @@ -8528,7 +11101,6 @@ class StatementParser extends ExpressionParser { parseExportSpecifiers() { const nodes = []; let first = true; - let needsFrom; this.expect(types.braceL); while (!this.eat(types.braceR)) { @@ -8539,18 +11111,12 @@ class StatementParser extends ExpressionParser { if (this.eat(types.braceR)) break; } - const isDefault = this.match(types._default); - if (isDefault && !needsFrom) needsFrom = true; const node = this.startNode(); - node.local = this.parseIdentifier(isDefault); + node.local = this.parseIdentifier(true); node.exported = this.eatContextual("as") ? this.parseIdentifier(true) : node.local.__clone(); nodes.push(this.finishNode(node, "ExportSpecifier")); } - if (needsFrom && !this.isContextual("from")) { - this.unexpected(); - } - return nodes; } @@ -8581,7 +11147,7 @@ class StatementParser extends ExpressionParser { parseImportSpecifierLocal(node, specifier, type, contextDescription) { specifier.local = this.parseIdentifier(); - this.checkLVal(specifier.local, true, undefined, contextDescription); + this.checkLVal(specifier.local, BIND_LEXICAL, undefined, contextDescription); node.specifiers.push(this.finishNode(specifier, type)); } @@ -8637,7 +11203,7 @@ class StatementParser extends ExpressionParser { specifier.local = specifier.imported.__clone(); } - this.checkLVal(specifier.local, true, undefined, "import specifier"); + this.checkLVal(specifier.local, BIND_LEXICAL, undefined, "import specifier"); node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); } @@ -8647,13 +11213,20 @@ 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; } + getScopeHandler() { + return ScopeHandler; + } + parse() { + this.scope.enter(SCOPE_PROGRAM); const file = this.startNode(); const program = this.startNode(); this.nextToken(); @@ -8674,1970 +11247,6 @@ function pluginsMap(plugins) { return pluginMap; } -function nonNull(x) { - if (x == null) { - throw new Error(`Unexpected ${x} value.`); - } - - return x; -} - -function assert(x) { - if (!x) { - throw new Error("Assert fail"); - } -} - -function keywordTypeFromName(value) { - switch (value) { - case "any": - return "TSAnyKeyword"; - - case "boolean": - return "TSBooleanKeyword"; - - case "bigint": - return "TSBigIntKeyword"; - - case "never": - return "TSNeverKeyword"; - - case "number": - return "TSNumberKeyword"; - - case "object": - return "TSObjectKeyword"; - - case "string": - return "TSStringKeyword"; - - case "symbol": - return "TSSymbolKeyword"; - - case "undefined": - return "TSUndefinedKeyword"; - - case "unknown": - return "TSUnknownKeyword"; - - default: - return undefined; - } -} - -var typescript = (superClass => class extends superClass { - tsIsIdentifier() { - return this.match(types.name); - } - - 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); - } - - tsParseModifier(allowedModifiers) { - if (!this.match(types.name)) { - return undefined; - } - - const modifier = this.state.value; - - if (allowedModifiers.indexOf(modifier) !== -1 && this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) { - return modifier; - } - - return undefined; - } - - tsIsListTerminator(kind) { - switch (kind) { - case "EnumMembers": - case "TypeMembers": - return this.match(types.braceR); - - case "HeritageClauseElement": - return this.match(types.braceL); - - case "TupleElementTypes": - return this.match(types.bracketR); - - case "TypeParametersOrArguments": - return this.isRelational(">"); - } - - throw new Error("Unreachable"); - } - - tsParseList(kind, parseElement) { - const result = []; - - while (!this.tsIsListTerminator(kind)) { - result.push(parseElement()); - } - - return result; - } - - tsParseDelimitedList(kind, parseElement) { - return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true)); - } - - tsTryParseDelimitedList(kind, parseElement) { - return this.tsParseDelimitedListWorker(kind, parseElement, false); - } - - tsParseDelimitedListWorker(kind, parseElement, expectSuccess) { - const result = []; - - while (true) { - if (this.tsIsListTerminator(kind)) { - break; - } - - const element = parseElement(); - - if (element == null) { - return undefined; - } - - result.push(element); - - if (this.eat(types.comma)) { - continue; - } - - if (this.tsIsListTerminator(kind)) { - break; - } - - if (expectSuccess) { - this.expect(types.comma); - } - - return undefined; - } - - return result; - } - - tsParseBracketedList(kind, parseElement, bracket, skipFirstToken) { - if (!skipFirstToken) { - if (bracket) { - this.expect(types.bracketL); - } else { - this.expectRelational("<"); - } - } - - const result = this.tsParseDelimitedList(kind, parseElement); - - if (bracket) { - this.expect(types.bracketR); - } else { - this.expectRelational(">"); - } - - return result; - } - - tsParseImportType() { - const node = this.startNode(); - this.expect(types._import); - this.expect(types.parenL); - - if (!this.match(types.string)) { - throw this.unexpected(null, "Argument in a type import must be a string literal"); - } - - node.argument = this.parseLiteral(this.state.value, "StringLiteral"); - this.expect(types.parenR); - - if (this.eat(types.dot)) { - node.qualifier = this.tsParseEntityName(true); - } - - if (this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); - } - - return this.finishNode(node, "TSImportType"); - } - - tsParseEntityName(allowReservedWords) { - let entity = this.parseIdentifier(); - - while (this.eat(types.dot)) { - const node = this.startNodeAtNode(entity); - node.left = entity; - node.right = this.parseIdentifier(allowReservedWords); - entity = this.finishNode(node, "TSQualifiedName"); - } - - return entity; - } - - tsParseTypeReference() { - const node = this.startNode(); - node.typeName = this.tsParseEntityName(false); - - if (!this.hasPrecedingLineBreak() && this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); - } - - return this.finishNode(node, "TSTypeReference"); - } - - tsParseThisTypePredicate(lhs) { - this.next(); - const node = this.startNodeAtNode(lhs); - node.parameterName = lhs; - node.typeAnnotation = this.tsParseTypeAnnotation(false); - return this.finishNode(node, "TSTypePredicate"); - } - - tsParseThisTypeNode() { - const node = this.startNode(); - this.next(); - return this.finishNode(node, "TSThisType"); - } - - tsParseTypeQuery() { - const node = this.startNode(); - this.expect(types._typeof); - - if (this.match(types._import)) { - node.exprName = this.tsParseImportType(); - } else { - node.exprName = this.tsParseEntityName(true); - } - - return this.finishNode(node, "TSTypeQuery"); - } - - 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"); - } - - tsTryParseTypeParameters() { - if (this.isRelational("<")) { - return this.tsParseTypeParameters(); - } - } - - tsParseTypeParameters() { - const node = this.startNode(); - - if (this.isRelational("<") || this.match(types.jsxTagStart)) { - this.next(); - } else { - this.unexpected(); - } - - node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true); - return this.finishNode(node, "TSTypeParameterDeclaration"); - } - - tsFillSignature(returnToken, signature) { - const returnTokenRequired = returnToken === types.arrow; - signature.typeParameters = this.tsTryParseTypeParameters(); - this.expect(types.parenL); - signature.parameters = this.tsParseBindingListForSignature(); - - if (returnTokenRequired) { - signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); - } else if (this.match(returnToken)) { - signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation(returnToken); - } - } - - 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; - }); - } - - tsParseTypeMemberSemicolon() { - if (!this.eat(types.comma)) { - this.semicolon(); - } - } - - tsParseSignatureMember(kind) { - const node = this.startNode(); - - if (kind === "TSConstructSignatureDeclaration") { - this.expect(types._new); - } - - this.tsFillSignature(types.colon, node); - this.tsParseTypeMemberSemicolon(); - return this.finishNode(node, kind); - } - - tsIsUnambiguouslyIndexSignature() { - this.next(); - return this.eat(types.name) && this.match(types.colon); - } - - tsTryParseIndexSignature(node) { - if (!(this.match(types.bracketL) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) { - return undefined; - } - - 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"); - } - - tsParsePropertyOrMethodSignature(node, readonly) { - this.parsePropertyName(node); - if (this.eat(types.question)) node.optional = true; - const nodeAny = node; - - if (!readonly && (this.match(types.parenL) || this.isRelational("<"))) { - const method = nodeAny; - this.tsFillSignature(types.colon, method); - this.tsParseTypeMemberSemicolon(); - return this.finishNode(method, "TSMethodSignature"); - } 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"); - } - } - - tsParseTypeMember() { - if (this.match(types.parenL) || this.isRelational("<")) { - return this.tsParseSignatureMember("TSCallSignatureDeclaration"); - } - - if (this.match(types._new) && this.tsLookAhead(this.tsIsStartOfConstructSignature.bind(this))) { - return this.tsParseSignatureMember("TSConstructSignatureDeclaration"); - } - - const node = this.startNode(); - const readonly = !!this.tsParseModifier(["readonly"]); - const idx = this.tsTryParseIndexSignature(node); - - if (idx) { - if (readonly) node.readonly = true; - return idx; - } - - return this.tsParsePropertyOrMethodSignature(node, readonly); - } - - tsIsStartOfConstructSignature() { - this.next(); - return this.match(types.parenL) || this.isRelational("<"); - } - - tsParseTypeLiteral() { - const node = this.startNode(); - node.members = this.tsParseObjectTypeMembers(); - return this.finishNode(node, "TSTypeLiteral"); - } - - tsParseObjectTypeMembers() { - this.expect(types.braceL); - const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this)); - this.expect(types.braceR); - return members; - } - - tsIsStartOfMappedType() { - this.next(); - - if (this.eat(types.plusMin)) { - return this.isContextual("readonly"); - } - - if (this.isContextual("readonly")) { - this.next(); - } - - if (!this.match(types.bracketL)) { - return false; - } - - this.next(); - - if (!this.tsIsIdentifier()) { - return false; - } - - this.next(); - return this.match(types._in); - } - - tsParseMappedTypeParameter() { - const node = this.startNode(); - node.name = this.parseIdentifierName(node.start); - node.constraint = this.tsExpectThenParseType(types._in); - return this.finishNode(node, "TSTypeParameter"); - } - - tsParseMappedType() { - const node = this.startNode(); - this.expect(types.braceL); - - if (this.match(types.plusMin)) { - node.readonly = this.state.value; - this.next(); - this.expectContextual("readonly"); - } else if (this.eatContextual("readonly")) { - node.readonly = true; - } - - this.expect(types.bracketL); - node.typeParameter = this.tsParseMappedTypeParameter(); - this.expect(types.bracketR); - - 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; - } - - node.typeAnnotation = this.tsTryParseType(); - this.semicolon(); - this.expect(types.braceR); - return this.finishNode(node, "TSMappedType"); - } - - 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"); - } - - 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"); - } - - const type = this.tsParseType(); - - if (this.eat(types.question)) { - const optionalTypeNode = this.startNodeAtNode(type); - optionalTypeNode.typeAnnotation = type; - return this.finishNode(optionalTypeNode, "TSOptionalType"); - } - - return type; - } - - tsParseParenthesizedType() { - const node = this.startNode(); - this.expect(types.parenL); - node.typeAnnotation = this.tsParseType(); - this.expect(types.parenR); - return this.finishNode(node, "TSParenthesizedType"); - } - - tsParseFunctionOrConstructorType(type) { - const node = this.startNode(); - - if (type === "TSConstructorType") { - this.expect(types._new); - } - - this.tsFillSignature(types.arrow, node); - return this.finishNode(node, type); - } - - tsParseLiteralTypeNode() { - const node = this.startNode(); - - node.literal = (() => { - switch (this.state.type) { - case types.num: - return this.parseLiteral(this.state.value, "NumericLiteral"); - - case types.string: - return this.parseLiteral(this.state.value, "StringLiteral"); - - case types._true: - case types._false: - return this.parseBooleanLiteral(); - - default: - throw this.unexpected(); - } - })(); - - return this.finishNode(node, "TSLiteralType"); - } - - 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 (type !== undefined && this.lookahead().type !== types.dot) { - const node = this.startNode(); - this.next(); - return this.finishNode(node, type); - } - - return this.tsParseTypeReference(); - } - - case types.string: - case types.num: - case types._true: - case types._false: - return this.tsParseLiteralTypeNode(); - - case types.plusMin: - if (this.state.value === "-") { - const node = this.startNode(); - this.next(); - - if (!this.match(types.num)) { - throw this.unexpected(); - } - - node.literal = this.parseLiteral(-this.state.value, "NumericLiteral", node.start, node.loc.start); - return this.finishNode(node, "TSLiteralType"); - } - - break; - - case types._this: - { - const thisKeyword = this.tsParseThisTypeNode(); - - if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { - return this.tsParseThisTypePredicate(thisKeyword); - } else { - return thisKeyword; - } - } - - case types._typeof: - return this.tsParseTypeQuery(); - - case types._import: - return this.tsParseImportType(); - - case types.braceL: - return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral(); - - case types.bracketL: - return this.tsParseTupleType(); - - case types.parenL: - return this.tsParseParenthesizedType(); - } - - throw this.unexpected(); - } - - tsParseArrayTypeOrHigher() { - let type = this.tsParseNonArrayType(); - - 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"); - } - } - - return type; - } - - tsParseTypeOperator(operator) { - const node = this.startNode(); - this.expectContextual(operator); - node.operator = operator; - node.typeAnnotation = this.tsParseTypeOperatorOrHigher(); - return this.finishNode(node, "TSTypeOperator"); - } - - 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"); - } - - tsParseTypeOperatorOrHigher() { - const operator = ["keyof", "unique"].find(kw => this.isContextual(kw)); - return operator ? this.tsParseTypeOperator(operator) : this.isContextual("infer") ? this.tsParseInferType() : this.tsParseArrayTypeOrHigher(); - } - - tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) { - this.eat(operator); - let type = parseConstituentType(); - - if (this.match(operator)) { - const types$$1 = [type]; - - while (this.eat(operator)) { - types$$1.push(parseConstituentType()); - } - - 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); - } - - tsParseUnionTypeOrHigher() { - return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), types.bitwiseOR); - } - - tsIsStartOfFunctionType() { - if (this.isRelational("<")) { - return true; - } - - return this.match(types.parenL) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this)); - } - - tsSkipParameterStart() { - if (this.match(types.name) || this.match(types._this)) { - this.next(); - return true; - } - - if (this.match(types.braceL)) { - let braceStackCounter = 1; - this.next(); - - while (braceStackCounter > 0) { - if (this.match(types.braceL)) { - ++braceStackCounter; - } else if (this.match(types.braceR)) { - --braceStackCounter; - } - - this.next(); - } - - 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 true; - } - - return false; - } - - tsIsUnambiguouslyStartOfFunctionType() { - this.next(); - - if (this.match(types.parenR) || this.match(types.ellipsis)) { - return true; - } - - if (this.tsSkipParameterStart()) { - if (this.match(types.colon) || this.match(types.comma) || this.match(types.question) || this.match(types.eq)) { - return true; - } - - if (this.match(types.parenR)) { - this.next(); - - if (this.match(types.arrow)) { - return true; - } - } - } - - return false; - } - - tsParseTypeOrTypePredicateAnnotation(returnToken) { - return this.tsInType(() => { - const t = this.startNode(); - this.expect(returnToken); - const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); - - 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"); - }); - } - - tsTryParseTypeOrTypePredicateAnnotation() { - return this.match(types.colon) ? this.tsParseTypeOrTypePredicateAnnotation(types.colon) : undefined; - } - - tsTryParseTypeAnnotation() { - return this.match(types.colon) ? this.tsParseTypeAnnotation() : undefined; - } - - tsTryParseType() { - return this.tsEatThenParseType(types.colon); - } - - tsParseTypePredicatePrefix() { - const id = this.parseIdentifier(); - - if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { - this.next(); - return id; - } - } - - tsParseTypeAnnotation(eatColon = true, t = this.startNode()) { - this.tsInType(() => { - if (eatColon) this.expect(types.colon); - t.typeAnnotation = this.tsParseType(); - }); - return this.finishNode(t, "TSTypeAnnotation"); - } - - tsParseType() { - assert(this.state.inType); - const type = this.tsParseNonConditionalType(); - - if (this.hasPrecedingLineBreak() || !this.eat(types._extends)) { - return type; - } - - 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"); - } - - tsParseNonConditionalType() { - if (this.tsIsStartOfFunctionType()) { - return this.tsParseFunctionOrConstructorType("TSFunctionType"); - } - - if (this.match(types._new)) { - return this.tsParseFunctionOrConstructorType("TSConstructorType"); - } - - 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)); - - if (!delimitedList.length) { - this.raise(originalStart, `'${descriptor}' list cannot be empty.`); - } - - return delimitedList; - } - - tsParseExpressionWithTypeArguments() { - const node = this.startNode(); - node.expression = this.tsParseEntityName(false); - - if (this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); - } - - return this.finishNode(node, "TSExpressionWithTypeArguments"); - } - - tsParseInterfaceDeclaration(node) { - node.id = this.parseIdentifier(); - node.typeParameters = this.tsTryParseTypeParameters(); - - if (this.eat(types._extends)) { - node.extends = this.tsParseHeritageClause("extends"); - } - - 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"); - } - - tsInNoContext(cb) { - const oldContext = this.state.context; - this.state.context = [oldContext[0]]; - - try { - return cb(); - } finally { - this.state.context = oldContext; - } - } - - tsInType(cb) { - const oldInType = this.state.inType; - this.state.inType = true; - - try { - return cb(); - } finally { - this.state.inType = oldInType; - } - } - - tsEatThenParseType(token) { - return !this.match(token) ? undefined : this.tsNextThenParseType(); - } - - tsExpectThenParseType(token) { - return this.tsDoThenParseType(() => this.expect(token)); - } - - tsNextThenParseType() { - return this.tsDoThenParseType(() => this.next()); - } - - tsDoThenParseType(cb) { - return this.tsInType(() => { - cb(); - return this.tsParseType(); - }); - } - - tsParseEnumMember() { - const node = this.startNode(); - node.id = this.match(types.string) ? this.parseLiteral(this.state.value, "StringLiteral") : this.parseIdentifier(true); - - if (this.eat(types.eq)) { - node.initializer = this.parseMaybeAssign(); - } - - return this.finishNode(node, "TSEnumMember"); - } - - 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"); - } - - tsParseModuleBlock() { - const node = this.startNode(); - this.expect(types.braceL); - this.parseBlockOrModuleBlockBody(node.body = [], undefined, true, types.braceR); - return this.finishNode(node, "TSModuleBlock"); - } - - tsParseModuleOrNamespaceDeclaration(node) { - node.id = this.parseIdentifier(); - - if (this.eat(types.dot)) { - const inner = this.startNode(); - this.tsParseModuleOrNamespaceDeclaration(inner); - node.body = inner; - } else { - node.body = this.tsParseModuleBlock(); - } - - return this.finishNode(node, "TSModuleDeclaration"); - } - - 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 (this.match(types.braceL)) { - node.body = this.tsParseModuleBlock(); - } else { - 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"); - } - - tsIsExternalModuleReference() { - return this.isContextual("require") && this.lookahead().type === types.parenL; - } - - tsParseModuleReference() { - return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false); - } - - tsParseExternalModuleReference() { - const node = this.startNode(); - this.expectContextual("require"); - this.expect(types.parenL); - - if (!this.match(types.string)) { - throw this.unexpected(); - } - - 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(); - - try { - return f(); - } catch (e) { - if (e instanceof SyntaxError) { - this.state = state; - return undefined; - } - - throw e; - } - } - - tsTryParse(f) { - const state = this.state.clone(); - const result = f(); - - if (result !== undefined && result !== false) { - return result; - } else { - this.state = state; - return undefined; - } - } - - nodeWithSamePosition(original, type) { - const node = this.startNodeAtNode(original); - node.type = type; - node.end = original.end; - node.loc.end = original.loc.end; - - if (original.leadingComments) { - node.leadingComments = original.leadingComments; - } - - if (original.trailingComments) { - node.trailingComments = original.trailingComments; - } - - if (original.innerComments) node.innerComments = original.innerComments; - return node; - } - - tsTryParseDeclare(nany) { - if (this.isLineTerminator()) { - return; - } - - let starttype = this.state.type; - let kind; - - if (this.isContextual("let")) { - starttype = types._var; - kind = "let"; - } - - switch (starttype) { - case types._function: - this.next(); - return this.parseFunction(nany, true); - - case types._class: - return this.parseClass(nany, true, false); - - case types._const: - if (this.match(types._const) && this.isLookaheadContextual("enum")) { - this.expect(types._const); - this.expectContextual("enum"); - return this.tsParseEnumDeclaration(nany, true); - } - - case types._var: - kind = kind || this.state.value; - return this.parseVarStatement(nany, kind); - - case types.name: - { - const value = this.state.value; - - if (value === "global") { - return this.tsParseAmbientExternalModuleDeclaration(nany); - } else { - return this.tsParseDeclaration(nany, value, true); - } - } - } - } - - tsTryParseExportDeclaration() { - return this.tsParseDeclaration(this.startNode(), this.state.value, true); - } - - tsParseExpressionStatement(node, expr) { - switch (expr.name) { - case "declare": - { - const declaration = this.tsTryParseDeclare(node); - - if (declaration) { - declaration.declare = true; - return declaration; - } - - break; - } - - 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"); - } - - break; - - default: - return this.tsParseDeclaration(node, expr.name, false); - } - } - - tsParseDeclaration(node, value, next) { - switch (value) { - case "abstract": - if (this.tsCheckLineTerminatorAndMatch(types._class, next)) { - const cls = node; - cls.abstract = true; - - if (next) { - this.next(); - - if (!this.match(types._class)) { - this.unexpected(null, types._class); - } - } - - return this.parseClass(cls, true, false); - } - - break; - - case "enum": - if (next || this.match(types.name)) { - if (next) this.next(); - return this.tsParseEnumDeclaration(node, false); - } - - break; - - case "interface": - if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - if (next) this.next(); - return this.tsParseInterfaceDeclaration(node); - } - - break; - - case "module": - if (next) this.next(); - - if (this.match(types.string)) { - return this.tsParseAmbientExternalModuleDeclaration(node); - } else if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - return this.tsParseModuleOrNamespaceDeclaration(node); - } - - break; - - case "namespace": - if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - if (next) this.next(); - return this.tsParseModuleOrNamespaceDeclaration(node); - } - - break; - - case "type": - if (this.tsCheckLineTerminatorAndMatch(types.name, next)) { - if (next) this.next(); - return this.tsParseTypeAliasDeclaration(node); - } - - break; - } - } - - tsCheckLineTerminatorAndMatch(tokenType, next) { - return (next || this.match(tokenType)) && !this.isLineTerminator(); - } - - 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; - }); - - if (!res) { - return undefined; - } - - 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"); - } - - 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"); - } - - 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 false; - } - - isExportDefaultSpecifier() { - if (this.tsIsDeclarationStart()) return false; - return super.isExportDefaultSpecifier(); - } - - parseAssignableListItem(allowModifiers, decorators) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - let accessibility; - let readonly = false; - - if (allowModifiers) { - accessibility = this.parseAccessModifier(); - readonly = !!this.tsParseModifier(["readonly"]); - } - - const left = this.parseMaybeDefault(); - this.parseAssignableListItemTypes(left); - const elt = this.parseMaybeDefault(left.start, left.loc.start, left); - - if (accessibility || readonly) { - const pp = this.startNodeAt(startPos, startLoc); - - if (decorators.length) { - pp.decorators = decorators; - } - - if (accessibility) pp.accessibility = accessibility; - if (readonly) pp.readonly = readonly; - - if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { - throw this.raise(pp.start, "A parameter property may not be declared using a binding pattern."); - } - - pp.parameter = elt; - return this.finishNode(pp, "TSParameterProperty"); - } - - if (decorators.length) { - left.decorators = decorators; - } - - return elt; - } - - parseFunctionBodyAndFinish(node, type, allowExpressionBody) { - if (!allowExpressionBody && 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, allowExpressionBody); - } - - 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 (this.isRelational("<")) { - const result = this.tsTryParseAndCatch(() => { - if (!noCalls && this.atPossibleAsync(base)) { - const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc); - - if (asyncArrowFn) { - return asyncArrowFn; - } - } - - const node = this.startNodeAt(startPos, startLoc); - node.callee = base; - const typeArguments = this.tsParseTypeArguments(); - - 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.unexpected(); - }); - if (result) return result; - } - - return super.parseSubscript(base, startPos, startLoc, noCalls, state); - } - - parseNewArguments(node) { - if (this.isRelational("<")) { - const typeParameters = this.tsTryParseAndCatch(() => { - const args = this.tsParseTypeArguments(); - if (!this.match(types.parenL)) this.unexpected(); - return args; - }); - - if (typeParameters) { - node.typeParameters = typeParameters; - } - } - - super.parseNewArguments(node); - } - - 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); - } - - return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn); - } - - checkReservedWord(word, startLoc, checkKeywords, isBinding) {} - - checkDuplicateExports() {} - - parseImport(node) { - if (this.match(types.name) && this.lookahead().type === types.eq) { - return this.tsParseImportEqualsDeclaration(node); - } - - return super.parseImport(node); - } - - 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); - } - } - - isAbstractClass() { - return this.isContextual("abstract") && this.lookahead().type === types._class; - } - - parseExportDefaultExpression() { - if (this.isAbstractClass()) { - const cls = this.startNode(); - this.next(); - this.parseClass(cls, true, true); - cls.abstract = true; - return cls; - } - - if (this.state.value === "interface") { - const result = this.tsParseDeclaration(this.startNode(), this.state.value, true); - if (result) return result; - } - - return super.parseExportDefaultExpression(); - } - - parseStatementContent(context, topLevel) { - if (this.state.type === types._const) { - const ahead = this.lookahead(); - - if (ahead.type === types.name && ahead.value === "enum") { - const node = this.startNode(); - this.expect(types._const); - this.expectContextual("enum"); - return this.tsParseEnumDeclaration(node, true); - } - } - - return super.parseStatementContent(context, topLevel); - } - - parseAccessModifier() { - return this.tsParseModifier(["public", "protected", "private"]); - } - - parseClassMember(classBody, member, state) { - const accessibility = this.parseAccessModifier(); - if (accessibility) member.accessibility = accessibility; - super.parseClassMember(classBody, member, state); - } - - 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"]); - - switch (mod) { - case "readonly": - readonly = true; - abstract = !!this.tsParseModifier(["abstract"]); - break; - - case "abstract": - abstract = true; - readonly = !!this.tsParseModifier(["readonly"]); - break; - } - - if (abstract) methodOrProp.abstract = true; - if (readonly) propOrIdx.readonly = true; - - if (!abstract && !isStatic && !methodOrProp.accessibility) { - const idx = this.tsTryParseIndexSignature(member); - - if (idx) { - classBody.body.push(idx); - return; - } - } - - if (readonly) { - methodOrProp.static = isStatic; - this.parseClassPropertyName(prop); - this.parsePostMemberNameModifiers(methodOrProp); - this.pushClassProperty(classBody, prop); - return; - } - - super.parseClassMemberWithIsStatic(classBody, member, state, isStatic); - } - - parsePostMemberNameModifiers(methodOrProp) { - const optional = this.eat(types.question); - if (optional) methodOrProp.optional = true; - } - - parseExpressionStatement(node, expr) { - const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr) : undefined; - return decl || super.parseExpressionStatement(node, expr); - } - - shouldParseExportDeclaration() { - if (this.tsIsDeclarationStart()) return true; - return super.shouldParseExportDeclaration(); - } - - parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) { - if (!refNeedsArrowPos || !this.match(types.question)) { - return super.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos); - } - - const state = this.state.clone(); - - try { - return super.parseConditional(expr, noIn, startPos, startLoc); - } catch (err) { - if (!(err instanceof SyntaxError)) { - throw err; - } - - this.state = state; - refNeedsArrowPos.start = err.pos || this.state.start; - return expr; - } - } - - parseParenItem(node, startPos, startLoc) { - node = super.parseParenItem(node, startPos, startLoc); - - if (this.eat(types.question)) { - node.optional = true; - } - - if (this.match(types.colon)) { - const typeCastNode = this.startNodeAt(startPos, startLoc); - typeCastNode.expression = node; - typeCastNode.typeAnnotation = this.tsParseTypeAnnotation(); - return this.finishNode(typeCastNode, "TSTypeCastExpression"); - } - - return this.finishNode(node, node.type); - } - - parseExportDeclaration(node) { - const startPos = this.state.start; - const startLoc = this.state.startLoc; - const isDeclare = this.eatContextual("declare"); - let declaration; - - if (this.match(types.name)) { - declaration = this.tsTryParseExportDeclaration(); - } - - if (!declaration) { - declaration = super.parseExportDeclaration(node); - } - - if (declaration && isDeclare) { - this.resetStartLocation(declaration, startPos, startLoc); - declaration.declare = true; - } - - return declaration; - } - - parseClassId(node, isStatement, optionalId) { - if ((!isStatement || optionalId) && this.isContextual("implements")) { - return; - } - - super.parseClassId(...arguments); - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) node.typeParameters = typeParameters; - } - - parseClassProperty(node) { - if (!node.optional && this.eat(types.bang)) { - node.definite = true; - } - - const type = this.tsTryParseTypeAnnotation(); - if (type) node.typeAnnotation = type; - return super.parseClassProperty(node); - } - - pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) method.typeParameters = typeParameters; - super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor); - } - - pushClassPrivateMethod(classBody, method, isGenerator, isAsync) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) method.typeParameters = typeParameters; - super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); - } - - parseClassSuper(node) { - super.parseClassSuper(node); - - if (node.superClass && this.isRelational("<")) { - node.superTypeParameters = this.tsParseTypeArguments(); - } - - if (this.eatContextual("implements")) { - node.implements = this.tsParseHeritageClause("implements"); - } - } - - parseObjPropValue(prop, ...args) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) prop.typeParameters = typeParameters; - super.parseObjPropValue(prop, ...args); - } - - parseFunctionParams(node, allowModifiers) { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) node.typeParameters = typeParameters; - super.parseFunctionParams(node, allowModifiers); - } - - parseVarId(decl, kind) { - super.parseVarId(decl, kind); - - if (decl.id.type === "Identifier" && this.eat(types.bang)) { - decl.definite = true; - } - - const type = this.tsTryParseTypeAnnotation(); - - if (type) { - decl.id.typeAnnotation = type; - this.finishNode(decl.id, decl.id.type); - } - } - - parseAsyncArrowFromCallExpression(node, call) { - if (this.match(types.colon)) { - node.returnType = this.tsParseTypeAnnotation(); - } - - return super.parseAsyncArrowFromCallExpression(node, call); - } - - 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(); - - try { - return super.parseMaybeAssign(...args); - } catch (err) { - if (!(err instanceof SyntaxError)) { - throw err; - } - - 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); - } - - let arrowExpression; - let typeParameters; - const state = this.state.clone(); - - try { - typeParameters = this.tsParseTypeParameters(); - arrowExpression = super.parseMaybeAssign(...args); - - if (arrowExpression.type !== "ArrowFunctionExpression") { - this.unexpected(); - } - } catch (err) { - if (!(err instanceof SyntaxError)) { - throw err; - } - - if (jsxError) { - throw jsxError; - } - - assert(!this.hasPlugin("jsx")); - this.state = state; - return super.parseMaybeAssign(...args); - } - - if (typeParameters && typeParameters.params.length !== 0) { - this.resetStartLocationFromNode(arrowExpression, typeParameters); - } - - arrowExpression.typeParameters = typeParameters; - return arrowExpression; - } - - parseMaybeUnary(refShorthandDefaultPos) { - if (!this.hasPlugin("jsx") && this.isRelational("<")) { - return this.tsParseTypeAssertion(); - } else { - return super.parseMaybeUnary(refShorthandDefaultPos); - } - } - - parseArrow(node) { - if (this.match(types.colon)) { - const state = this.state.clone(); - - 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; - } else { - throw err; - } - } - } - - return super.parseArrow(node); - } - - 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); - } - - toAssignable(node, isBinding, contextDescription) { - switch (node.type) { - case "TSTypeCastExpression": - return super.toAssignable(this.typeCastToParameter(node), isBinding, contextDescription); - - case "TSParameterProperty": - return super.toAssignable(node, isBinding, contextDescription); - - case "TSAsExpression": - case "TSNonNullExpression": - case "TSTypeAssertion": - node.expression = this.toAssignable(node.expression, isBinding, contextDescription); - return node; - - default: - return super.toAssignable(node, isBinding, contextDescription); - } - } - - 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; - - default: - super.checkLVal(expr, isBinding, checkClashes, contextDescription); - return; - } - } - - parseBindingAtom() { - switch (this.state.type) { - case types._this: - return this.parseIdentifier(true); - - default: - return super.parseBindingAtom(); - } - } - - parseMaybeDecoratorArguments(expr) { - if (this.isRelational("<")) { - const typeArguments = this.tsParseTypeArguments(); - - if (this.match(types.parenL)) { - const call = super.parseMaybeDecoratorArguments(expr); - call.typeParameters = typeArguments; - return call; - } - - this.unexpected(this.state.start, types.parenL); - } - - return super.parseMaybeDecoratorArguments(expr); - } - - isClassMethod() { - return this.isRelational("<") || super.isClassMethod(); - } - - isClassProperty() { - return this.match(types.bang) || this.match(types.colon) || super.isClassProperty(); - } - - parseMaybeDefault(...args) { - const node = super.parseMaybeDefault(...args); - - 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`"); - } - - return node; - } - - getTokenFromCode(code) { - if (this.state.inType && (code === 62 || code === 60)) { - return this.finishOp(types.relational, 1); - } else { - return super.getTokenFromCode(code); - } - } - - 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); - } - - typeCastToParameter(node) { - node.expression.typeAnnotation = node.typeAnnotation; - return this.finishNodeAt(node.expression, node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end); - } - - 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."); - } - } - - return exprList; - } - - shouldParseArrow() { - return this.match(types.colon) || super.shouldParseArrow(); - } - - shouldParseAsyncArrow() { - return this.match(types.colon) || super.shouldParseAsyncArrow(); - } - - canHaveLeadingDecorator() { - return super.canHaveLeadingDecorator() || this.isAbstractClass(); - } - - jsxParseOpeningElementAfterName(node) { - const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArguments()); - if (typeArguments) node.typeParameters = typeArguments; - return super.jsxParseOpeningElementAfterName(node); - } - -}); - -function hasPlugin(plugins, name) { - return plugins.some(plugin => { - if (Array.isArray(plugin)) { - return plugin[0] === name; - } else { - return plugin === name; - } - }); -} -function getPluginOption(plugins, name, option) { - const plugin = plugins.find(plugin => { - if (Array.isArray(plugin)) { - return plugin[0] === name; - } else { - return plugin === name; - } - }); - - if (plugin && Array.isArray(plugin)) { - return plugin[1][option]; - } - - 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"); - - 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 (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) { - throw new Error("Cannot combine flow and typescript plugins."); - } - - 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 mixinPluginNames = ["estree", "jsx", "flow", "typescript"]; -const mixinPlugins = { - estree, - jsx, - flow, - typescript -}; - function parse(input, options) { if (options && options.sourceType === "unambiguous") { options = Object.assign({}, options); @@ -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<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>; + arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>; 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<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>; + arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>; optional?: true | false; typeArguments?: BabelNodeTypeParameterInstantiation; typeParameters?: BabelNodeTSTypeParameterInstantiation; @@ -297,6 +297,11 @@ declare class BabelNodeSequenceExpression extends BabelNode { expressions: Array<BabelNodeExpression>; } +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<BabelNodeIdentifier | BabelNodeRestElement>; + parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>; typeAnnotation?: BabelNodeTSTypeAnnotation; } declare class BabelNodeTSConstructSignatureDeclaration extends BabelNode { type: "TSConstructSignatureDeclaration"; typeParameters?: BabelNodeTSTypeParameterDeclaration; - parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>; + parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>; typeAnnotation?: BabelNodeTSTypeAnnotation; } @@ -1120,7 +1130,7 @@ declare class BabelNodeTSMethodSignature extends BabelNode { type: "TSMethodSignature"; key: BabelNodeExpression; typeParameters?: BabelNodeTSTypeParameterDeclaration; - parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>; + parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>; 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<BabelNodeIdentifier | BabelNodeRestElement>; typeAnnotation?: BabelNodeTSTypeAnnotation; - parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>; } declare class BabelNodeTSConstructorType extends BabelNode { type: "TSConstructorType"; typeParameters?: BabelNodeTSTypeParameterDeclaration; + parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>; typeAnnotation?: BabelNodeTSTypeAnnotation; - parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>; } 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<BabelNodeStatement>, directives?: Array<BabelNodeDirective>): BabelNodeBlockStatement; declare function breakStatement(label?: BabelNodeIdentifier): BabelNodeBreakStatement; - declare function callExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeCallExpression; + declare function callExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>, 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<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeNewExpression; + declare function newExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeNewExpression; declare function program(body: Array<BabelNodeStatement>, directives?: Array<BabelNodeDirective>, sourceType?: "script" | "module", interpreter?: BabelNodeInterpreterDirective, sourceFile?: string): BabelNodeProgram; declare function objectExpression(properties: Array<BabelNodeObjectMethod | BabelNodeObjectProperty | BabelNodeSpreadElement>): BabelNodeObjectExpression; declare function objectMethod(kind?: "method" | "get" | "set", key: any, params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement | BabelNodeTSParameterProperty>, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: Array<BabelNodeDecorator>, 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<BabelNodeDecorator>, typeAnnotation?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop): BabelNodeRestElement; declare function returnStatement(argument?: BabelNodeExpression): BabelNodeReturnStatement; declare function sequenceExpression(expressions: Array<BabelNodeExpression>): BabelNodeSequenceExpression; + declare function parenthesizedExpression(expression: BabelNodeExpression): BabelNodeParenthesizedExpression; declare function switchCase(test?: BabelNodeExpression, consequent: Array<BabelNodeStatement>): BabelNodeSwitchCase; declare function switchStatement(discriminant: BabelNodeExpression, cases: Array<BabelNodeSwitchCase>): 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<BabelNodeDecorator>, 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<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement | BabelNodeTSParameterProperty>, returnType?: BabelNodeTSTypeAnnotation | BabelNodeNoop, async?: boolean, declare?: boolean, generator?: boolean): BabelNodeTSDeclareFunction; declare function tsDeclareMethod(decorators?: Array<BabelNodeDecorator>, key: BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration | BabelNodeNoop, params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement | BabelNodeTSParameterProperty>, 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<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSCallSignatureDeclaration; - declare function tsConstructSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructSignatureDeclaration; + declare function tsCallSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSCallSignatureDeclaration; + declare function tsConstructSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, 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<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation, computed?: boolean, optional?: boolean): BabelNodeTSMethodSignature; + declare function tsMethodSignature(key: BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation, computed?: boolean, optional?: boolean): BabelNodeTSMethodSignature; declare function tsIndexSignature(parameters: Array<BabelNodeIdentifier>, 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<BabelNodeIdentifier | BabelNodeRestElement>): BabelNodeTSFunctionType; - declare function tsConstructorType(typeParameters?: BabelNodeTSTypeParameterDeclaration, typeAnnotation?: BabelNodeTSTypeAnnotation, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>): BabelNodeTSConstructorType; + declare function tsFunctionType(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSFunctionType; + declare function tsConstructorType(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, 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" |