diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-05-14 14:05:49 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-05-14 14:05:49 +0800 |
| commit | 06823fbf1c2e763a5bf76c3990ca98fbbcd98691 (patch) | |
| tree | 4280bece3888d12a022093bf1a9cd1b049393602 /node_modules/@babel/parser/lib/index.js | |
| parent | 1368909b3cd552dbb0d12d5863c597f5be46177d (diff) | |
updated node_modules
Diffstat (limited to 'node_modules/@babel/parser/lib/index.js')
| -rw-r--r-- | node_modules/@babel/parser/lib/index.js | 1866 |
1 files changed, 716 insertions, 1150 deletions
diff --git a/node_modules/@babel/parser/lib/index.js b/node_modules/@babel/parser/lib/index.js index 68ee00ca..63373c8c 100644 --- a/node_modules/@babel/parser/lib/index.js +++ b/node_modules/@babel/parser/lib/index.js @@ -79,10 +79,7 @@ const NodeDescriptions = { VariableDeclarator: "variable declaration", YieldExpression: "yield expression" }; -const toNodeDescription = ({ - type, - prefix -}) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type]; +const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type]; var StandardErrors = { AccessorIsGenerator: ({ kind @@ -293,6 +290,7 @@ var StandardErrors = { UnterminatedRegExp: "Unterminated regular expression.", UnterminatedString: "Unterminated string constant.", UnterminatedTemplate: "Unterminated template.", + UsingDeclarationExport: "Using declaration cannot be exported.", UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.", VarRedeclaration: ({ identifierName @@ -335,8 +333,8 @@ var PipelineOperatorErrors = { PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.", PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.' }; -const _excluded$1 = ["toMessage"], - _excluded2$1 = ["message"]; +const _excluded = ["toMessage"], + _excluded2 = ["message"]; function defineHidden(obj, key, value) { Object.defineProperty(obj, key, { enumerable: false, @@ -348,11 +346,8 @@ function toParseErrorConstructor(_ref) { let { toMessage } = _ref, - properties = _objectWithoutPropertiesLoose(_ref, _excluded$1); - return function constructor({ - loc, - details - }) { + properties = _objectWithoutPropertiesLoose(_ref, _excluded); + return function constructor(loc, details) { const error = new SyntaxError(); Object.assign(error, properties, { loc, @@ -370,10 +365,7 @@ function toParseErrorConstructor(_ref) { column, index } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc; - return constructor({ - loc: new Position(line, column, index), - details: Object.assign({}, details, overrides.details) - }); + return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details)); }); defineHidden(error, "details", details); Object.defineProperty(error, "message", { @@ -408,7 +400,7 @@ function ParseErrorEnum(argument, syntaxPlugin) { { message } = _ref2, - rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1); + rest = _objectWithoutPropertiesLoose(_ref2, _excluded2); const toMessage = typeof message === "string" ? () => message : message; ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({ code: "BABEL_PARSER_SYNTAX_ERROR", @@ -588,6 +580,10 @@ var estree = superClass => class ESTreeParserMixin extends superClass { } return this.finishNode(node, "MethodDefinition"); } + nameIsConstructor(key) { + if (key.type === "Literal") return key.value === "constructor"; + return super.nameIsConstructor(key); + } parseClassProperty(...args) { const propertyNode = super.parseClassProperty(...args); { @@ -652,14 +648,10 @@ var estree = superClass => class ESTreeParserMixin extends superClass { } } toAssignableObjectExpressionProp(prop, isLast, isLHS) { - if (prop.kind === "get" || prop.kind === "set") { - this.raise(Errors.PatternHasAccessor, { - at: prop.key - }); - } else if (prop.method) { - this.raise(Errors.PatternHasMethod, { - at: prop.key - }); + if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) { + this.raise(Errors.PatternHasAccessor, prop.key); + } else if (prop.type === "Property" && prop.method) { + this.raise(Errors.PatternHasMethod, prop.key); } else { super.toAssignableObjectExpressionProp(prop, isLast, isLHS); } @@ -670,9 +662,9 @@ var estree = superClass => class ESTreeParserMixin extends superClass { node.type = "ImportExpression"; node.source = node.arguments[0]; if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) { - var _node$arguments$, _node$arguments$2; - node.options = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null; - node.attributes = (_node$arguments$2 = node.arguments[1]) != null ? _node$arguments$2 : null; + var _ref, _ref2; + node.options = (_ref = node.arguments[1]) != null ? _ref : null; + node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null; } delete node.arguments; delete node.callee; @@ -744,7 +736,7 @@ var estree = superClass => class ESTreeParserMixin extends superClass { return node.type === "Property" && node.kind === "init" && !node.method; } isObjectMethod(node) { - return node.method || node.kind === "get" || node.kind === "set"; + return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set"); } finishNodeAt(node, type, endLoc) { return toESTreeLocation(super.finishNodeAt(node, type, endLoc)); @@ -1395,9 +1387,9 @@ function canBeReservedWord(word) { } class Scope { constructor(flags) { - this.var = new Set(); - this.lexical = new Set(); - this.functions = new Set(); + this.flags = 0; + this.names = new Map(); + this.firstLexicalName = ""; this.flags = flags; } } @@ -1465,11 +1457,16 @@ class ScopeHandler { let scope = this.currentScope(); if (bindingType & 8 || bindingType & 16) { this.checkRedeclarationInScope(scope, name, bindingType, loc); + let type = scope.names.get(name) || 0; if (bindingType & 16) { - scope.functions.add(name); + type = type | 4; } else { - scope.lexical.add(name); + if (!scope.firstLexicalName) { + scope.firstLexicalName = name; + } + type = type | 2; } + scope.names.set(name, type); if (bindingType & 8) { this.maybeExportDefined(scope, name); } @@ -1477,7 +1474,7 @@ class ScopeHandler { for (let i = this.scopeStack.length - 1; i >= 0; --i) { scope = this.scopeStack[i]; this.checkRedeclarationInScope(scope, name, bindingType, loc); - scope.var.add(name); + scope.names.set(name, (scope.names.get(name) || 0) | 1); this.maybeExportDefined(scope, name); if (scope.flags & 387) break; } @@ -1493,8 +1490,7 @@ class ScopeHandler { } checkRedeclarationInScope(scope, name, bindingType, loc) { if (this.isRedeclaredInScope(scope, name, bindingType)) { - this.parser.raise(Errors.VarRedeclaration, { - at: loc, + this.parser.raise(Errors.VarRedeclaration, loc, { identifierName: name }); } @@ -1502,19 +1498,20 @@ class ScopeHandler { isRedeclaredInScope(scope, name, bindingType) { if (!(bindingType & 1)) return false; if (bindingType & 8) { - return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name); + return scope.names.has(name); } + const type = scope.names.get(name); if (bindingType & 16) { - return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name); + return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0; } - return scope.lexical.has(name) && !(scope.flags & 8 && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name); + return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0; } checkLocalExport(id) { const { name } = id; const topLevelScope = this.scopeStack[0]; - if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) { + if (!topLevelScope.names.has(name)) { this.undefinedExports.set(name, id.loc.start); } } @@ -1564,8 +1561,9 @@ class FlowScopeHandler extends ScopeHandler { } isRedeclaredInScope(scope, name, bindingType) { if (super.isRedeclaredInScope(scope, name, bindingType)) return true; - if (bindingType & 2048) { - return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name)); + if (bindingType & 2048 && !scope.declareFunctions.has(name)) { + const type = scope.names.get(name); + return (type & 4) > 0 || (type & 2) > 0; } return false; } @@ -1638,7 +1636,14 @@ function adjustInnerComments(node, elements, commentWS) { class CommentsParser extends BaseParser { addComment(comment) { if (this.filename) comment.loc.filename = this.filename; - this.state.comments.push(comment); + const { + commentsLen + } = this.state; + if (this.comments.length !== commentsLen) { + this.comments.length = commentsLen; + } + this.comments.push(comment); + this.state.commentsLen++; } processComment(node) { const { @@ -1827,7 +1832,7 @@ function isWhitespace(code) { } class State { constructor() { - this.strict = void 0; + this.flags = 1024; this.curLine = void 0; this.lineStart = void 0; this.startLoc = void 0; @@ -1836,21 +1841,12 @@ class State { this.potentialArrowAt = -1; this.noArrowAt = []; this.noArrowParamsConversionAt = []; - this.maybeInArrowParameters = false; - this.inType = false; - this.noAnonFunctionType = false; - this.hasFlowComment = false; - this.isAmbientContext = false; - this.inAbstractClass = false; - this.inDisallowConditionalTypesContext = false; this.topicContext = { maxNumOfResolvableTopics: 0, maxTopicIndex: null }; - this.soloAwait = false; - this.inFSharpPipelineDirectBody = false; this.labels = []; - this.comments = []; + this.commentsLen = 0; this.commentStack = []; this.pos = 0; this.type = 139; @@ -1859,14 +1855,21 @@ class State { this.end = 0; this.lastTokEndLoc = null; this.lastTokStartLoc = null; - this.lastTokStart = 0; this.context = [types.brace]; - this.canStartJSXElement = true; - this.containsEsc = false; this.firstInvalidTemplateEscapePos = null; this.strictErrors = new Map(); this.tokensLength = 0; } + get strict() { + return (this.flags & 1) > 0; + } + set strict(value) { + if (value) { + this.flags |= 1; + } else { + this.flags &= ~1; + } + } init({ strictMode, sourceType, @@ -1878,20 +1881,145 @@ class State { this.lineStart = -startColumn; this.startLoc = this.endLoc = new Position(startLine, startColumn, 0); } + get maybeInArrowParameters() { + return (this.flags & 2) > 0; + } + set maybeInArrowParameters(value) { + if (value) { + this.flags |= 2; + } else { + this.flags &= ~2; + } + } + get inType() { + return (this.flags & 4) > 0; + } + set inType(value) { + if (value) { + this.flags |= 4; + } else { + this.flags &= ~4; + } + } + get noAnonFunctionType() { + return (this.flags & 8) > 0; + } + set noAnonFunctionType(value) { + if (value) { + this.flags |= 8; + } else { + this.flags &= ~8; + } + } + get hasFlowComment() { + return (this.flags & 16) > 0; + } + set hasFlowComment(value) { + if (value) { + this.flags |= 16; + } else { + this.flags &= ~16; + } + } + get isAmbientContext() { + return (this.flags & 32) > 0; + } + set isAmbientContext(value) { + if (value) { + this.flags |= 32; + } else { + this.flags &= ~32; + } + } + get inAbstractClass() { + return (this.flags & 64) > 0; + } + set inAbstractClass(value) { + if (value) { + this.flags |= 64; + } else { + this.flags &= ~64; + } + } + get inDisallowConditionalTypesContext() { + return (this.flags & 128) > 0; + } + set inDisallowConditionalTypesContext(value) { + if (value) { + this.flags |= 128; + } else { + this.flags &= ~128; + } + } + get soloAwait() { + return (this.flags & 256) > 0; + } + set soloAwait(value) { + if (value) { + this.flags |= 256; + } else { + this.flags &= ~256; + } + } + get inFSharpPipelineDirectBody() { + return (this.flags & 512) > 0; + } + set inFSharpPipelineDirectBody(value) { + if (value) { + this.flags |= 512; + } else { + this.flags &= ~512; + } + } + get canStartJSXElement() { + return (this.flags & 1024) > 0; + } + set canStartJSXElement(value) { + if (value) { + this.flags |= 1024; + } else { + this.flags &= ~1024; + } + } + get containsEsc() { + return (this.flags & 2048) > 0; + } + set containsEsc(value) { + if (value) { + this.flags |= 2048; + } else { + this.flags &= ~2048; + } + } curPosition() { return new Position(this.curLine, this.pos - this.lineStart, this.pos); } - clone(skipArrays) { + clone() { const state = new State(); - const keys = Object.keys(this); - for (let i = 0, length = keys.length; i < length; i++) { - const key = keys[i]; - let val = this[key]; - if (!skipArrays && Array.isArray(val)) { - val = val.slice(); - } - state[key] = val; - } + state.flags = this.flags; + state.curLine = this.curLine; + state.lineStart = this.lineStart; + state.startLoc = this.startLoc; + state.endLoc = this.endLoc; + state.errors = this.errors.slice(); + state.potentialArrowAt = this.potentialArrowAt; + state.noArrowAt = this.noArrowAt.slice(); + state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice(); + state.topicContext = this.topicContext; + state.labels = this.labels.slice(); + state.commentsLen = this.commentsLen; + state.commentStack = this.commentStack.slice(); + state.pos = this.pos; + state.type = this.type; + state.value = this.value; + state.start = this.start; + state.end = this.end; + state.lastTokEndLoc = this.lastTokEndLoc; + state.lastTokStartLoc = this.lastTokStartLoc; + state.context = this.context.slice(); + state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos; + state.strictErrors = this.strictErrors; + state.tokensLength = this.tokensLength; return state; } } @@ -2180,8 +2308,6 @@ function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) { pos }; } -const _excluded = ["at"], - _excluded2 = ["at"]; function buildPosition(pos, lineStart, curLine) { return new Position(curLine, pos - lineStart, pos); } @@ -2203,8 +2329,7 @@ class Tokenizer extends CommentsParser { this.errorHandlers_readInt = { invalidDigit: (pos, lineStart, curLine, radix) => { if (!this.options.errorRecovery) return false; - this.raise(Errors.InvalidDigit, { - at: buildPosition(pos, lineStart, curLine), + this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), { radix }); return true; @@ -2218,28 +2343,23 @@ class Tokenizer extends CommentsParser { }); this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, { strictNumericEscape: (pos, lineStart, curLine) => { - this.recordStrictModeErrors(Errors.StrictNumericEscape, { - at: buildPosition(pos, lineStart, curLine) - }); + this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine)); }, unterminated: (pos, lineStart, curLine) => { - throw this.raise(Errors.UnterminatedString, { - at: buildPosition(pos - 1, lineStart, curLine) - }); + throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine)); } }); this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, { strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape), unterminated: (pos, lineStart, curLine) => { - throw this.raise(Errors.UnterminatedTemplate, { - at: buildPosition(pos, lineStart, curLine) - }); + throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine)); } }); this.state = new State(); this.state.init(options); this.input = input; this.length = input.length; + this.comments = []; this.isLookahead = false; } pushToken(token) { @@ -2252,7 +2372,6 @@ class Tokenizer extends CommentsParser { if (this.options.tokens) { this.pushToken(new Token(this.state)); } - this.state.lastTokStart = this.state.start; this.state.lastTokEndLoc = this.state.endLoc; this.state.lastTokStartLoc = this.state.startLoc; this.nextToken(); @@ -2327,9 +2446,7 @@ class Tokenizer extends CommentsParser { setStrict(strict) { this.state.strict = strict; if (strict) { - this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, { - at - })); + this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at)); this.state.strictErrors.clear(); } } @@ -2352,9 +2469,7 @@ class Tokenizer extends CommentsParser { const start = this.state.pos; const end = this.input.indexOf(commentEnd, start + 2); if (end === -1) { - throw this.raise(Errors.UnterminatedComment, { - at: this.state.curPosition() - }); + throw this.raise(Errors.UnterminatedComment, this.state.curPosition()); } this.state.pos = end + commentEnd.length; lineBreakG.lastIndex = start + 2; @@ -2506,16 +2621,12 @@ class Tokenizer extends CommentsParser { const nextPos = this.state.pos + 1; const next = this.codePointAtPos(nextPos); if (next >= 48 && next <= 57) { - throw this.raise(Errors.UnexpectedDigitAfterHash, { - at: this.state.curPosition() - }); + throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition()); } if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) { this.expectPlugin("recordAndTuple"); if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") { - throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, { - at: this.state.curPosition() - }); + throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition()); } this.state.pos += 2; if (next === 123) { @@ -2600,9 +2711,7 @@ class Tokenizer extends CommentsParser { } if (this.hasPlugin("recordAndTuple") && next === 125) { if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") { - throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, { - at: this.state.curPosition() - }); + throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition()); } this.state.pos += 2; this.finishToken(9); @@ -2610,9 +2719,7 @@ class Tokenizer extends CommentsParser { } if (this.hasPlugin("recordAndTuple") && next === 93) { if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") { - throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, { - at: this.state.curPosition() - }); + throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition()); } this.state.pos += 2; this.finishToken(4); @@ -2758,9 +2865,7 @@ class Tokenizer extends CommentsParser { case 91: if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) { if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") { - throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, { - at: this.state.curPosition() - }); + throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition()); } this.state.pos += 2; this.finishToken(2); @@ -2776,9 +2881,7 @@ class Tokenizer extends CommentsParser { case 123: if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) { if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") { - throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, { - at: this.state.curPosition() - }); + throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition()); } this.state.pos += 2; this.finishToken(6); @@ -2882,8 +2985,7 @@ class Tokenizer extends CommentsParser { return; } } - throw this.raise(Errors.InvalidOrUnexpectedToken, { - at: this.state.curPosition(), + throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), { unexpected: String.fromCodePoint(code) }); } @@ -2901,15 +3003,11 @@ class Tokenizer extends CommentsParser { } = this.state; for (;; ++pos) { if (pos >= this.length) { - throw this.raise(Errors.UnterminatedRegExp, { - at: createPositionWithColumnOffset(startLoc, 1) - }); + throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1)); } const ch = this.input.charCodeAt(pos); if (isNewLine(ch)) { - throw this.raise(Errors.UnterminatedRegExp, { - at: createPositionWithColumnOffset(startLoc, 1) - }); + throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1)); } if (escaped) { escaped = false; @@ -2934,26 +3032,18 @@ class Tokenizer extends CommentsParser { if (VALID_REGEX_FLAGS.has(cp)) { if (cp === 118) { if (mods.includes("u")) { - this.raise(Errors.IncompatibleRegExpUVFlags, { - at: nextPos() - }); + this.raise(Errors.IncompatibleRegExpUVFlags, nextPos()); } } else if (cp === 117) { if (mods.includes("v")) { - this.raise(Errors.IncompatibleRegExpUVFlags, { - at: nextPos() - }); + this.raise(Errors.IncompatibleRegExpUVFlags, nextPos()); } } if (mods.includes(char)) { - this.raise(Errors.DuplicateRegExpFlags, { - at: nextPos() - }); + this.raise(Errors.DuplicateRegExpFlags, nextPos()); } } else if (isIdentifierChar(cp) || cp === 92) { - this.raise(Errors.MalformedRegExpFlags, { - at: nextPos() - }); + this.raise(Errors.MalformedRegExpFlags, nextPos()); } else { break; } @@ -2980,8 +3070,7 @@ class Tokenizer extends CommentsParser { this.state.pos += 2; const val = this.readInt(radix); if (val == null) { - this.raise(Errors.InvalidDigit, { - at: createPositionWithColumnOffset(startLoc, 2), + this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), { radix }); } @@ -2990,14 +3079,10 @@ class Tokenizer extends CommentsParser { ++this.state.pos; isBigInt = true; } else if (next === 109) { - throw this.raise(Errors.InvalidDecimal, { - at: startLoc - }); + throw this.raise(Errors.InvalidDecimal, startLoc); } if (isIdentifierStart(this.codePointAtPos(this.state.pos))) { - throw this.raise(Errors.NumberIdentifier, { - at: this.state.curPosition() - }); + throw this.raise(Errors.NumberIdentifier, this.state.curPosition()); } if (isBigInt) { const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, ""); @@ -3015,22 +3100,16 @@ class Tokenizer extends CommentsParser { let hasExponent = false; let isOctal = false; if (!startsWithDot && this.readInt(10) === null) { - this.raise(Errors.InvalidNumber, { - at: this.state.curPosition() - }); + this.raise(Errors.InvalidNumber, this.state.curPosition()); } const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48; if (hasLeadingZero) { const integer = this.input.slice(start, this.state.pos); - this.recordStrictModeErrors(Errors.StrictOctalLiteral, { - at: startLoc - }); + this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc); if (!this.state.strict) { const underscorePos = integer.indexOf("_"); if (underscorePos > 0) { - this.raise(Errors.ZeroDigitNumericSeparator, { - at: createPositionWithColumnOffset(startLoc, underscorePos) - }); + this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos)); } } isOctal = hasLeadingZero && !/[89]/.test(integer); @@ -3048,9 +3127,7 @@ class Tokenizer extends CommentsParser { ++this.state.pos; } if (this.readInt(10) === null) { - this.raise(Errors.InvalidOrMissingExponent, { - at: startLoc - }); + this.raise(Errors.InvalidOrMissingExponent, startLoc); } isFloat = true; hasExponent = true; @@ -3058,9 +3135,7 @@ class Tokenizer extends CommentsParser { } if (next === 110) { if (isFloat || hasLeadingZero) { - this.raise(Errors.InvalidBigIntLiteral, { - at: startLoc - }); + this.raise(Errors.InvalidBigIntLiteral, startLoc); } ++this.state.pos; isBigInt = true; @@ -3068,17 +3143,13 @@ class Tokenizer extends CommentsParser { if (next === 109) { this.expectPlugin("decimal", this.state.curPosition()); if (hasExponent || hasLeadingZero) { - this.raise(Errors.InvalidDecimal, { - at: startLoc - }); + this.raise(Errors.InvalidDecimal, startLoc); } ++this.state.pos; isDecimal = true; } if (isIdentifierStart(this.codePointAtPos(this.state.pos))) { - throw this.raise(Errors.NumberIdentifier, { - at: this.state.curPosition() - }); + throw this.raise(Errors.NumberIdentifier, this.state.curPosition()); } const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, ""); if (isBigInt) { @@ -3141,14 +3212,10 @@ class Tokenizer extends CommentsParser { this.finishToken(25, firstInvalidLoc ? null : opening + str + "${"); } } - recordStrictModeErrors(toParseError, { - at - }) { + recordStrictModeErrors(toParseError, at) { const index = at.index; if (this.state.strict && !this.state.strictErrors.has(index)) { - this.raise(toParseError, { - at - }); + this.raise(toParseError, at); } else { this.state.strictErrors.set(index, [toParseError, at]); } @@ -3171,9 +3238,7 @@ class Tokenizer extends CommentsParser { const escStart = this.state.curPosition(); const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar; if (this.input.charCodeAt(++this.state.pos) !== 117) { - this.raise(Errors.MissingUnicodeEscape, { - at: this.state.curPosition() - }); + this.raise(Errors.MissingUnicodeEscape, this.state.curPosition()); chunkStart = this.state.pos - 1; continue; } @@ -3181,9 +3246,7 @@ class Tokenizer extends CommentsParser { const esc = this.readCodePoint(true); if (esc !== null) { if (!identifierCheck(esc)) { - this.raise(Errors.EscapedCharNotAnIdentifier, { - at: escStart - }); + this.raise(Errors.EscapedCharNotAnIdentifier, escStart); } word += String.fromCodePoint(esc); } @@ -3208,75 +3271,55 @@ class Tokenizer extends CommentsParser { type } = this.state; if (tokenIsKeyword(type) && this.state.containsEsc) { - this.raise(Errors.InvalidEscapedReservedWord, { - at: this.state.startLoc, + this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, { reservedWord: tokenLabelName(type) }); } } - raise(toParseError, raiseProperties) { - const { - at - } = raiseProperties, - details = _objectWithoutPropertiesLoose(raiseProperties, _excluded); + raise(toParseError, at, details = {}) { const loc = at instanceof Position ? at : at.loc.start; - const error = toParseError({ - loc, - details - }); + const error = toParseError(loc, details); if (!this.options.errorRecovery) throw error; if (!this.isLookahead) this.state.errors.push(error); return error; } - raiseOverwrite(toParseError, raiseProperties) { - const { - at - } = raiseProperties, - details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2); + raiseOverwrite(toParseError, at, details = {}) { const loc = at instanceof Position ? at : at.loc.start; const pos = loc.index; const errors = this.state.errors; for (let i = errors.length - 1; i >= 0; i--) { const error = errors[i]; if (error.loc.index === pos) { - return errors[i] = toParseError({ - loc, - details - }); + return errors[i] = toParseError(loc, details); } if (error.loc.index < pos) break; } - return this.raise(toParseError, raiseProperties); + return this.raise(toParseError, at, details); } updateContext(prevType) {} unexpected(loc, type) { - throw this.raise(Errors.UnexpectedToken, { - expected: type ? tokenLabelName(type) : null, - at: loc != null ? loc : this.state.startLoc + throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, { + expected: type ? tokenLabelName(type) : null }); } expectPlugin(pluginName, loc) { if (this.hasPlugin(pluginName)) { return true; } - throw this.raise(Errors.MissingPlugin, { - at: loc != null ? loc : this.state.startLoc, + throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, { missingPlugin: [pluginName] }); } expectOnePlugin(pluginNames) { if (!pluginNames.some(name => this.hasPlugin(name))) { - throw this.raise(Errors.MissingOneOfPlugins, { - at: this.state.startLoc, + throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, { missingPlugin: pluginNames }); } } errorBuilder(error) { return (pos, lineStart, curLine) => { - this.raise(error, { - at: buildPosition(pos, lineStart, curLine) - }); + this.raise(error, buildPosition(pos, lineStart, curLine)); }; } } @@ -3309,8 +3352,7 @@ class ClassScopeHandler { current.undefinedPrivateNames.set(name, loc); } } else { - this.parser.raise(Errors.InvalidPrivateFieldResolution, { - at: loc, + this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, { identifierName: name }); } @@ -3337,8 +3379,7 @@ class ClassScopeHandler { } } if (redefined) { - this.parser.raise(Errors.PrivateNameRedeclaration, { - at: loc, + this.parser.raise(Errors.PrivateNameRedeclaration, loc, { identifierName: name }); } @@ -3353,8 +3394,7 @@ class ClassScopeHandler { if (classScope) { classScope.undefinedPrivateNames.set(name, loc); } else { - this.parser.raise(Errors.InvalidPrivateFieldResolution, { - at: loc, + this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, { identifierName: name }); } @@ -3376,9 +3416,7 @@ class ArrowHeadParsingScope extends ExpressionScope { super(type); this.declarationErrors = new Map(); } - recordDeclarationError(ParsingErrorClass, { - at - }) { + recordDeclarationError(ParsingErrorClass, at) { const index = at.index; this.declarationErrors.set(index, [ParsingErrorClass, at]); } @@ -3401,12 +3439,8 @@ class ExpressionScopeHandler { exit() { this.stack.pop(); } - recordParameterInitializerError(toParseError, { - at: node - }) { - const origin = { - at: node.loc.start - }; + recordParameterInitializerError(toParseError, node) { + const origin = node.loc.start; const { stack } = this; @@ -3422,16 +3456,12 @@ class ExpressionScopeHandler { } this.parser.raise(toParseError, origin); } - recordArrowParameterBindingError(error, { - at: node - }) { + recordArrowParameterBindingError(error, node) { const { stack } = this; const scope = stack[stack.length - 1]; - const origin = { - at: node.loc.start - }; + const origin = node.loc.start; if (scope.isCertainlyParameterDeclaration()) { this.parser.raise(error, origin); } else if (scope.canBeArrowParameterDeclaration()) { @@ -3440,9 +3470,7 @@ class ExpressionScopeHandler { return; } } - recordAsyncArrowParametersError({ - at - }) { + recordAsyncArrowParametersError(at) { const { stack } = this; @@ -3450,9 +3478,7 @@ class ExpressionScopeHandler { let scope = stack[i]; while (scope.canBeArrowParameterDeclaration()) { if (scope.type === 2) { - scope.recordDeclarationError(Errors.AwaitBindingIdentifier, { - at - }); + scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at); } scope = stack[--i]; } @@ -3464,9 +3490,7 @@ class ExpressionScopeHandler { const currentScope = stack[stack.length - 1]; if (!currentScope.canBeArrowParameterDeclaration()) return; currentScope.iterateErrors(([toParseError, loc]) => { - this.parser.raise(toParseError, { - at: loc - }); + this.parser.raise(toParseError, loc); let i = stack.length - 2; let scope = stack[i]; while (scope.canBeArrowParameterDeclaration()) { @@ -3555,9 +3579,7 @@ class UtilParser extends Tokenizer { expectContextual(token, toParseError) { if (!this.eatContextual(token)) { if (toParseError != null) { - throw this.raise(toParseError, { - at: this.state.startLoc - }); + throw this.raise(toParseError, this.state.startLoc); } this.unexpected(null, token); } @@ -3577,9 +3599,7 @@ class UtilParser extends Tokenizer { } semicolon(allowAsi = true) { if (allowAsi ? this.isLineTerminator() : this.eat(13)) return; - this.raise(Errors.MissingSemicolon, { - at: this.state.lastTokEndLoc - }); + this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc); } expect(type, loc) { this.eat(type) || this.unexpected(loc, type); @@ -3649,19 +3669,13 @@ class UtilParser extends Tokenizer { return hasErrors; } if (shorthandAssignLoc != null) { - this.raise(Errors.InvalidCoverInitializedName, { - at: shorthandAssignLoc - }); + this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc); } if (doubleProtoLoc != null) { - this.raise(Errors.DuplicateProto, { - at: doubleProtoLoc - }); + this.raise(Errors.DuplicateProto, doubleProtoLoc); } if (privateKeyLoc != null) { - this.raise(Errors.UnexpectedPrivateField, { - at: privateKeyLoc - }); + this.raise(Errors.UnexpectedPrivateField, privateKeyLoc); } if (optionalParametersLoc != null) { this.unexpected(optionalParametersLoc); @@ -3814,7 +3828,8 @@ function cloneStringLiteral(node) { } class NodeUtils extends UtilParser { startNode() { - return new Node(this, this.state.start, this.state.startLoc); + const loc = this.state.startLoc; + return new Node(this, loc.index, loc); } startNodeAt(loc) { return new Node(this, loc.index, loc); @@ -4010,10 +4025,8 @@ var flow = superClass => class FlowParserMixin extends superClass { const moduloLoc = this.state.startLoc; this.next(); this.expectContextual(110); - if (this.state.lastTokStart > moduloLoc.index + 1) { - this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, { - at: moduloLoc - }); + if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) { + this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc); } if (this.eat(10)) { node.value = super.parseExpression(); @@ -4082,9 +4095,7 @@ var flow = superClass => class FlowParserMixin extends superClass { return this.flowParseDeclareModuleExports(node); } else { if (insideModule) { - this.raise(FlowErrors.NestedDeclareModule, { - at: this.state.lastTokStartLoc - }); + this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc); } return this.flowParseDeclareModule(node); } @@ -4122,9 +4133,7 @@ var flow = superClass => class FlowParserMixin extends superClass { if (this.match(83)) { this.next(); if (!this.isContextual(130) && !this.match(87)) { - this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, { - at: this.state.lastTokStartLoc - }); + this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc); } super.parseImport(bodyNode); } else { @@ -4141,21 +4150,15 @@ var flow = superClass => class FlowParserMixin extends superClass { body.forEach(bodyElement => { if (isEsModuleType(bodyElement)) { if (kind === "CommonJS") { - this.raise(FlowErrors.AmbiguousDeclareModuleKind, { - at: bodyElement - }); + this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement); } kind = "ES"; } else if (bodyElement.type === "DeclareModuleExports") { if (hasModuleExport) { - this.raise(FlowErrors.DuplicateDeclareModuleExports, { - at: bodyElement - }); + this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement); } if (kind === "ES") { - this.raise(FlowErrors.AmbiguousDeclareModuleKind, { - at: bodyElement - }); + this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement); } kind = "CommonJS"; hasModuleExport = true; @@ -4178,8 +4181,7 @@ var flow = superClass => class FlowParserMixin extends superClass { } else { if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) { const label = this.state.value; - throw this.raise(FlowErrors.UnsupportedDeclareExportKind, { - at: this.state.startLoc, + throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, { unsupportedExportKind: label, suggestion: exportSuggestions[label] }); @@ -4277,15 +4279,12 @@ var flow = superClass => class FlowParserMixin extends superClass { } checkNotUnderscore(word) { if (word === "_") { - this.raise(FlowErrors.UnexpectedReservedUnderscore, { - at: this.state.startLoc - }); + this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc); } } checkReservedType(word, startLoc, declaration) { if (!reservedTypes.has(word)) return; - this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, { - at: startLoc, + this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, { reservedType: word }); } @@ -4338,9 +4337,7 @@ var flow = superClass => class FlowParserMixin extends superClass { node.default = this.flowParseType(); } else { if (requireDefault) { - this.raise(FlowErrors.MissingTypeParamDefault, { - at: nodeStartLoc - }); + this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc); } } return this.finishNode(node, "TypeParameter"); @@ -4580,9 +4577,7 @@ var flow = superClass => class FlowParserMixin extends superClass { } this.flowObjectTypeSemicolon(); if (inexactStartLoc && !this.match(8) && !this.match(9)) { - this.raise(FlowErrors.UnexpectedExplicitInexactInObject, { - at: inexactStartLoc - }); + this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc); } } this.expect(endDelim); @@ -4598,33 +4593,23 @@ var flow = superClass => class FlowParserMixin extends superClass { const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9); if (isInexactToken) { if (!allowSpread) { - this.raise(FlowErrors.InexactInsideNonObject, { - at: this.state.lastTokStartLoc - }); + this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc); } else if (!allowInexact) { - this.raise(FlowErrors.InexactInsideExact, { - at: this.state.lastTokStartLoc - }); + this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc); } if (variance) { - this.raise(FlowErrors.InexactVariance, { - at: variance - }); + this.raise(FlowErrors.InexactVariance, variance); } return null; } if (!allowSpread) { - this.raise(FlowErrors.UnexpectedSpreadType, { - at: this.state.lastTokStartLoc - }); + this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc); } if (protoStartLoc != null) { this.unexpected(protoStartLoc); } if (variance) { - this.raise(FlowErrors.SpreadVariance, { - at: variance - }); + this.raise(FlowErrors.SpreadVariance, variance); } node.argument = this.flowParseType(); return this.finishNode(node, "ObjectTypeSpreadProperty"); @@ -4647,9 +4632,7 @@ var flow = superClass => class FlowParserMixin extends superClass { this.flowCheckGetterSetterParams(node); } if (!allowSpread && node.key.name === "constructor" && node.value.this) { - this.raise(FlowErrors.ThisParamBannedInConstructor, { - at: node.value.this - }); + this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this); } } else { if (kind !== "init") this.unexpected(); @@ -4668,19 +4651,13 @@ var flow = superClass => class FlowParserMixin extends superClass { const paramCount = property.kind === "get" ? 0 : 1; const length = property.value.params.length + (property.value.rest ? 1 : 0); if (property.value.this) { - this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, { - at: property.value.this - }); + this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this); } if (length !== paramCount) { - this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, { - at: property - }); + this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property); } if (property.kind === "set" && property.value.rest) { - this.raise(Errors.BadSetterRestParameter, { - at: property - }); + this.raise(Errors.BadSetterRestParameter, property); } } flowObjectTypeSemicolon() { @@ -4736,17 +4713,13 @@ var flow = superClass => class FlowParserMixin extends superClass { const isThis = this.state.type === 78; if (lh.type === 14 || lh.type === 17) { if (isThis && !first) { - this.raise(FlowErrors.ThisParamMustBeFirst, { - at: node - }); + this.raise(FlowErrors.ThisParamMustBeFirst, node); } name = this.parseIdentifier(isThis); if (this.eat(17)) { optional = true; if (isThis) { - this.raise(FlowErrors.ThisParamMayNotBeOptional, { - at: node - }); + this.raise(FlowErrors.ThisParamMayNotBeOptional, node); } } typeAnnotation = this.flowParseTypeInitialiser(); @@ -4842,50 +4815,56 @@ var flow = superClass => class FlowParserMixin extends superClass { this.state.noAnonFunctionType = oldNoAnonFunctionType; return type; case 47: - node.typeParameters = this.flowParseTypeParameterDeclaration(); - this.expect(10); - tmp = this.flowParseFunctionTypeParams(); - node.params = tmp.params; - node.rest = tmp.rest; - node.this = tmp._this; - this.expect(11); - this.expect(19); - node.returnType = this.flowParseType(); - return this.finishNode(node, "FunctionTypeAnnotation"); + { + const node = this.startNode(); + node.typeParameters = this.flowParseTypeParameterDeclaration(); + this.expect(10); + tmp = this.flowParseFunctionTypeParams(); + node.params = tmp.params; + node.rest = tmp.rest; + node.this = tmp._this; + this.expect(11); + this.expect(19); + node.returnType = this.flowParseType(); + return this.finishNode(node, "FunctionTypeAnnotation"); + } case 10: - this.next(); - if (!this.match(11) && !this.match(21)) { - if (tokenIsIdentifier(this.state.type) || this.match(78)) { - const token = this.lookahead().type; - isGroupedType = token !== 17 && token !== 14; - } else { - isGroupedType = true; + { + const node = this.startNode(); + this.next(); + if (!this.match(11) && !this.match(21)) { + if (tokenIsIdentifier(this.state.type) || this.match(78)) { + const token = this.lookahead().type; + isGroupedType = token !== 17 && token !== 14; + } else { + isGroupedType = true; + } } - } - if (isGroupedType) { - this.state.noAnonFunctionType = false; - type = this.flowParseType(); - this.state.noAnonFunctionType = oldNoAnonFunctionType; - if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) { - this.expect(11); - return type; + if (isGroupedType) { + this.state.noAnonFunctionType = false; + type = this.flowParseType(); + this.state.noAnonFunctionType = oldNoAnonFunctionType; + if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) { + this.expect(11); + return type; + } else { + this.eat(12); + } + } + if (type) { + tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]); } else { - this.eat(12); + tmp = this.flowParseFunctionTypeParams(); } + node.params = tmp.params; + node.rest = tmp.rest; + node.this = tmp._this; + this.expect(11); + this.expect(19); + node.returnType = this.flowParseType(); + node.typeParameters = null; + return this.finishNode(node, "FunctionTypeAnnotation"); } - if (type) { - tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]); - } else { - tmp = this.flowParseFunctionTypeParams(); - } - node.params = tmp.params; - node.rest = tmp.rest; - node.this = tmp._this; - this.expect(11); - this.expect(19); - node.returnType = this.flowParseType(); - node.typeParameters = null; - return this.finishNode(node, "FunctionTypeAnnotation"); case 133: return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation"); case 85: @@ -4902,9 +4881,7 @@ var flow = superClass => class FlowParserMixin extends superClass { if (this.match(135)) { return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node); } - throw this.raise(FlowErrors.UnexpectedSubtractionOperand, { - at: this.state.startLoc - }); + throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc); } this.unexpected(); return; @@ -5168,9 +5145,7 @@ var flow = superClass => class FlowParserMixin extends superClass { [valid, invalid] = this.getArrowLikeExpressions(consequent); } if (failed && valid.length > 1) { - this.raise(FlowErrors.AmbiguousConditionalArrow, { - at: state.startLoc - }); + this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc); } if (failed && valid.length === 1) { this.state = state; @@ -5205,7 +5180,7 @@ var flow = superClass => class FlowParserMixin extends superClass { const arrows = []; while (stack.length !== 0) { const node = stack.pop(); - if (node.type === "ArrowFunctionExpression") { + if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") { if (node.typeParameters || !node.returnType) { this.finishArrowValidation(node); } else { @@ -5242,18 +5217,18 @@ var flow = superClass => class FlowParserMixin extends superClass { return result; } parseParenItem(node, startLoc) { - node = super.parseParenItem(node, startLoc); + const newNode = super.parseParenItem(node, startLoc); if (this.eat(17)) { - node.optional = true; + newNode.optional = true; this.resetEndLocation(node); } if (this.match(14)) { const typeCastNode = this.startNodeAt(startLoc); - typeCastNode.expression = node; + typeCastNode.expression = newNode; typeCastNode.typeAnnotation = this.flowParseTypeAnnotation(); return this.finishNode(typeCastNode, "TypeCastExpression"); } - return node; + return newNode; } assertModuleNodeAllowed(node) { if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") { @@ -5331,13 +5306,9 @@ var flow = superClass => class FlowParserMixin extends superClass { super.parseClassMember(classBody, member, state); if (member.declare) { if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") { - this.raise(FlowErrors.DeclareClassElement, { - at: startLoc - }); + this.raise(FlowErrors.DeclareClassElement, startLoc); } else if (member.value) { - this.raise(FlowErrors.DeclareClassFieldInitializer, { - at: member.value - }); + this.raise(FlowErrors.DeclareClassFieldInitializer, member.value); } } } @@ -5348,8 +5319,7 @@ var flow = superClass => class FlowParserMixin extends superClass { const word = super.readWord1(); const fullWord = "@@" + word; if (!this.isIterator(word) || !this.state.inType) { - this.raise(Errors.InvalidIdentifier, { - at: this.state.curPosition(), + this.raise(Errors.InvalidIdentifier, this.state.curPosition(), { identifierName: fullWord }); } @@ -5401,9 +5371,7 @@ var flow = superClass => class FlowParserMixin extends superClass { var _expr$extra; const expr = exprList[i]; if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) { - this.raise(FlowErrors.TypeCastInPattern, { - at: expr.typeAnnotation - }); + this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation); } } return exprList; @@ -5451,16 +5419,12 @@ var flow = superClass => class FlowParserMixin extends superClass { if (method.params && isConstructor) { const params = method.params; if (params.length > 0 && this.isThisParam(params[0])) { - this.raise(FlowErrors.ThisParamBannedInConstructor, { - at: method - }); + this.raise(FlowErrors.ThisParamBannedInConstructor, method); } } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) { const params = method.value.params; if (params.length > 0 && this.isThisParam(params[0])) { - this.raise(FlowErrors.ThisParamBannedInConstructor, { - at: method - }); + this.raise(FlowErrors.ThisParamBannedInConstructor, method); } } } @@ -5500,13 +5464,9 @@ var flow = superClass => class FlowParserMixin extends superClass { if (params.length > 0) { const param = params[0]; if (this.isThisParam(param) && method.kind === "get") { - this.raise(FlowErrors.GetterMayNotHaveThisParam, { - at: param - }); + this.raise(FlowErrors.GetterMayNotHaveThisParam, param); } else if (this.isThisParam(param)) { - this.raise(FlowErrors.SetterMayNotHaveThisParam, { - at: param - }); + this.raise(FlowErrors.SetterMayNotHaveThisParam, param); } } } @@ -5532,28 +5492,20 @@ var flow = superClass => class FlowParserMixin extends superClass { parseAssignableListItemTypes(param) { if (this.eat(17)) { if (param.type !== "Identifier") { - this.raise(FlowErrors.PatternIsOptional, { - at: param - }); + this.raise(FlowErrors.PatternIsOptional, param); } if (this.isThisParam(param)) { - this.raise(FlowErrors.ThisParamMayNotBeOptional, { - at: param - }); + this.raise(FlowErrors.ThisParamMayNotBeOptional, param); } param.optional = true; } if (this.match(14)) { param.typeAnnotation = this.flowParseTypeAnnotation(); } else if (this.isThisParam(param)) { - this.raise(FlowErrors.ThisParamAnnotationRequired, { - at: param - }); + this.raise(FlowErrors.ThisParamAnnotationRequired, param); } if (this.match(29) && this.isThisParam(param)) { - this.raise(FlowErrors.ThisParamNoDefault, { - at: param - }); + this.raise(FlowErrors.ThisParamNoDefault, param); } this.resetEndLocation(param); return param; @@ -5561,18 +5513,14 @@ var flow = superClass => class FlowParserMixin extends superClass { parseMaybeDefault(startLoc, left) { const node = super.parseMaybeDefault(startLoc, left); if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) { - this.raise(FlowErrors.TypeBeforeInitializer, { - at: node.typeAnnotation - }); + this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation); } return node; } checkImportReflection(node) { super.checkImportReflection(node); if (node.module && node.importKind !== "value") { - this.raise(FlowErrors.ImportReflectionHasImportType, { - at: node.specifiers[0].loc.start - }); + this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start); } } parseImportSpecifierLocal(node, specifier, type) { @@ -5628,8 +5576,7 @@ var flow = superClass => class FlowParserMixin extends superClass { specifier.importKind = specifierTypeKind; } else { if (importedIsString) { - throw this.raise(Errors.ImportBindingIsString, { - at: specifier, + throw this.raise(Errors.ImportBindingIsString, specifier, { importName: firstIdent.value }); } @@ -5645,9 +5592,7 @@ var flow = superClass => class FlowParserMixin extends superClass { } const specifierIsTypeImport = hasTypeImportKind(specifier); if (isInTypeOnlyImport && specifierIsTypeImport) { - this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, { - at: specifier - }); + this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier); } if (isInTypeOnlyImport || specifierIsTypeImport) { this.checkReservedType(specifier.local.name, specifier.local.loc.start, true); @@ -5730,9 +5675,7 @@ var flow = superClass => class FlowParserMixin extends superClass { if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") { if (!arrow.error && !arrow.aborted) { if (arrow.node.async) { - this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, { - at: typeParameters - }); + this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters); } return arrow.node; } @@ -5748,9 +5691,7 @@ var flow = superClass => class FlowParserMixin extends superClass { } if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error; if (arrow.thrown) throw arrow.error; - throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, { - at: typeParameters - }); + throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters); } return super.parseMaybeAssign(refExpressionErrors, afterLeftParse); } @@ -5788,9 +5729,7 @@ var flow = superClass => class FlowParserMixin extends superClass { } for (let i = 0; i < node.params.length; i++) { if (this.isThisParam(node.params[i]) && i > 0) { - this.raise(FlowErrors.ThisParamMustBeFirst, { - at: node.params[i] - }); + this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]); } } super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged); @@ -5892,18 +5831,14 @@ var flow = superClass => class FlowParserMixin extends superClass { parseTopLevel(file, program) { const fileNode = super.parseTopLevel(file, program); if (this.state.hasFlowComment) { - this.raise(FlowErrors.UnterminatedFlowComment, { - at: this.state.curPosition() - }); + this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition()); } return fileNode; } skipBlockComment() { if (this.hasPlugin("flowComments") && this.skipFlowComment()) { if (this.state.hasFlowComment) { - throw this.raise(FlowErrors.NestedFlowComment, { - at: this.state.startLoc - }); + throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc); } this.hasFlowCommentCompletion(); const commentSkip = this.skipFlowComment(); @@ -5939,43 +5874,26 @@ var flow = superClass => class FlowParserMixin extends superClass { hasFlowCommentCompletion() { const end = this.input.indexOf("*/", this.state.pos); if (end === -1) { - throw this.raise(Errors.UnterminatedComment, { - at: this.state.curPosition() - }); + throw this.raise(Errors.UnterminatedComment, this.state.curPosition()); } } flowEnumErrorBooleanMemberNotInitialized(loc, { enumName, memberName }) { - this.raise(FlowErrors.EnumBooleanMemberNotInitialized, { - at: loc, + this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, { memberName, enumName }); } flowEnumErrorInvalidMemberInitializer(loc, enumContext) { - return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({ - at: loc - }, enumContext)); + return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext); } - flowEnumErrorNumberMemberNotInitialized(loc, { - enumName, - memberName - }) { - this.raise(FlowErrors.EnumNumberMemberNotInitialized, { - at: loc, - enumName, - memberName - }); + flowEnumErrorNumberMemberNotInitialized(loc, details) { + this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details); } - flowEnumErrorStringMemberInconsistentlyInitialized(node, { - enumName - }) { - this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, { - at: node, - enumName - }); + flowEnumErrorStringMemberInconsistentlyInitialized(node, details) { + this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details); } flowEnumMemberInit() { const startLoc = this.state.startLoc; @@ -6084,16 +6002,14 @@ var flow = superClass => class FlowParserMixin extends superClass { continue; } if (/^[a-z]/.test(memberName)) { - this.raise(FlowErrors.EnumInvalidMemberName, { - at: id, + this.raise(FlowErrors.EnumInvalidMemberName, id, { memberName, suggestion: memberName[0].toUpperCase() + memberName.slice(1), enumName }); } if (seenNames.has(memberName)) { - this.raise(FlowErrors.EnumDuplicateMemberName, { - at: id, + this.raise(FlowErrors.EnumDuplicateMemberName, id, { memberName, enumName }); @@ -6182,8 +6098,7 @@ var flow = superClass => class FlowParserMixin extends superClass { }) { if (!this.eatContextual(102)) return null; if (!tokenIsIdentifier(this.state.type)) { - throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, { - at: this.state.startLoc, + throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, { enumName }); } @@ -6192,8 +6107,7 @@ var flow = superClass => class FlowParserMixin extends superClass { } = this.state; this.next(); if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") { - this.raise(FlowErrors.EnumInvalidExplicitType, { - at: this.state.startLoc, + this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, { enumName, invalidEnumType: value }); @@ -6278,8 +6192,7 @@ var flow = superClass => class FlowParserMixin extends superClass { this.expect(8); return this.finishNode(node, "EnumNumberBody"); } else { - this.raise(FlowErrors.EnumInconsistentMemberValues, { - at: nameLoc, + this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, { enumName }); return empty(); @@ -6597,9 +6510,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { let chunkStart = this.state.pos; for (;;) { if (this.state.pos >= this.length) { - throw this.raise(JsxErrors.UnterminatedJsxContent, { - at: this.state.startLoc - }); + throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc); } const ch = this.input.charCodeAt(this.state.pos); switch (ch) { @@ -6654,9 +6565,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { let chunkStart = ++this.state.pos; for (;;) { if (this.state.pos >= this.length) { - throw this.raise(Errors.UnterminatedString, { - at: this.state.startLoc - }); + throw this.raise(Errors.UnterminatedString, this.state.startLoc); } const ch = this.input.charCodeAt(this.state.pos); if (ch === quote) break; @@ -6692,7 +6601,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { } else { let count = 0; let semi = false; - while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) { + while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) { ++this.state.pos; } if (semi) { @@ -6759,18 +6668,14 @@ var jsx = superClass => class JSXParserMixin extends superClass { this.next(); node = this.jsxParseExpressionContainer(node, types.j_oTag); if (node.expression.type === "JSXEmptyExpression") { - this.raise(JsxErrors.AttributeIsEmpty, { - at: node - }); + this.raise(JsxErrors.AttributeIsEmpty, node); } return node; case 142: case 133: return this.parseExprAtom(); default: - throw this.raise(JsxErrors.UnsupportedJsxValue, { - at: this.state.startLoc - }); + throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc); } } jsxParseEmptyExpression() { @@ -6858,7 +6763,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { children.push(this.jsxParseElementAt(startLoc)); break; case 141: - children.push(this.parseExprAtom()); + children.push(this.parseLiteral(this.state.value, "JSXText")); break; case 5: { @@ -6877,18 +6782,14 @@ var jsx = superClass => class JSXParserMixin extends superClass { } } if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) { - this.raise(JsxErrors.MissingClosingTagFragment, { - at: closingElement - }); + this.raise(JsxErrors.MissingClosingTagFragment, closingElement); } else if (!isFragment(openingElement) && isFragment(closingElement)) { - this.raise(JsxErrors.MissingClosingTagElement, { - at: closingElement, + this.raise(JsxErrors.MissingClosingTagElement, closingElement, { openingTagName: getQualifiedJSXName(openingElement.name) }); } else if (!isFragment(openingElement) && !isFragment(closingElement)) { if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { - this.raise(JsxErrors.MissingClosingTagElement, { - at: closingElement, + this.raise(JsxErrors.MissingClosingTagElement, closingElement, { openingTagName: getQualifiedJSXName(openingElement.name) }); } @@ -6903,9 +6804,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { } node.children = children; if (this.match(47)) { - throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, { - at: this.state.startLoc - }); + throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc); } return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement"); } @@ -6921,9 +6820,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { context[context.length - 1] = newContext; } parseExprAtom(refExpressionErrors) { - if (this.match(141)) { - return this.parseLiteral(this.state.value, "JSXText"); - } else if (this.match(142)) { + if (this.match(142)) { return this.jsxParseElement(); } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) { this.replaceToken(142); @@ -6991,11 +6888,7 @@ var jsx = superClass => class JSXParserMixin extends superClass { class TypeScriptScope extends Scope { constructor(...args) { super(...args); - this.types = new Set(); - this.enums = new Set(); - this.constEnums = new Set(); - this.classes = new Set(); - this.exportOnlyBindings = new Set(); + this.tsNames = new Map(); } } class TypeScriptScopeHandler extends ScopeHandler { @@ -7008,14 +6901,14 @@ class TypeScriptScopeHandler extends ScopeHandler { return new TypeScriptScope(flags); } enter(flags) { - if (flags == 256) { + if (flags === 256) { this.importsStack.push(new Set()); } super.enter(flags); } exit() { const flags = super.exit(); - if (flags == 256) { + if (flags === 256) { this.importsStack.pop(); } return flags; @@ -7035,8 +6928,7 @@ class TypeScriptScopeHandler extends ScopeHandler { declareName(name, bindingType, loc) { if (bindingType & 4096) { if (this.hasImport(name, true)) { - this.parser.raise(Errors.VarRedeclaration, { - at: loc, + this.parser.raise(Errors.VarRedeclaration, loc, { identifierName: name }); } @@ -7044,9 +6936,10 @@ class TypeScriptScopeHandler extends ScopeHandler { return; } const scope = this.currentScope(); + let type = scope.tsNames.get(name) || 0; if (bindingType & 1024) { this.maybeExportDefined(scope, name); - scope.exportOnlyBindings.add(name); + scope.tsNames.set(name, type | 16); return; } super.declareName(name, bindingType, loc); @@ -7055,31 +6948,37 @@ class TypeScriptScopeHandler extends ScopeHandler { this.checkRedeclarationInScope(scope, name, bindingType, loc); this.maybeExportDefined(scope, name); } - scope.types.add(name); + type = type | 1; + } + if (bindingType & 256) { + type = type | 2; } - if (bindingType & 256) scope.enums.add(name); if (bindingType & 512) { - scope.constEnums.add(name); + type = type | 4; + } + if (bindingType & 128) { + type = type | 8; } - if (bindingType & 128) scope.classes.add(name); + if (type) scope.tsNames.set(name, type); } isRedeclaredInScope(scope, name, bindingType) { - if (scope.enums.has(name)) { + const type = scope.tsNames.get(name); + if ((type & 2) > 0) { if (bindingType & 256) { const isConst = !!(bindingType & 512); - const wasConst = scope.constEnums.has(name); + const wasConst = (type & 4) > 0; return isConst !== wasConst; } return true; } - if (bindingType & 128 && scope.classes.has(name)) { - if (scope.lexical.has(name)) { + if (bindingType & 128 && (type & 8) > 0) { + if (scope.names.get(name) & 2) { return !!(bindingType & 1); } else { return false; } } - if (bindingType & 2 && scope.types.has(name)) { + if (bindingType & 2 && (type & 1) > 0) { return true; } return super.isRedeclaredInScope(scope, name, bindingType); @@ -7092,12 +6991,15 @@ class TypeScriptScopeHandler extends ScopeHandler { const len = this.scopeStack.length; for (let i = len - 1; i >= 0; i--) { const scope = this.scopeStack[i]; - if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return; + const type = scope.tsNames.get(name); + if ((type & 1) > 0 || (type & 16) > 0) { + return; + } } super.checkLocalExport(id); } } -const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key]; +const getOwn$1 = (object, key) => hasOwnProperty.call(object, key) && object[key]; const unwrapParenthesizedExpression = node => { return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node; }; @@ -7109,18 +7011,12 @@ class LValParser extends NodeUtils { parenthesized = unwrapParenthesizedExpression(node); if (isLHS) { if (parenthesized.type === "Identifier") { - this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, { - at: node - }); + this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node); } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) { - this.raise(Errors.InvalidParenthesizedAssignment, { - at: node - }); + this.raise(Errors.InvalidParenthesizedAssignment, node); } } else { - this.raise(Errors.InvalidParenthesizedAssignment, { - at: node - }); + this.raise(Errors.InvalidParenthesizedAssignment, node); } } switch (node.type) { @@ -7138,9 +7034,7 @@ class LValParser extends NodeUtils { const isLast = i === last; this.toAssignableObjectExpressionProp(prop, isLast, isLHS); if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) { - this.raise(Errors.RestTrailingComma, { - at: node.extra.trailingCommaLoc - }); + this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc); } } break; @@ -7166,9 +7060,7 @@ class LValParser extends NodeUtils { break; case "AssignmentExpression": if (node.operator !== "=") { - this.raise(Errors.MissingEqInAssignment, { - at: node.left.loc.end - }); + this.raise(Errors.MissingEqInAssignment, node.left.loc.end); } node.type = "AssignmentPattern"; delete node.operator; @@ -7181,18 +7073,14 @@ class LValParser extends NodeUtils { } toAssignableObjectExpressionProp(prop, isLast, isLHS) { if (prop.type === "ObjectMethod") { - this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, { - at: prop.key - }); + this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key); } else if (prop.type === "SpreadElement") { prop.type = "RestElement"; const arg = prop.argument; this.checkToRestConversion(arg, false); this.toAssignable(arg, isLHS); if (!isLast) { - this.raise(Errors.RestTrailingComma, { - at: prop - }); + this.raise(Errors.RestTrailingComma, prop); } } else { this.toAssignable(prop, isLHS); @@ -7213,13 +7101,9 @@ class LValParser extends NodeUtils { } if (elt.type === "RestElement") { if (i < end) { - this.raise(Errors.RestTrailingComma, { - at: elt - }); + this.raise(Errors.RestTrailingComma, elt); } else if (trailingCommaLoc) { - this.raise(Errors.RestTrailingComma, { - at: trailingCommaLoc - }); + this.raise(Errors.RestTrailingComma, trailingCommaLoc); } } } @@ -7316,9 +7200,7 @@ class LValParser extends NodeUtils { } else { const decorators = []; if (this.match(26) && this.hasPlugin("decorators")) { - this.raise(Errors.UnsupportedParameterDecorator, { - at: this.state.startLoc - }); + this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc); } while (this.match(26)) { decorators.push(this.parseDecorator()); @@ -7335,14 +7217,15 @@ class LValParser extends NodeUtils { return this.finishNode(prop, "RestElement"); } parseBindingProperty() { - const prop = this.startNode(); const { type, startLoc } = this.state; if (type === 21) { - return this.parseBindingRestProperty(prop); - } else if (type === 138) { + return this.parseBindingRestProperty(this.startNode()); + } + const prop = this.startNode(); + if (type === 138) { this.expectPlugin("destructuringPrivate", startLoc); this.classScope.usePrivateName(this.state.value, startLoc); prop.key = this.parsePrivateName(); @@ -7402,16 +7285,13 @@ class LValParser extends NodeUtils { if (isOptionalMemberExpression) { this.expectPlugin("optionalChainingAssign", expression.loc.start); if (ancestor.type !== "AssignmentExpression") { - this.raise(Errors.InvalidLhsOptionalChaining, { - at: expression, + this.raise(Errors.InvalidLhsOptionalChaining, expression, { ancestor }); } } if (binding !== 64) { - this.raise(Errors.InvalidPropertyBindingPattern, { - at: expression - }); + this.raise(Errors.InvalidPropertyBindingPattern, expression); } return; } @@ -7422,9 +7302,7 @@ class LValParser extends NodeUtils { } = expression; if (checkClashes) { if (checkClashes.has(name)) { - this.raise(Errors.ParamDupe, { - at: expression - }); + this.raise(Errors.ParamDupe, expression); } else { checkClashes.add(name); } @@ -7435,8 +7313,7 @@ class LValParser extends NodeUtils { if (validity === true) return; if (validity === false) { const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding; - this.raise(ParseErrorClass, { - at: expression, + this.raise(ParseErrorClass, expression, { ancestor }); return; @@ -7460,21 +7337,17 @@ class LValParser extends NodeUtils { checkIdentifier(at, bindingType, strictModeChanged = false) { if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) { if (bindingType === 64) { - this.raise(Errors.StrictEvalArguments, { - at, + this.raise(Errors.StrictEvalArguments, at, { referenceName: at.name }); } else { - this.raise(Errors.StrictEvalArgumentsBinding, { - at, + this.raise(Errors.StrictEvalArgumentsBinding, at, { bindingName: at.name }); } } if (bindingType & 8192 && at.name === "let") { - this.raise(Errors.LetInLexicalBinding, { - at - }); + this.raise(Errors.LetInLexicalBinding, at); } if (!(bindingType & 64)) { this.declareNameFromIdentifier(at, bindingType); @@ -7495,22 +7368,18 @@ class LValParser extends NodeUtils { case "ObjectExpression": if (allowPattern) break; default: - this.raise(Errors.InvalidRestAssignmentPattern, { - at: node - }); + this.raise(Errors.InvalidRestAssignmentPattern, node); } } checkCommaAfterRest(close) { if (!this.match(12)) { return false; } - this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, { - at: this.state.startLoc - }); + this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc); return true; } } -const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key]; +const getOwn = (object, key) => hasOwnProperty.call(object, key) && object[key]; function nonNull(x) { if (x == null) { throw new Error(`Unexpected ${x} value.`); @@ -7702,16 +7571,14 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { }, modified) { const enforceOrder = (loc, modifier, before, after) => { if (modifier === before && modified[after]) { - this.raise(TSErrors.InvalidModifiersOrder, { - at: loc, + this.raise(TSErrors.InvalidModifiersOrder, loc, { orderedModifiers: [before, after] }); } }; const incompatible = (loc, modifier, mod1, mod2) => { if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) { - this.raise(TSErrors.IncompatibleModifiers, { - at: loc, + this.raise(TSErrors.IncompatibleModifiers, loc, { modifiers: [mod1, mod2] }); } @@ -7724,8 +7591,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { if (!modifier) break; if (tsIsAccessModifier(modifier)) { if (modified.accessibility) { - this.raise(TSErrors.DuplicateAccessibilityModifier, { - at: startLoc, + this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, { modifier }); } else { @@ -7736,17 +7602,15 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } } else if (tsIsVarianceAnnotations(modifier)) { if (modified[modifier]) { - this.raise(TSErrors.DuplicateModifier, { - at: startLoc, + this.raise(TSErrors.DuplicateModifier, startLoc, { modifier }); } modified[modifier] = true; enforceOrder(startLoc, modifier, "in", "out"); } else { - if (Object.hasOwnProperty.call(modified, modifier)) { - this.raise(TSErrors.DuplicateModifier, { - at: startLoc, + if (hasOwnProperty.call(modified, modifier)) { + this.raise(TSErrors.DuplicateModifier, startLoc, { modifier }); } else { @@ -7760,8 +7624,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { modified[modifier] = true; } if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) { - this.raise(errorTemplate, { - at: startLoc, + this.raise(errorTemplate, startLoc, { modifier }); } @@ -7804,7 +7667,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } result.push(element); if (this.eat(12)) { - trailingCommaPos = this.state.lastTokStart; + trailingCommaPos = this.state.lastTokStartLoc.index; continue; } if (this.tsIsListTerminator(kind)) { @@ -7841,11 +7704,19 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { this.expect(83); this.expect(10); if (!this.match(133)) { - this.raise(TSErrors.UnsupportedImportTypeArgument, { - at: this.state.startLoc - }); + this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc); } node.argument = super.parseExprAtom(); + if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) { + node.options = null; + } + if (this.eat(12)) { + this.expectImportAttributesPlugin(); + if (!this.match(11)) { + node.options = super.parseMaybeAssignAllowIn(); + this.eat(12); + } + } this.expect(11); if (this.eat(16)) { node.qualifier = this.tsParseEntityName(); @@ -7924,9 +7795,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { }; node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos); if (node.params.length === 0) { - this.raise(TSErrors.EmptyTypeParameters, { - at: node - }); + this.raise(TSErrors.EmptyTypeParameters, node); } if (refTrailingCommaPos.value !== -1) { this.addExtra(node, "trailingComma", refTrailingCommaPos.value); @@ -7953,8 +7822,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { type } = pattern; if (type === "AssignmentPattern" || type === "TSParameterProperty") { - this.raise(TSErrors.UnsupportedSignatureParameterKind, { - at: pattern, + this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, { type }); } @@ -7999,15 +7867,11 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { const nodeAny = node; if (this.match(10) || this.match(47)) { if (readonly) { - this.raise(TSErrors.ReadonlyForMethodSignature, { - at: node - }); + this.raise(TSErrors.ReadonlyForMethodSignature, node); } const method = nodeAny; if (method.kind && this.match(47)) { - this.raise(TSErrors.AccesorCannotHaveTypeParameters, { - at: this.state.curPosition() - }); + this.raise(TSErrors.AccesorCannotHaveTypeParameters, this.state.curPosition()); } this.tsFillSignature(14, method); this.tsParseTypeMemberSemicolon(); @@ -8015,42 +7879,28 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { const returnTypeKey = "typeAnnotation"; if (method.kind === "get") { if (method[paramsKey].length > 0) { - this.raise(Errors.BadGetterArity, { - at: this.state.curPosition() - }); + this.raise(Errors.BadGetterArity, this.state.curPosition()); if (this.isThisParam(method[paramsKey][0])) { - this.raise(TSErrors.AccesorCannotDeclareThisParameter, { - at: this.state.curPosition() - }); + this.raise(TSErrors.AccesorCannotDeclareThisParameter, this.state.curPosition()); } } } else if (method.kind === "set") { if (method[paramsKey].length !== 1) { - this.raise(Errors.BadSetterArity, { - at: this.state.curPosition() - }); + this.raise(Errors.BadSetterArity, this.state.curPosition()); } else { const firstParameter = method[paramsKey][0]; if (this.isThisParam(firstParameter)) { - this.raise(TSErrors.AccesorCannotDeclareThisParameter, { - at: this.state.curPosition() - }); + this.raise(TSErrors.AccesorCannotDeclareThisParameter, this.state.curPosition()); } if (firstParameter.type === "Identifier" && firstParameter.optional) { - this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, { - at: this.state.curPosition() - }); + this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, this.state.curPosition()); } if (firstParameter.type === "RestElement") { - this.raise(TSErrors.SetAccesorCannotHaveRestParameter, { - at: this.state.curPosition() - }); + this.raise(TSErrors.SetAccesorCannotHaveRestParameter, this.state.curPosition()); } } if (method[returnTypeKey]) { - this.raise(TSErrors.SetAccesorCannotHaveReturnType, { - at: method[returnTypeKey] - }); + this.raise(TSErrors.SetAccesorCannotHaveReturnType, method[returnTypeKey]); } } else { method.kind = "method"; @@ -8165,9 +8015,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { type } = elementNode; if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) { - this.raise(TSErrors.OptionalTypeBeforeRequired, { - at: elementNode - }); + this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode); } seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType"); }); @@ -8220,16 +8068,12 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { labeledNode.elementType = type; if (this.eat(17)) { labeledNode.optional = true; - this.raise(TSErrors.TupleOptionalAfterType, { - at: this.state.lastTokStartLoc - }); + this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc); } } else { labeledNode = this.startNodeAtNode(type); labeledNode.optional = optional; - this.raise(TSErrors.InvalidTupleMemberLabel, { - at: type - }); + this.raise(TSErrors.InvalidTupleMemberLabel, type); labeledNode.label = type; labeledNode.elementType = this.tsParseType(); } @@ -8382,9 +8226,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { case "TSArrayType": return; default: - this.raise(TSErrors.UnexpectedReadonly, { - at: node - }); + this.raise(TSErrors.UnexpectedReadonly, node); } } tsParseInferType() { @@ -8552,8 +8394,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { return false; } if (containsEsc) { - this.raise(Errors.InvalidEscapedReservedWord, { - at: this.state.lastTokStartLoc, + this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, { reservedWord: "asserts" }); } @@ -8597,9 +8438,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } tsParseTypeAssertion() { if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) { - this.raise(TSErrors.ReservedTypeAssertion, { - at: this.state.startLoc - }); + this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc); } const node = this.startNode(); node.typeAnnotation = this.tsInType(() => { @@ -8621,8 +8460,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { return this.finishNode(node, "TSExpressionWithTypeArguments"); }); if (!delimitedList.length) { - this.raise(TSErrors.EmptyHeritageClauseType, { - at: originalStartLoc, + this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, { token }); } @@ -8637,9 +8475,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { this.checkIdentifier(node.id, 130); } else { node.id = null; - this.raise(TSErrors.MissingInterfaceName, { - at: this.state.startLoc - }); + this.raise(TSErrors.MissingInterfaceName, this.state.startLoc); } node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers); if (this.eat(81)) { @@ -8791,9 +8627,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { this.expect(29); const moduleReference = this.tsParseModuleReference(); if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") { - this.raise(TSErrors.ImportAliasHasImportType, { - at: moduleReference - }); + this.raise(TSErrors.ImportAliasHasImportType, moduleReference); } node.moduleReference = moduleReference; this.semicolon(); @@ -8979,9 +8813,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this)); })); if (node.params.length === 0) { - this.raise(TSErrors.EmptyTypeArguments, { - at: node - }); + this.raise(TSErrors.EmptyTypeArguments, node); } else if (!this.state.inType && this.curContext() === types.brace) { this.reScan_lt_gt(); } @@ -9005,9 +8837,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { const override = modified.override; const readonly = modified.readonly; if (!(flags & 4) && (accessibility || readonly || override)) { - this.raise(TSErrors.UnexpectedParameterModifier, { - at: startLoc - }); + this.raise(TSErrors.UnexpectedParameterModifier, startLoc); } const left = this.parseMaybeDefault(); this.parseAssignableListItemTypes(left, flags); @@ -9021,9 +8851,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { if (readonly) pp.readonly = readonly; if (override) pp.override = override; if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { - this.raise(TSErrors.UnsupportedParameterPropertyKind, { - at: pp - }); + this.raise(TSErrors.UnsupportedParameterPropertyKind, pp); } pp.parameter = elt; return this.finishNode(pp, "TSParameterProperty"); @@ -9039,9 +8867,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { tsDisallowOptionalPattern(node) { for (const param of node.params) { if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) { - this.raise(TSErrors.PatternIsOptional, { - at: param - }); + this.raise(TSErrors.PatternIsOptional, param); } } } @@ -9058,9 +8884,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { return this.finishNode(node, bodilessType); } if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) { - this.raise(TSErrors.DeclareFunctionHasImplementation, { - at: node - }); + this.raise(TSErrors.DeclareFunctionHasImplementation, node); if (node.declare) { return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod); } @@ -9078,9 +8902,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { tsCheckForInvalidTypeCasts(items) { items.forEach(node => { if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") { - this.raise(TSErrors.UnexpectedTypeAnnotation, { - at: node.typeAnnotation - }); + this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation); } }); } @@ -9157,9 +8979,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } if (result) { if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) { - this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, { - at: this.state.startLoc - }); + this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc); } return result; } @@ -9186,8 +9006,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { this.next(); if (this.match(75)) { if (isSatisfies) { - this.raise(Errors.UnexpectedKeyword, { - at: this.state.startLoc, + this.raise(Errors.UnexpectedKeyword, this.state.startLoc, { keyword: "const" }); } @@ -9209,9 +9028,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { checkImportReflection(node) { super.checkImportReflection(node); if (node.module && node.importKind !== "value") { - this.raise(TSErrors.ImportReflectionHasImportType, { - at: node.specifiers[0].loc.start - }); + this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start); } } checkDuplicateExports() {} @@ -9251,22 +9068,21 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { importNode = super.parseImport(node); } if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") { - this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, { - at: importNode - }); + this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode); } return importNode; } parseExport(node, decorators) { if (this.match(83)) { this.next(); + const nodeImportEquals = node; let maybeDefaultIdentifier = null; if (this.isContextual(130) && this.isPotentialImportPhase(false)) { - maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false); + maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false); } else { - node.importKind = "value"; + nodeImportEquals.importKind = "value"; } - return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true); + return this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true); } else if (this.eat(29)) { const assign = node; assign.expression = super.parseExpression(); @@ -9311,13 +9127,9 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } of declaration.declarations) { if (!init) continue; if (kind !== "const" || !!id.typeAnnotation) { - this.raise(TSErrors.InitializerNotAllowedInAmbientContext, { - at: init - }); + this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init); } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) { - this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, { - at: init - }); + this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, init); } } return declaration; @@ -9366,9 +9178,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { this.next(); this.next(); if (this.tsHasSomeModifiers(member, modifiers)) { - this.raise(TSErrors.StaticBlockCannotHaveModifier, { - at: this.state.curPosition() - }); + this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition()); } super.parseClassStaticBlock(classBody, member); } else { @@ -9386,38 +9196,27 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { if (idx) { classBody.body.push(idx); if (member.abstract) { - this.raise(TSErrors.IndexSignatureHasAbstract, { - at: member - }); + this.raise(TSErrors.IndexSignatureHasAbstract, member); } if (member.accessibility) { - this.raise(TSErrors.IndexSignatureHasAccessibility, { - at: member, + this.raise(TSErrors.IndexSignatureHasAccessibility, member, { modifier: member.accessibility }); } if (member.declare) { - this.raise(TSErrors.IndexSignatureHasDeclare, { - at: member - }); + this.raise(TSErrors.IndexSignatureHasDeclare, member); } if (member.override) { - this.raise(TSErrors.IndexSignatureHasOverride, { - at: member - }); + this.raise(TSErrors.IndexSignatureHasOverride, member); } return; } if (!this.state.inAbstractClass && member.abstract) { - this.raise(TSErrors.NonAbstractClassHasAbstractMethod, { - at: member - }); + this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member); } if (member.override) { if (!state.hadSuperClass) { - this.raise(TSErrors.OverrideNotInSubClass, { - at: member - }); + this.raise(TSErrors.OverrideNotInSubClass, member); } } super.parseClassMemberWithIsStatic(classBody, member, state, isStatic); @@ -9426,14 +9225,10 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { const optional = this.eat(17); if (optional) methodOrProp.optional = true; if (methodOrProp.readonly && this.match(10)) { - this.raise(TSErrors.ClassMethodHasReadonly, { - at: methodOrProp - }); + this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp); } if (methodOrProp.declare && this.match(10)) { - this.raise(TSErrors.ClassMethodHasDeclare, { - at: methodOrProp - }); + this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp); } } parseExpressionStatement(node, expr, decorators) { @@ -9459,9 +9254,9 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { return result.node; } parseParenItem(node, startLoc) { - node = super.parseParenItem(node, startLoc); + const newNode = super.parseParenItem(node, startLoc); if (this.eat(17)) { - node.optional = true; + newNode.optional = true; this.resetEndLocation(node); } if (this.match(14)) { @@ -9479,9 +9274,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { const startLoc = this.state.startLoc; const isDeclare = this.eatContextual(125); if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) { - throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, { - at: this.state.startLoc - }); + throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc); } const isIdentifier = tokenIsIdentifier(this.state.type); const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node); @@ -9517,16 +9310,13 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { parseClassProperty(node) { this.parseClassPropertyAnnotation(node); if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) { - this.raise(TSErrors.DeclareClassFieldHasInitializer, { - at: this.state.startLoc - }); + this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc); } if (node.abstract && this.match(29)) { const { key } = node; - this.raise(TSErrors.AbstractPropertyHasInitializer, { - at: this.state.startLoc, + this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, { propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]` }); } @@ -9534,13 +9324,10 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } parseClassPrivateProperty(node) { if (node.abstract) { - this.raise(TSErrors.PrivateElementHasAbstract, { - at: node - }); + this.raise(TSErrors.PrivateElementHasAbstract, node); } if (node.accessibility) { - this.raise(TSErrors.PrivateElementHasAccessibility, { - at: node, + this.raise(TSErrors.PrivateElementHasAccessibility, node, { modifier: node.accessibility }); } @@ -9550,26 +9337,21 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { parseClassAccessorProperty(node) { this.parseClassPropertyAnnotation(node); if (node.optional) { - this.raise(TSErrors.AccessorCannotBeOptional, { - at: node - }); + this.raise(TSErrors.AccessorCannotBeOptional, node); } return super.parseClassAccessorProperty(node); } pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier); if (typeParameters && isConstructor) { - this.raise(TSErrors.ConstructorHasTypeParameters, { - at: typeParameters - }); + this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters); } const { declare = false, kind } = method; if (declare && (kind === "get" || kind === "set")) { - this.raise(TSErrors.DeclareAccessor, { - at: method, + this.raise(TSErrors.DeclareAccessor, method, { kind }); } @@ -9583,7 +9365,9 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } declareClassPrivateMethodInScope(node, kind) { if (node.type === "TSDeclareMethod") return; - if (node.type === "MethodDefinition" && !node.value.body) return; + if (node.type === "MethodDefinition" && !hasOwnProperty.call(node.value, "body")) { + return; + } super.declareClassPrivateMethodInScope(node, kind); } parseClassSuper(node) { @@ -9684,9 +9468,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { reportReservedArrowTypeParam(node) { var _node$extra; if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) { - this.raise(TSErrors.ReservedArrowTypeParam, { - at: node - }); + this.raise(TSErrors.ReservedArrowTypeParam, node); } } parseMaybeUnary(refExpressionErrors, sawUnary) { @@ -9740,13 +9522,9 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { case "TSNonNullExpression": case "TSTypeAssertion": if (isLHS) { - this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, { - at: node - }); + this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node); } else { - this.raise(TSErrors.UnexpectedTypeCastInParameter, { - at: node - }); + this.raise(TSErrors.UnexpectedTypeCastInParameter, node); } this.toAssignable(node.expression, isLHS); break; @@ -9827,9 +9605,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { parseMaybeDefault(startLoc, left) { const node = super.parseMaybeDefault(startLoc, left); if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) { - this.raise(TSErrors.TypeAnnotationAfterAssign, { - at: node.typeAnnotation - }); + this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation); } return node; } @@ -9943,9 +9719,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } else if (this.isContextual(129)) { if (!this.hasFollowingLineBreak()) { node.abstract = true; - this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, { - at: node - }); + this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, node); return this.tsParseInterfaceDeclaration(node); } } else { @@ -9960,8 +9734,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { const { key } = method; - this.raise(TSErrors.AbstractMethodHasImplementation, { - at: method, + this.raise(TSErrors.AbstractMethodHasImplementation, method, { methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]` }); } @@ -10043,9 +9816,7 @@ var typescript = superClass => class TypeScriptParserMixin extends superClass { } } if (hasTypeSpecifier && isInTypeOnlyImportExport) { - this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, { - at: loc - }); + this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc); } node[leftOfAsKey] = leftOfAs; node[rightOfAsKey] = rightOfAs; @@ -10148,9 +9919,12 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas } } finishPlaceholder(node, expectedNode) { - const isFinished = !!(node.expectedNode && node.type === "Placeholder"); - node.expectedNode = expectedNode; - return isFinished ? node : this.finishNode(node, "Placeholder"); + let placeholder = node; + if (!placeholder.expectedNode || !placeholder.type) { + placeholder = this.finishNode(placeholder, "Placeholder"); + } + placeholder.expectedNode = expectedNode; + return placeholder; } getTokenFromCode(code) { if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) { @@ -10210,8 +9984,9 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas return this.finishNode(stmt, "LabeledStatement"); } this.semicolon(); - node.name = expr.name; - return this.finishPlaceholder(node, "Statement"); + const stmtPlaceholder = node; + stmtPlaceholder.name = expr.name; + return this.finishPlaceholder(stmtPlaceholder, "Statement"); } parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) { return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse); @@ -10232,9 +10007,7 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas node.body = this.finishPlaceholder(placeholder, "ClassBody"); return this.finishNode(node, type); } else { - throw this.raise(PlaceholderErrors.ClassNameIsRequired, { - at: this.state.startLoc - }); + throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc); } } else { this.parseClassId(node, isStatement, optionalId); @@ -10246,17 +10019,18 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas parseExport(node, decorators) { const placeholder = this.parsePlaceholder("Identifier"); if (!placeholder) return super.parseExport(node, decorators); + const node2 = node; if (!this.isContextual(98) && !this.match(12)) { - node.specifiers = []; - node.source = null; - node.declaration = this.finishPlaceholder(placeholder, "Declaration"); - return this.finishNode(node, "ExportNamedDeclaration"); + node2.specifiers = []; + node2.source = null; + node2.declaration = this.finishPlaceholder(placeholder, "Declaration"); + return this.finishNode(node2, "ExportNamedDeclaration"); } this.expectPlugin("exportDefaultFrom"); const specifier = this.startNode(); specifier.exported = placeholder; - node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; - return super.parseExport(node, decorators); + node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + return super.parseExport(node2, decorators); } isExportDefaultSpecifier() { if (this.match(65)) { @@ -10312,9 +10086,7 @@ var placeholders = superClass => class PlaceholdersParserMixin extends superClas } assertNoSpace() { if (this.state.start > this.state.lastTokEndLoc.index) { - this.raise(PlaceholderErrors.UnexpectedSpace, { - at: this.state.lastTokEndLoc - }); + this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc); } } }; @@ -10503,9 +10275,7 @@ class ExpressionParser extends LValParser { const name = key.type === "Identifier" ? key.name : key.value; if (name === "__proto__") { if (isRecord) { - this.raise(Errors.RecordNoProto, { - at: key - }); + this.raise(Errors.RecordNoProto, key); return; } if (protoRef.used) { @@ -10514,9 +10284,7 @@ class ExpressionParser extends LValParser { refExpressionErrors.doubleProtoLoc = key.loc.start; } } else { - this.raise(Errors.DuplicateProto, { - at: key - }); + this.raise(Errors.DuplicateProto, key); } } protoRef.used = true; @@ -10533,7 +10301,7 @@ class ExpressionParser extends LValParser { this.unexpected(); } this.finalizeRemainingComments(); - expr.comments = this.state.comments; + expr.comments = this.comments; expr.errors = this.state.errors; if (this.options.tokens) { expr.tokens = this.tokens; @@ -10666,8 +10434,7 @@ class ExpressionParser extends LValParser { if (this.isPrivateName(left)) { const value = this.getPrivateNameSV(left); if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) { - this.raise(Errors.PrivateInExpectedIn, { - at: left, + this.raise(Errors.PrivateInExpectedIn, left, { identifierName: value }); } @@ -10697,18 +10464,14 @@ class ExpressionParser extends LValParser { proposal: "minimal" }])) { if (this.state.type === 96 && this.prodParam.hasAwait) { - throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, { - at: this.state.startLoc - }); + throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc); } } node.right = this.parseExprOpRightExpr(op, prec); const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression"); const nextOp = this.state.type; if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) { - throw this.raise(Errors.MixingCoalesceWithLogical, { - at: this.state.startLoc - }); + throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc); } return this.parseExprOp(finishedNode, leftStartLoc, minPrec); } @@ -10727,9 +10490,7 @@ class ExpressionParser extends LValParser { case "smart": return this.withTopicBindingContext(() => { if (this.prodParam.hasYield && this.isContextual(108)) { - throw this.raise(Errors.PipeBodyIsTighter, { - at: this.state.startLoc - }); + throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc); } return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc); }); @@ -10754,23 +10515,18 @@ class ExpressionParser extends LValParser { const body = this.parseMaybeAssign(); const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type); if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) { - this.raise(Errors.PipeUnparenthesizedBody, { - at: startLoc, + this.raise(Errors.PipeUnparenthesizedBody, startLoc, { type: body.type }); } if (!this.topicReferenceWasUsedInCurrentContext()) { - this.raise(Errors.PipeTopicUnused, { - at: startLoc - }); + this.raise(Errors.PipeTopicUnused, startLoc); } return body; } checkExponentialAfterUnary(node) { if (this.match(57)) { - this.raise(Errors.UnexpectedTokenUnaryExponentiation, { - at: node.argument - }); + this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument); } } parseMaybeUnary(refExpressionErrors, sawUnary) { @@ -10797,13 +10553,9 @@ class ExpressionParser extends LValParser { if (this.state.strict && isDelete) { const arg = node.argument; if (arg.type === "Identifier") { - this.raise(Errors.StrictDelete, { - at: node - }); + this.raise(Errors.StrictDelete, node); } else if (this.hasPropertyAsPrivateName(arg)) { - this.raise(Errors.DeletePrivateField, { - at: node - }); + this.raise(Errors.DeletePrivateField, node); } } if (!update) { @@ -10820,9 +10572,7 @@ class ExpressionParser extends LValParser { } = this.state; const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54); if (startsExpr && !this.isAmbiguousAwait()) { - this.raiseOverwrite(Errors.AwaitNotInAsyncContext, { - at: startLoc - }); + this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc); return this.parseAwait(startLoc); } } @@ -10884,9 +10634,7 @@ class ExpressionParser extends LValParser { let optional = false; if (type === 18) { if (noCalls) { - this.raise(Errors.OptionalChainingNoNew, { - at: this.state.startLoc - }); + this.raise(Errors.OptionalChainingNoNew, this.state.startLoc); if (this.lookaheadCharCode() === 40) { state.stop = true; return base; @@ -10916,9 +10664,7 @@ class ExpressionParser extends LValParser { this.expect(3); } else if (this.match(138)) { if (base.type === "Super") { - this.raise(Errors.SuperPrivateField, { - at: startLoc - }); + this.raise(Errors.SuperPrivateField, startLoc); } this.classScope.usePrivateName(this.state.value, this.state.startLoc); node.property = this.parsePrivateName(); @@ -10988,9 +10734,7 @@ class ExpressionParser extends LValParser { node.tag = base; node.quasi = this.parseTemplate(true); if (state.optionalChainMember) { - this.raise(Errors.OptionalChainingNoTemplate, { - at: startLoc - }); + this.raise(Errors.OptionalChainingNoTemplate, startLoc); } return this.finishNode(node, "TaggedTemplateExpression"); } @@ -11012,16 +10756,13 @@ class ExpressionParser extends LValParser { } } if (node.arguments.length === 0 || node.arguments.length > 2) { - this.raise(Errors.ImportCallArity, { - at: node, + this.raise(Errors.ImportCallArity, node, { maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1 }); } else { for (const arg of node.arguments) { if (arg.type === "SpreadElement") { - this.raise(Errors.ImportCallSpreadArgument, { - at: arg - }); + this.raise(Errors.ImportCallSpreadArgument, arg); } } } @@ -11040,9 +10781,7 @@ class ExpressionParser extends LValParser { this.expect(12); if (this.match(close)) { if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) { - this.raise(Errors.ImportCallArgumentTrailingComma, { - at: this.state.lastTokStartLoc - }); + this.raise(Errors.ImportCallArgumentTrailingComma, this.state.lastTokStartLoc); } if (nodeForExtra) { this.addTrailingCommaExtraToNode(nodeForExtra); @@ -11098,9 +10837,7 @@ class ExpressionParser extends LValParser { return this.finishNode(node, "Import"); } } else { - this.raise(Errors.UnsupportedImport, { - at: this.state.lastTokStartLoc - }); + this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc); return this.finishNode(node, "Import"); } case 78: @@ -11174,15 +10911,12 @@ class ExpressionParser extends LValParser { if (callee.type === "MemberExpression") { return this.finishNode(node, "BindExpression"); } else { - throw this.raise(Errors.UnsupportedBind, { - at: callee - }); + throw this.raise(Errors.UnsupportedBind, callee); } } case 138: { - this.raise(Errors.PrivateInExpectedIn, { - at: this.state.startLoc, + this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, { identifierName: this.state.value }); return this.parsePrivateName(); @@ -11282,15 +11016,12 @@ class ExpressionParser extends LValParser { if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) { const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference"; if (!this.topicReferenceIsAllowedInCurrentContext()) { - this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, { - at: startLoc - }); + this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, startLoc); } this.registerTopicReference(); return this.finishNode(node, nodeType); } else { - throw this.raise(Errors.PipeTopicUnconfiguredToken, { - at: startLoc, + throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, { token: tokenLabelName(tokenType) }); } @@ -11306,9 +11037,7 @@ class ExpressionParser extends LValParser { case "smart": return tokenType === 27; default: - throw this.raise(Errors.PipeTopicRequiresHackPipes, { - at: startLoc - }); + throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc); } } parseAsyncArrowUnaryFunction(node) { @@ -11316,9 +11045,7 @@ class ExpressionParser extends LValParser { const params = [this.parseIdentifier()]; this.prodParam.exit(); if (this.hasPrecedingLineBreak()) { - this.raise(Errors.LineTerminatorBeforeArrow, { - at: this.state.curPosition() - }); + this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition()); } this.expect(19); return this.parseArrowExpression(node, params, true); @@ -11346,18 +11073,12 @@ class ExpressionParser extends LValParser { const node = this.startNode(); this.next(); if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) { - this.raise(Errors.SuperNotAllowed, { - at: node - }); + this.raise(Errors.SuperNotAllowed, node); } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) { - this.raise(Errors.UnexpectedSuper, { - at: node - }); + this.raise(Errors.UnexpectedSuper, node); } if (!this.match(10) && !this.match(0) && !this.match(16)) { - this.raise(Errors.UnsupportedSuper, { - at: node - }); + this.raise(Errors.UnsupportedSuper, node); } return this.finishNode(node, "Super"); } @@ -11389,8 +11110,7 @@ class ExpressionParser extends LValParser { const containsEsc = this.state.containsEsc; node.property = this.parseIdentifier(true); if (node.property.name !== propertyName || containsEsc) { - this.raise(Errors.UnsupportedMetaProperty, { - at: node.property, + this.raise(Errors.UnsupportedMetaProperty, node.property, { target: meta.name, onlyValidPropertyName: propertyName }); @@ -11402,9 +11122,7 @@ class ExpressionParser extends LValParser { this.next(); if (this.isContextual(101)) { if (!this.inModule) { - this.raise(Errors.ImportMetaOutsideModule, { - at: id - }); + this.raise(Errors.ImportMetaOutsideModule, id); } this.sawUnambiguousESM = true; } else if (this.isContextual(105) || this.isContextual(97)) { @@ -11412,8 +11130,7 @@ class ExpressionParser extends LValParser { if (!isSource) this.unexpected(); this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation"); if (!this.options.createImportExpressions) { - throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, { - at: this.state.startLoc, + throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, this.state.startLoc, { phase: this.state.value }); } @@ -11559,9 +11276,7 @@ class ExpressionParser extends LValParser { this.next(); const metaProp = this.parseMetaProperty(node, meta, "target"); if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) { - this.raise(Errors.UnexpectedNewTarget, { - at: metaProp - }); + this.raise(Errors.UnexpectedNewTarget, metaProp); } return metaProp; } @@ -11583,9 +11298,7 @@ class ExpressionParser extends LValParser { const callee = this.parseNoCallExpr(); node.callee = callee; if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) { - this.raise(Errors.ImportCallNotNewExpression, { - at: callee - }); + this.raise(Errors.ImportCallNotNewExpression, callee); } } parseTemplateElement(isTagged) { @@ -11599,9 +11312,7 @@ class ExpressionParser extends LValParser { const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1)); if (value === null) { if (!isTagged) { - this.raise(Errors.InvalidEscapeSequenceTemplate, { - at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1) - }); + this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)); } } const isTail = this.match(24); @@ -11619,14 +11330,16 @@ class ExpressionParser extends LValParser { } parseTemplate(isTagged) { const node = this.startNode(); - node.expressions = []; let curElt = this.parseTemplateElement(isTagged); - node.quasis = [curElt]; + const quasis = [curElt]; + const substitutions = []; while (!curElt.tail) { - node.expressions.push(this.parseTemplateSubstitution()); + substitutions.push(this.parseTemplateSubstitution()); this.readTemplateContinuation(); - node.quasis.push(curElt = this.parseTemplateElement(isTagged)); + quasis.push(curElt = this.parseTemplateElement(isTagged)); } + node.expressions = substitutions; + node.quasis = quasis; return this.finishNode(node, "TemplateLiteral"); } parseTemplateSubstitution() { @@ -11661,9 +11374,7 @@ class ExpressionParser extends LValParser { this.checkProto(prop, isRecord, propHash, refExpressionErrors); } if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") { - this.raise(Errors.InvalidRecordProperty, { - at: prop - }); + this.raise(Errors.InvalidRecordProperty, prop); } if (prop.shorthand) { this.addExtra(prop, "shorthand", true); @@ -11681,7 +11392,7 @@ class ExpressionParser extends LValParser { return this.finishNode(node, type); } addTrailingCommaExtraToNode(node) { - this.addExtra(node, "trailingComma", this.state.lastTokStart); + this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index); this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false); } maybeAsyncOrAccessorProp(prop) { @@ -11691,9 +11402,7 @@ class ExpressionParser extends LValParser { let decorators = []; if (this.match(26)) { if (this.hasPlugin("decorators")) { - this.raise(Errors.UnsupportedPropertyDecorator, { - at: this.state.startLoc - }); + this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc); } while (this.match(26)) { decorators.push(this.parseDecorator()); @@ -11718,8 +11427,11 @@ class ExpressionParser extends LValParser { let isGenerator = this.eat(55); this.parsePropertyNamePrefixOperator(prop); const containsEsc = this.state.containsEsc; - const key = this.parsePropertyName(prop, refExpressionErrors); + this.parsePropertyName(prop, refExpressionErrors); if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) { + const { + key + } = prop; const keyName = key.name; if (keyName === "async" && !this.hasPrecedingLineBreak()) { isAsync = true; @@ -11733,8 +11445,7 @@ class ExpressionParser extends LValParser { prop.kind = keyName; if (this.match(55)) { isGenerator = true; - this.raise(Errors.AccessorIsGenerator, { - at: this.state.curPosition(), + this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), { kind: keyName }); this.next(); @@ -11755,14 +11466,10 @@ class ExpressionParser extends LValParser { const paramCount = this.getGetterSetterExpectedParamCount(method); const params = this.getObjectOrClassMethodParams(method); if (params.length !== paramCount) { - this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, { - at: method - }); + this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method); } if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") { - this.raise(Errors.BadSetterRestParameter, { - at: method - }); + this.raise(Errors.BadSetterRestParameter, method); } } parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) { @@ -11795,9 +11502,7 @@ class ExpressionParser extends LValParser { refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc; } } else { - this.raise(Errors.InvalidCoverInitializedName, { - at: shorthandAssignLoc - }); + this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc); } prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key)); } else { @@ -11847,9 +11552,7 @@ class ExpressionParser extends LValParser { refExpressionErrors.privateKeyLoc = privateKeyLoc; } } else { - this.raise(Errors.UnexpectedPrivateField, { - at: privateKeyLoc - }); + this.raise(Errors.UnexpectedPrivateField, privateKeyLoc); } key = this.parsePrivateName(); break; @@ -11863,7 +11566,6 @@ class ExpressionParser extends LValParser { prop.computed = false; } } - return prop.key; } initFunction(node, isAsync) { node.id = null; @@ -11935,9 +11637,7 @@ class ExpressionParser extends LValParser { node.body = this.parseBlock(true, false, hasStrictModeDirective => { const nonSimple = !this.isSimpleParamList(node.params); if (hasStrictModeDirective && nonSimple) { - this.raise(Errors.IllegalLanguageModeDirective, { - at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node - }); + this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node); } const strictModeChanged = !oldStrict && this.state.strict; this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged); @@ -11997,8 +11697,7 @@ class ExpressionParser extends LValParser { let elt; if (this.match(12)) { if (!allowEmpty) { - this.raise(Errors.UnexpectedToken, { - at: this.state.curPosition(), + this.raise(Errors.UnexpectedToken, this.state.curPosition(), { unexpected: "," }); } @@ -12009,9 +11708,7 @@ class ExpressionParser extends LValParser { } else if (this.match(17)) { this.expectPlugin("partialApplication"); if (!allowPlaceholder) { - this.raise(Errors.UnexpectedArgumentPlaceholder, { - at: this.state.startLoc - }); + this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc); } const node = this.startNode(); this.next(); @@ -12061,47 +11758,35 @@ class ExpressionParser extends LValParser { return; } if (checkKeywords && isKeyword(word)) { - this.raise(Errors.UnexpectedKeyword, { - at: startLoc, + this.raise(Errors.UnexpectedKeyword, startLoc, { keyword: word }); return; } const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord; if (reservedTest(word, this.inModule)) { - this.raise(Errors.UnexpectedReservedWord, { - at: startLoc, + this.raise(Errors.UnexpectedReservedWord, startLoc, { reservedWord: word }); return; } else if (word === "yield") { if (this.prodParam.hasYield) { - this.raise(Errors.YieldBindingIdentifier, { - at: startLoc - }); + this.raise(Errors.YieldBindingIdentifier, startLoc); return; } } else if (word === "await") { if (this.prodParam.hasAwait) { - this.raise(Errors.AwaitBindingIdentifier, { - at: startLoc - }); + this.raise(Errors.AwaitBindingIdentifier, startLoc); return; } if (this.scope.inStaticBlock) { - this.raise(Errors.AwaitBindingIdentifierInStaticBlock, { - at: startLoc - }); + this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc); return; } - this.expressionScope.recordAsyncArrowParametersError({ - at: startLoc - }); + this.expressionScope.recordAsyncArrowParametersError(startLoc); } else if (word === "arguments") { if (this.scope.inClassAndNotInNonArrowFunction) { - this.raise(Errors.ArgumentsInClass, { - at: startLoc - }); + this.raise(Errors.ArgumentsInClass, startLoc); return; } } @@ -12115,13 +11800,9 @@ class ExpressionParser extends LValParser { } parseAwait(startLoc) { const node = this.startNodeAt(startLoc); - this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, { - at: node - }); + this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node); if (this.eat(55)) { - this.raise(Errors.ObsoleteAwaitStar, { - at: node - }); + this.raise(Errors.ObsoleteAwaitStar, node); } if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) { if (this.isAmbiguousAwait()) { @@ -12144,9 +11825,7 @@ class ExpressionParser extends LValParser { } parseYield() { const node = this.startNode(); - this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, { - at: node - }); + this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node); this.next(); let delegating = false; let argument = null; @@ -12191,9 +11870,7 @@ class ExpressionParser extends LValParser { proposal: "smart" }])) { if (left.type === "SequenceExpression") { - this.raise(Errors.PipelineHeadSequenceExpression, { - at: leftStartLoc - }); + this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc); } } } @@ -12221,14 +11898,10 @@ class ExpressionParser extends LValParser { } checkSmartPipeTopicBodyEarlyErrors(startLoc) { if (this.match(19)) { - throw this.raise(Errors.PipelineBodyNoArrow, { - at: this.state.startLoc - }); + throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc); } if (!this.topicReferenceWasUsedInCurrentContext()) { - this.raise(Errors.PipelineTopicUnused, { - at: startLoc - }); + this.raise(Errors.PipelineTopicUnused, startLoc); } } withTopicBindingContext(callback) { @@ -12335,10 +12008,10 @@ class ExpressionParser extends LValParser { parsePropertyNamePrefixOperator(prop) {} } const loopLabel = { - kind: "loop" + kind: 1 }, switchLabel = { - kind: "switch" + kind: 2 }; const loneSurrogate = /[\uD800-\uDFFF]/u; const keywordRelationalOperator = /in(?:stanceof)?/y; @@ -12452,7 +12125,7 @@ function babel7CompatTokens(tokens, input) { class StatementParser extends ExpressionParser { parseTopLevel(file, program) { file.program = this.parseProgram(program); - file.comments = this.state.comments; + file.comments = this.comments; if (this.options.tokens) { file.tokens = babel7CompatTokens(this.tokens, this.input); } @@ -12464,8 +12137,7 @@ class StatementParser extends ExpressionParser { this.parseBlockBody(program, true, true, end); if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) { for (const [localName, at] of Array.from(this.scope.undefinedExports)) { - this.raise(Errors.ModuleExportUndefined, { - at, + this.raise(Errors.ModuleExportUndefined, at, { localName }); } @@ -12607,9 +12279,7 @@ class StatementParser extends ExpressionParser { case 68: if (this.lookaheadCharCode() === 46) break; if (!allowFunctionDeclaration) { - this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, { - at: this.state.startLoc - }); + this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc); } return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration); case 80: @@ -12628,13 +12298,9 @@ class StatementParser extends ExpressionParser { case 96: if (!this.state.containsEsc && this.startsAwaitUsing()) { if (!this.isAwaitAllowed()) { - this.raise(Errors.AwaitUsingNotInAsyncContext, { - at: node - }); + this.raise(Errors.AwaitUsingNotInAsyncContext, node); } else if (!allowDeclaration) { - this.raise(Errors.UnexpectedLexicalDeclaration, { - at: node - }); + this.raise(Errors.UnexpectedLexicalDeclaration, node); } this.next(); return this.parseVarStatement(node, "await using"); @@ -12646,13 +12312,9 @@ class StatementParser extends ExpressionParser { } this.expectPlugin("explicitResourceManagement"); if (!this.scope.inModule && this.scope.inTopLevel) { - this.raise(Errors.UnexpectedUsingDeclaration, { - at: this.state.startLoc - }); + this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc); } else if (!allowDeclaration) { - this.raise(Errors.UnexpectedLexicalDeclaration, { - at: this.state.startLoc - }); + this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc); } return this.parseVarStatement(node, "using"); case 100: @@ -12672,9 +12334,7 @@ class StatementParser extends ExpressionParser { case 75: { if (!allowDeclaration) { - this.raise(Errors.UnexpectedLexicalDeclaration, { - at: this.state.startLoc - }); + this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc); } } case 74: @@ -12700,9 +12360,7 @@ class StatementParser extends ExpressionParser { case 82: { if (!this.options.allowImportExportEverywhere && !topLevel) { - this.raise(Errors.UnexpectedImportExport, { - at: this.state.startLoc - }); + this.raise(Errors.UnexpectedImportExport, this.state.startLoc); } this.next(); let result; @@ -12724,9 +12382,7 @@ class StatementParser extends ExpressionParser { { if (this.isAsyncFunction()) { if (!allowDeclaration) { - this.raise(Errors.AsyncFunctionInSingleStatementContext, { - at: this.state.startLoc - }); + this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc); } this.next(); return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration); @@ -12743,9 +12399,7 @@ class StatementParser extends ExpressionParser { } assertModuleNodeAllowed(node) { if (!this.options.allowImportExportEverywhere && !this.inModule) { - this.raise(Errors.ImportOutsideModule, { - at: node - }); + this.raise(Errors.ImportOutsideModule, node); } } decoratorsEnabledBeforeExport() { @@ -12756,9 +12410,7 @@ class StatementParser extends ExpressionParser { if (maybeDecorators) { if (classNode.decorators && classNode.decorators.length > 0) { if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") { - this.raise(Errors.DecoratorsBeforeAfterExport, { - at: classNode.decorators[0] - }); + this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]); } classNode.decorators.unshift(...maybeDecorators); } else { @@ -12782,14 +12434,10 @@ class StatementParser extends ExpressionParser { this.unexpected(); } if (!this.decoratorsEnabledBeforeExport()) { - this.raise(Errors.DecoratorExportClass, { - at: this.state.startLoc - }); + this.raise(Errors.DecoratorExportClass, this.state.startLoc); } } else if (!this.canHaveLeadingDecorator()) { - throw this.raise(Errors.UnexpectedLeadingDecorator, { - at: this.state.startLoc - }); + throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc); } return decorators; } @@ -12809,9 +12457,7 @@ class StatementParser extends ExpressionParser { const paramsStartLoc = this.state.startLoc; node.expression = this.parseMaybeDecoratorArguments(expr); if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) { - this.raise(Errors.DecoratorArgumentsOutsideParentheses, { - at: paramsStartLoc - }); + this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc); } } else { expr = this.parseIdentifier(false); @@ -12860,14 +12506,15 @@ class StatementParser extends ExpressionParser { for (i = 0; i < this.state.labels.length; ++i) { const lab = this.state.labels[i]; if (node.label == null || lab.name === node.label.name) { - if (lab.kind != null && (isBreak || lab.kind === "loop")) break; + if (lab.kind != null && (isBreak || lab.kind === 1)) { + break; + } if (node.label && isBreak) break; } } if (i === this.state.labels.length) { const type = isBreak ? "BreakStatement" : "ContinueStatement"; - this.raise(Errors.IllegalBreakContinue, { - at: node, + this.raise(Errors.IllegalBreakContinue, node, { type }); } @@ -12919,9 +12566,7 @@ class StatementParser extends ExpressionParser { if (startsWithAwaitUsing) { kind = "await using"; if (!this.isAwaitAllowed()) { - this.raise(Errors.AwaitUsingNotInAsyncContext, { - at: this.state.startLoc - }); + this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc); } this.next(); } else { @@ -12932,9 +12577,7 @@ class StatementParser extends ExpressionParser { const init = this.finishNode(initNode, "VariableDeclaration"); const isForIn = this.match(58); if (isForIn && starsWithUsingDeclaration) { - this.raise(Errors.ForInUsing, { - at: init - }); + this.raise(Errors.ForInUsing, init); } if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) { return this.parseForIn(node, init, awaitAt); @@ -12951,14 +12594,10 @@ class StatementParser extends ExpressionParser { const isForOf = this.isContextual(102); if (isForOf) { if (startsWithLet) { - this.raise(Errors.ForOfLet, { - at: init - }); + this.raise(Errors.ForOfLet, init); } if (awaitAt === null && startsWithAsync && init.type === "Identifier") { - this.raise(Errors.ForOfAsync, { - at: init - }); + this.raise(Errors.ForOfAsync, init); } } if (isForOf || this.match(58)) { @@ -12992,9 +12631,7 @@ class StatementParser extends ExpressionParser { } parseReturnStatement(node) { if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) { - this.raise(Errors.IllegalReturn, { - at: this.state.startLoc - }); + this.raise(Errors.IllegalReturn, this.state.startLoc); } this.next(); if (this.isLineTerminator()) { @@ -13024,9 +12661,7 @@ class StatementParser extends ExpressionParser { cur.test = this.parseExpression(); } else { if (sawDefault) { - this.raise(Errors.MultipleDefaultsInSwitch, { - at: this.state.lastTokStartLoc - }); + this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc); } sawDefault = true; cur.test = null; @@ -13049,9 +12684,7 @@ class StatementParser extends ExpressionParser { parseThrowStatement(node) { this.next(); if (this.hasPrecedingLineBreak()) { - this.raise(Errors.NewlineAfterThrow, { - at: this.state.lastTokEndLoc - }); + this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc); } node.argument = this.parseExpression(); this.semicolon(); @@ -13089,9 +12722,7 @@ class StatementParser extends ExpressionParser { } node.finalizer = this.eat(67) ? this.parseBlock() : null; if (!node.handler && !node.finalizer) { - this.raise(Errors.NoCatchOrFinally, { - at: node - }); + this.raise(Errors.NoCatchOrFinally, node); } return this.finishNode(node, "TryStatement"); } @@ -13111,9 +12742,7 @@ class StatementParser extends ExpressionParser { } parseWithStatement(node) { if (this.state.strict) { - this.raise(Errors.StrictWith, { - at: this.state.startLoc - }); + this.raise(Errors.StrictWith, this.state.startLoc); } this.next(); node.object = this.parseHeaderExpression(); @@ -13127,13 +12756,12 @@ class StatementParser extends ExpressionParser { parseLabeledStatement(node, maybeName, expr, flags) { for (const label of this.state.labels) { if (label.name === maybeName) { - this.raise(Errors.LabelRedeclaration, { - at: expr, + this.raise(Errors.LabelRedeclaration, expr, { labelName: maybeName }); } } - const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null; + const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null; for (let i = this.state.labels.length - 1; i >= 0; i--) { const label = this.state.labels[i]; if (label.statementStart === node.start) { @@ -13229,14 +12857,12 @@ class StatementParser extends ExpressionParser { node.await = awaitAt !== null; } if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || !this.options.annexB || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) { - this.raise(Errors.ForInOfLoopInitializer, { - at: init, + this.raise(Errors.ForInOfLoopInitializer, init, { type: isForIn ? "ForInStatement" : "ForOfStatement" }); } if (init.type === "AssignmentPattern") { - this.raise(Errors.InvalidLhs, { - at: init, + this.raise(Errors.InvalidLhs, init, { ancestor: { type: "ForStatement" } @@ -13259,14 +12885,12 @@ class StatementParser extends ExpressionParser { decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn(); if (decl.init === null && !allowMissingInitializer) { if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) { - this.raise(Errors.DeclarationMissingInitializer, { - at: this.state.lastTokEndLoc, + this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, { kind: "destructuring" }); - } else if (kind === "const" && !(this.match(58) || this.isContextual(102))) { - this.raise(Errors.DeclarationMissingInitializer, { - at: this.state.lastTokEndLoc, - kind: "const" + } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) { + this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, { + kind }); } } @@ -13296,9 +12920,7 @@ class StatementParser extends ExpressionParser { this.initFunction(node, isAsync); if (this.match(55)) { if (hangingDeclaration) { - this.raise(Errors.GeneratorInSingleStatementContext, { - at: this.state.startLoc - }); + this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc); } this.next(); node.generator = true; @@ -13353,8 +12975,11 @@ class StatementParser extends ExpressionParser { isClassMethod() { return this.match(10); } + nameIsConstructor(key) { + return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor"; + } isNonstaticConstructor(method) { - return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor"); + return !method.computed && !method.static && this.nameIsConstructor(method.key); } parseClassBody(hadSuperClass, oldStrict) { this.classScope.enter(); @@ -13370,9 +12995,7 @@ class StatementParser extends ExpressionParser { while (!this.match(8)) { if (this.eat(13)) { if (decorators.length > 0) { - throw this.raise(Errors.DecoratorSemicolon, { - at: this.state.lastTokEndLoc - }); + throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc); } continue; } @@ -13388,18 +13011,14 @@ class StatementParser extends ExpressionParser { } this.parseClassMember(classBody, member, state); if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) { - this.raise(Errors.DecoratorConstructor, { - at: member - }); + this.raise(Errors.DecoratorConstructor, member); } } }); this.state.strict = oldStrict; this.next(); if (decorators.length) { - throw this.raise(Errors.TrailingDecorator, { - at: this.state.startLoc - }); + throw this.raise(Errors.TrailingDecorator, this.state.startLoc); } this.classScope.exit(); return this.finishNode(classBody, "ClassBody"); @@ -13457,16 +13076,15 @@ class StatementParser extends ExpressionParser { return; } if (this.isNonstaticConstructor(publicMethod)) { - this.raise(Errors.ConstructorIsGenerator, { - at: publicMethod.key - }); + this.raise(Errors.ConstructorIsGenerator, publicMethod.key); } this.pushClassMethod(classBody, publicMethod, true, false, false, false); return; } - const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc; - const isPrivate = this.match(138); + const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type); const key = this.parseClassElementName(member); + const maybeContextualKw = isContextual ? key.name : null; + const isPrivate = this.isPrivateName(key); const maybeQuestionTokenStartLoc = this.state.startLoc; this.parsePostMemberNameModifiers(publicMember); if (this.isClassMethod()) { @@ -13480,14 +13098,10 @@ class StatementParser extends ExpressionParser { if (isConstructor) { publicMethod.kind = "constructor"; if (state.hadConstructor && !this.hasPlugin("typescript")) { - this.raise(Errors.DuplicateConstructor, { - at: key - }); + this.raise(Errors.DuplicateConstructor, key); } if (isConstructor && this.hasPlugin("typescript") && member.override) { - this.raise(Errors.OverrideOnConstructor, { - at: key - }); + this.raise(Errors.OverrideOnConstructor, key); } state.hadConstructor = true; allowsDirectSuper = state.hadSuperClass; @@ -13499,7 +13113,7 @@ class StatementParser extends ExpressionParser { } else { this.pushClassProperty(classBody, publicProp); } - } else if (isContextual && key.name === "async" && !this.isLineTerminator()) { + } else if (maybeContextualKw === "async" && !this.isLineTerminator()) { this.resetPreviousNodeTrailingComments(key); const isGenerator = this.eat(55); if (publicMember.optional) { @@ -13513,29 +13127,25 @@ class StatementParser extends ExpressionParser { this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true); } else { if (this.isNonstaticConstructor(publicMethod)) { - this.raise(Errors.ConstructorIsAsync, { - at: publicMethod.key - }); + this.raise(Errors.ConstructorIsAsync, publicMethod.key); } this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false); } - } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) { + } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) { this.resetPreviousNodeTrailingComments(key); - method.kind = key.name; + method.kind = maybeContextualKw; const isPrivate = this.match(138); this.parseClassElementName(publicMethod); if (isPrivate) { this.pushClassPrivateMethod(classBody, privateMethod, false, false); } else { if (this.isNonstaticConstructor(publicMethod)) { - this.raise(Errors.ConstructorIsAccessor, { - at: publicMethod.key - }); + this.raise(Errors.ConstructorIsAccessor, publicMethod.key); } this.pushClassMethod(classBody, publicMethod, false, false, false, false); } this.checkGetterSetterParams(publicMethod); - } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) { + } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) { this.expectPlugin("decoratorAutoAccessors"); this.resetPreviousNodeTrailingComments(key); const isPrivate = this.match(138); @@ -13557,21 +13167,18 @@ class StatementParser extends ExpressionParser { value } = this.state; if ((type === 132 || type === 133) && member.static && value === "prototype") { - this.raise(Errors.StaticPrototype, { - at: this.state.startLoc - }); + this.raise(Errors.StaticPrototype, this.state.startLoc); } if (type === 138) { if (value === "constructor") { - this.raise(Errors.ConstructorClassPrivateField, { - at: this.state.startLoc - }); + this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc); } const key = this.parsePrivateName(); member.key = key; return key; } - return this.parsePropertyName(member); + this.parsePropertyName(member); + return member.key; } parseClassStaticBlock(classBody, member) { var _member$decorators; @@ -13586,16 +13193,12 @@ class StatementParser extends ExpressionParser { this.state.labels = oldLabels; classBody.body.push(this.finishNode(member, "StaticBlock")); if ((_member$decorators = member.decorators) != null && _member$decorators.length) { - this.raise(Errors.DecoratorStaticBlock, { - at: member - }); + this.raise(Errors.DecoratorStaticBlock, member); } } pushClassProperty(classBody, prop) { - if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) { - this.raise(Errors.ConstructorClassField, { - at: prop.key - }); + if (!prop.computed && this.nameIsConstructor(prop.key)) { + this.raise(Errors.ConstructorClassField, prop.key); } classBody.body.push(this.parseClassProperty(prop)); } @@ -13605,13 +13208,8 @@ class StatementParser extends ExpressionParser { this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start); } pushClassAccessorProperty(classBody, prop, isPrivate) { - if (!isPrivate && !prop.computed) { - const key = prop.key; - if (key.name === "constructor" || key.value === "constructor") { - this.raise(Errors.ConstructorClassField, { - at: key - }); - } + if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) { + this.raise(Errors.ConstructorClassField, prop.key); } const node = this.parseClassAccessorProperty(prop); classBody.body.push(node); @@ -13666,9 +13264,7 @@ class StatementParser extends ExpressionParser { if (optionalId || !isStatement) { node.id = null; } else { - throw this.raise(Errors.MissingClassName, { - at: this.state.startLoc - }); + throw this.raise(Errors.MissingClassName, this.state.startLoc); } } } @@ -13686,9 +13282,7 @@ class StatementParser extends ExpressionParser { if (hasStar && !hasNamespace) { if (hasDefault) this.unexpected(); if (decorators) { - throw this.raise(Errors.UnsupportedDecoratorExport, { - at: node - }); + throw this.raise(Errors.UnsupportedDecoratorExport, node); } this.parseExportFrom(node, true); return this.finishNode(node, "ExportAllDeclaration"); @@ -13704,9 +13298,7 @@ class StatementParser extends ExpressionParser { if (isFromRequired || hasSpecifiers) { hasDeclaration = false; if (decorators) { - throw this.raise(Errors.UnsupportedDecoratorExport, { - at: node - }); + throw this.raise(Errors.UnsupportedDecoratorExport, node); } this.parseExportFrom(node, isFromRequired); } else { @@ -13719,9 +13311,7 @@ class StatementParser extends ExpressionParser { if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") { this.maybeTakeDecorators(decorators, node2.declaration, node2); } else if (decorators) { - throw this.raise(Errors.UnsupportedDecoratorExport, { - at: node - }); + throw this.raise(Errors.UnsupportedDecoratorExport, node); } return this.finishNode(node2, "ExportNamedDeclaration"); } @@ -13732,9 +13322,7 @@ class StatementParser extends ExpressionParser { if (decl.type === "ClassDeclaration") { this.maybeTakeDecorators(decorators, decl, node2); } else if (decorators) { - throw this.raise(Errors.UnsupportedDecoratorExport, { - at: node - }); + throw this.raise(Errors.UnsupportedDecoratorExport, node); } this.checkExport(node2, true, true); return this.finishNode(node2, "ExportDefaultDeclaration"); @@ -13757,7 +13345,8 @@ class StatementParser extends ExpressionParser { } maybeParseExportNamespaceSpecifier(node) { if (this.isContextual(93)) { - if (!node.specifiers) node.specifiers = []; + var _ref, _ref$specifiers; + (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = []; const specifier = this.startNodeAt(this.state.lastTokStartLoc); this.next(); specifier.exported = this.parseModuleExportName(); @@ -13768,13 +13357,14 @@ class StatementParser extends ExpressionParser { } maybeParseExportNamedSpecifiers(node) { if (this.match(5)) { - if (!node.specifiers) node.specifiers = []; - const isTypeExport = node.exportKind === "type"; - node.specifiers.push(...this.parseExportSpecifiers(isTypeExport)); - node.source = null; - node.declaration = null; + const node2 = node; + if (!node2.specifiers) node2.specifiers = []; + const isTypeExport = node2.exportKind === "type"; + node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport)); + node2.source = null; + node2.declaration = null; if (this.hasPlugin("importAssertions")) { - node.assertions = []; + node2.assertions = []; } return true; } @@ -13812,16 +13402,12 @@ class StatementParser extends ExpressionParser { } if (this.match(26)) { if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) { - this.raise(Errors.DecoratorBeforeExport, { - at: this.state.startLoc - }); + this.raise(Errors.DecoratorBeforeExport, this.state.startLoc); } return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true); } if (this.match(75) || this.match(74) || this.isLet()) { - throw this.raise(Errors.UnsupportedDefaultExport, { - at: this.state.startLoc - }); + throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc); } const res = this.parseMaybeAssignAllowIn(); this.semicolon(); @@ -13884,13 +13470,19 @@ class StatementParser extends ExpressionParser { this.expectOnePlugin(["decorators", "decorators-legacy"]); if (this.hasPlugin("decorators")) { if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) { - this.raise(Errors.DecoratorBeforeExport, { - at: this.state.startLoc - }); + this.raise(Errors.DecoratorBeforeExport, this.state.startLoc); } return true; } } + if (this.isContextual(107)) { + this.raise(Errors.UsingDeclarationExport, this.state.startLoc); + return true; + } + if (this.isContextual(96) && this.startsAwaitUsing()) { + this.raise(Errors.UsingDeclarationExport, this.state.startLoc); + return true; + } return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction(); } checkExport(node, checkNames, isDefault, isFrom) { @@ -13902,9 +13494,7 @@ class StatementParser extends ExpressionParser { var _declaration$extra; const declaration = node.declaration; if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) { - this.raise(Errors.ExportDefaultFromAsIdentifier, { - at: declaration - }); + this.raise(Errors.ExportDefaultFromAsIdentifier, declaration); } } } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) { @@ -13919,8 +13509,7 @@ class StatementParser extends ExpressionParser { local } = specifier; if (local.type !== "Identifier") { - this.raise(Errors.ExportBindingIsString, { - at: specifier, + this.raise(Errors.ExportBindingIsString, specifier, { localName: local.value, exportName }); @@ -13931,12 +13520,15 @@ class StatementParser extends ExpressionParser { } } } else if (node.declaration) { - if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") { - const id = node.declaration.id; + const decl = node.declaration; + if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") { + const { + id + } = decl; if (!id) throw new Error("Assertion failure"); this.checkDuplicateExports(node, id.name); - } else if (node.declaration.type === "VariableDeclaration") { - for (const declaration of node.declaration.declarations) { + } else if (decl.type === "VariableDeclaration") { + for (const declaration of decl.declarations) { this.checkDeclaration(declaration.id); } } @@ -13967,12 +13559,9 @@ class StatementParser extends ExpressionParser { checkDuplicateExports(node, exportName) { if (this.exportedIdentifiers.has(exportName)) { if (exportName === "default") { - this.raise(Errors.DuplicateDefaultExport, { - at: node - }); + this.raise(Errors.DuplicateDefaultExport, node); } else { - this.raise(Errors.DuplicateExport, { - at: node, + this.raise(Errors.DuplicateExport, node, { exportName }); } @@ -14013,8 +13602,7 @@ class StatementParser extends ExpressionParser { const result = this.parseStringLiteral(this.state.value); const surrogate = result.value.match(loneSurrogate); if (surrogate) { - this.raise(Errors.ModuleExportNameHasLoneSurrogate, { - at: result, + this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, { surrogateCharCode: surrogate[0].charCodeAt(0) }); } @@ -14040,27 +13628,19 @@ class StatementParser extends ExpressionParser { const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null; if (node.phase === "source") { if (singleBindingType !== "ImportDefaultSpecifier") { - this.raise(Errors.SourcePhaseImportRequiresDefault, { - at: specifiers[0].loc.start - }); + this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start); } } else if (node.phase === "defer") { if (singleBindingType !== "ImportNamespaceSpecifier") { - this.raise(Errors.DeferImportRequiresNamespace, { - at: specifiers[0].loc.start - }); + this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start); } } else if (node.module) { var _node$assertions; if (singleBindingType !== "ImportDefaultSpecifier") { - this.raise(Errors.ImportReflectionNotBinding, { - at: specifiers[0].loc.start - }); + this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start); } if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) { - this.raise(Errors.ImportReflectionHasAssertion, { - at: node.specifiers[0].loc.start - }); + this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start); } } } @@ -14082,9 +13662,7 @@ class StatementParser extends ExpressionParser { } }); if (nonDefaultNamedSpecifier !== undefined) { - this.raise(Errors.ImportJSONBindingNotDefault, { - at: nonDefaultNamedSpecifier.loc.start - }); + this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start); } } } @@ -14191,8 +13769,7 @@ class StatementParser extends ExpressionParser { const node = this.startNode(); const keyName = this.state.value; if (attrNames.has(keyName)) { - this.raise(Errors.ModuleAttributesWithDuplicateKeys, { - at: this.state.startLoc, + this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, { key: keyName }); } @@ -14204,9 +13781,7 @@ class StatementParser extends ExpressionParser { } this.expect(14); if (!this.match(133)) { - throw this.raise(Errors.ModuleAttributeInvalidValue, { - at: this.state.startLoc - }); + throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc); } node.value = this.parseStringLiteral(this.state.value); attrs.push(this.finishNode(node, "ImportAttribute")); @@ -14221,22 +13796,17 @@ class StatementParser extends ExpressionParser { const node = this.startNode(); node.key = this.parseIdentifier(true); if (node.key.name !== "type") { - this.raise(Errors.ModuleAttributeDifferentFromType, { - at: node.key - }); + this.raise(Errors.ModuleAttributeDifferentFromType, node.key); } if (attributes.has(node.key.name)) { - this.raise(Errors.ModuleAttributesWithDuplicateKeys, { - at: node.key, + this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, { key: node.key.name }); } attributes.add(node.key.name); this.expect(14); if (!this.match(133)) { - throw this.raise(Errors.ModuleAttributeInvalidValue, { - at: this.state.startLoc - }); + throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc); } node.value = this.parseStringLiteral(this.state.value); attrs.push(this.finishNode(node, "ImportAttribute")); @@ -14263,9 +13833,7 @@ class StatementParser extends ExpressionParser { } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) { if (this.hasPlugin("importAttributes")) { if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) { - this.raise(Errors.ImportAttributesUseAssert, { - at: this.state.startLoc - }); + this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc); } this.addExtra(node, "deprecatedAssertSyntax", true); } else { @@ -14316,9 +13884,7 @@ class StatementParser extends ExpressionParser { first = false; } else { if (this.eat(14)) { - throw this.raise(Errors.DestructureNamedImport, { - at: this.state.startLoc - }); + throw this.raise(Errors.DestructureNamedImport, this.state.startLoc); } this.expect(12); if (this.eat(8)) break; @@ -14339,8 +13905,7 @@ class StatementParser extends ExpressionParser { imported } = specifier; if (importedIsString) { - throw this.raise(Errors.ImportBindingIsString, { - at: specifier, + throw this.raise(Errors.ImportBindingIsString, specifier, { importName: imported.value }); } @@ -14375,6 +13940,7 @@ class Parser extends StatementParser { file.errors = null; this.parseTopLevel(file, program); file.errors = this.state.errors; + file.comments.length = this.state.commentsLen; return file; } } |
