Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -11,6 +11,8 @@ var N = _interopRequireWildcard(require("../types"));
var _scopeflags = require("../util/scopeflags");
var _error = require("../parser/error");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -45,6 +47,13 @@ var _default = superClass => class extends superClass {
return node;
}
estreeParseDecimalLiteral(value) {
const decimal = null;
const node = this.estreeParseLiteral(decimal);
node.decimal = String(node.value || value);
return node;
}
estreeParseLiteral(value) {
return this.parseLiteral(value, "Literal");
}
@@ -73,20 +82,8 @@ var _default = superClass => class extends superClass {
}
}
checkGetterSetterParams(method) {
const prop = method;
const paramCount = prop.kind === "get" ? 0 : 1;
const start = prop.start;
if (prop.value.params.length !== paramCount) {
if (prop.kind === "get") {
this.raise(start, "getter must not have any formal parameters");
} else {
this.raise(start, "setter must have exactly one formal parameter");
}
} else if (prop.kind === "set" && prop.value.params[0].type === "RestElement") {
this.raise(start, "setter function argument must not be a rest parameter");
}
getObjectOrClassMethodParams(method) {
return method.value.params;
}
checkLVal(expr, bindingType = _scopeflags.BIND_NONE, checkClashes, contextDescription, disallowLetBinding) {
@@ -102,29 +99,16 @@ var _default = superClass => class extends superClass {
}
}
checkDuplicatedProto(prop, protoRef, refExpressionErrors) {
if (prop.type === "SpreadElement" || prop.computed || prop.method || prop.shorthand) {
checkProto(prop, isRecord, protoRef, refExpressionErrors) {
if (prop.method) {
return;
}
const key = prop.key;
const name = key.type === "Identifier" ? key.name : String(key.value);
if (name === "__proto__" && prop.kind === "init") {
if (protoRef.used) {
if (refExpressionErrors && refExpressionErrors.doubleProto === -1) {
refExpressionErrors.doubleProto = key.start;
} else {
this.raise(key.start, "Redefinition of __proto__ property");
}
}
protoRef.used = true;
}
super.checkProto(prop, isRecord, protoRef, refExpressionErrors);
}
isValidDirective(stmt) {
return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && (!stmt.expression.extra || !stmt.expression.extra.parenthesized);
return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !stmt.expression.extra?.parenthesized;
}
stmtToDirective(stmt) {
@@ -164,6 +148,9 @@ var _default = superClass => class extends superClass {
case _types.types.bigint:
return this.estreeParseBigIntLiteral(this.state.value);
case _types.types.decimal:
return this.estreeParseDecimalLiteral(this.state.value);
case _types.types._null:
return this.estreeParseLiteral(null);
@@ -201,8 +188,8 @@ var _default = superClass => class extends superClass {
return this.finishNode(node, type);
}
parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) {
const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc);
parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
if (node) {
node.type = "Property";
@@ -235,9 +222,9 @@ var _default = superClass => class extends superClass {
toAssignableObjectExpressionProp(prop, isLast) {
if (prop.kind === "get" || prop.kind === "set") {
throw this.raise(prop.key.start, "Object pattern can't contain getter or setter");
throw this.raise(prop.key.start, _error.Errors.PatternHasAccessor);
} else if (prop.method) {
throw this.raise(prop.key.start, "Object pattern can't contain methods");
throw this.raise(prop.key.start, _error.Errors.PatternHasMethod);
} else {
super.toAssignableObjectExpressionProp(prop, isLast);
}
@@ -256,12 +243,53 @@ var _default = superClass => class extends superClass {
return node;
}
toReferencedListDeep(exprList, isParenthesizedExpr) {
if (!exprList) {
toReferencedArguments(node) {
if (node.type === "ImportExpression") {
return;
}
super.toReferencedListDeep(exprList, isParenthesizedExpr);
super.toReferencedArguments(node);
}
parseExport(node) {
super.parseExport(node);
switch (node.type) {
case "ExportAllDeclaration":
node.exported = null;
break;
case "ExportNamedDeclaration":
if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
node.type = "ExportAllDeclaration";
node.exported = node.specifiers[0].exported;
delete node.specifiers;
}
break;
}
return node;
}
parseSubscript(base, startPos, startLoc, noCalls, state) {
const node = super.parseSubscript(base, startPos, startLoc, noCalls, state);
if (state.optionalChainMember) {
if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
node.type = node.type.substring(8);
}
if (state.stop) {
const chain = this.startNodeAtNode(node);
chain.expression = node;
return this.finishNode(chain, "ChainExpression");
}
} else if (node.type === "MemberExpression" || node.type === "CallExpression") {
node.optional = false;
}
return node;
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -17,6 +17,8 @@ var _identifier = require("../../util/identifier");
var _whitespace = require("../../util/whitespace");
var _error = require("../../parser/error");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -25,6 +27,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
const HEX_NUMBER = /^[\da-fA-F]+$/;
const DECIMAL_NUMBER = /^\d+$/;
const JsxErrors = Object.freeze({
AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression",
MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>",
MissingClosingTagElement: "Expected corresponding JSX closing tag for <%0>",
UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text",
UnterminatedJsxContent: "Unterminated JSX contents",
UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
});
_context.types.j_oTag = new _context.TokContext("<tag", false);
_context.types.j_cTag = new _context.TokContext("</tag", false);
_context.types.j_expr = new _context.TokContext("<tag>...</tag>", true, true);
@@ -81,7 +91,7 @@ var _default = superClass => class extends superClass {
for (;;) {
if (this.state.pos >= this.length) {
throw this.raise(this.state.start, "Unterminated JSX contents");
throw this.raise(this.state.start, JsxErrors.UnterminatedJsxContent);
}
const ch = this.input.charCodeAt(this.state.pos);
@@ -143,7 +153,7 @@ var _default = superClass => class extends superClass {
for (;;) {
if (this.state.pos >= this.length) {
throw this.raise(this.state.start, "Unterminated string constant");
throw this.raise(this.state.start, _error.Errors.UnterminatedString);
}
const ch = this.input.charCodeAt(this.state.pos);
@@ -275,7 +285,7 @@ var _default = superClass => class extends superClass {
node = this.jsxParseExpressionContainer(node);
if (node.expression.type === "JSXEmptyExpression") {
this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
this.raise(node.start, JsxErrors.AttributeIsEmpty);
}
return node;
@@ -285,7 +295,7 @@ var _default = superClass => class extends superClass {
return this.parseExprAtom();
default:
throw this.raise(this.state.start, "JSX value should be either an expression or a quoted JSX text");
throw this.raise(this.state.start, JsxErrors.UnsupportedJsxValue);
}
}
@@ -317,7 +327,7 @@ var _default = superClass => class extends superClass {
if (this.eat(_types.types.braceL)) {
this.expect(_types.types.ellipsis);
node.argument = this.parseMaybeAssign();
node.argument = this.parseMaybeAssignAllowIn();
this.expect(_types.types.braceR);
return this.finishNode(node, "JSXSpreadAttribute");
}
@@ -411,12 +421,12 @@ var _default = superClass => class extends superClass {
}
if (isFragment(openingElement) && !isFragment(closingElement)) {
this.raise(closingElement.start, "Expected corresponding JSX closing tag for <>");
this.raise(closingElement.start, JsxErrors.MissingClosingTagFragment);
} else if (!isFragment(openingElement) && isFragment(closingElement)) {
this.raise(closingElement.start, "Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">");
this.raise(closingElement.start, JsxErrors.MissingClosingTagElement, getQualifiedJSXName(openingElement.name));
} else if (!isFragment(openingElement) && !isFragment(closingElement)) {
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
this.raise(closingElement.start, "Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">");
this.raise(closingElement.start, JsxErrors.MissingClosingTagElement, getQualifiedJSXName(openingElement.name));
}
}
}
@@ -432,7 +442,7 @@ var _default = superClass => class extends superClass {
node.children = children;
if (this.isRelational("<")) {
throw this.raise(this.state.start, "Adjacent JSX elements must be wrapped in an enclosing tag. " + "Did you want a JSX fragment <>...</>?");
throw this.raise(this.state.start, JsxErrors.UnwrappedAdjacentJSXElements);
}
return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");

View File

@@ -108,6 +108,7 @@ var _default = superClass => class extends superClass {
const type = isStatement ? "ClassDeclaration" : "ClassExpression";
this.next();
this.takeDecorators(node);
const oldStrict = this.state.strict;
const placeholder = this.parsePlaceholder("Identifier");
if (placeholder) {
@@ -125,7 +126,7 @@ var _default = superClass => class extends superClass {
}
this.parseClassSuper(node);
node.body = this.parsePlaceholder("ClassBody") || this.parseClassBody(!!node.superClass);
node.body = this.parsePlaceholder("ClassBody") || this.parseClassBody(!!node.superClass, oldStrict);
return this.finishNode(node, type);
}
@@ -147,6 +148,20 @@ var _default = superClass => class extends superClass {
return super.parseExport(node);
}
isExportDefaultSpecifier() {
if (this.match(_types.types._default)) {
const next = this.nextTokenStart();
if (this.isUnparsedContextual(next, "from")) {
if (this.input.startsWith(_types.types.placeholder.label, this.nextTokenStartSince(next + 4))) {
return true;
}
}
}
return super.isExportDefaultSpecifier();
}
maybeParseExportDefaultSpecifier(node) {
if (node.specifiers && node.specifiers.length > 0) {
return true;
@@ -160,7 +175,7 @@ var _default = superClass => class extends superClass {
specifiers
} = node;
if (specifiers && specifiers.length) {
if (specifiers?.length) {
node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
}

View File

@@ -15,6 +15,10 @@ var _scopeflags = require("../../util/scopeflags");
var _scope = _interopRequireDefault(require("./scope"));
var _productionParameter = require("../../util/production-parameter");
var _error = require("../../parser/error");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
@@ -35,6 +39,36 @@ function assert(x) {
}
}
const TSErrors = Object.freeze({
ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier",
ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier",
ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
DuplicateModifier: "Duplicate modifier: '%0'",
EmptyHeritageClauseType: "'%0' list cannot be empty.",
EmptyTypeArguments: "Type argument list cannot be empty.",
EmptyTypeParameters: "Type parameter list cannot be empty.",
IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier",
IndexSignatureHasAccessibility: "Index signatures cannot have an accessibility modifier ('%0')",
IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier",
IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier",
InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
PrivateElementHasAccessibility: "Private elements cannot have an accessibility modifier ('%0')",
TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`",
UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
UnsupportedImportTypeArgument: "Argument in a type import must be a string literal",
UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
UnsupportedSignatureParameterKind: "Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got %0"
});
function keywordTypeFromName(value) {
switch (value) {
case "any":
@@ -100,22 +134,18 @@ var _default = superClass => class extends superClass {
return undefined;
}
tsParseModifiers(allowedModifiers) {
const modifiers = Object.create(null);
while (true) {
tsParseModifiers(modified, allowedModifiers) {
for (;;) {
const startPos = this.state.start;
const modifier = this.tsParseModifier(allowedModifiers);
if (!modifier) break;
if (Object.hasOwnProperty.call(modifiers, modifier)) {
this.raise(startPos, `Duplicate modifier: '${modifier}'`);
if (Object.hasOwnProperty.call(modified, modifier)) {
this.raise(startPos, TSErrors.DuplicateModifier, modifier);
}
modifiers[modifier] = true;
modified[modifier] = true;
}
return modifiers;
}
tsIsListTerminator(kind) {
@@ -154,7 +184,7 @@ var _default = superClass => class extends superClass {
tsParseDelimitedListWorker(kind, parseElement, expectSuccess) {
const result = [];
while (true) {
for (;;) {
if (this.tsIsListTerminator(kind)) {
break;
}
@@ -211,7 +241,7 @@ var _default = superClass => class extends superClass {
this.expect(_types.types.parenL);
if (!this.match(_types.types.string)) {
this.raise(this.state.start, "Argument in a type import must be a string literal");
this.raise(this.state.start, TSErrors.UnsupportedImportTypeArgument);
}
node.argument = this.parseExprAtom();
@@ -303,6 +333,11 @@ var _default = superClass => class extends superClass {
}
node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this), false, true);
if (node.params.length === 0) {
this.raise(node.start, TSErrors.EmptyTypeParameters);
}
return this.finishNode(node, "TSTypeParameterDeclaration");
}
@@ -331,7 +366,7 @@ var _default = superClass => class extends superClass {
tsParseBindingListForSignature() {
return this.parseBindingList(_types.types.parenR, 41).map(pattern => {
if (pattern.type !== "Identifier" && pattern.type !== "RestElement" && pattern.type !== "ObjectPattern" && pattern.type !== "ArrayPattern") {
this.raise(pattern.start, "Name in a signature must be an Identifier, ObjectPattern or ArrayPattern," + `instead got ${pattern.type}`);
this.raise(pattern.start, TSErrors.UnsupportedSignatureParameterKind, pattern.type);
}
return pattern;
@@ -481,6 +516,7 @@ var _default = superClass => class extends superClass {
this.expect(_types.types.bracketL);
node.typeParameter = this.tsParseMappedTypeParameter();
node.nameType = this.eatContextual("as") ? this.tsParseType() : null;
this.expect(_types.types.bracketR);
if (this.match(_types.types.plusMin)) {
@@ -501,35 +537,66 @@ var _default = superClass => class extends superClass {
const node = this.startNode();
node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
let seenOptionalElement = false;
let labeledElements = null;
node.elementTypes.forEach(elementNode => {
if (elementNode.type === "TSOptionalType") {
seenOptionalElement = true;
} else if (seenOptionalElement && elementNode.type !== "TSRestType") {
this.raise(elementNode.start, "A required element cannot follow an optional element.");
let {
type
} = elementNode;
if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
this.raise(elementNode.start, TSErrors.OptionalTypeBeforeRequired);
}
seenOptionalElement = seenOptionalElement || type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType";
if (type === "TSRestType") {
elementNode = elementNode.typeAnnotation;
type = elementNode.type;
}
const isLabeled = type === "TSNamedTupleMember";
labeledElements = labeledElements ?? isLabeled;
if (labeledElements !== isLabeled) {
this.raise(elementNode.start, TSErrors.MixedLabeledAndUnlabeledElements);
}
});
return this.finishNode(node, "TSTupleType");
}
tsParseTupleElementType() {
if (this.match(_types.types.ellipsis)) {
const restNode = this.startNode();
this.next();
restNode.typeAnnotation = this.tsParseType();
const {
start: startPos,
startLoc
} = this.state;
const rest = this.eat(_types.types.ellipsis);
let type = this.tsParseType();
const optional = this.eat(_types.types.question);
const labeled = this.eat(_types.types.colon);
if (this.match(_types.types.comma) && this.lookaheadCharCode() !== 93) {
this.raiseRestNotLast(this.state.start);
if (labeled) {
const labeledNode = this.startNodeAtNode(type);
labeledNode.optional = optional;
if (type.type === "TSTypeReference" && !type.typeParameters && type.typeName.type === "Identifier") {
labeledNode.label = type.typeName;
} else {
this.raise(type.start, TSErrors.InvalidTupleMemberLabel);
labeledNode.label = type;
}
return this.finishNode(restNode, "TSRestType");
}
const type = this.tsParseType();
if (this.eat(_types.types.question)) {
labeledNode.elementType = this.tsParseType();
type = this.finishNode(labeledNode, "TSNamedTupleMember");
} else if (optional) {
const optionalTypeNode = this.startNodeAtNode(type);
optionalTypeNode.typeAnnotation = type;
return this.finishNode(optionalTypeNode, "TSOptionalType");
type = this.finishNode(optionalTypeNode, "TSOptionalType");
}
if (rest) {
const restNode = this.startNodeAt(startPos, startLoc);
restNode.typeAnnotation = type;
type = this.finishNode(restNode, "TSRestType");
}
return type;
@@ -560,6 +627,7 @@ var _default = superClass => class extends superClass {
node.literal = (() => {
switch (this.state.type) {
case _types.types.num:
case _types.types.bigint:
case _types.types.string:
case _types.types._true:
case _types.types._false:
@@ -575,16 +643,15 @@ var _default = superClass => class extends superClass {
tsParseTemplateLiteralType() {
const node = this.startNode();
const templateNode = this.parseTemplate(false);
if (templateNode.expressions.length > 0) {
this.raise(templateNode.expressions[0].start, "Template literal types cannot have any substitution");
}
node.literal = templateNode;
node.literal = this.parseTemplate(false);
return this.finishNode(node, "TSLiteralType");
}
parseTemplateSubstitution() {
if (this.state.inType) return this.tsParseType();
return super.parseTemplateSubstitution();
}
tsParseThisTypeOrThisTypePredicate() {
const thisKeyword = this.tsParseThisTypeNode();
@@ -614,6 +681,7 @@ var _default = superClass => class extends superClass {
case _types.types.string:
case _types.types.num:
case _types.types.bigint:
case _types.types._true:
case _types.types._false:
return this.tsParseLiteralTypeNode();
@@ -621,8 +689,9 @@ var _default = superClass => class extends superClass {
case _types.types.plusMin:
if (this.state.value === "-") {
const node = this.startNode();
const nextToken = this.lookahead();
if (this.lookahead().type !== _types.types.num) {
if (nextToken.type !== _types.types.num && nextToken.type !== _types.types.bigint) {
throw this.unexpected();
}
@@ -698,7 +767,7 @@ var _default = superClass => class extends superClass {
return;
default:
this.raise(node.start, "'readonly' type modifier is only permitted on array and tuple literal types.");
this.raise(node.start, TSErrors.UnexpectedReadonly);
}
}
@@ -822,7 +891,7 @@ var _default = superClass => class extends superClass {
return this.tsInType(() => {
const t = this.startNode();
this.expect(returnToken);
const asserts = this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
if (asserts && this.match(_types.types._this)) {
let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
@@ -898,7 +967,7 @@ var _default = superClass => class extends superClass {
}
if (containsEsc) {
this.raise(this.state.lastTokStart, "Escape sequence in keyword asserts");
this.raise(this.state.lastTokStart, _error.Errors.InvalidEscapedReservedWord, "asserts");
}
return true;
@@ -958,7 +1027,7 @@ var _default = superClass => class extends superClass {
const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", this.tsParseExpressionWithTypeArguments.bind(this));
if (!delimitedList.length) {
this.raise(originalStart, `'${descriptor}' list cannot be empty.`);
this.raise(originalStart, TSErrors.EmptyHeritageClauseType, descriptor);
}
return delimitedList;
@@ -994,7 +1063,17 @@ var _default = superClass => class extends superClass {
node.id = this.parseIdentifier();
this.checkLVal(node.id, _scopeflags.BIND_TS_TYPE, undefined, "typescript type alias");
node.typeParameters = this.tsTryParseTypeParameters();
node.typeAnnotation = this.tsExpectThenParseType(_types.types.eq);
node.typeAnnotation = this.tsInType(() => {
this.expect(_types.types.eq);
if (this.isContextual("intrinsic") && this.lookahead().type !== _types.types.dot) {
const node = this.startNode();
this.next();
return this.finishNode(node, "TSIntrinsicKeyword");
}
return this.tsParseType();
});
this.semicolon();
return this.finishNode(node, "TSTypeAliasDeclaration");
}
@@ -1045,7 +1124,7 @@ var _default = superClass => class extends superClass {
node.id = this.match(_types.types.string) ? this.parseExprAtom() : this.parseIdentifier(true);
if (this.eat(_types.types.eq)) {
node.initializer = this.parseMaybeAssign();
node.initializer = this.parseMaybeAssignAllowIn();
}
return this.finishNode(node, "TSEnumMember");
@@ -1083,7 +1162,9 @@ var _default = superClass => class extends superClass {
node.body = inner;
} else {
this.scope.enter(_scopeflags.SCOPE_TS_MODULE);
this.prodParam.enter(_productionParameter.PARAM);
node.body = this.tsParseModuleBlock();
this.prodParam.exit();
this.scope.exit();
}
@@ -1102,7 +1183,9 @@ var _default = superClass => class extends superClass {
if (this.match(_types.types.braceL)) {
this.scope.enter(_scopeflags.SCOPE_TS_MODULE);
this.prodParam.enter(_productionParameter.PARAM);
node.body = this.tsParseModuleBlock();
this.prodParam.exit();
this.scope.exit();
} else {
this.semicolon();
@@ -1182,36 +1265,39 @@ var _default = superClass => class extends superClass {
kind = "let";
}
switch (starttype) {
case _types.types._function:
return this.parseFunctionStatement(nany, false, true);
return this.tsInDeclareContext(() => {
switch (starttype) {
case _types.types._function:
nany.declare = true;
return this.parseFunctionStatement(nany, false, true);
case _types.types._class:
nany.declare = true;
return this.parseClass(nany, true, false);
case _types.types._class:
nany.declare = true;
return this.parseClass(nany, true, false);
case _types.types._const:
if (this.match(_types.types._const) && this.isLookaheadContextual("enum")) {
this.expect(_types.types._const);
this.expectContextual("enum");
return this.tsParseEnumDeclaration(nany, true);
}
case _types.types._var:
kind = kind || this.state.value;
return this.parseVarStatement(nany, kind);
case _types.types.name:
{
const value = this.state.value;
if (value === "global") {
return this.tsParseAmbientExternalModuleDeclaration(nany);
} else {
return this.tsParseDeclaration(nany, value, true);
case _types.types._const:
if (this.match(_types.types._const) && this.isLookaheadContextual("enum")) {
this.expect(_types.types._const);
this.expectContextual("enum");
return this.tsParseEnumDeclaration(nany, true);
}
}
}
case _types.types._var:
kind = kind || this.state.value;
return this.parseVarStatement(nany, kind);
case _types.types.name:
{
const value = this.state.value;
if (value === "global") {
return this.tsParseAmbientExternalModuleDeclaration(nany);
} else {
return this.tsParseDeclaration(nany, value, true);
}
}
}
});
}
tsTryParseExportDeclaration() {
@@ -1235,11 +1321,13 @@ var _default = superClass => class extends superClass {
case "global":
if (this.match(_types.types.braceL)) {
this.scope.enter(_scopeflags.SCOPE_TS_MODULE);
this.prodParam.enter(_productionParameter.PARAM);
const mod = node;
mod.global = true;
mod.id = expr;
mod.body = this.tsParseModuleBlock();
this.scope.exit();
this.prodParam.exit();
return this.finishNode(mod, "TSModuleDeclaration");
}
@@ -1324,6 +1412,8 @@ var _default = superClass => class extends superClass {
return undefined;
}
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
this.state.maybeInArrowParameters = true;
const res = this.tsTryParseAndCatch(() => {
const node = this.startNodeAt(startPos, startLoc);
node.typeParameters = this.tsParseTypeParameters();
@@ -1332,6 +1422,7 @@ var _default = superClass => class extends superClass {
this.expect(_types.types.arrow);
return node;
});
this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
if (!res) {
return undefined;
@@ -1346,6 +1437,11 @@ var _default = superClass => class extends superClass {
this.expectRelational("<");
return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
}));
if (node.params.length === 0) {
this.raise(node.start, TSErrors.EmptyTypeArguments);
}
this.state.exprAllowed = false;
this.expectRelational(">");
return this.finishNode(node, "TSTypeParameterInstantiation");
@@ -1379,9 +1475,13 @@ var _default = superClass => class extends superClass {
let accessibility;
let readonly = false;
if (allowModifiers) {
if (allowModifiers !== undefined) {
accessibility = this.parseAccessModifier();
readonly = !!this.tsParseModifier(["readonly"]);
if (allowModifiers === false && (accessibility || readonly)) {
this.raise(startPos, TSErrors.UnexpectedParameterModifier);
}
}
const left = this.parseMaybeDefault();
@@ -1399,7 +1499,7 @@ var _default = superClass => class extends superClass {
if (readonly) pp.readonly = readonly;
if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
this.raise(pp.start, "A parameter property may not be declared using a binding pattern.");
this.raise(pp.start, TSErrors.UnsupportedParameterPropertyKind);
}
pp.parameter = elt;
@@ -1425,6 +1525,15 @@ var _default = superClass => class extends superClass {
return;
}
if (bodilessType === "TSDeclareFunction" && this.state.isDeclareContext) {
this.raise(node.start, TSErrors.DeclareFunctionHasImplementation);
if (node.declare) {
super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
return;
}
}
super.parseFunctionBodyAndFinish(node, type, isMethod);
}
@@ -1436,6 +1545,29 @@ var _default = superClass => class extends superClass {
}
}
tsCheckForInvalidTypeCasts(items) {
items.forEach(node => {
if (node?.type === "TSTypeCastExpression") {
this.raise(node.typeAnnotation.start, TSErrors.UnexpectedTypeAnnotation);
}
});
}
toReferencedList(exprList, isInParens) {
this.tsCheckForInvalidTypeCasts(exprList);
return exprList;
}
parseArrayLike(...args) {
const node = super.parseArrayLike(...args);
if (node.type === "ArrayExpression") {
this.tsCheckForInvalidTypeCasts(node.elements);
}
return node;
}
parseSubscript(base, startPos, startLoc, noCalls, state) {
if (!this.hasPrecedingLineBreak() && this.match(_types.types.bang)) {
this.state.exprAllowed = false;
@@ -1447,7 +1579,7 @@ var _default = superClass => class extends superClass {
if (this.isRelational("<")) {
const result = this.tsTryParseAndCatch(() => {
if (!noCalls && this.atPossibleAsync(base)) {
if (!noCalls && this.atPossibleAsyncArrow(base)) {
const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startPos, startLoc);
if (asyncArrowFn) {
@@ -1462,10 +1594,13 @@ var _default = superClass => class extends superClass {
if (typeArguments) {
if (!noCalls && this.eat(_types.types.parenL)) {
node.arguments = this.parseCallExpressionArguments(_types.types.parenR, false);
this.tsCheckForInvalidTypeCasts(node.arguments);
node.typeParameters = typeArguments;
return this.finishCallExpression(node, state.optionalChainMember);
} else if (this.match(_types.types.backQuote)) {
return this.parseTaggedTemplateExpression(startPos, startLoc, base, state, typeArguments);
const result = this.parseTaggedTemplateExpression(base, startPos, startLoc, state);
result.typeParameters = typeArguments;
return result;
}
}
@@ -1493,7 +1628,7 @@ var _default = superClass => class extends superClass {
super.parseNewArguments(node);
}
parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn) {
parseExprOp(left, leftStartPos, leftStartLoc, minPrec) {
if (nonNull(_types.types._in.binop) > minPrec && !this.hasPrecedingLineBreak() && this.isContextual("as")) {
const node = this.startNodeAt(leftStartPos, leftStartLoc);
node.expression = left;
@@ -1507,10 +1642,11 @@ var _default = superClass => class extends superClass {
}
this.finishNode(node, "TSAsExpression");
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
this.reScan_lt_gt();
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec);
}
return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn);
return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec);
}
checkReservedWord(word, startLoc, checkKeywords, isBinding) {}
@@ -1518,11 +1654,30 @@ var _default = superClass => class extends superClass {
checkDuplicateExports() {}
parseImport(node) {
if (this.match(_types.types.name) && this.lookahead().type === _types.types.eq) {
return this.tsParseImportEqualsDeclaration(node);
if (this.match(_types.types.name) || this.match(_types.types.star) || this.match(_types.types.braceL)) {
const ahead = this.lookahead();
if (this.match(_types.types.name) && ahead.type === _types.types.eq) {
return this.tsParseImportEqualsDeclaration(node);
}
if (this.isContextual("type") && ahead.type !== _types.types.comma && !(ahead.type === _types.types.name && ahead.value === "from")) {
node.importKind = "type";
this.next();
}
}
return super.parseImport(node);
if (!node.importKind) {
node.importKind = "value";
}
const importNode = super.parseImport(node);
if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
this.raise(importNode.start, "A type-only import can specify a default import or named bindings, but not both.");
}
return importNode;
}
parseExport(node) {
@@ -1541,6 +1696,13 @@ var _default = superClass => class extends superClass {
this.semicolon();
return this.finishNode(decl, "TSNamespaceExportDeclaration");
} else {
if (this.isContextual("type") && this.lookahead().type === _types.types.braceL) {
this.next();
node.exportKind = "type";
} else {
node.exportKind = "value";
}
return super.parseExport(node);
}
}
@@ -1585,36 +1747,50 @@ var _default = superClass => class extends superClass {
return this.tsParseModifier(["public", "protected", "private"]);
}
parseClassMember(classBody, member, state, constructorAllowsSuper) {
parseClassMember(classBody, member, state) {
this.tsParseModifiers(member, ["declare"]);
const accessibility = this.parseAccessModifier();
if (accessibility) member.accessibility = accessibility;
super.parseClassMember(classBody, member, state, constructorAllowsSuper);
this.tsParseModifiers(member, ["declare"]);
const callParseClassMember = () => {
super.parseClassMember(classBody, member, state);
};
if (member.declare) {
this.tsInDeclareContext(callParseClassMember);
} else {
callParseClassMember();
}
}
parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper) {
const modifiers = this.tsParseModifiers(["abstract", "readonly", "declare"]);
Object.assign(member, modifiers);
parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
this.tsParseModifiers(member, ["abstract", "readonly", "declare"]);
const idx = this.tsTryParseIndexSignature(member);
if (idx) {
classBody.body.push(idx);
if (modifiers.abstract) {
this.raise(member.start, "Index signatures cannot have the 'abstract' modifier");
if (member.abstract) {
this.raise(member.start, TSErrors.IndexSignatureHasAbstract);
}
if (isStatic) {
this.raise(member.start, "Index signatures cannot have the 'static' modifier");
this.raise(member.start, TSErrors.IndexSignatureHasStatic);
}
if (member.accessibility) {
this.raise(member.start, `Index signatures cannot have an accessibility modifier ('${member.accessibility}')`);
this.raise(member.start, TSErrors.IndexSignatureHasAccessibility, member.accessibility);
}
if (member.declare) {
this.raise(member.start, TSErrors.IndexSignatureHasDeclare);
}
return;
}
super.parseClassMemberWithIsStatic(classBody, member, state, isStatic, constructorAllowsSuper);
super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
}
parsePostMemberNameModifiers(methodOrProp) {
@@ -1622,11 +1798,11 @@ var _default = superClass => class extends superClass {
if (optional) methodOrProp.optional = true;
if (methodOrProp.readonly && this.match(_types.types.parenL)) {
this.raise(methodOrProp.start, "Class methods cannot have the 'readonly' modifier");
this.raise(methodOrProp.start, TSErrors.ClassMethodHasReadonly);
}
if (methodOrProp.declare && this.match(_types.types.parenL)) {
this.raise(methodOrProp.start, "Class methods cannot have the 'declare' modifier");
this.raise(methodOrProp.start, TSErrors.ClassMethodHasDeclare);
}
}
@@ -1640,12 +1816,12 @@ var _default = superClass => class extends superClass {
return super.shouldParseExportDeclaration();
}
parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos) {
parseConditional(expr, startPos, startLoc, refNeedsArrowPos) {
if (!refNeedsArrowPos || !this.match(_types.types.question)) {
return super.parseConditional(expr, noIn, startPos, startLoc, refNeedsArrowPos);
return super.parseConditional(expr, startPos, startLoc, refNeedsArrowPos);
}
const result = this.tryParse(() => super.parseConditional(expr, noIn, startPos, startLoc));
const result = this.tryParse(() => super.parseConditional(expr, startPos, startLoc));
if (!result.node) {
refNeedsArrowPos.start = result.error.pos || this.state.start;
@@ -1688,6 +1864,10 @@ var _default = superClass => class extends superClass {
declaration = super.parseExportDeclaration(node);
}
if (declaration && (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare)) {
node.exportKind = "type";
}
if (declaration && isDeclare) {
this.resetStartLocation(declaration, startPos, startLoc);
declaration.declare = true;
@@ -1718,8 +1898,8 @@ var _default = superClass => class extends superClass {
parseClassProperty(node) {
this.parseClassPropertyAnnotation(node);
if (node.declare && this.match(_types.types.equal)) {
this.raise(this.state.start, "'declare' class fields cannot have an initializer");
if (this.state.isDeclareContext && this.match(_types.types.eq)) {
this.raise(this.state.start, TSErrors.DeclareClassFieldHasInitializer);
}
return super.parseClassProperty(node);
@@ -1727,11 +1907,11 @@ var _default = superClass => class extends superClass {
parseClassPrivateProperty(node) {
if (node.abstract) {
this.raise(node.start, "Private elements cannot have the 'abstract' modifier.");
this.raise(node.start, TSErrors.PrivateElementHasAbstract);
}
if (node.accessibility) {
this.raise(node.start, `Private elements cannot have an accessibility modifier ('${node.accessibility}')`);
this.raise(node.start, TSErrors.PrivateElementHasAccessibility, node.accessibility);
}
this.parseClassPropertyAnnotation(node);
@@ -1740,6 +1920,11 @@ var _default = superClass => class extends superClass {
pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
const typeParameters = this.tsTryParseTypeParameters();
if (typeParameters && isConstructor) {
this.raise(typeParameters.start, TSErrors.ConstructorHasTypeParameters);
}
if (typeParameters) method.typeParameters = typeParameters;
super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
}
@@ -1817,7 +2002,7 @@ var _default = superClass => class extends superClass {
}
}
if (!(jsx && jsx.error) && !this.isRelational("<")) {
if (!jsx?.error && !this.isRelational("<")) {
return super.parseMaybeAssign(...args);
}
@@ -1831,7 +2016,7 @@ var _default = superClass => class extends superClass {
abort();
}
if (typeParameters && typeParameters.params.length !== 0) {
if (typeParameters?.params.length !== 0) {
this.resetStartLocationFromNode(expr, typeParameters);
}
@@ -1846,7 +2031,7 @@ var _default = superClass => class extends superClass {
if (!typeCast.error) return typeCast.node;
}
if (jsx && jsx.node) {
if (jsx?.node) {
this.state = jsx.failState;
return jsx.node;
}
@@ -1856,15 +2041,15 @@ var _default = superClass => class extends superClass {
return arrow.node;
}
if (typeCast && typeCast.node) {
if (typeCast?.node) {
this.state = typeCast.failState;
return typeCast.node;
}
if (jsx && jsx.thrown) throw jsx.error;
if (jsx?.thrown) throw jsx.error;
if (arrow.thrown) throw arrow.error;
if (typeCast && typeCast.thrown) throw typeCast.error;
throw jsx && jsx.error || arrow.error || typeCast && typeCast.error;
if (typeCast?.thrown) throw typeCast.error;
throw jsx?.error || arrow.error || typeCast?.error;
}
parseMaybeUnary(refExpressionErrors) {
@@ -1895,8 +2080,8 @@ var _default = superClass => class extends superClass {
parseAssignableListItemTypes(param) {
if (this.eat(_types.types.question)) {
if (param.type !== "Identifier") {
this.raise(param.start, "A binding pattern parameter cannot be optional in an implementation signature.");
if (param.type !== "Identifier" && !this.state.isDeclareContext && !this.state.inType) {
this.raise(param.start, TSErrors.PatternIsOptional);
}
param.optional = true;
@@ -1986,7 +2171,7 @@ var _default = superClass => class extends superClass {
const node = super.parseMaybeDefault(...args);
if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, " + "e.g. instead of `age = 25: number` use `age: number = 25`");
this.raise(node.typeAnnotation.start, TSErrors.TypeAnnotationAfterAssign);
}
return node;
@@ -2000,6 +2185,17 @@ var _default = superClass => class extends superClass {
}
}
reScan_lt_gt() {
if (this.match(_types.types.relational)) {
const code = this.input.charCodeAt(this.state.start);
if (code === 60 || code === 62) {
this.state.pos -= 1;
this.readToken_lt_gt(code);
}
}
}
toAssignableList(exprList) {
for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i];
@@ -2015,7 +2211,7 @@ var _default = superClass => class extends superClass {
if (!this.state.maybeInArrowParameters) {
exprList[i] = this.typeCastToParameter(expr);
} else {
this.raise(expr.start, "Unexpected type cast in parameter position.");
this.raise(expr.start, TSErrors.UnexpectedTypeCastInParameter);
}
break;
@@ -2031,18 +2227,6 @@ var _default = superClass => class extends superClass {
return node.expression;
}
toReferencedList(exprList, isInParens) {
for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i];
if (expr && expr.type === "TSTypeCastExpression") {
this.raise(expr.start, "Did not expect a type annotation here.");
}
}
return exprList;
}
shouldParseArrow() {
return this.match(_types.types.colon) || super.shouldParseArrow();
}
@@ -2071,6 +2255,29 @@ var _default = superClass => class extends superClass {
return hasContextParam ? baseCount + 1 : baseCount;
}
parseCatchClauseParam() {
const param = super.parseCatchClauseParam();
const type = this.tsTryParseTypeAnnotation();
if (type) {
param.typeAnnotation = type;
this.resetEndLocation(param);
}
return param;
}
tsInDeclareContext(cb) {
const oldIsDeclareContext = this.state.isDeclareContext;
this.state.isDeclareContext = true;
try {
return cb();
} finally {
this.state.isDeclareContext = oldIsDeclareContext;
}
}
};
exports.default = _default;