From 4c7ca9fafa0d8a671e6ad5f462b2b714fb52be6b Mon Sep 17 00:00:00 2001 From: majie77 Date: Thu, 20 Feb 2025 09:35:16 +0800 Subject: [PATCH] Remove some properties from Identifier and Optimized interface Remove some properties from Identifier Optimized resolveEntityName Interface Signed-off-by: majie77 Change-Id: I2e3e44f7e2fcb9b45d653aabd9707066f01642dc --- lib/tsc.js | 316 ++++++++++----- lib/tsserver.js | 373 ++++++++++++------ lib/tsserverlibrary.d.ts | 15 +- lib/tsserverlibrary.js | 373 ++++++++++++------ lib/typescript.d.ts | 15 +- lib/typescript.js | 373 ++++++++++++------ lib/typescriptServices.d.ts | 15 +- lib/typescriptServices.js | 373 ++++++++++++------ lib/typingsInstaller.js | 341 +++++++++++----- src/compiler/binder.ts | 14 +- src/compiler/checker.ts | 106 +++-- src/compiler/emitter.ts | 2 +- src/compiler/factory/emitNode.ts | 22 ++ src/compiler/factory/nodeFactory.ts | 40 +- src/compiler/parser.ts | 30 +- src/compiler/transformers/es2015.ts | 2 +- src/compiler/transformers/es5.ts | 2 +- src/compiler/transformers/jsx.ts | 2 +- src/compiler/types.ts | 132 +++---- src/compiler/utilities.ts | 105 ++++- src/compiler/utilitiesPublic.ts | 17 +- src/compiler/visitorPublic.ts | 8 +- .../4.0/nodeFactoryTopLevelExports.ts | 2 +- src/harness/harnessUtils.ts | 14 +- src/services/codefixes/convertToEsModule.ts | 4 +- src/services/completions.ts | 15 +- src/services/findAllReferences.ts | 4 +- src/services/refactors/extractSymbol.ts | 2 +- src/services/rename.ts | 2 +- src/services/services.ts | 2 +- src/services/textChanges.ts | 1 - .../reference/api/tsserverlibrary.d.ts | 15 +- tests/baselines/reference/api/typescript.d.ts | 15 +- 33 files changed, 1904 insertions(+), 848 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 907a9903a4..425bee4293 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -9932,6 +9932,11 @@ var ts; return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } ts.idText = idText; + function identifierToKeywordKind(node) { + var token = ts.stringToToken(node.escapedText); + return token ? ts.tryCast(token, ts.isKeyword) : undefined; + } + ts.identifierToKeywordKind = identifierToKeywordKind; function symbolName(symbol) { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -10258,13 +10263,17 @@ var ts; } ts.getJSDocReturnType = getJSDocReturnType; function getJSDocTagsWorker(node, noCache) { - var tags = node.jsDocCache; + var _a, _b; + if (!ts.canHaveJSDoc(node)) + return ts.emptyArray; + var tags = (_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache; if (tags === undefined || noCache) { var comments = ts.getJSDocCommentsAndTags(node, noCache); ts.Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = ts.flatMap(comments, function (j) { return ts.isJSDoc(j) ? j.tags : j; }); if (!noCache) { - node.jsDocCache = tags; + (_b = node.jsDoc) !== null && _b !== void 0 ? _b : (node.jsDoc = []); + node.jsDoc.jsDocCache = tags; } } return tags; @@ -12328,6 +12337,12 @@ var ts; return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + function scanTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.languageVariant, sourceFile.text, undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + ts.scanTokenAtPosition = scanTokenAtPosition; function getErrorSpanForArrowFunction(sourceFile, node) { var pos = ts.skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === 242) { @@ -13797,6 +13812,82 @@ var ts; ? node.body : undefined; } + function canHaveJSDoc(node) { + switch (node.kind) { + case 219: + case 266: + case 172: + case 227: + case 242: + case 253: + case 179: + case 298: + case 264: + case 232: + case 175: + case 176: + case 185: + case 180: + case 252: + case 260: + case 247: + case 212: + case 243: + case 1: + case 269: + case 308: + case 280: + case 281: + case 284: + case 245: + case 250: + case 251: + case 249: + case 263: + case 218: + case 184: + case 177: + case 79: + case 246: + case 275: + case 274: + case 181: + case 267: + case 326: + case 332: + case 257: + case 174: + case 173: + case 270: + case 202: + case 273: + case 210: + case 168: + case 217: + case 211: + case 305: + case 171: + case 170: + case 254: + case 241: + case 178: + case 306: + case 307: + case 256: + case 258: + case 259: + case 268: + case 167: + case 261: + case 244: + case 248: + case 255: + return true; + default: + return false; + } + } + ts.canHaveJSDoc = canHaveJSDoc; function getJSDocCommentsAndTags(hostNode, noCache) { var result; if (isVariableLike(hostNode) && ts.hasInitializer(hostNode) && ts.hasJSDocNodes(hostNode.initializer)) { @@ -14308,8 +14399,8 @@ var ts; return token !== undefined && isKeyword(token); } ts.isStringAKeyword = isStringAKeyword; - function isIdentifierANonContextualKeyword(_a) { - var originalKeywordKind = _a.originalKeywordKind; + function isIdentifierANonContextualKeyword(node) { + var originalKeywordKind = ts.identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } ts.isIdentifierANonContextualKeyword = isIdentifierANonContextualKeyword; @@ -15114,7 +15205,7 @@ var ts; } ts.isThisInTypeQuery = isThisInTypeQuery; function identifierIsThisKeyword(id) { - return id.originalKeywordKind === 109; + return id.escapedText === "this"; } ts.identifierIsThisKeyword = identifierIsThisKeyword; function getAllAccessorDeclarations(declarations, accessor) { @@ -15458,7 +15549,7 @@ var ts; ts.getEffectiveModifierFlagsNoCache = getEffectiveModifierFlagsNoCache; function getSyntacticModifierFlagsNoCache(node) { var flags = ts.canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0; - if (node.flags & 4 || (node.kind === 79 && node.isInJSDocNamespace)) { + if (node.flags & 4 || (node.kind === 79 && node.flags & 2048)) { flags |= 1; } return flags; @@ -16295,7 +16386,6 @@ var ts; this.transformFlags = 0; this.parent = undefined; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(fileName, text, skipTrivia) { this.fileName = fileName; @@ -16313,8 +16403,15 @@ var ts; getSignatureConstructor: function () { return Signature; }, getSourceMapSourceConstructor: function () { return SourceMapSource; }, }; + var objectAllocatorPatchers = []; + function addObjectAllocatorPatcher(fn) { + objectAllocatorPatchers.push(fn); + fn(ts.objectAllocator); + } + ts.addObjectAllocatorPatcher = addObjectAllocatorPatcher; function setObjectAllocator(alloc) { Object.assign(ts.objectAllocator, alloc); + ts.forEach(objectAllocatorPatchers, function (fn) { return fn(ts.objectAllocator); }); } ts.setObjectAllocator = setObjectAllocator; function formatStringFromArgs(text, args, baseIndex) { @@ -18361,7 +18458,6 @@ var ts; createRegularExpressionLiteral: createRegularExpressionLiteral, createLiteralLikeNode: createLiteralLikeNode, createIdentifier: createIdentifier, - updateIdentifier: updateIdentifier, createTempVariable: createTempVariable, createLoopVariable: createLoopVariable, createUniqueName: createUniqueName, @@ -19019,20 +19115,13 @@ var ts; case 14: return createTemplateLiteralLikeNode(kind, text, undefined, 0); } } - function createBaseIdentifier(text, originalKeywordKind) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = ts.stringToToken(text); - } - if (originalKeywordKind === 79) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text) { var node = baseFactory.createBaseIdentifierNode(79); - node.originalKeywordKind = originalKeywordKind; node.escapedText = ts.escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) { - var node = createBaseIdentifier(text, undefined); + var node = createBaseIdentifier(text); node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -19040,25 +19129,24 @@ var ts; nextAutoGenerateId++; return node; } - function createIdentifier(text, typeArguments, originalKeywordKind, hasExtendedUnicodeEscape) { - var node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = ts.stringToToken(text); } - if (node.originalKeywordKind === 134) { + if (originalKeywordKind === 79) { + originalKeywordKind = undefined; + } + var node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) + node.flags |= 128; + if (node.escapedText === "await") { node.transformFlags |= 67108864; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & 128) { node.transformFlags |= 1024; } return node; } - function updateIdentifier(node, typeArguments) { - return node.typeArguments !== typeArguments - ? update(createIdentifier(ts.idText(node), typeArguments), node) - : node; - } function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) { var flags = 1; if (reservedInNestedScopes) @@ -23470,6 +23558,26 @@ var ts; return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.typeNode; } ts.getTypeNode = getTypeNode; + function setIdentifierTypeArguments(node, typeArguments) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + ts.setIdentifierTypeArguments = setIdentifierTypeArguments; + function getIdentifierTypeArguments(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.identifierTypeArguments; + } + ts.getIdentifierTypeArguments = getIdentifierTypeArguments; + function setIdentifierGeneratedImportReference(node, value) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + ts.setIdentifierGeneratedImportReference = setIdentifierGeneratedImportReference; + function getIdentifierGeneratedImportReference(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.generatedImportReference; + } + ts.getIdentifierGeneratedImportReference = getIdentifierGeneratedImportReference; })(ts || (ts = {})); var ts; (function (ts) { @@ -27540,7 +27648,7 @@ var ts; parseErrorAtCurrentToken(diagnosticMessage, arg0); } var pos = getNodePos(); - var result = kind === 79 ? factory.createIdentifier("", undefined, undefined) : + var result = kind === 79 ? factory.createIdentifier("", undefined) : ts.isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", undefined) : kind === 8 ? factory.createNumericLiteral("", undefined) : kind === 10 ? factory.createStringLiteral("", undefined) : @@ -27563,7 +27671,7 @@ var ts; var text = internIdentifier(scanner.getTokenValue()); var hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === 80) { parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage || ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); @@ -27575,7 +27683,7 @@ var ts; if (stateStylesRootNode && inEtsStateStylesContext() && token() === 24) { identifierCount++; var pos = getNodePos(); - return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), undefined, 79), pos, pos); + return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79), pos, pos); } identifierCount++; var reportAtCurrentPosition = token() === 1; @@ -27918,6 +28026,7 @@ var ts; return parseElement(); } function currentNode(parsingContext, pos) { + var _a; if (!syntaxCursor || !isReusableParsingContext(parsingContext) || parseErrorBeforeNextFinishedNode) { return undefined; } @@ -27932,8 +28041,8 @@ var ts; if (!canReuseNode(node, parsingContext)) { return undefined; } - if (node.jsDocCache) { - node.jsDocCache = undefined; + if (ts.canHaveJSDoc(node) && ((_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache)) { + node.jsDoc.jsDocCache = undefined; } return node; } @@ -27994,7 +28103,7 @@ var ts; case 174: var methodDeclaration = node; var nameIsConstructor = methodDeclaration.name.kind === 79 && - methodDeclaration.name.originalKeywordKind === 136; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } } @@ -28191,13 +28300,10 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var pos = getNodePos(); var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - var dotPos = getNodePos(); while (parseOptional(24)) { if (token() === 29) { - entity.jsdocDotPos = dotPos; break; } - dotPos = getNodePos(); entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, false)), pos); } return entity; @@ -29772,13 +29878,13 @@ var ts; var pos = getNodePos(); var expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === 24) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, undefined, 79), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, 79), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === 24) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, undefined, 79), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, 79), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === 24) { - expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), undefined, 79), pos, pos); + expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79), pos, pos); } else { expression = parsePrimaryExpression(); @@ -32876,7 +32982,7 @@ var ts; return finishNode(jsDocNamespaceNode, pos); } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + typeNameOrNamespaceName.flags |= 2048; } return typeNameOrNamespaceName; } @@ -33053,7 +33159,7 @@ var ts; var end = scanner.getTextPos(); var originalKeywordKind = token(); var text = internIdentifier(scanner.getTokenValue()); - var result = finishNode(factory.createIdentifier(text, undefined, originalKeywordKind), pos, end); + var result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } @@ -39839,7 +39945,7 @@ var ts; case 270: return getModuleInstanceState(node, visited); case 79: - if (node.isInJSDocNamespace) { + if (node.flags & 2048) { return 0; } } @@ -40267,6 +40373,7 @@ var ts; else if (containerFlags & 64) { seenThisKeyword = false; bindChildren(node); + ts.Debug.assertNotNode(node, ts.isIdentifier); node.flags = seenThisKeyword ? node.flags | 128 : node.flags & ~128; } else { @@ -41532,12 +41639,13 @@ var ts; !(node.flags & 16777216) && !(node.flags & 8388608) && !ts.isIdentifierName(node)) { + var originalKeywordKind = ts.identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind >= 118 && - node.originalKeywordKind <= 126) { + originalKeywordKind >= 118 && + originalKeywordKind <= 126) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } - else if (node.originalKeywordKind === 134) { + else if (originalKeywordKind === 134) { if (ts.isExternalModule(file) && ts.isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, ts.declarationNameToString(node))); } @@ -41545,7 +41653,7 @@ var ts; file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } - else if (node.originalKeywordKind === 126 && node.flags & 8192) { + else if (originalKeywordKind === 126 && node.flags & 8192) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } @@ -41743,7 +41851,7 @@ var ts; function bindWorker(node) { switch (node.kind) { case 79: - if (node.isInJSDocNamespace) { + if (node.flags & 2048) { var parentNode = node.parent; while (parentNode && !ts.isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; @@ -47355,10 +47463,14 @@ var ts; var qualifier = root.qualifier; if (qualifier) { if (ts.isIdentifier(qualifier)) { - qualifier = ts.factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier)) { + qualifier = ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier.right)) { + qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -47373,10 +47485,14 @@ var ts; var typeArguments = root.typeArguments; var typeName = root.typeName; if (ts.isIdentifier(typeName)) { - typeName = ts.factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName)) { + typeName = ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName), typeArguments); + } } else { - typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName.right)) { + typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; var ids = getAccessStack(ref); @@ -47981,7 +48097,7 @@ var ts; if (!nonRootParts || ts.isEntityName(nonRootParts)) { if (nonRootParts) { var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + ts.setIdentifierTypeArguments(lastId, undefined); } return ts.factory.createImportTypeNode(lit, assertion, nonRootParts, typeParameterNodes, isTypeOf); } @@ -48000,8 +48116,8 @@ var ts; } else { var lastId = ts.isIdentifier(entityName) ? entityName : entityName.right; - var lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + var lastTypeArgs = ts.getIdentifierTypeArguments(lastId); + ts.setIdentifierTypeArguments(lastId, undefined); return ts.factory.createTypeReferenceNode(entityName, lastTypeArgs); } function createAccessFromSymbolChain(chain, index, stopper) { @@ -48049,7 +48165,9 @@ var ts; return ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode(LHS, typeParameterNodes), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(symbolName))); } } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { var LHS = createAccessFromSymbolChain(chain, index - 1, stopper); @@ -48092,7 +48210,9 @@ var ts; text = "".concat(rawtext, "_").concat(i); } if (text !== rawtext) { - result = ts.factory.createIdentifier(text, result.typeArguments); + var typeArguments = ts.getIdentifierTypeArguments(result); + result = ts.factory.createIdentifier(text); + ts.setIdentifierTypeArguments(result, typeArguments); } (context.typeParameterNamesByTextNextNameCount || (context.typeParameterNamesByTextNextNameCount = new ts.Map())).set(rawtext, i); (context.typeParameterNames || (context.typeParameterNames = new ts.Map())).set(getTypeId(type), result); @@ -48118,7 +48238,9 @@ var ts; if (index === 0) { context.flags ^= 16777216; } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -48144,7 +48266,9 @@ var ts; symbolName.length > 1 && ts.isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : ts.isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -48161,8 +48285,11 @@ var ts; expression = ts.factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216); - expression.symbol = symbol; + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return ts.factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -60542,15 +60669,17 @@ var ts; break; case 168: var param = declaration; - if (ts.isIdentifier(param.name) && - (ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, 788968, undefined, param.name.escapedText, true) || - param.name.originalKeywordKind && ts.isTypeNodeKind(param.name.originalKeywordKind))) { - var newName = "arg" + param.parent.parameters.indexOf(param); - var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (ts.isIdentifier(param.name)) { + var originalKeywordKind = ts.identifierToKeywordKind(param.name); + if ((ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, 788968, undefined, param.name.escapedText, true) || + originalKeywordKind && ts.isTypeNodeKind(originalKeywordKind))) { + var newName = "arg" + param.parent.parameters.indexOf(param); + var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = declaration.dotDotDotToken ? noImplicitAny ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -72595,8 +72724,11 @@ var ts; } function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === 183 && node.typeName.jsdocDotPos !== undefined && !ts.isInJSFile(node) && !ts.isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === 183 && !ts.isInJSFile(node) && !ts.isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + var sourceFile = ts.getSourceFileOfNode(node); + if (ts.scanTokenAtPosition(sourceFile, node.typeName.end) === 24) { + grammarErrorAtPos(node, ts.skipTrivia(sourceFile.text, node.typeName.end), 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } ts.forEach(node.typeArguments, checkSourceElement); var type = getTypeFromTypeReference(node); @@ -73568,7 +73700,7 @@ var ts; if (!ident) { return undefined; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, true); + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -77029,7 +77161,7 @@ var ts; if (!ident) { return; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, true); + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -77771,7 +77903,7 @@ var ts; } return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name, ignoreErrors) { + function getSymbolOfNameOrPropertyAccessExpression(name) { if (ts.isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -77843,11 +77975,11 @@ var ts; var symbol = getIntrinsicTagSymbol(name.parent); return symbol === unknownSymbol ? undefined : symbol; } - var result = resolveEntityName(name, meaning, ignoreErrors, true, ts.getHostSignatureFromJSDoc(name)); + var result = resolveEntityName(name, meaning, true, true, ts.getHostSignatureFromJSDoc(name)); if (!result && isJSDoc_1) { var container = ts.findAncestor(name, ts.or(ts.isClassLike, ts.isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, true, getSymbolOfNode(container)); } } if (result && isJSDoc_1) { @@ -77912,11 +78044,11 @@ var ts; } else if (isTypeReferenceIdentifier(name)) { var meaning = name.parent.kind === 183 ? 788968 : 1920; - var symbol = resolveEntityName(name, meaning, false, true); + var symbol = resolveEntityName(name, meaning, true, true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name); } if (name.parent.kind === 182) { - return resolveEntityName(name, 1); + return resolveEntityName(name, 1, true); } return undefined; } @@ -78056,7 +78188,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 306) { - return resolveEntityName(location.name, 111551 | 2097152); + return resolveEntityName(location.name, 111551 | 2097152, true); } return undefined; } @@ -78064,10 +78196,10 @@ var ts; if (ts.isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, 111551 | 788968 | 1920 | 2097152); + resolveEntityName(node.propertyName || node.name, 111551 | 788968 | 1920 | 2097152, true); } else { - return resolveEntityName(node, 111551 | 788968 | 1920 | 2097152); + return resolveEntityName(node, 111551 | 788968 | 1920 | 2097152, true); } } function getTypeOfNode(node) { @@ -78299,8 +78431,9 @@ var ts; } } function getReferencedImportDeclaration(nodeIn) { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + var specifier = ts.getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier); if (node) { @@ -80262,7 +80395,7 @@ var ts; } function checkGrammarNameInLetOrConstDeclarations(name) { if (name.kind === 79) { - if (name.originalKeywordKind === 120) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } @@ -80912,9 +81045,6 @@ var ts; } ts.visitEachChild = visitEachChild; var visitEachChildTable = (_a = {}, - _a[79] = function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, ts.isTypeNodeOrTypeParameterDeclaration)); - }, _a[165] = function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, ts.isEntityName), nodeVisitor(node.right, visitor, ts.isIdentifier)); }, @@ -87790,7 +87920,7 @@ var ts; } var generatedName = factory.createUniqueName("_".concat(name), 16 | 32 | 64); var specifier = factory.createImportSpecifier(false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + ts.setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } @@ -88713,7 +88843,7 @@ var ts; return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & 128) { return ts.setOriginalNode(ts.setTextRange(factory.createIdentifier(ts.unescapeLeadingUnderscores(node.escapedText)), node), node); } return node; @@ -90536,7 +90666,7 @@ var ts; return node; } function trySubstituteReservedName(name) { - var token = name.originalKeywordKind || (ts.nodeIsSynthesized(name) ? ts.stringToToken(ts.idText(name)) : undefined); + var token = ts.identifierToKeywordKind(name); if (token !== undefined && token >= 81 && token <= 117) { return ts.setTextRange(factory.createStringLiteralFromNode(name), name); } @@ -98162,7 +98292,7 @@ var ts; function emitIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, false), node.symbol); - emitList(node, node.typeArguments, 53776); + emitList(node, ts.getIdentifierTypeArguments(node), 53776); } function emitPrivateIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; diff --git a/lib/tsserver.js b/lib/tsserver.js index 9ad0643d78..a7ff17067d 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -4819,6 +4819,9 @@ var ts; // never cleared on SourceFiles which get re-used in between incremental parses. // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`. /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags"; + // The following flags repurpose other NodeFlags as different meanings for Identifier nodes + /** @internal */ NodeFlags[NodeFlags["IdentifierHasExtendedUnicodeEscape"] = 128] = "IdentifierHasExtendedUnicodeEscape"; + /** @internal */ NodeFlags[NodeFlags["IdentifierIsInJSDocNamespace"] = 2048] = "IdentifierIsInJSDocNamespace"; })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {})); var EtsFlags; (function (EtsFlags) { @@ -13211,6 +13214,15 @@ var ts; return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } ts.idText = idText; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node) { + var token = ts.stringToToken(node.escapedText); + return token ? ts.tryCast(token, ts.isKeyword) : undefined; + } + ts.identifierToKeywordKind = identifierToKeywordKind; function symbolName(symbol) { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -13615,14 +13627,18 @@ var ts; } ts.getJSDocReturnType = getJSDocReturnType; function getJSDocTagsWorker(node, noCache) { - var tags = node.jsDocCache; + var _a, _b; + if (!ts.canHaveJSDoc(node)) + return ts.emptyArray; + var tags = (_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. if (tags === undefined || noCache) { var comments = ts.getJSDocCommentsAndTags(node, noCache); ts.Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = ts.flatMap(comments, function (j) { return ts.isJSDoc(j) ? j.tags : j; }); if (!noCache) { - node.jsDocCache = tags; + (_b = node.jsDoc) !== null && _b !== void 0 ? _b : (node.jsDoc = []); + node.jsDoc.jsDocCache = tags; } } return tags; @@ -15990,6 +16006,13 @@ var ts; return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + /** @internal */ + function scanTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + ts.scanTokenAtPosition = scanTokenAtPosition; function getErrorSpanForArrowFunction(sourceFile, node) { var pos = ts.skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === 242 /* SyntaxKind.Block */) { @@ -17604,6 +17627,83 @@ var ts; ? node.body : undefined; } + /** @internal */ + function canHaveJSDoc(node) { + switch (node.kind) { + case 219 /* SyntaxKind.ArrowFunction */: + case 266 /* SyntaxKind.AnnotationDeclaration */: + case 172 /* SyntaxKind.AnnotationPropertyDeclaration */: + case 227 /* SyntaxKind.BinaryExpression */: + case 242 /* SyntaxKind.Block */: + case 253 /* SyntaxKind.BreakStatement */: + case 179 /* SyntaxKind.CallSignature */: + case 298 /* SyntaxKind.CaseClause */: + case 264 /* SyntaxKind.ClassDeclaration */: + case 232 /* SyntaxKind.ClassExpression */: + case 175 /* SyntaxKind.ClassStaticBlockDeclaration */: + case 176 /* SyntaxKind.Constructor */: + case 185 /* SyntaxKind.ConstructorType */: + case 180 /* SyntaxKind.ConstructSignature */: + case 252 /* SyntaxKind.ContinueStatement */: + case 260 /* SyntaxKind.DebuggerStatement */: + case 247 /* SyntaxKind.DoStatement */: + case 212 /* SyntaxKind.ElementAccessExpression */: + case 243 /* SyntaxKind.EmptyStatement */: + case 1 /* SyntaxKind.EndOfFileToken */: + case 269 /* SyntaxKind.EnumDeclaration */: + case 308 /* SyntaxKind.EnumMember */: + case 280 /* SyntaxKind.ExportAssignment */: + case 281 /* SyntaxKind.ExportDeclaration */: + case 284 /* SyntaxKind.ExportSpecifier */: + case 245 /* SyntaxKind.ExpressionStatement */: + case 250 /* SyntaxKind.ForInStatement */: + case 251 /* SyntaxKind.ForOfStatement */: + case 249 /* SyntaxKind.ForStatement */: + case 263 /* SyntaxKind.FunctionDeclaration */: + case 218 /* SyntaxKind.FunctionExpression */: + case 184 /* SyntaxKind.FunctionType */: + case 177 /* SyntaxKind.GetAccessor */: + case 79 /* SyntaxKind.Identifier */: + case 246 /* SyntaxKind.IfStatement */: + case 275 /* SyntaxKind.ImportDeclaration */: + case 274 /* SyntaxKind.ImportEqualsDeclaration */: + case 181 /* SyntaxKind.IndexSignature */: + case 267 /* SyntaxKind.InterfaceDeclaration */: + case 326 /* SyntaxKind.JSDocFunctionType */: + case 332 /* SyntaxKind.JSDocSignature */: + case 257 /* SyntaxKind.LabeledStatement */: + case 174 /* SyntaxKind.MethodDeclaration */: + case 173 /* SyntaxKind.MethodSignature */: + case 270 /* SyntaxKind.ModuleDeclaration */: + case 202 /* SyntaxKind.NamedTupleMember */: + case 273 /* SyntaxKind.NamespaceExportDeclaration */: + case 210 /* SyntaxKind.ObjectLiteralExpression */: + case 168 /* SyntaxKind.Parameter */: + case 217 /* SyntaxKind.ParenthesizedExpression */: + case 211 /* SyntaxKind.PropertyAccessExpression */: + case 305 /* SyntaxKind.PropertyAssignment */: + case 171 /* SyntaxKind.PropertyDeclaration */: + case 170 /* SyntaxKind.PropertySignature */: + case 254 /* SyntaxKind.ReturnStatement */: + case 241 /* SyntaxKind.SemicolonClassElement */: + case 178 /* SyntaxKind.SetAccessor */: + case 306 /* SyntaxKind.ShorthandPropertyAssignment */: + case 307 /* SyntaxKind.SpreadAssignment */: + case 256 /* SyntaxKind.SwitchStatement */: + case 258 /* SyntaxKind.ThrowStatement */: + case 259 /* SyntaxKind.TryStatement */: + case 268 /* SyntaxKind.TypeAliasDeclaration */: + case 167 /* SyntaxKind.TypeParameter */: + case 261 /* SyntaxKind.VariableDeclaration */: + case 244 /* SyntaxKind.VariableStatement */: + case 248 /* SyntaxKind.WhileStatement */: + case 255 /* SyntaxKind.WithStatement */: + return true; + default: + return false; + } + } + ts.canHaveJSDoc = canHaveJSDoc; function getJSDocCommentsAndTags(hostNode, noCache) { var result; // Pull parameter comments from declaring function as well @@ -18175,8 +18275,8 @@ var ts; return token !== undefined && isKeyword(token); } ts.isStringAKeyword = isStringAKeyword; - function isIdentifierANonContextualKeyword(_a) { - var originalKeywordKind = _a.originalKeywordKind; + function isIdentifierANonContextualKeyword(node) { + var originalKeywordKind = ts.identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } ts.isIdentifierANonContextualKeyword = isIdentifierANonContextualKeyword; @@ -19228,7 +19328,7 @@ var ts; } ts.isThisInTypeQuery = isThisInTypeQuery; function identifierIsThisKeyword(id) { - return id.originalKeywordKind === 109 /* SyntaxKind.ThisKeyword */; + return id.escapedText === "this"; } ts.identifierIsThisKeyword = identifierIsThisKeyword; function getAllAccessorDeclarations(declarations, accessor) { @@ -19652,7 +19752,7 @@ var ts; */ function getSyntacticModifierFlagsNoCache(node) { var flags = ts.canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0 /* ModifierFlags.None */; - if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.isInJSDocNamespace)) { + if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */)) { flags |= 1 /* ModifierFlags.Export */; } return flags; @@ -20585,7 +20685,6 @@ var ts; this.transformFlags = 0 /* TransformFlags.None */; this.parent = undefined; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(fileName, text, skipTrivia) { this.fileName = fileName; @@ -20604,8 +20703,19 @@ var ts; getSignatureConstructor: function () { return Signature; }, getSourceMapSourceConstructor: function () { return SourceMapSource; }, }; + var objectAllocatorPatchers = []; + /** + * Used by `deprecatedCompat` to patch the object allocator to apply deprecations. + * @internal + */ + function addObjectAllocatorPatcher(fn) { + objectAllocatorPatchers.push(fn); + fn(ts.objectAllocator); + } + ts.addObjectAllocatorPatcher = addObjectAllocatorPatcher; function setObjectAllocator(alloc) { Object.assign(ts.objectAllocator, alloc); + ts.forEach(objectAllocatorPatchers, function (fn) { return fn(ts.objectAllocator); }); } ts.setObjectAllocator = setObjectAllocator; function formatStringFromArgs(text, args, baseIndex) { @@ -23082,7 +23192,6 @@ var ts; createRegularExpressionLiteral: createRegularExpressionLiteral, createLiteralLikeNode: createLiteralLikeNode, createIdentifier: createIdentifier, - updateIdentifier: updateIdentifier, createTempVariable: createTempVariable, createLoopVariable: createLoopVariable, createUniqueName: createUniqueName, @@ -23774,20 +23883,13 @@ var ts; // // Identifiers // - function createBaseIdentifier(text, originalKeywordKind) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = ts.stringToToken(text); - } - if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text) { var node = baseFactory.createBaseIdentifierNode(79 /* SyntaxKind.Identifier */); - node.originalKeywordKind = originalKeywordKind; node.escapedText = ts.escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) { - var node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined); + var node = createBaseIdentifier(text); node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -23796,28 +23898,25 @@ var ts; return node; } // @api - function createIdentifier(text, typeArguments, originalKeywordKind, hasExtendedUnicodeEscape) { - var node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = ts.stringToToken(text); + } + if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { + originalKeywordKind = undefined; } - if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + var node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) + node.flags |= 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */; + if (node.escapedText === "await") { node.transformFlags |= 67108864 /* TransformFlags.ContainsPossibleTopLevelAwait */; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { node.transformFlags |= 1024 /* TransformFlags.ContainsES2015 */; } return node; } // @api - function updateIdentifier(node, typeArguments) { - return node.typeArguments !== typeArguments - ? update(createIdentifier(ts.idText(node), typeArguments), node) - : node; - } - // @api function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) { var flags = 1 /* GeneratedIdentifierFlags.Auto */; if (reservedInNestedScopes) @@ -29078,6 +29177,30 @@ var ts; return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.typeNode; } ts.getTypeNode = getTypeNode; + /** @internal */ + function setIdentifierTypeArguments(node, typeArguments) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + ts.setIdentifierTypeArguments = setIdentifierTypeArguments; + /** @internal */ + function getIdentifierTypeArguments(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.identifierTypeArguments; + } + ts.getIdentifierTypeArguments = getIdentifierTypeArguments; + /** @internal */ + function setIdentifierGeneratedImportReference(node, value) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + ts.setIdentifierGeneratedImportReference = setIdentifierGeneratedImportReference; + /** @internal */ + function getIdentifierGeneratedImportReference(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.generatedImportReference; + } + ts.getIdentifierGeneratedImportReference = getIdentifierGeneratedImportReference; })(ts || (ts = {})); /* @internal */ var ts; @@ -33968,7 +34091,7 @@ var ts; parseErrorAtCurrentToken(diagnosticMessage, arg0); } var pos = getNodePos(); - var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined) : + var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*originalKeywordKind*/ undefined) : ts.isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === 8 /* SyntaxKind.NumericLiteral */ ? factory.createNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === 10 /* SyntaxKind.StringLiteral */ ? factory.createStringLiteral("", /*isSingleQuote*/ undefined) : @@ -33995,7 +34118,7 @@ var ts; var text = internIdentifier(scanner.getTokenValue()); var hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === 80 /* SyntaxKind.PrivateIdentifier */) { parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage || ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); @@ -34008,7 +34131,7 @@ var ts; if (stateStylesRootNode && inEtsStateStylesContext() && token() === 24 /* SyntaxKind.DotToken */) { identifierCount++; var pos = getNodePos(); - return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } identifierCount++; // Only for end of file because the error gets reported incorrectly on embedded script tags. @@ -34402,6 +34525,7 @@ var ts; return parseElement(); } function currentNode(parsingContext, pos) { + var _a; // If we don't have a cursor or the parsing context isn't reusable, there's nothing to reuse. // // If there is an outstanding parse error that we've encountered, but not attached to @@ -34442,9 +34566,9 @@ var ts; if (!canReuseNode(node, parsingContext)) { return undefined; } - if (node.jsDocCache) { + if (ts.canHaveJSDoc(node) && ((_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache)) { // jsDocCache may include tags from parent nodes, which might have been modified. - node.jsDocCache = undefined; + node.jsDoc.jsDocCache = undefined; } return node; } @@ -34548,7 +34672,7 @@ var ts; // into an actual .ConstructorDeclaration. var methodDeclaration = node; var nameIsConstructor = methodDeclaration.name.kind === 79 /* SyntaxKind.Identifier */ && - methodDeclaration.name.originalKeywordKind === 136 /* SyntaxKind.ConstructorKeyword */; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } } @@ -34779,14 +34903,12 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var pos = getNodePos(); var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - var dotPos = getNodePos(); while (parseOptional(24 /* SyntaxKind.DotToken */)) { if (token() === 29 /* SyntaxKind.LessThanToken */) { - // the entity is part of a JSDoc-style generic, so record the trailing dot for later error reporting - entity.jsdocDotPos = dotPos; + // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and + // `typeArguments` to report it as a grammar error in the checker. break; } - dotPos = getNodePos(); entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos); } return entity; @@ -36907,13 +37029,13 @@ var ts; var pos = getNodePos(); var expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } else { expression = parsePrimaryExpression(); @@ -40376,7 +40498,7 @@ var ts; return finishNode(jsDocNamespaceNode, pos); } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + typeNameOrNamespaceName.flags |= 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */; } return typeNameOrNamespaceName; } @@ -40567,7 +40689,7 @@ var ts; var end = scanner.getTextPos(); var originalKeywordKind = token(); var text = internIdentifier(scanner.getTokenValue()); - var result = finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos, end); + var result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } @@ -48328,7 +48450,7 @@ var ts; case 79 /* SyntaxKind.Identifier */: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { return 0 /* ModuleInstanceState.NonInstantiated */; } } @@ -48898,6 +49020,7 @@ var ts; else if (containerFlags & 64 /* ContainerFlags.IsInterface */) { seenThisKeyword = false; bindChildren(node); + ts.Debug.assertNotNode(node, ts.isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier node.flags = seenThisKeyword ? node.flags | 128 /* NodeFlags.ContainsThis */ : node.flags & ~128 /* NodeFlags.ContainsThis */; } else { @@ -50285,12 +50408,13 @@ var ts; !(node.flags & 8388608 /* NodeFlags.JSDoc */) && !ts.isIdentifierName(node)) { // strict mode identifiers + var originalKeywordKind = ts.identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && - node.originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { + originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && + originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } - else if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + else if (originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { if (ts.isExternalModule(file) && ts.isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, ts.declarationNameToString(node))); } @@ -50298,7 +50422,7 @@ var ts; file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } - else if (node.originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { + else if (originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } @@ -50556,7 +50680,7 @@ var ts; // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { var parentNode = node.parent; while (parentNode && !ts.isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; @@ -57097,10 +57221,14 @@ var ts; var qualifier = root.qualifier; if (qualifier) { if (ts.isIdentifier(qualifier)) { - qualifier = ts.factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier)) { + qualifier = ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier.right)) { + qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -57117,10 +57245,14 @@ var ts; var typeArguments = root.typeArguments; var typeName = root.typeName; if (ts.isIdentifier(typeName)) { - typeName = ts.factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName)) { + typeName = ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName), typeArguments); + } } else { - typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName.right)) { + typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; // then move qualifiers @@ -57781,7 +57913,7 @@ var ts; if (!nonRootParts || ts.isEntityName(nonRootParts)) { if (nonRootParts) { var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); } return ts.factory.createImportTypeNode(lit, assertion, nonRootParts, typeParameterNodes, isTypeOf); } @@ -57800,8 +57932,8 @@ var ts; } else { var lastId = ts.isIdentifier(entityName) ? entityName : entityName.right; - var lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + var lastTypeArgs = ts.getIdentifierTypeArguments(lastId); + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); return ts.factory.createTypeReferenceNode(entityName, lastTypeArgs); } function createAccessFromSymbolChain(chain, index, stopper) { @@ -57850,7 +57982,9 @@ var ts; return ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode(LHS, typeParameterNodes), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(symbolName))); } } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { var LHS = createAccessFromSymbolChain(chain, index - 1, stopper); @@ -57893,7 +58027,9 @@ var ts; text = "".concat(rawtext, "_").concat(i); } if (text !== rawtext) { - result = ts.factory.createIdentifier(text, result.typeArguments); + var typeArguments = ts.getIdentifierTypeArguments(result); + result = ts.factory.createIdentifier(text); + ts.setIdentifierTypeArguments(result, typeArguments); } // avoiding iterations of the above loop turns out to be worth it when `i` starts to get large, so we cache the max // `i` we've used thus far, to save work later @@ -57921,7 +58057,9 @@ var ts; if (index === 0) { context.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */; } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57947,7 +58085,9 @@ var ts; symbolName.length > 1 && ts.isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : ts.isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57964,8 +58104,11 @@ var ts; expression = ts.factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); - expression.symbol = symbol; + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return ts.factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -72264,15 +72407,17 @@ var ts; break; case 168 /* SyntaxKind.Parameter */: var param = declaration; - if (ts.isIdentifier(param.name) && - (ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || - param.name.originalKeywordKind && ts.isTypeNodeKind(param.name.originalKeywordKind))) { - var newName = "arg" + param.parent.parameters.indexOf(param); - var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (ts.isIdentifier(param.name)) { + var originalKeywordKind = ts.identifierToKeywordKind(param.name); + if ((ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || + originalKeywordKind && ts.isTypeNodeKind(originalKeywordKind))) { + var newName = "arg" + param.parent.parameters.indexOf(param); + var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = declaration.dotDotDotToken ? noImplicitAny ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -86148,8 +86293,12 @@ var ts; } function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === 183 /* SyntaxKind.TypeReference */ && node.typeName.jsdocDotPos !== undefined && !ts.isInJSFile(node) && !ts.isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === 183 /* SyntaxKind.TypeReference */ && !ts.isInJSFile(node) && !ts.isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + // If there was a token between the type name and the type arguments, check if it was a DotToken + var sourceFile = ts.getSourceFileOfNode(node); + if (ts.scanTokenAtPosition(sourceFile, node.typeName.end) === 24 /* SyntaxKind.DotToken */) { + grammarErrorAtPos(node, ts.skipTrivia(sourceFile.text, node.typeName.end), 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } ts.forEach(node.typeArguments, checkSourceElement); var type = getTypeFromTypeReference(node); @@ -87359,7 +87508,8 @@ var ts; if (!ident) { return undefined; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -91379,7 +91529,8 @@ var ts; if (!ident) { return; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -92202,7 +92353,7 @@ var ts; } return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name, ignoreErrors) { + function getSymbolOfNameOrPropertyAccessExpression(name) { if (ts.isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -92281,11 +92432,11 @@ var ts; var symbol = getIntrinsicTagSymbol(name.parent); return symbol === unknownSymbol ? undefined : symbol; } - var result = resolveEntityName(name, meaning, /*ignoreErrors*/ ignoreErrors, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); + var result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); if (!result && isJSDoc_1) { var container = ts.findAncestor(name, ts.or(ts.isClassLike, ts.isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfNode(container)); } } if (result && isJSDoc_1) { @@ -92350,11 +92501,11 @@ var ts; } else if (isTypeReferenceIdentifier(name)) { var meaning = name.parent.kind === 183 /* SyntaxKind.TypeReference */ ? 788968 /* SymbolFlags.Type */ : 1920 /* SymbolFlags.Namespace */; - var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); + var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name); } if (name.parent.kind === 182 /* SyntaxKind.TypePredicate */) { - return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */); + return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */, /*ignoreErrors*/ true); } return undefined; } @@ -92520,7 +92671,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 306 /* SyntaxKind.ShorthandPropertyAssignment */) { - return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } return undefined; } @@ -92529,10 +92680,10 @@ var ts; if (ts.isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } else { - return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } } function getTypeOfNode(node) { @@ -92817,8 +92968,9 @@ var ts; // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(nodeIn) { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + var specifier = ts.getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier); if (node) { @@ -94948,7 +95100,7 @@ var ts; } function checkGrammarNameInLetOrConstDeclarations(name) { if (name.kind === 79 /* SyntaxKind.Identifier */) { - if (name.originalKeywordKind === 120 /* SyntaxKind.LetKeyword */) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } @@ -95682,9 +95834,6 @@ var ts; // NOTE: Before you can add a new method to `visitEachChildTable`, you must first ensure the `Node` subtype you // wish to add is defined in the `HasChildren` union in types.ts. var visitEachChildTable = (_a = {}, - _a[79 /* SyntaxKind.Identifier */] = function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, ts.isTypeNodeOrTypeParameterDeclaration)); - }, _a[165 /* SyntaxKind.QualifiedName */] = function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, ts.isEntityName), nodeVisitor(node.right, visitor, ts.isIdentifier)); }, @@ -104501,7 +104650,7 @@ var ts; } var generatedName = factory.createUniqueName("_".concat(name), 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */ | 64 /* GeneratedIdentifierFlags.AllowNameSubstitution */); var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + ts.setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } @@ -105626,7 +105775,7 @@ var ts; return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { return ts.setOriginalNode(ts.setTextRange(factory.createIdentifier(ts.unescapeLeadingUnderscores(node.escapedText)), node), node); } return node; @@ -108538,7 +108687,7 @@ var ts; * @param name An Identifier */ function trySubstituteReservedName(name) { - var token = name.originalKeywordKind || (ts.nodeIsSynthesized(name) ? ts.stringToToken(ts.idText(name)) : undefined); + var token = ts.identifierToKeywordKind(name); if (token !== undefined && token >= 81 /* SyntaxKind.FirstReservedWord */ && token <= 117 /* SyntaxKind.LastReservedWord */) { return ts.setTextRange(factory.createStringLiteralFromNode(name), name); } @@ -118681,7 +118830,7 @@ var ts; function emitIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol); - emitList(node, node.typeArguments, 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments + emitList(node, ts.getIdentifierTypeArguments(node), 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments } // // Names @@ -140627,8 +140776,11 @@ var ts; if (ts.isModifier(node)) { return node.kind; } - if (ts.isIdentifier(node) && node.originalKeywordKind && ts.isModifierKind(node.originalKeywordKind)) { - return node.originalKeywordKind; + if (ts.isIdentifier(node)) { + var originalKeywordKind = ts.identifierToKeywordKind(node); + if (originalKeywordKind && ts.isModifierKind(originalKeywordKind)) { + return originalKeywordKind; + } } return undefined; } @@ -143184,7 +143336,8 @@ var ts; || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); } function keywordForNode(node) { - return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* SyntaxKind.Unknown */ : node.kind; + var _a; + return ts.isIdentifier(node) ? (_a = ts.identifierToKeywordKind(node)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */ : node.kind; } function getContextualKeywords(contextToken, position) { var entries = []; @@ -143269,6 +143422,7 @@ var ts; * on the condition that one exists and that the context implies completion should be given. */ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position) { + var _a; // class c { method() { } | method2() { } } switch (location.kind) { case 357 /* SyntaxKind.SyntaxList */: @@ -143280,8 +143434,8 @@ var ts; } break; case 79 /* SyntaxKind.Identifier */: { - var originalKeywordKind = location.originalKeywordKind; - if (originalKeywordKind && ts.isKeyword(originalKeywordKind)) { + var originalKeywordKind = ts.identifierToKeywordKind(location); + if (originalKeywordKind) { return undefined; } // class c { public prop = c| } @@ -143323,7 +143477,7 @@ var ts; return undefined; } var isValidKeyword = ts.isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword; - return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword(ts.stringToToken(contextToken.text))) // TODO: GH#18217 + return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword((_a = ts.identifierToKeywordKind(contextToken)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */)) ? contextToken.parent.parent : undefined; } } @@ -146379,8 +146533,8 @@ var ts; } // For `export { foo as bar }`, rename `foo`, but not `bar`. if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) { - var isDefaultExport = referenceLocation.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ - || exportSpecifier.name.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */; + var isDefaultExport = referenceLocation.escapedText === "default" + || exportSpecifier.name.escapedText === "default"; var exportKind = isDefaultExport ? 1 /* ExportKind.Default */ : 0 /* ExportKind.Named */; var exportSymbol = ts.Debug.checkDefined(exportSpecifier.symbol); var exportInfo = FindAllReferences.getExportInfo(exportSymbol, exportKind, state.checker); @@ -151489,7 +151643,7 @@ var ts; return getRenameInfoError(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library); } // Cannot rename `default` as in `import { default as foo } from "./someModule"; - if (ts.isIdentifier(node) && node.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { + if (ts.isIdentifier(node) && node.escapedText === "default" && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { return undefined; } if (ts.isStringLiteralLike(node) && ts.tryGetImportFromModuleSpecifier(node)) { @@ -157891,7 +158045,6 @@ var ts; parent.parent : parent.parent.parent; jsDocNode.jsDoc = parent.jsDoc; - jsDocNode.jsDocCache = parent.jsDocCache; return jsDocNode; } function tryMergeJsdocTags(oldTag, newTag) { @@ -160546,8 +160699,8 @@ var ts; function collectExportRenames(sourceFile, checker, identifiers) { var res = new ts.Map(); forEachExportReference(sourceFile, function (node) { - var _a = node.name, text = _a.text, originalKeywordKind = _a.originalKeywordKind; - if (!res.has(text) && (originalKeywordKind !== undefined && ts.isNonContextualKeyword(originalKeywordKind) + var text = node.name.text; + if (!res.has(text) && (ts.isIdentifierANonContextualKeyword(node.name) || checker.resolveName(text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ true))) { // Unconditionally add an underscore in case `text` is a keyword. res.set(text, makeUniqueName("_".concat(text), identifiers)); @@ -169782,7 +169935,7 @@ var ts; var checker = context.program.getTypeChecker(); // Make a unique name for the extracted variable var file = scope.getSourceFile(); - var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.isKeyword(node.name.originalKeywordKind) + var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.identifierToKeywordKind(node.name) ? node.name.text : ts.getUniqueName(ts.isClassLike(scope) ? "newProperty" : "newLocal", file); var isJS = ts.isInJSFile(scope); @@ -189001,7 +189154,7 @@ var ts; }, factoryDeprecation); /** @deprecated Use `factory.createIdentifier` or the factory supplied by your transformation context instead. */ ts.createIdentifier = ts.Debug.deprecate(function createIdentifier(text) { - return ts.factory.createIdentifier(text, /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined); + return ts.factory.createIdentifier(text, /*originalKeywordKind*/ undefined); }, factoryDeprecation); /** @deprecated Use `factory.createTempVariable` or the factory supplied by your transformation context instead. */ ts.createTempVariable = ts.Debug.deprecate(function createTempVariable(recordTempVariable) { diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index b86d15474f..572f9cdf9c 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -633,9 +633,10 @@ declare namespace ts { locals?: SymbolTable; skipCheck?: boolean; } - export interface JSDocContainer { + export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AnnotationPropertyDeclaration | AnnotationDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken; + export type HasJSDoc = AccessorDeclaration | AnnotationDeclaration | AnnotationPropertyDeclaration | ArrowFunction | Block | BreakStatement | CallSignatureDeclaration | CaseClause | ClassLikeDeclaration | ClassStaticBlockDeclaration | ConstructorDeclaration | ConstructorTypeNode | ConstructSignatureDeclaration | ContinueStatement | DebuggerStatement | DoStatement | EmptyStatement | EndOfFileToken | EnumDeclaration | EnumMember | ExportAssignment | ExportDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | FunctionTypeNode | IfStatement | ImportDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | InterfaceDeclaration | JSDocFunctionType | LabeledStatement | MethodDeclaration | MethodSignature | ModuleDeclaration | NamedTupleMember | NamespaceExportDeclaration | ParameterDeclaration | ParenthesizedExpression | PropertyAssignment | PropertyDeclaration | PropertySignature | ReturnStatement | ShorthandPropertyAssignment | SpreadAssignment | SwitchStatement | ThrowStatement | TryStatement | TypeAliasDeclaration | VariableDeclaration | VariableStatement | WhileStatement | WithStatement; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | AnnotationPropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -711,8 +712,6 @@ declare namespace ts { * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ readonly escapedText: __String; - readonly originalKeywordKind?: SyntaxKind; - isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; @@ -3711,11 +3710,12 @@ declare namespace ts { createToken(token: SyntaxKind.NullKeyword): NullLiteral; createToken(token: SyntaxKind.TrueKeyword): TrueLiteral; createToken(token: SyntaxKind.FalseKeyword): FalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + createToken(token: SyntaxKind.Unknown): Token; createToken(token: TKind): PunctuationToken; createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - createToken(token: TKind): Token; createSuper(): SuperExpression; createThis(): ThisExpression; createNull(): NullLiteral; @@ -4817,6 +4817,11 @@ declare namespace ts { */ function unescapeLeadingUnderscores(identifier: __String): string; function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; function symbolName(symbol: Symbol): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 5d3587cedc..8b064e3234 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -4818,6 +4818,9 @@ var ts; // never cleared on SourceFiles which get re-used in between incremental parses. // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`. /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags"; + // The following flags repurpose other NodeFlags as different meanings for Identifier nodes + /** @internal */ NodeFlags[NodeFlags["IdentifierHasExtendedUnicodeEscape"] = 128] = "IdentifierHasExtendedUnicodeEscape"; + /** @internal */ NodeFlags[NodeFlags["IdentifierIsInJSDocNamespace"] = 2048] = "IdentifierIsInJSDocNamespace"; })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {})); var EtsFlags; (function (EtsFlags) { @@ -13210,6 +13213,15 @@ var ts; return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } ts.idText = idText; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node) { + var token = ts.stringToToken(node.escapedText); + return token ? ts.tryCast(token, ts.isKeyword) : undefined; + } + ts.identifierToKeywordKind = identifierToKeywordKind; function symbolName(symbol) { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -13614,14 +13626,18 @@ var ts; } ts.getJSDocReturnType = getJSDocReturnType; function getJSDocTagsWorker(node, noCache) { - var tags = node.jsDocCache; + var _a, _b; + if (!ts.canHaveJSDoc(node)) + return ts.emptyArray; + var tags = (_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. if (tags === undefined || noCache) { var comments = ts.getJSDocCommentsAndTags(node, noCache); ts.Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = ts.flatMap(comments, function (j) { return ts.isJSDoc(j) ? j.tags : j; }); if (!noCache) { - node.jsDocCache = tags; + (_b = node.jsDoc) !== null && _b !== void 0 ? _b : (node.jsDoc = []); + node.jsDoc.jsDocCache = tags; } } return tags; @@ -15989,6 +16005,13 @@ var ts; return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + /** @internal */ + function scanTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + ts.scanTokenAtPosition = scanTokenAtPosition; function getErrorSpanForArrowFunction(sourceFile, node) { var pos = ts.skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === 242 /* SyntaxKind.Block */) { @@ -17603,6 +17626,83 @@ var ts; ? node.body : undefined; } + /** @internal */ + function canHaveJSDoc(node) { + switch (node.kind) { + case 219 /* SyntaxKind.ArrowFunction */: + case 266 /* SyntaxKind.AnnotationDeclaration */: + case 172 /* SyntaxKind.AnnotationPropertyDeclaration */: + case 227 /* SyntaxKind.BinaryExpression */: + case 242 /* SyntaxKind.Block */: + case 253 /* SyntaxKind.BreakStatement */: + case 179 /* SyntaxKind.CallSignature */: + case 298 /* SyntaxKind.CaseClause */: + case 264 /* SyntaxKind.ClassDeclaration */: + case 232 /* SyntaxKind.ClassExpression */: + case 175 /* SyntaxKind.ClassStaticBlockDeclaration */: + case 176 /* SyntaxKind.Constructor */: + case 185 /* SyntaxKind.ConstructorType */: + case 180 /* SyntaxKind.ConstructSignature */: + case 252 /* SyntaxKind.ContinueStatement */: + case 260 /* SyntaxKind.DebuggerStatement */: + case 247 /* SyntaxKind.DoStatement */: + case 212 /* SyntaxKind.ElementAccessExpression */: + case 243 /* SyntaxKind.EmptyStatement */: + case 1 /* SyntaxKind.EndOfFileToken */: + case 269 /* SyntaxKind.EnumDeclaration */: + case 308 /* SyntaxKind.EnumMember */: + case 280 /* SyntaxKind.ExportAssignment */: + case 281 /* SyntaxKind.ExportDeclaration */: + case 284 /* SyntaxKind.ExportSpecifier */: + case 245 /* SyntaxKind.ExpressionStatement */: + case 250 /* SyntaxKind.ForInStatement */: + case 251 /* SyntaxKind.ForOfStatement */: + case 249 /* SyntaxKind.ForStatement */: + case 263 /* SyntaxKind.FunctionDeclaration */: + case 218 /* SyntaxKind.FunctionExpression */: + case 184 /* SyntaxKind.FunctionType */: + case 177 /* SyntaxKind.GetAccessor */: + case 79 /* SyntaxKind.Identifier */: + case 246 /* SyntaxKind.IfStatement */: + case 275 /* SyntaxKind.ImportDeclaration */: + case 274 /* SyntaxKind.ImportEqualsDeclaration */: + case 181 /* SyntaxKind.IndexSignature */: + case 267 /* SyntaxKind.InterfaceDeclaration */: + case 326 /* SyntaxKind.JSDocFunctionType */: + case 332 /* SyntaxKind.JSDocSignature */: + case 257 /* SyntaxKind.LabeledStatement */: + case 174 /* SyntaxKind.MethodDeclaration */: + case 173 /* SyntaxKind.MethodSignature */: + case 270 /* SyntaxKind.ModuleDeclaration */: + case 202 /* SyntaxKind.NamedTupleMember */: + case 273 /* SyntaxKind.NamespaceExportDeclaration */: + case 210 /* SyntaxKind.ObjectLiteralExpression */: + case 168 /* SyntaxKind.Parameter */: + case 217 /* SyntaxKind.ParenthesizedExpression */: + case 211 /* SyntaxKind.PropertyAccessExpression */: + case 305 /* SyntaxKind.PropertyAssignment */: + case 171 /* SyntaxKind.PropertyDeclaration */: + case 170 /* SyntaxKind.PropertySignature */: + case 254 /* SyntaxKind.ReturnStatement */: + case 241 /* SyntaxKind.SemicolonClassElement */: + case 178 /* SyntaxKind.SetAccessor */: + case 306 /* SyntaxKind.ShorthandPropertyAssignment */: + case 307 /* SyntaxKind.SpreadAssignment */: + case 256 /* SyntaxKind.SwitchStatement */: + case 258 /* SyntaxKind.ThrowStatement */: + case 259 /* SyntaxKind.TryStatement */: + case 268 /* SyntaxKind.TypeAliasDeclaration */: + case 167 /* SyntaxKind.TypeParameter */: + case 261 /* SyntaxKind.VariableDeclaration */: + case 244 /* SyntaxKind.VariableStatement */: + case 248 /* SyntaxKind.WhileStatement */: + case 255 /* SyntaxKind.WithStatement */: + return true; + default: + return false; + } + } + ts.canHaveJSDoc = canHaveJSDoc; function getJSDocCommentsAndTags(hostNode, noCache) { var result; // Pull parameter comments from declaring function as well @@ -18174,8 +18274,8 @@ var ts; return token !== undefined && isKeyword(token); } ts.isStringAKeyword = isStringAKeyword; - function isIdentifierANonContextualKeyword(_a) { - var originalKeywordKind = _a.originalKeywordKind; + function isIdentifierANonContextualKeyword(node) { + var originalKeywordKind = ts.identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } ts.isIdentifierANonContextualKeyword = isIdentifierANonContextualKeyword; @@ -19227,7 +19327,7 @@ var ts; } ts.isThisInTypeQuery = isThisInTypeQuery; function identifierIsThisKeyword(id) { - return id.originalKeywordKind === 109 /* SyntaxKind.ThisKeyword */; + return id.escapedText === "this"; } ts.identifierIsThisKeyword = identifierIsThisKeyword; function getAllAccessorDeclarations(declarations, accessor) { @@ -19651,7 +19751,7 @@ var ts; */ function getSyntacticModifierFlagsNoCache(node) { var flags = ts.canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0 /* ModifierFlags.None */; - if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.isInJSDocNamespace)) { + if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */)) { flags |= 1 /* ModifierFlags.Export */; } return flags; @@ -20584,7 +20684,6 @@ var ts; this.transformFlags = 0 /* TransformFlags.None */; this.parent = undefined; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(fileName, text, skipTrivia) { this.fileName = fileName; @@ -20603,8 +20702,19 @@ var ts; getSignatureConstructor: function () { return Signature; }, getSourceMapSourceConstructor: function () { return SourceMapSource; }, }; + var objectAllocatorPatchers = []; + /** + * Used by `deprecatedCompat` to patch the object allocator to apply deprecations. + * @internal + */ + function addObjectAllocatorPatcher(fn) { + objectAllocatorPatchers.push(fn); + fn(ts.objectAllocator); + } + ts.addObjectAllocatorPatcher = addObjectAllocatorPatcher; function setObjectAllocator(alloc) { Object.assign(ts.objectAllocator, alloc); + ts.forEach(objectAllocatorPatchers, function (fn) { return fn(ts.objectAllocator); }); } ts.setObjectAllocator = setObjectAllocator; function formatStringFromArgs(text, args, baseIndex) { @@ -23081,7 +23191,6 @@ var ts; createRegularExpressionLiteral: createRegularExpressionLiteral, createLiteralLikeNode: createLiteralLikeNode, createIdentifier: createIdentifier, - updateIdentifier: updateIdentifier, createTempVariable: createTempVariable, createLoopVariable: createLoopVariable, createUniqueName: createUniqueName, @@ -23773,20 +23882,13 @@ var ts; // // Identifiers // - function createBaseIdentifier(text, originalKeywordKind) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = ts.stringToToken(text); - } - if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text) { var node = baseFactory.createBaseIdentifierNode(79 /* SyntaxKind.Identifier */); - node.originalKeywordKind = originalKeywordKind; node.escapedText = ts.escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) { - var node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined); + var node = createBaseIdentifier(text); node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -23795,28 +23897,25 @@ var ts; return node; } // @api - function createIdentifier(text, typeArguments, originalKeywordKind, hasExtendedUnicodeEscape) { - var node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = ts.stringToToken(text); + } + if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { + originalKeywordKind = undefined; } - if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + var node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) + node.flags |= 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */; + if (node.escapedText === "await") { node.transformFlags |= 67108864 /* TransformFlags.ContainsPossibleTopLevelAwait */; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { node.transformFlags |= 1024 /* TransformFlags.ContainsES2015 */; } return node; } // @api - function updateIdentifier(node, typeArguments) { - return node.typeArguments !== typeArguments - ? update(createIdentifier(ts.idText(node), typeArguments), node) - : node; - } - // @api function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) { var flags = 1 /* GeneratedIdentifierFlags.Auto */; if (reservedInNestedScopes) @@ -29077,6 +29176,30 @@ var ts; return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.typeNode; } ts.getTypeNode = getTypeNode; + /** @internal */ + function setIdentifierTypeArguments(node, typeArguments) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + ts.setIdentifierTypeArguments = setIdentifierTypeArguments; + /** @internal */ + function getIdentifierTypeArguments(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.identifierTypeArguments; + } + ts.getIdentifierTypeArguments = getIdentifierTypeArguments; + /** @internal */ + function setIdentifierGeneratedImportReference(node, value) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + ts.setIdentifierGeneratedImportReference = setIdentifierGeneratedImportReference; + /** @internal */ + function getIdentifierGeneratedImportReference(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.generatedImportReference; + } + ts.getIdentifierGeneratedImportReference = getIdentifierGeneratedImportReference; })(ts || (ts = {})); /* @internal */ var ts; @@ -33967,7 +34090,7 @@ var ts; parseErrorAtCurrentToken(diagnosticMessage, arg0); } var pos = getNodePos(); - var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined) : + var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*originalKeywordKind*/ undefined) : ts.isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === 8 /* SyntaxKind.NumericLiteral */ ? factory.createNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === 10 /* SyntaxKind.StringLiteral */ ? factory.createStringLiteral("", /*isSingleQuote*/ undefined) : @@ -33994,7 +34117,7 @@ var ts; var text = internIdentifier(scanner.getTokenValue()); var hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === 80 /* SyntaxKind.PrivateIdentifier */) { parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage || ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); @@ -34007,7 +34130,7 @@ var ts; if (stateStylesRootNode && inEtsStateStylesContext() && token() === 24 /* SyntaxKind.DotToken */) { identifierCount++; var pos = getNodePos(); - return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } identifierCount++; // Only for end of file because the error gets reported incorrectly on embedded script tags. @@ -34401,6 +34524,7 @@ var ts; return parseElement(); } function currentNode(parsingContext, pos) { + var _a; // If we don't have a cursor or the parsing context isn't reusable, there's nothing to reuse. // // If there is an outstanding parse error that we've encountered, but not attached to @@ -34441,9 +34565,9 @@ var ts; if (!canReuseNode(node, parsingContext)) { return undefined; } - if (node.jsDocCache) { + if (ts.canHaveJSDoc(node) && ((_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache)) { // jsDocCache may include tags from parent nodes, which might have been modified. - node.jsDocCache = undefined; + node.jsDoc.jsDocCache = undefined; } return node; } @@ -34547,7 +34671,7 @@ var ts; // into an actual .ConstructorDeclaration. var methodDeclaration = node; var nameIsConstructor = methodDeclaration.name.kind === 79 /* SyntaxKind.Identifier */ && - methodDeclaration.name.originalKeywordKind === 136 /* SyntaxKind.ConstructorKeyword */; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } } @@ -34778,14 +34902,12 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var pos = getNodePos(); var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - var dotPos = getNodePos(); while (parseOptional(24 /* SyntaxKind.DotToken */)) { if (token() === 29 /* SyntaxKind.LessThanToken */) { - // the entity is part of a JSDoc-style generic, so record the trailing dot for later error reporting - entity.jsdocDotPos = dotPos; + // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and + // `typeArguments` to report it as a grammar error in the checker. break; } - dotPos = getNodePos(); entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos); } return entity; @@ -36906,13 +37028,13 @@ var ts; var pos = getNodePos(); var expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } else { expression = parsePrimaryExpression(); @@ -40375,7 +40497,7 @@ var ts; return finishNode(jsDocNamespaceNode, pos); } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + typeNameOrNamespaceName.flags |= 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */; } return typeNameOrNamespaceName; } @@ -40566,7 +40688,7 @@ var ts; var end = scanner.getTextPos(); var originalKeywordKind = token(); var text = internIdentifier(scanner.getTokenValue()); - var result = finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos, end); + var result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } @@ -48327,7 +48449,7 @@ var ts; case 79 /* SyntaxKind.Identifier */: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { return 0 /* ModuleInstanceState.NonInstantiated */; } } @@ -48897,6 +49019,7 @@ var ts; else if (containerFlags & 64 /* ContainerFlags.IsInterface */) { seenThisKeyword = false; bindChildren(node); + ts.Debug.assertNotNode(node, ts.isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier node.flags = seenThisKeyword ? node.flags | 128 /* NodeFlags.ContainsThis */ : node.flags & ~128 /* NodeFlags.ContainsThis */; } else { @@ -50284,12 +50407,13 @@ var ts; !(node.flags & 8388608 /* NodeFlags.JSDoc */) && !ts.isIdentifierName(node)) { // strict mode identifiers + var originalKeywordKind = ts.identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && - node.originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { + originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && + originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } - else if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + else if (originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { if (ts.isExternalModule(file) && ts.isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, ts.declarationNameToString(node))); } @@ -50297,7 +50421,7 @@ var ts; file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } - else if (node.originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { + else if (originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } @@ -50555,7 +50679,7 @@ var ts; // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { var parentNode = node.parent; while (parentNode && !ts.isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; @@ -57096,10 +57220,14 @@ var ts; var qualifier = root.qualifier; if (qualifier) { if (ts.isIdentifier(qualifier)) { - qualifier = ts.factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier)) { + qualifier = ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier.right)) { + qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -57116,10 +57244,14 @@ var ts; var typeArguments = root.typeArguments; var typeName = root.typeName; if (ts.isIdentifier(typeName)) { - typeName = ts.factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName)) { + typeName = ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName), typeArguments); + } } else { - typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName.right)) { + typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; // then move qualifiers @@ -57780,7 +57912,7 @@ var ts; if (!nonRootParts || ts.isEntityName(nonRootParts)) { if (nonRootParts) { var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); } return ts.factory.createImportTypeNode(lit, assertion, nonRootParts, typeParameterNodes, isTypeOf); } @@ -57799,8 +57931,8 @@ var ts; } else { var lastId = ts.isIdentifier(entityName) ? entityName : entityName.right; - var lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + var lastTypeArgs = ts.getIdentifierTypeArguments(lastId); + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); return ts.factory.createTypeReferenceNode(entityName, lastTypeArgs); } function createAccessFromSymbolChain(chain, index, stopper) { @@ -57849,7 +57981,9 @@ var ts; return ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode(LHS, typeParameterNodes), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(symbolName))); } } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { var LHS = createAccessFromSymbolChain(chain, index - 1, stopper); @@ -57892,7 +58026,9 @@ var ts; text = "".concat(rawtext, "_").concat(i); } if (text !== rawtext) { - result = ts.factory.createIdentifier(text, result.typeArguments); + var typeArguments = ts.getIdentifierTypeArguments(result); + result = ts.factory.createIdentifier(text); + ts.setIdentifierTypeArguments(result, typeArguments); } // avoiding iterations of the above loop turns out to be worth it when `i` starts to get large, so we cache the max // `i` we've used thus far, to save work later @@ -57920,7 +58056,9 @@ var ts; if (index === 0) { context.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */; } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57946,7 +58084,9 @@ var ts; symbolName.length > 1 && ts.isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : ts.isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57963,8 +58103,11 @@ var ts; expression = ts.factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); - expression.symbol = symbol; + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return ts.factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -72263,15 +72406,17 @@ var ts; break; case 168 /* SyntaxKind.Parameter */: var param = declaration; - if (ts.isIdentifier(param.name) && - (ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || - param.name.originalKeywordKind && ts.isTypeNodeKind(param.name.originalKeywordKind))) { - var newName = "arg" + param.parent.parameters.indexOf(param); - var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (ts.isIdentifier(param.name)) { + var originalKeywordKind = ts.identifierToKeywordKind(param.name); + if ((ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || + originalKeywordKind && ts.isTypeNodeKind(originalKeywordKind))) { + var newName = "arg" + param.parent.parameters.indexOf(param); + var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = declaration.dotDotDotToken ? noImplicitAny ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -86147,8 +86292,12 @@ var ts; } function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === 183 /* SyntaxKind.TypeReference */ && node.typeName.jsdocDotPos !== undefined && !ts.isInJSFile(node) && !ts.isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === 183 /* SyntaxKind.TypeReference */ && !ts.isInJSFile(node) && !ts.isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + // If there was a token between the type name and the type arguments, check if it was a DotToken + var sourceFile = ts.getSourceFileOfNode(node); + if (ts.scanTokenAtPosition(sourceFile, node.typeName.end) === 24 /* SyntaxKind.DotToken */) { + grammarErrorAtPos(node, ts.skipTrivia(sourceFile.text, node.typeName.end), 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } ts.forEach(node.typeArguments, checkSourceElement); var type = getTypeFromTypeReference(node); @@ -87358,7 +87507,8 @@ var ts; if (!ident) { return undefined; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -91378,7 +91528,8 @@ var ts; if (!ident) { return; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -92201,7 +92352,7 @@ var ts; } return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name, ignoreErrors) { + function getSymbolOfNameOrPropertyAccessExpression(name) { if (ts.isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -92280,11 +92431,11 @@ var ts; var symbol = getIntrinsicTagSymbol(name.parent); return symbol === unknownSymbol ? undefined : symbol; } - var result = resolveEntityName(name, meaning, /*ignoreErrors*/ ignoreErrors, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); + var result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); if (!result && isJSDoc_1) { var container = ts.findAncestor(name, ts.or(ts.isClassLike, ts.isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfNode(container)); } } if (result && isJSDoc_1) { @@ -92349,11 +92500,11 @@ var ts; } else if (isTypeReferenceIdentifier(name)) { var meaning = name.parent.kind === 183 /* SyntaxKind.TypeReference */ ? 788968 /* SymbolFlags.Type */ : 1920 /* SymbolFlags.Namespace */; - var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); + var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name); } if (name.parent.kind === 182 /* SyntaxKind.TypePredicate */) { - return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */); + return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */, /*ignoreErrors*/ true); } return undefined; } @@ -92519,7 +92670,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 306 /* SyntaxKind.ShorthandPropertyAssignment */) { - return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } return undefined; } @@ -92528,10 +92679,10 @@ var ts; if (ts.isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } else { - return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } } function getTypeOfNode(node) { @@ -92816,8 +92967,9 @@ var ts; // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(nodeIn) { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + var specifier = ts.getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier); if (node) { @@ -94947,7 +95099,7 @@ var ts; } function checkGrammarNameInLetOrConstDeclarations(name) { if (name.kind === 79 /* SyntaxKind.Identifier */) { - if (name.originalKeywordKind === 120 /* SyntaxKind.LetKeyword */) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } @@ -95681,9 +95833,6 @@ var ts; // NOTE: Before you can add a new method to `visitEachChildTable`, you must first ensure the `Node` subtype you // wish to add is defined in the `HasChildren` union in types.ts. var visitEachChildTable = (_a = {}, - _a[79 /* SyntaxKind.Identifier */] = function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, ts.isTypeNodeOrTypeParameterDeclaration)); - }, _a[165 /* SyntaxKind.QualifiedName */] = function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, ts.isEntityName), nodeVisitor(node.right, visitor, ts.isIdentifier)); }, @@ -104500,7 +104649,7 @@ var ts; } var generatedName = factory.createUniqueName("_".concat(name), 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */ | 64 /* GeneratedIdentifierFlags.AllowNameSubstitution */); var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + ts.setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } @@ -105625,7 +105774,7 @@ var ts; return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { return ts.setOriginalNode(ts.setTextRange(factory.createIdentifier(ts.unescapeLeadingUnderscores(node.escapedText)), node), node); } return node; @@ -108537,7 +108686,7 @@ var ts; * @param name An Identifier */ function trySubstituteReservedName(name) { - var token = name.originalKeywordKind || (ts.nodeIsSynthesized(name) ? ts.stringToToken(ts.idText(name)) : undefined); + var token = ts.identifierToKeywordKind(name); if (token !== undefined && token >= 81 /* SyntaxKind.FirstReservedWord */ && token <= 117 /* SyntaxKind.LastReservedWord */) { return ts.setTextRange(factory.createStringLiteralFromNode(name), name); } @@ -118680,7 +118829,7 @@ var ts; function emitIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol); - emitList(node, node.typeArguments, 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments + emitList(node, ts.getIdentifierTypeArguments(node), 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments } // // Names @@ -141046,8 +141195,11 @@ var ts; if (ts.isModifier(node)) { return node.kind; } - if (ts.isIdentifier(node) && node.originalKeywordKind && ts.isModifierKind(node.originalKeywordKind)) { - return node.originalKeywordKind; + if (ts.isIdentifier(node)) { + var originalKeywordKind = ts.identifierToKeywordKind(node); + if (originalKeywordKind && ts.isModifierKind(originalKeywordKind)) { + return originalKeywordKind; + } } return undefined; } @@ -143603,7 +143755,8 @@ var ts; || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); } function keywordForNode(node) { - return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* SyntaxKind.Unknown */ : node.kind; + var _a; + return ts.isIdentifier(node) ? (_a = ts.identifierToKeywordKind(node)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */ : node.kind; } function getContextualKeywords(contextToken, position) { var entries = []; @@ -143688,6 +143841,7 @@ var ts; * on the condition that one exists and that the context implies completion should be given. */ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position) { + var _a; // class c { method() { } | method2() { } } switch (location.kind) { case 357 /* SyntaxKind.SyntaxList */: @@ -143699,8 +143853,8 @@ var ts; } break; case 79 /* SyntaxKind.Identifier */: { - var originalKeywordKind = location.originalKeywordKind; - if (originalKeywordKind && ts.isKeyword(originalKeywordKind)) { + var originalKeywordKind = ts.identifierToKeywordKind(location); + if (originalKeywordKind) { return undefined; } // class c { public prop = c| } @@ -143742,7 +143896,7 @@ var ts; return undefined; } var isValidKeyword = ts.isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword; - return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword(ts.stringToToken(contextToken.text))) // TODO: GH#18217 + return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword((_a = ts.identifierToKeywordKind(contextToken)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */)) ? contextToken.parent.parent : undefined; } } @@ -146798,8 +146952,8 @@ var ts; } // For `export { foo as bar }`, rename `foo`, but not `bar`. if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) { - var isDefaultExport = referenceLocation.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ - || exportSpecifier.name.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */; + var isDefaultExport = referenceLocation.escapedText === "default" + || exportSpecifier.name.escapedText === "default"; var exportKind = isDefaultExport ? 1 /* ExportKind.Default */ : 0 /* ExportKind.Named */; var exportSymbol = ts.Debug.checkDefined(exportSpecifier.symbol); var exportInfo = FindAllReferences.getExportInfo(exportSymbol, exportKind, state.checker); @@ -151908,7 +152062,7 @@ var ts; return getRenameInfoError(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library); } // Cannot rename `default` as in `import { default as foo } from "./someModule"; - if (ts.isIdentifier(node) && node.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { + if (ts.isIdentifier(node) && node.escapedText === "default" && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { return undefined; } if (ts.isStringLiteralLike(node) && ts.tryGetImportFromModuleSpecifier(node)) { @@ -158310,7 +158464,6 @@ var ts; parent.parent : parent.parent.parent; jsDocNode.jsDoc = parent.jsDoc; - jsDocNode.jsDocCache = parent.jsDocCache; return jsDocNode; } function tryMergeJsdocTags(oldTag, newTag) { @@ -160965,8 +161118,8 @@ var ts; function collectExportRenames(sourceFile, checker, identifiers) { var res = new ts.Map(); forEachExportReference(sourceFile, function (node) { - var _a = node.name, text = _a.text, originalKeywordKind = _a.originalKeywordKind; - if (!res.has(text) && (originalKeywordKind !== undefined && ts.isNonContextualKeyword(originalKeywordKind) + var text = node.name.text; + if (!res.has(text) && (ts.isIdentifierANonContextualKeyword(node.name) || checker.resolveName(text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ true))) { // Unconditionally add an underscore in case `text` is a keyword. res.set(text, makeUniqueName("_".concat(text), identifiers)); @@ -170201,7 +170354,7 @@ var ts; var checker = context.program.getTypeChecker(); // Make a unique name for the extracted variable var file = scope.getSourceFile(); - var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.isKeyword(node.name.originalKeywordKind) + var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.identifierToKeywordKind(node.name) ? node.name.text : ts.getUniqueName(ts.isClassLike(scope) ? "newProperty" : "newLocal", file); var isJS = ts.isInJSFile(scope); @@ -188746,7 +188899,7 @@ var ts; }, factoryDeprecation); /** @deprecated Use `factory.createIdentifier` or the factory supplied by your transformation context instead. */ ts.createIdentifier = ts.Debug.deprecate(function createIdentifier(text) { - return ts.factory.createIdentifier(text, /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined); + return ts.factory.createIdentifier(text, /*originalKeywordKind*/ undefined); }, factoryDeprecation); /** @deprecated Use `factory.createTempVariable` or the factory supplied by your transformation context instead. */ ts.createTempVariable = ts.Debug.deprecate(function createTempVariable(recordTempVariable) { diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 6a74eb1412..20ad9bbae3 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -633,9 +633,10 @@ declare namespace ts { locals?: SymbolTable; skipCheck?: boolean; } - export interface JSDocContainer { + export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AnnotationPropertyDeclaration | AnnotationDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken; + export type HasJSDoc = AccessorDeclaration | AnnotationDeclaration | AnnotationPropertyDeclaration | ArrowFunction | Block | BreakStatement | CallSignatureDeclaration | CaseClause | ClassLikeDeclaration | ClassStaticBlockDeclaration | ConstructorDeclaration | ConstructorTypeNode | ConstructSignatureDeclaration | ContinueStatement | DebuggerStatement | DoStatement | EmptyStatement | EndOfFileToken | EnumDeclaration | EnumMember | ExportAssignment | ExportDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | FunctionTypeNode | IfStatement | ImportDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | InterfaceDeclaration | JSDocFunctionType | LabeledStatement | MethodDeclaration | MethodSignature | ModuleDeclaration | NamedTupleMember | NamespaceExportDeclaration | ParameterDeclaration | ParenthesizedExpression | PropertyAssignment | PropertyDeclaration | PropertySignature | ReturnStatement | ShorthandPropertyAssignment | SpreadAssignment | SwitchStatement | ThrowStatement | TryStatement | TypeAliasDeclaration | VariableDeclaration | VariableStatement | WhileStatement | WithStatement; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | AnnotationPropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -711,8 +712,6 @@ declare namespace ts { * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ readonly escapedText: __String; - readonly originalKeywordKind?: SyntaxKind; - isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; @@ -3711,11 +3710,12 @@ declare namespace ts { createToken(token: SyntaxKind.NullKeyword): NullLiteral; createToken(token: SyntaxKind.TrueKeyword): TrueLiteral; createToken(token: SyntaxKind.FalseKeyword): FalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + createToken(token: SyntaxKind.Unknown): Token; createToken(token: TKind): PunctuationToken; createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - createToken(token: TKind): Token; createSuper(): SuperExpression; createThis(): ThisExpression; createNull(): NullLiteral; @@ -4817,6 +4817,11 @@ declare namespace ts { */ function unescapeLeadingUnderscores(identifier: __String): string; function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; function symbolName(symbol: Symbol): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; diff --git a/lib/typescript.js b/lib/typescript.js index 805ed32e84..359db6720a 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -4809,6 +4809,9 @@ var ts; // never cleared on SourceFiles which get re-used in between incremental parses. // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`. /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags"; + // The following flags repurpose other NodeFlags as different meanings for Identifier nodes + /** @internal */ NodeFlags[NodeFlags["IdentifierHasExtendedUnicodeEscape"] = 128] = "IdentifierHasExtendedUnicodeEscape"; + /** @internal */ NodeFlags[NodeFlags["IdentifierIsInJSDocNamespace"] = 2048] = "IdentifierIsInJSDocNamespace"; })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {})); var EtsFlags; (function (EtsFlags) { @@ -13201,6 +13204,15 @@ var ts; return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } ts.idText = idText; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node) { + var token = ts.stringToToken(node.escapedText); + return token ? ts.tryCast(token, ts.isKeyword) : undefined; + } + ts.identifierToKeywordKind = identifierToKeywordKind; function symbolName(symbol) { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -13605,14 +13617,18 @@ var ts; } ts.getJSDocReturnType = getJSDocReturnType; function getJSDocTagsWorker(node, noCache) { - var tags = node.jsDocCache; + var _a, _b; + if (!ts.canHaveJSDoc(node)) + return ts.emptyArray; + var tags = (_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. if (tags === undefined || noCache) { var comments = ts.getJSDocCommentsAndTags(node, noCache); ts.Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = ts.flatMap(comments, function (j) { return ts.isJSDoc(j) ? j.tags : j; }); if (!noCache) { - node.jsDocCache = tags; + (_b = node.jsDoc) !== null && _b !== void 0 ? _b : (node.jsDoc = []); + node.jsDoc.jsDocCache = tags; } } return tags; @@ -15980,6 +15996,13 @@ var ts; return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + /** @internal */ + function scanTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + ts.scanTokenAtPosition = scanTokenAtPosition; function getErrorSpanForArrowFunction(sourceFile, node) { var pos = ts.skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === 242 /* SyntaxKind.Block */) { @@ -17594,6 +17617,83 @@ var ts; ? node.body : undefined; } + /** @internal */ + function canHaveJSDoc(node) { + switch (node.kind) { + case 219 /* SyntaxKind.ArrowFunction */: + case 266 /* SyntaxKind.AnnotationDeclaration */: + case 172 /* SyntaxKind.AnnotationPropertyDeclaration */: + case 227 /* SyntaxKind.BinaryExpression */: + case 242 /* SyntaxKind.Block */: + case 253 /* SyntaxKind.BreakStatement */: + case 179 /* SyntaxKind.CallSignature */: + case 298 /* SyntaxKind.CaseClause */: + case 264 /* SyntaxKind.ClassDeclaration */: + case 232 /* SyntaxKind.ClassExpression */: + case 175 /* SyntaxKind.ClassStaticBlockDeclaration */: + case 176 /* SyntaxKind.Constructor */: + case 185 /* SyntaxKind.ConstructorType */: + case 180 /* SyntaxKind.ConstructSignature */: + case 252 /* SyntaxKind.ContinueStatement */: + case 260 /* SyntaxKind.DebuggerStatement */: + case 247 /* SyntaxKind.DoStatement */: + case 212 /* SyntaxKind.ElementAccessExpression */: + case 243 /* SyntaxKind.EmptyStatement */: + case 1 /* SyntaxKind.EndOfFileToken */: + case 269 /* SyntaxKind.EnumDeclaration */: + case 308 /* SyntaxKind.EnumMember */: + case 280 /* SyntaxKind.ExportAssignment */: + case 281 /* SyntaxKind.ExportDeclaration */: + case 284 /* SyntaxKind.ExportSpecifier */: + case 245 /* SyntaxKind.ExpressionStatement */: + case 250 /* SyntaxKind.ForInStatement */: + case 251 /* SyntaxKind.ForOfStatement */: + case 249 /* SyntaxKind.ForStatement */: + case 263 /* SyntaxKind.FunctionDeclaration */: + case 218 /* SyntaxKind.FunctionExpression */: + case 184 /* SyntaxKind.FunctionType */: + case 177 /* SyntaxKind.GetAccessor */: + case 79 /* SyntaxKind.Identifier */: + case 246 /* SyntaxKind.IfStatement */: + case 275 /* SyntaxKind.ImportDeclaration */: + case 274 /* SyntaxKind.ImportEqualsDeclaration */: + case 181 /* SyntaxKind.IndexSignature */: + case 267 /* SyntaxKind.InterfaceDeclaration */: + case 326 /* SyntaxKind.JSDocFunctionType */: + case 332 /* SyntaxKind.JSDocSignature */: + case 257 /* SyntaxKind.LabeledStatement */: + case 174 /* SyntaxKind.MethodDeclaration */: + case 173 /* SyntaxKind.MethodSignature */: + case 270 /* SyntaxKind.ModuleDeclaration */: + case 202 /* SyntaxKind.NamedTupleMember */: + case 273 /* SyntaxKind.NamespaceExportDeclaration */: + case 210 /* SyntaxKind.ObjectLiteralExpression */: + case 168 /* SyntaxKind.Parameter */: + case 217 /* SyntaxKind.ParenthesizedExpression */: + case 211 /* SyntaxKind.PropertyAccessExpression */: + case 305 /* SyntaxKind.PropertyAssignment */: + case 171 /* SyntaxKind.PropertyDeclaration */: + case 170 /* SyntaxKind.PropertySignature */: + case 254 /* SyntaxKind.ReturnStatement */: + case 241 /* SyntaxKind.SemicolonClassElement */: + case 178 /* SyntaxKind.SetAccessor */: + case 306 /* SyntaxKind.ShorthandPropertyAssignment */: + case 307 /* SyntaxKind.SpreadAssignment */: + case 256 /* SyntaxKind.SwitchStatement */: + case 258 /* SyntaxKind.ThrowStatement */: + case 259 /* SyntaxKind.TryStatement */: + case 268 /* SyntaxKind.TypeAliasDeclaration */: + case 167 /* SyntaxKind.TypeParameter */: + case 261 /* SyntaxKind.VariableDeclaration */: + case 244 /* SyntaxKind.VariableStatement */: + case 248 /* SyntaxKind.WhileStatement */: + case 255 /* SyntaxKind.WithStatement */: + return true; + default: + return false; + } + } + ts.canHaveJSDoc = canHaveJSDoc; function getJSDocCommentsAndTags(hostNode, noCache) { var result; // Pull parameter comments from declaring function as well @@ -18165,8 +18265,8 @@ var ts; return token !== undefined && isKeyword(token); } ts.isStringAKeyword = isStringAKeyword; - function isIdentifierANonContextualKeyword(_a) { - var originalKeywordKind = _a.originalKeywordKind; + function isIdentifierANonContextualKeyword(node) { + var originalKeywordKind = ts.identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } ts.isIdentifierANonContextualKeyword = isIdentifierANonContextualKeyword; @@ -19218,7 +19318,7 @@ var ts; } ts.isThisInTypeQuery = isThisInTypeQuery; function identifierIsThisKeyword(id) { - return id.originalKeywordKind === 109 /* SyntaxKind.ThisKeyword */; + return id.escapedText === "this"; } ts.identifierIsThisKeyword = identifierIsThisKeyword; function getAllAccessorDeclarations(declarations, accessor) { @@ -19642,7 +19742,7 @@ var ts; */ function getSyntacticModifierFlagsNoCache(node) { var flags = ts.canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0 /* ModifierFlags.None */; - if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.isInJSDocNamespace)) { + if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */)) { flags |= 1 /* ModifierFlags.Export */; } return flags; @@ -20575,7 +20675,6 @@ var ts; this.transformFlags = 0 /* TransformFlags.None */; this.parent = undefined; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(fileName, text, skipTrivia) { this.fileName = fileName; @@ -20594,8 +20693,19 @@ var ts; getSignatureConstructor: function () { return Signature; }, getSourceMapSourceConstructor: function () { return SourceMapSource; }, }; + var objectAllocatorPatchers = []; + /** + * Used by `deprecatedCompat` to patch the object allocator to apply deprecations. + * @internal + */ + function addObjectAllocatorPatcher(fn) { + objectAllocatorPatchers.push(fn); + fn(ts.objectAllocator); + } + ts.addObjectAllocatorPatcher = addObjectAllocatorPatcher; function setObjectAllocator(alloc) { Object.assign(ts.objectAllocator, alloc); + ts.forEach(objectAllocatorPatchers, function (fn) { return fn(ts.objectAllocator); }); } ts.setObjectAllocator = setObjectAllocator; function formatStringFromArgs(text, args, baseIndex) { @@ -23072,7 +23182,6 @@ var ts; createRegularExpressionLiteral: createRegularExpressionLiteral, createLiteralLikeNode: createLiteralLikeNode, createIdentifier: createIdentifier, - updateIdentifier: updateIdentifier, createTempVariable: createTempVariable, createLoopVariable: createLoopVariable, createUniqueName: createUniqueName, @@ -23764,20 +23873,13 @@ var ts; // // Identifiers // - function createBaseIdentifier(text, originalKeywordKind) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = ts.stringToToken(text); - } - if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text) { var node = baseFactory.createBaseIdentifierNode(79 /* SyntaxKind.Identifier */); - node.originalKeywordKind = originalKeywordKind; node.escapedText = ts.escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) { - var node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined); + var node = createBaseIdentifier(text); node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -23786,28 +23888,25 @@ var ts; return node; } // @api - function createIdentifier(text, typeArguments, originalKeywordKind, hasExtendedUnicodeEscape) { - var node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = ts.stringToToken(text); + } + if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { + originalKeywordKind = undefined; } - if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + var node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) + node.flags |= 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */; + if (node.escapedText === "await") { node.transformFlags |= 67108864 /* TransformFlags.ContainsPossibleTopLevelAwait */; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { node.transformFlags |= 1024 /* TransformFlags.ContainsES2015 */; } return node; } // @api - function updateIdentifier(node, typeArguments) { - return node.typeArguments !== typeArguments - ? update(createIdentifier(ts.idText(node), typeArguments), node) - : node; - } - // @api function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) { var flags = 1 /* GeneratedIdentifierFlags.Auto */; if (reservedInNestedScopes) @@ -29068,6 +29167,30 @@ var ts; return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.typeNode; } ts.getTypeNode = getTypeNode; + /** @internal */ + function setIdentifierTypeArguments(node, typeArguments) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + ts.setIdentifierTypeArguments = setIdentifierTypeArguments; + /** @internal */ + function getIdentifierTypeArguments(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.identifierTypeArguments; + } + ts.getIdentifierTypeArguments = getIdentifierTypeArguments; + /** @internal */ + function setIdentifierGeneratedImportReference(node, value) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + ts.setIdentifierGeneratedImportReference = setIdentifierGeneratedImportReference; + /** @internal */ + function getIdentifierGeneratedImportReference(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.generatedImportReference; + } + ts.getIdentifierGeneratedImportReference = getIdentifierGeneratedImportReference; })(ts || (ts = {})); /* @internal */ var ts; @@ -33958,7 +34081,7 @@ var ts; parseErrorAtCurrentToken(diagnosticMessage, arg0); } var pos = getNodePos(); - var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined) : + var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*originalKeywordKind*/ undefined) : ts.isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === 8 /* SyntaxKind.NumericLiteral */ ? factory.createNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === 10 /* SyntaxKind.StringLiteral */ ? factory.createStringLiteral("", /*isSingleQuote*/ undefined) : @@ -33985,7 +34108,7 @@ var ts; var text = internIdentifier(scanner.getTokenValue()); var hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === 80 /* SyntaxKind.PrivateIdentifier */) { parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage || ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); @@ -33998,7 +34121,7 @@ var ts; if (stateStylesRootNode && inEtsStateStylesContext() && token() === 24 /* SyntaxKind.DotToken */) { identifierCount++; var pos = getNodePos(); - return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } identifierCount++; // Only for end of file because the error gets reported incorrectly on embedded script tags. @@ -34392,6 +34515,7 @@ var ts; return parseElement(); } function currentNode(parsingContext, pos) { + var _a; // If we don't have a cursor or the parsing context isn't reusable, there's nothing to reuse. // // If there is an outstanding parse error that we've encountered, but not attached to @@ -34432,9 +34556,9 @@ var ts; if (!canReuseNode(node, parsingContext)) { return undefined; } - if (node.jsDocCache) { + if (ts.canHaveJSDoc(node) && ((_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache)) { // jsDocCache may include tags from parent nodes, which might have been modified. - node.jsDocCache = undefined; + node.jsDoc.jsDocCache = undefined; } return node; } @@ -34538,7 +34662,7 @@ var ts; // into an actual .ConstructorDeclaration. var methodDeclaration = node; var nameIsConstructor = methodDeclaration.name.kind === 79 /* SyntaxKind.Identifier */ && - methodDeclaration.name.originalKeywordKind === 136 /* SyntaxKind.ConstructorKeyword */; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } } @@ -34769,14 +34893,12 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var pos = getNodePos(); var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - var dotPos = getNodePos(); while (parseOptional(24 /* SyntaxKind.DotToken */)) { if (token() === 29 /* SyntaxKind.LessThanToken */) { - // the entity is part of a JSDoc-style generic, so record the trailing dot for later error reporting - entity.jsdocDotPos = dotPos; + // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and + // `typeArguments` to report it as a grammar error in the checker. break; } - dotPos = getNodePos(); entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos); } return entity; @@ -36897,13 +37019,13 @@ var ts; var pos = getNodePos(); var expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } else { expression = parsePrimaryExpression(); @@ -40366,7 +40488,7 @@ var ts; return finishNode(jsDocNamespaceNode, pos); } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + typeNameOrNamespaceName.flags |= 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */; } return typeNameOrNamespaceName; } @@ -40557,7 +40679,7 @@ var ts; var end = scanner.getTextPos(); var originalKeywordKind = token(); var text = internIdentifier(scanner.getTokenValue()); - var result = finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos, end); + var result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } @@ -48318,7 +48440,7 @@ var ts; case 79 /* SyntaxKind.Identifier */: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { return 0 /* ModuleInstanceState.NonInstantiated */; } } @@ -48888,6 +49010,7 @@ var ts; else if (containerFlags & 64 /* ContainerFlags.IsInterface */) { seenThisKeyword = false; bindChildren(node); + ts.Debug.assertNotNode(node, ts.isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier node.flags = seenThisKeyword ? node.flags | 128 /* NodeFlags.ContainsThis */ : node.flags & ~128 /* NodeFlags.ContainsThis */; } else { @@ -50275,12 +50398,13 @@ var ts; !(node.flags & 8388608 /* NodeFlags.JSDoc */) && !ts.isIdentifierName(node)) { // strict mode identifiers + var originalKeywordKind = ts.identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && - node.originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { + originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && + originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } - else if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + else if (originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { if (ts.isExternalModule(file) && ts.isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, ts.declarationNameToString(node))); } @@ -50288,7 +50412,7 @@ var ts; file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } - else if (node.originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { + else if (originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } @@ -50546,7 +50670,7 @@ var ts; // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { var parentNode = node.parent; while (parentNode && !ts.isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; @@ -57087,10 +57211,14 @@ var ts; var qualifier = root.qualifier; if (qualifier) { if (ts.isIdentifier(qualifier)) { - qualifier = ts.factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier)) { + qualifier = ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier.right)) { + qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -57107,10 +57235,14 @@ var ts; var typeArguments = root.typeArguments; var typeName = root.typeName; if (ts.isIdentifier(typeName)) { - typeName = ts.factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName)) { + typeName = ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName), typeArguments); + } } else { - typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName.right)) { + typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; // then move qualifiers @@ -57771,7 +57903,7 @@ var ts; if (!nonRootParts || ts.isEntityName(nonRootParts)) { if (nonRootParts) { var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); } return ts.factory.createImportTypeNode(lit, assertion, nonRootParts, typeParameterNodes, isTypeOf); } @@ -57790,8 +57922,8 @@ var ts; } else { var lastId = ts.isIdentifier(entityName) ? entityName : entityName.right; - var lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + var lastTypeArgs = ts.getIdentifierTypeArguments(lastId); + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); return ts.factory.createTypeReferenceNode(entityName, lastTypeArgs); } function createAccessFromSymbolChain(chain, index, stopper) { @@ -57840,7 +57972,9 @@ var ts; return ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode(LHS, typeParameterNodes), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(symbolName))); } } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { var LHS = createAccessFromSymbolChain(chain, index - 1, stopper); @@ -57883,7 +58017,9 @@ var ts; text = "".concat(rawtext, "_").concat(i); } if (text !== rawtext) { - result = ts.factory.createIdentifier(text, result.typeArguments); + var typeArguments = ts.getIdentifierTypeArguments(result); + result = ts.factory.createIdentifier(text); + ts.setIdentifierTypeArguments(result, typeArguments); } // avoiding iterations of the above loop turns out to be worth it when `i` starts to get large, so we cache the max // `i` we've used thus far, to save work later @@ -57911,7 +58047,9 @@ var ts; if (index === 0) { context.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */; } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57937,7 +58075,9 @@ var ts; symbolName.length > 1 && ts.isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : ts.isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57954,8 +58094,11 @@ var ts; expression = ts.factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); - expression.symbol = symbol; + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return ts.factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -72254,15 +72397,17 @@ var ts; break; case 168 /* SyntaxKind.Parameter */: var param = declaration; - if (ts.isIdentifier(param.name) && - (ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || - param.name.originalKeywordKind && ts.isTypeNodeKind(param.name.originalKeywordKind))) { - var newName = "arg" + param.parent.parameters.indexOf(param); - var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (ts.isIdentifier(param.name)) { + var originalKeywordKind = ts.identifierToKeywordKind(param.name); + if ((ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || + originalKeywordKind && ts.isTypeNodeKind(originalKeywordKind))) { + var newName = "arg" + param.parent.parameters.indexOf(param); + var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = declaration.dotDotDotToken ? noImplicitAny ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -86138,8 +86283,12 @@ var ts; } function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === 183 /* SyntaxKind.TypeReference */ && node.typeName.jsdocDotPos !== undefined && !ts.isInJSFile(node) && !ts.isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === 183 /* SyntaxKind.TypeReference */ && !ts.isInJSFile(node) && !ts.isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + // If there was a token between the type name and the type arguments, check if it was a DotToken + var sourceFile = ts.getSourceFileOfNode(node); + if (ts.scanTokenAtPosition(sourceFile, node.typeName.end) === 24 /* SyntaxKind.DotToken */) { + grammarErrorAtPos(node, ts.skipTrivia(sourceFile.text, node.typeName.end), 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } ts.forEach(node.typeArguments, checkSourceElement); var type = getTypeFromTypeReference(node); @@ -87349,7 +87498,8 @@ var ts; if (!ident) { return undefined; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -91369,7 +91519,8 @@ var ts; if (!ident) { return; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -92192,7 +92343,7 @@ var ts; } return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name, ignoreErrors) { + function getSymbolOfNameOrPropertyAccessExpression(name) { if (ts.isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -92271,11 +92422,11 @@ var ts; var symbol = getIntrinsicTagSymbol(name.parent); return symbol === unknownSymbol ? undefined : symbol; } - var result = resolveEntityName(name, meaning, /*ignoreErrors*/ ignoreErrors, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); + var result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); if (!result && isJSDoc_1) { var container = ts.findAncestor(name, ts.or(ts.isClassLike, ts.isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfNode(container)); } } if (result && isJSDoc_1) { @@ -92340,11 +92491,11 @@ var ts; } else if (isTypeReferenceIdentifier(name)) { var meaning = name.parent.kind === 183 /* SyntaxKind.TypeReference */ ? 788968 /* SymbolFlags.Type */ : 1920 /* SymbolFlags.Namespace */; - var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); + var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name); } if (name.parent.kind === 182 /* SyntaxKind.TypePredicate */) { - return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */); + return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */, /*ignoreErrors*/ true); } return undefined; } @@ -92510,7 +92661,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 306 /* SyntaxKind.ShorthandPropertyAssignment */) { - return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } return undefined; } @@ -92519,10 +92670,10 @@ var ts; if (ts.isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } else { - return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } } function getTypeOfNode(node) { @@ -92807,8 +92958,9 @@ var ts; // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(nodeIn) { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + var specifier = ts.getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier); if (node) { @@ -94938,7 +95090,7 @@ var ts; } function checkGrammarNameInLetOrConstDeclarations(name) { if (name.kind === 79 /* SyntaxKind.Identifier */) { - if (name.originalKeywordKind === 120 /* SyntaxKind.LetKeyword */) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } @@ -95672,9 +95824,6 @@ var ts; // NOTE: Before you can add a new method to `visitEachChildTable`, you must first ensure the `Node` subtype you // wish to add is defined in the `HasChildren` union in types.ts. var visitEachChildTable = (_a = {}, - _a[79 /* SyntaxKind.Identifier */] = function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, ts.isTypeNodeOrTypeParameterDeclaration)); - }, _a[165 /* SyntaxKind.QualifiedName */] = function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, ts.isEntityName), nodeVisitor(node.right, visitor, ts.isIdentifier)); }, @@ -104491,7 +104640,7 @@ var ts; } var generatedName = factory.createUniqueName("_".concat(name), 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */ | 64 /* GeneratedIdentifierFlags.AllowNameSubstitution */); var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + ts.setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } @@ -105616,7 +105765,7 @@ var ts; return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { return ts.setOriginalNode(ts.setTextRange(factory.createIdentifier(ts.unescapeLeadingUnderscores(node.escapedText)), node), node); } return node; @@ -108528,7 +108677,7 @@ var ts; * @param name An Identifier */ function trySubstituteReservedName(name) { - var token = name.originalKeywordKind || (ts.nodeIsSynthesized(name) ? ts.stringToToken(ts.idText(name)) : undefined); + var token = ts.identifierToKeywordKind(name); if (token !== undefined && token >= 81 /* SyntaxKind.FirstReservedWord */ && token <= 117 /* SyntaxKind.LastReservedWord */) { return ts.setTextRange(factory.createStringLiteralFromNode(name), name); } @@ -118671,7 +118820,7 @@ var ts; function emitIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol); - emitList(node, node.typeArguments, 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments + emitList(node, ts.getIdentifierTypeArguments(node), 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments } // // Names @@ -141037,8 +141186,11 @@ var ts; if (ts.isModifier(node)) { return node.kind; } - if (ts.isIdentifier(node) && node.originalKeywordKind && ts.isModifierKind(node.originalKeywordKind)) { - return node.originalKeywordKind; + if (ts.isIdentifier(node)) { + var originalKeywordKind = ts.identifierToKeywordKind(node); + if (originalKeywordKind && ts.isModifierKind(originalKeywordKind)) { + return originalKeywordKind; + } } return undefined; } @@ -143594,7 +143746,8 @@ var ts; || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); } function keywordForNode(node) { - return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* SyntaxKind.Unknown */ : node.kind; + var _a; + return ts.isIdentifier(node) ? (_a = ts.identifierToKeywordKind(node)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */ : node.kind; } function getContextualKeywords(contextToken, position) { var entries = []; @@ -143679,6 +143832,7 @@ var ts; * on the condition that one exists and that the context implies completion should be given. */ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position) { + var _a; // class c { method() { } | method2() { } } switch (location.kind) { case 357 /* SyntaxKind.SyntaxList */: @@ -143690,8 +143844,8 @@ var ts; } break; case 79 /* SyntaxKind.Identifier */: { - var originalKeywordKind = location.originalKeywordKind; - if (originalKeywordKind && ts.isKeyword(originalKeywordKind)) { + var originalKeywordKind = ts.identifierToKeywordKind(location); + if (originalKeywordKind) { return undefined; } // class c { public prop = c| } @@ -143733,7 +143887,7 @@ var ts; return undefined; } var isValidKeyword = ts.isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword; - return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword(ts.stringToToken(contextToken.text))) // TODO: GH#18217 + return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword((_a = ts.identifierToKeywordKind(contextToken)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */)) ? contextToken.parent.parent : undefined; } } @@ -146789,8 +146943,8 @@ var ts; } // For `export { foo as bar }`, rename `foo`, but not `bar`. if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) { - var isDefaultExport = referenceLocation.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ - || exportSpecifier.name.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */; + var isDefaultExport = referenceLocation.escapedText === "default" + || exportSpecifier.name.escapedText === "default"; var exportKind = isDefaultExport ? 1 /* ExportKind.Default */ : 0 /* ExportKind.Named */; var exportSymbol = ts.Debug.checkDefined(exportSpecifier.symbol); var exportInfo = FindAllReferences.getExportInfo(exportSymbol, exportKind, state.checker); @@ -151899,7 +152053,7 @@ var ts; return getRenameInfoError(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library); } // Cannot rename `default` as in `import { default as foo } from "./someModule"; - if (ts.isIdentifier(node) && node.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { + if (ts.isIdentifier(node) && node.escapedText === "default" && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { return undefined; } if (ts.isStringLiteralLike(node) && ts.tryGetImportFromModuleSpecifier(node)) { @@ -158301,7 +158455,6 @@ var ts; parent.parent : parent.parent.parent; jsDocNode.jsDoc = parent.jsDoc; - jsDocNode.jsDocCache = parent.jsDocCache; return jsDocNode; } function tryMergeJsdocTags(oldTag, newTag) { @@ -160956,8 +161109,8 @@ var ts; function collectExportRenames(sourceFile, checker, identifiers) { var res = new ts.Map(); forEachExportReference(sourceFile, function (node) { - var _a = node.name, text = _a.text, originalKeywordKind = _a.originalKeywordKind; - if (!res.has(text) && (originalKeywordKind !== undefined && ts.isNonContextualKeyword(originalKeywordKind) + var text = node.name.text; + if (!res.has(text) && (ts.isIdentifierANonContextualKeyword(node.name) || checker.resolveName(text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ true))) { // Unconditionally add an underscore in case `text` is a keyword. res.set(text, makeUniqueName("_".concat(text), identifiers)); @@ -170192,7 +170345,7 @@ var ts; var checker = context.program.getTypeChecker(); // Make a unique name for the extracted variable var file = scope.getSourceFile(); - var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.isKeyword(node.name.originalKeywordKind) + var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.identifierToKeywordKind(node.name) ? node.name.text : ts.getUniqueName(ts.isClassLike(scope) ? "newProperty" : "newLocal", file); var isJS = ts.isInJSFile(scope); @@ -177840,7 +177993,7 @@ var ts; }, factoryDeprecation); /** @deprecated Use `factory.createIdentifier` or the factory supplied by your transformation context instead. */ ts.createIdentifier = ts.Debug.deprecate(function createIdentifier(text) { - return ts.factory.createIdentifier(text, /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined); + return ts.factory.createIdentifier(text, /*originalKeywordKind*/ undefined); }, factoryDeprecation); /** @deprecated Use `factory.createTempVariable` or the factory supplied by your transformation context instead. */ ts.createTempVariable = ts.Debug.deprecate(function createTempVariable(recordTempVariable) { diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index a273ee24d7..1aa77dc410 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -633,9 +633,10 @@ declare namespace ts { locals?: SymbolTable; skipCheck?: boolean; } - export interface JSDocContainer { + export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AnnotationPropertyDeclaration | AnnotationDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken; + export type HasJSDoc = AccessorDeclaration | AnnotationDeclaration | AnnotationPropertyDeclaration | ArrowFunction | Block | BreakStatement | CallSignatureDeclaration | CaseClause | ClassLikeDeclaration | ClassStaticBlockDeclaration | ConstructorDeclaration | ConstructorTypeNode | ConstructSignatureDeclaration | ContinueStatement | DebuggerStatement | DoStatement | EmptyStatement | EndOfFileToken | EnumDeclaration | EnumMember | ExportAssignment | ExportDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | FunctionTypeNode | IfStatement | ImportDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | InterfaceDeclaration | JSDocFunctionType | LabeledStatement | MethodDeclaration | MethodSignature | ModuleDeclaration | NamedTupleMember | NamespaceExportDeclaration | ParameterDeclaration | ParenthesizedExpression | PropertyAssignment | PropertyDeclaration | PropertySignature | ReturnStatement | ShorthandPropertyAssignment | SpreadAssignment | SwitchStatement | ThrowStatement | TryStatement | TypeAliasDeclaration | VariableDeclaration | VariableStatement | WhileStatement | WithStatement; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | AnnotationPropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -711,8 +712,6 @@ declare namespace ts { * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ readonly escapedText: __String; - readonly originalKeywordKind?: SyntaxKind; - isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; @@ -3711,11 +3710,12 @@ declare namespace ts { createToken(token: SyntaxKind.NullKeyword): NullLiteral; createToken(token: SyntaxKind.TrueKeyword): TrueLiteral; createToken(token: SyntaxKind.FalseKeyword): FalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + createToken(token: SyntaxKind.Unknown): Token; createToken(token: TKind): PunctuationToken; createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - createToken(token: TKind): Token; createSuper(): SuperExpression; createThis(): ThisExpression; createNull(): NullLiteral; @@ -4817,6 +4817,11 @@ declare namespace ts { */ function unescapeLeadingUnderscores(identifier: __String): string; function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; function symbolName(symbol: Symbol): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index c3916ec18f..a02f33c2b2 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -4809,6 +4809,9 @@ var ts; // never cleared on SourceFiles which get re-used in between incremental parses. // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`. /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags"; + // The following flags repurpose other NodeFlags as different meanings for Identifier nodes + /** @internal */ NodeFlags[NodeFlags["IdentifierHasExtendedUnicodeEscape"] = 128] = "IdentifierHasExtendedUnicodeEscape"; + /** @internal */ NodeFlags[NodeFlags["IdentifierIsInJSDocNamespace"] = 2048] = "IdentifierIsInJSDocNamespace"; })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {})); var EtsFlags; (function (EtsFlags) { @@ -13201,6 +13204,15 @@ var ts; return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } ts.idText = idText; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node) { + var token = ts.stringToToken(node.escapedText); + return token ? ts.tryCast(token, ts.isKeyword) : undefined; + } + ts.identifierToKeywordKind = identifierToKeywordKind; function symbolName(symbol) { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -13605,14 +13617,18 @@ var ts; } ts.getJSDocReturnType = getJSDocReturnType; function getJSDocTagsWorker(node, noCache) { - var tags = node.jsDocCache; + var _a, _b; + if (!ts.canHaveJSDoc(node)) + return ts.emptyArray; + var tags = (_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. if (tags === undefined || noCache) { var comments = ts.getJSDocCommentsAndTags(node, noCache); ts.Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = ts.flatMap(comments, function (j) { return ts.isJSDoc(j) ? j.tags : j; }); if (!noCache) { - node.jsDocCache = tags; + (_b = node.jsDoc) !== null && _b !== void 0 ? _b : (node.jsDoc = []); + node.jsDoc.jsDocCache = tags; } } return tags; @@ -15980,6 +15996,13 @@ var ts; return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + /** @internal */ + function scanTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + ts.scanTokenAtPosition = scanTokenAtPosition; function getErrorSpanForArrowFunction(sourceFile, node) { var pos = ts.skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === 242 /* SyntaxKind.Block */) { @@ -17594,6 +17617,83 @@ var ts; ? node.body : undefined; } + /** @internal */ + function canHaveJSDoc(node) { + switch (node.kind) { + case 219 /* SyntaxKind.ArrowFunction */: + case 266 /* SyntaxKind.AnnotationDeclaration */: + case 172 /* SyntaxKind.AnnotationPropertyDeclaration */: + case 227 /* SyntaxKind.BinaryExpression */: + case 242 /* SyntaxKind.Block */: + case 253 /* SyntaxKind.BreakStatement */: + case 179 /* SyntaxKind.CallSignature */: + case 298 /* SyntaxKind.CaseClause */: + case 264 /* SyntaxKind.ClassDeclaration */: + case 232 /* SyntaxKind.ClassExpression */: + case 175 /* SyntaxKind.ClassStaticBlockDeclaration */: + case 176 /* SyntaxKind.Constructor */: + case 185 /* SyntaxKind.ConstructorType */: + case 180 /* SyntaxKind.ConstructSignature */: + case 252 /* SyntaxKind.ContinueStatement */: + case 260 /* SyntaxKind.DebuggerStatement */: + case 247 /* SyntaxKind.DoStatement */: + case 212 /* SyntaxKind.ElementAccessExpression */: + case 243 /* SyntaxKind.EmptyStatement */: + case 1 /* SyntaxKind.EndOfFileToken */: + case 269 /* SyntaxKind.EnumDeclaration */: + case 308 /* SyntaxKind.EnumMember */: + case 280 /* SyntaxKind.ExportAssignment */: + case 281 /* SyntaxKind.ExportDeclaration */: + case 284 /* SyntaxKind.ExportSpecifier */: + case 245 /* SyntaxKind.ExpressionStatement */: + case 250 /* SyntaxKind.ForInStatement */: + case 251 /* SyntaxKind.ForOfStatement */: + case 249 /* SyntaxKind.ForStatement */: + case 263 /* SyntaxKind.FunctionDeclaration */: + case 218 /* SyntaxKind.FunctionExpression */: + case 184 /* SyntaxKind.FunctionType */: + case 177 /* SyntaxKind.GetAccessor */: + case 79 /* SyntaxKind.Identifier */: + case 246 /* SyntaxKind.IfStatement */: + case 275 /* SyntaxKind.ImportDeclaration */: + case 274 /* SyntaxKind.ImportEqualsDeclaration */: + case 181 /* SyntaxKind.IndexSignature */: + case 267 /* SyntaxKind.InterfaceDeclaration */: + case 326 /* SyntaxKind.JSDocFunctionType */: + case 332 /* SyntaxKind.JSDocSignature */: + case 257 /* SyntaxKind.LabeledStatement */: + case 174 /* SyntaxKind.MethodDeclaration */: + case 173 /* SyntaxKind.MethodSignature */: + case 270 /* SyntaxKind.ModuleDeclaration */: + case 202 /* SyntaxKind.NamedTupleMember */: + case 273 /* SyntaxKind.NamespaceExportDeclaration */: + case 210 /* SyntaxKind.ObjectLiteralExpression */: + case 168 /* SyntaxKind.Parameter */: + case 217 /* SyntaxKind.ParenthesizedExpression */: + case 211 /* SyntaxKind.PropertyAccessExpression */: + case 305 /* SyntaxKind.PropertyAssignment */: + case 171 /* SyntaxKind.PropertyDeclaration */: + case 170 /* SyntaxKind.PropertySignature */: + case 254 /* SyntaxKind.ReturnStatement */: + case 241 /* SyntaxKind.SemicolonClassElement */: + case 178 /* SyntaxKind.SetAccessor */: + case 306 /* SyntaxKind.ShorthandPropertyAssignment */: + case 307 /* SyntaxKind.SpreadAssignment */: + case 256 /* SyntaxKind.SwitchStatement */: + case 258 /* SyntaxKind.ThrowStatement */: + case 259 /* SyntaxKind.TryStatement */: + case 268 /* SyntaxKind.TypeAliasDeclaration */: + case 167 /* SyntaxKind.TypeParameter */: + case 261 /* SyntaxKind.VariableDeclaration */: + case 244 /* SyntaxKind.VariableStatement */: + case 248 /* SyntaxKind.WhileStatement */: + case 255 /* SyntaxKind.WithStatement */: + return true; + default: + return false; + } + } + ts.canHaveJSDoc = canHaveJSDoc; function getJSDocCommentsAndTags(hostNode, noCache) { var result; // Pull parameter comments from declaring function as well @@ -18165,8 +18265,8 @@ var ts; return token !== undefined && isKeyword(token); } ts.isStringAKeyword = isStringAKeyword; - function isIdentifierANonContextualKeyword(_a) { - var originalKeywordKind = _a.originalKeywordKind; + function isIdentifierANonContextualKeyword(node) { + var originalKeywordKind = ts.identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } ts.isIdentifierANonContextualKeyword = isIdentifierANonContextualKeyword; @@ -19218,7 +19318,7 @@ var ts; } ts.isThisInTypeQuery = isThisInTypeQuery; function identifierIsThisKeyword(id) { - return id.originalKeywordKind === 109 /* SyntaxKind.ThisKeyword */; + return id.escapedText === "this"; } ts.identifierIsThisKeyword = identifierIsThisKeyword; function getAllAccessorDeclarations(declarations, accessor) { @@ -19642,7 +19742,7 @@ var ts; */ function getSyntacticModifierFlagsNoCache(node) { var flags = ts.canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0 /* ModifierFlags.None */; - if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.isInJSDocNamespace)) { + if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */)) { flags |= 1 /* ModifierFlags.Export */; } return flags; @@ -20575,7 +20675,6 @@ var ts; this.transformFlags = 0 /* TransformFlags.None */; this.parent = undefined; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(fileName, text, skipTrivia) { this.fileName = fileName; @@ -20594,8 +20693,19 @@ var ts; getSignatureConstructor: function () { return Signature; }, getSourceMapSourceConstructor: function () { return SourceMapSource; }, }; + var objectAllocatorPatchers = []; + /** + * Used by `deprecatedCompat` to patch the object allocator to apply deprecations. + * @internal + */ + function addObjectAllocatorPatcher(fn) { + objectAllocatorPatchers.push(fn); + fn(ts.objectAllocator); + } + ts.addObjectAllocatorPatcher = addObjectAllocatorPatcher; function setObjectAllocator(alloc) { Object.assign(ts.objectAllocator, alloc); + ts.forEach(objectAllocatorPatchers, function (fn) { return fn(ts.objectAllocator); }); } ts.setObjectAllocator = setObjectAllocator; function formatStringFromArgs(text, args, baseIndex) { @@ -23072,7 +23182,6 @@ var ts; createRegularExpressionLiteral: createRegularExpressionLiteral, createLiteralLikeNode: createLiteralLikeNode, createIdentifier: createIdentifier, - updateIdentifier: updateIdentifier, createTempVariable: createTempVariable, createLoopVariable: createLoopVariable, createUniqueName: createUniqueName, @@ -23764,20 +23873,13 @@ var ts; // // Identifiers // - function createBaseIdentifier(text, originalKeywordKind) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = ts.stringToToken(text); - } - if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text) { var node = baseFactory.createBaseIdentifierNode(79 /* SyntaxKind.Identifier */); - node.originalKeywordKind = originalKeywordKind; node.escapedText = ts.escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) { - var node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined); + var node = createBaseIdentifier(text); node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -23786,28 +23888,25 @@ var ts; return node; } // @api - function createIdentifier(text, typeArguments, originalKeywordKind, hasExtendedUnicodeEscape) { - var node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = ts.stringToToken(text); + } + if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { + originalKeywordKind = undefined; } - if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + var node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) + node.flags |= 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */; + if (node.escapedText === "await") { node.transformFlags |= 67108864 /* TransformFlags.ContainsPossibleTopLevelAwait */; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { node.transformFlags |= 1024 /* TransformFlags.ContainsES2015 */; } return node; } // @api - function updateIdentifier(node, typeArguments) { - return node.typeArguments !== typeArguments - ? update(createIdentifier(ts.idText(node), typeArguments), node) - : node; - } - // @api function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) { var flags = 1 /* GeneratedIdentifierFlags.Auto */; if (reservedInNestedScopes) @@ -29068,6 +29167,30 @@ var ts; return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.typeNode; } ts.getTypeNode = getTypeNode; + /** @internal */ + function setIdentifierTypeArguments(node, typeArguments) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + ts.setIdentifierTypeArguments = setIdentifierTypeArguments; + /** @internal */ + function getIdentifierTypeArguments(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.identifierTypeArguments; + } + ts.getIdentifierTypeArguments = getIdentifierTypeArguments; + /** @internal */ + function setIdentifierGeneratedImportReference(node, value) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + ts.setIdentifierGeneratedImportReference = setIdentifierGeneratedImportReference; + /** @internal */ + function getIdentifierGeneratedImportReference(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.generatedImportReference; + } + ts.getIdentifierGeneratedImportReference = getIdentifierGeneratedImportReference; })(ts || (ts = {})); /* @internal */ var ts; @@ -33958,7 +34081,7 @@ var ts; parseErrorAtCurrentToken(diagnosticMessage, arg0); } var pos = getNodePos(); - var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined) : + var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*originalKeywordKind*/ undefined) : ts.isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === 8 /* SyntaxKind.NumericLiteral */ ? factory.createNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === 10 /* SyntaxKind.StringLiteral */ ? factory.createStringLiteral("", /*isSingleQuote*/ undefined) : @@ -33985,7 +34108,7 @@ var ts; var text = internIdentifier(scanner.getTokenValue()); var hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === 80 /* SyntaxKind.PrivateIdentifier */) { parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage || ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); @@ -33998,7 +34121,7 @@ var ts; if (stateStylesRootNode && inEtsStateStylesContext() && token() === 24 /* SyntaxKind.DotToken */) { identifierCount++; var pos = getNodePos(); - return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } identifierCount++; // Only for end of file because the error gets reported incorrectly on embedded script tags. @@ -34392,6 +34515,7 @@ var ts; return parseElement(); } function currentNode(parsingContext, pos) { + var _a; // If we don't have a cursor or the parsing context isn't reusable, there's nothing to reuse. // // If there is an outstanding parse error that we've encountered, but not attached to @@ -34432,9 +34556,9 @@ var ts; if (!canReuseNode(node, parsingContext)) { return undefined; } - if (node.jsDocCache) { + if (ts.canHaveJSDoc(node) && ((_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache)) { // jsDocCache may include tags from parent nodes, which might have been modified. - node.jsDocCache = undefined; + node.jsDoc.jsDocCache = undefined; } return node; } @@ -34538,7 +34662,7 @@ var ts; // into an actual .ConstructorDeclaration. var methodDeclaration = node; var nameIsConstructor = methodDeclaration.name.kind === 79 /* SyntaxKind.Identifier */ && - methodDeclaration.name.originalKeywordKind === 136 /* SyntaxKind.ConstructorKeyword */; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } } @@ -34769,14 +34893,12 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var pos = getNodePos(); var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - var dotPos = getNodePos(); while (parseOptional(24 /* SyntaxKind.DotToken */)) { if (token() === 29 /* SyntaxKind.LessThanToken */) { - // the entity is part of a JSDoc-style generic, so record the trailing dot for later error reporting - entity.jsdocDotPos = dotPos; + // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and + // `typeArguments` to report it as a grammar error in the checker. break; } - dotPos = getNodePos(); entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos); } return entity; @@ -36897,13 +37019,13 @@ var ts; var pos = getNodePos(); var expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } else { expression = parsePrimaryExpression(); @@ -40366,7 +40488,7 @@ var ts; return finishNode(jsDocNamespaceNode, pos); } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + typeNameOrNamespaceName.flags |= 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */; } return typeNameOrNamespaceName; } @@ -40557,7 +40679,7 @@ var ts; var end = scanner.getTextPos(); var originalKeywordKind = token(); var text = internIdentifier(scanner.getTokenValue()); - var result = finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos, end); + var result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } @@ -48318,7 +48440,7 @@ var ts; case 79 /* SyntaxKind.Identifier */: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { return 0 /* ModuleInstanceState.NonInstantiated */; } } @@ -48888,6 +49010,7 @@ var ts; else if (containerFlags & 64 /* ContainerFlags.IsInterface */) { seenThisKeyword = false; bindChildren(node); + ts.Debug.assertNotNode(node, ts.isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier node.flags = seenThisKeyword ? node.flags | 128 /* NodeFlags.ContainsThis */ : node.flags & ~128 /* NodeFlags.ContainsThis */; } else { @@ -50275,12 +50398,13 @@ var ts; !(node.flags & 8388608 /* NodeFlags.JSDoc */) && !ts.isIdentifierName(node)) { // strict mode identifiers + var originalKeywordKind = ts.identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && - node.originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { + originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && + originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } - else if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + else if (originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { if (ts.isExternalModule(file) && ts.isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, ts.declarationNameToString(node))); } @@ -50288,7 +50412,7 @@ var ts; file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } - else if (node.originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { + else if (originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } @@ -50546,7 +50670,7 @@ var ts; // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { var parentNode = node.parent; while (parentNode && !ts.isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; @@ -57087,10 +57211,14 @@ var ts; var qualifier = root.qualifier; if (qualifier) { if (ts.isIdentifier(qualifier)) { - qualifier = ts.factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier)) { + qualifier = ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier.right)) { + qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -57107,10 +57235,14 @@ var ts; var typeArguments = root.typeArguments; var typeName = root.typeName; if (ts.isIdentifier(typeName)) { - typeName = ts.factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName)) { + typeName = ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName), typeArguments); + } } else { - typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName.right)) { + typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; // then move qualifiers @@ -57771,7 +57903,7 @@ var ts; if (!nonRootParts || ts.isEntityName(nonRootParts)) { if (nonRootParts) { var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); } return ts.factory.createImportTypeNode(lit, assertion, nonRootParts, typeParameterNodes, isTypeOf); } @@ -57790,8 +57922,8 @@ var ts; } else { var lastId = ts.isIdentifier(entityName) ? entityName : entityName.right; - var lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + var lastTypeArgs = ts.getIdentifierTypeArguments(lastId); + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); return ts.factory.createTypeReferenceNode(entityName, lastTypeArgs); } function createAccessFromSymbolChain(chain, index, stopper) { @@ -57840,7 +57972,9 @@ var ts; return ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode(LHS, typeParameterNodes), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(symbolName))); } } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { var LHS = createAccessFromSymbolChain(chain, index - 1, stopper); @@ -57883,7 +58017,9 @@ var ts; text = "".concat(rawtext, "_").concat(i); } if (text !== rawtext) { - result = ts.factory.createIdentifier(text, result.typeArguments); + var typeArguments = ts.getIdentifierTypeArguments(result); + result = ts.factory.createIdentifier(text); + ts.setIdentifierTypeArguments(result, typeArguments); } // avoiding iterations of the above loop turns out to be worth it when `i` starts to get large, so we cache the max // `i` we've used thus far, to save work later @@ -57911,7 +58047,9 @@ var ts; if (index === 0) { context.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */; } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57937,7 +58075,9 @@ var ts; symbolName.length > 1 && ts.isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : ts.isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57954,8 +58094,11 @@ var ts; expression = ts.factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); - expression.symbol = symbol; + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return ts.factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -72254,15 +72397,17 @@ var ts; break; case 168 /* SyntaxKind.Parameter */: var param = declaration; - if (ts.isIdentifier(param.name) && - (ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || - param.name.originalKeywordKind && ts.isTypeNodeKind(param.name.originalKeywordKind))) { - var newName = "arg" + param.parent.parameters.indexOf(param); - var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (ts.isIdentifier(param.name)) { + var originalKeywordKind = ts.identifierToKeywordKind(param.name); + if ((ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || + originalKeywordKind && ts.isTypeNodeKind(originalKeywordKind))) { + var newName = "arg" + param.parent.parameters.indexOf(param); + var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = declaration.dotDotDotToken ? noImplicitAny ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -86138,8 +86283,12 @@ var ts; } function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === 183 /* SyntaxKind.TypeReference */ && node.typeName.jsdocDotPos !== undefined && !ts.isInJSFile(node) && !ts.isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === 183 /* SyntaxKind.TypeReference */ && !ts.isInJSFile(node) && !ts.isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + // If there was a token between the type name and the type arguments, check if it was a DotToken + var sourceFile = ts.getSourceFileOfNode(node); + if (ts.scanTokenAtPosition(sourceFile, node.typeName.end) === 24 /* SyntaxKind.DotToken */) { + grammarErrorAtPos(node, ts.skipTrivia(sourceFile.text, node.typeName.end), 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } ts.forEach(node.typeArguments, checkSourceElement); var type = getTypeFromTypeReference(node); @@ -87349,7 +87498,8 @@ var ts; if (!ident) { return undefined; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -91369,7 +91519,8 @@ var ts; if (!ident) { return; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -92192,7 +92343,7 @@ var ts; } return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name, ignoreErrors) { + function getSymbolOfNameOrPropertyAccessExpression(name) { if (ts.isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -92271,11 +92422,11 @@ var ts; var symbol = getIntrinsicTagSymbol(name.parent); return symbol === unknownSymbol ? undefined : symbol; } - var result = resolveEntityName(name, meaning, /*ignoreErrors*/ ignoreErrors, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); + var result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); if (!result && isJSDoc_1) { var container = ts.findAncestor(name, ts.or(ts.isClassLike, ts.isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfNode(container)); } } if (result && isJSDoc_1) { @@ -92340,11 +92491,11 @@ var ts; } else if (isTypeReferenceIdentifier(name)) { var meaning = name.parent.kind === 183 /* SyntaxKind.TypeReference */ ? 788968 /* SymbolFlags.Type */ : 1920 /* SymbolFlags.Namespace */; - var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); + var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name); } if (name.parent.kind === 182 /* SyntaxKind.TypePredicate */) { - return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */); + return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */, /*ignoreErrors*/ true); } return undefined; } @@ -92510,7 +92661,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 306 /* SyntaxKind.ShorthandPropertyAssignment */) { - return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } return undefined; } @@ -92519,10 +92670,10 @@ var ts; if (ts.isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } else { - return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } } function getTypeOfNode(node) { @@ -92807,8 +92958,9 @@ var ts; // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(nodeIn) { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + var specifier = ts.getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier); if (node) { @@ -94938,7 +95090,7 @@ var ts; } function checkGrammarNameInLetOrConstDeclarations(name) { if (name.kind === 79 /* SyntaxKind.Identifier */) { - if (name.originalKeywordKind === 120 /* SyntaxKind.LetKeyword */) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } @@ -95672,9 +95824,6 @@ var ts; // NOTE: Before you can add a new method to `visitEachChildTable`, you must first ensure the `Node` subtype you // wish to add is defined in the `HasChildren` union in types.ts. var visitEachChildTable = (_a = {}, - _a[79 /* SyntaxKind.Identifier */] = function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, ts.isTypeNodeOrTypeParameterDeclaration)); - }, _a[165 /* SyntaxKind.QualifiedName */] = function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, ts.isEntityName), nodeVisitor(node.right, visitor, ts.isIdentifier)); }, @@ -104491,7 +104640,7 @@ var ts; } var generatedName = factory.createUniqueName("_".concat(name), 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */ | 64 /* GeneratedIdentifierFlags.AllowNameSubstitution */); var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + ts.setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } @@ -105616,7 +105765,7 @@ var ts; return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { return ts.setOriginalNode(ts.setTextRange(factory.createIdentifier(ts.unescapeLeadingUnderscores(node.escapedText)), node), node); } return node; @@ -108528,7 +108677,7 @@ var ts; * @param name An Identifier */ function trySubstituteReservedName(name) { - var token = name.originalKeywordKind || (ts.nodeIsSynthesized(name) ? ts.stringToToken(ts.idText(name)) : undefined); + var token = ts.identifierToKeywordKind(name); if (token !== undefined && token >= 81 /* SyntaxKind.FirstReservedWord */ && token <= 117 /* SyntaxKind.LastReservedWord */) { return ts.setTextRange(factory.createStringLiteralFromNode(name), name); } @@ -118671,7 +118820,7 @@ var ts; function emitIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol); - emitList(node, node.typeArguments, 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments + emitList(node, ts.getIdentifierTypeArguments(node), 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments } // // Names @@ -141037,8 +141186,11 @@ var ts; if (ts.isModifier(node)) { return node.kind; } - if (ts.isIdentifier(node) && node.originalKeywordKind && ts.isModifierKind(node.originalKeywordKind)) { - return node.originalKeywordKind; + if (ts.isIdentifier(node)) { + var originalKeywordKind = ts.identifierToKeywordKind(node); + if (originalKeywordKind && ts.isModifierKind(originalKeywordKind)) { + return originalKeywordKind; + } } return undefined; } @@ -143594,7 +143746,8 @@ var ts; || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); } function keywordForNode(node) { - return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* SyntaxKind.Unknown */ : node.kind; + var _a; + return ts.isIdentifier(node) ? (_a = ts.identifierToKeywordKind(node)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */ : node.kind; } function getContextualKeywords(contextToken, position) { var entries = []; @@ -143679,6 +143832,7 @@ var ts; * on the condition that one exists and that the context implies completion should be given. */ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position) { + var _a; // class c { method() { } | method2() { } } switch (location.kind) { case 357 /* SyntaxKind.SyntaxList */: @@ -143690,8 +143844,8 @@ var ts; } break; case 79 /* SyntaxKind.Identifier */: { - var originalKeywordKind = location.originalKeywordKind; - if (originalKeywordKind && ts.isKeyword(originalKeywordKind)) { + var originalKeywordKind = ts.identifierToKeywordKind(location); + if (originalKeywordKind) { return undefined; } // class c { public prop = c| } @@ -143733,7 +143887,7 @@ var ts; return undefined; } var isValidKeyword = ts.isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword; - return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword(ts.stringToToken(contextToken.text))) // TODO: GH#18217 + return (isValidKeyword(contextToken.kind) || contextToken.kind === 41 /* SyntaxKind.AsteriskToken */ || ts.isIdentifier(contextToken) && isValidKeyword((_a = ts.identifierToKeywordKind(contextToken)) !== null && _a !== void 0 ? _a : 0 /* SyntaxKind.Unknown */)) ? contextToken.parent.parent : undefined; } } @@ -146789,8 +146943,8 @@ var ts; } // For `export { foo as bar }`, rename `foo`, but not `bar`. if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) { - var isDefaultExport = referenceLocation.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ - || exportSpecifier.name.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */; + var isDefaultExport = referenceLocation.escapedText === "default" + || exportSpecifier.name.escapedText === "default"; var exportKind = isDefaultExport ? 1 /* ExportKind.Default */ : 0 /* ExportKind.Named */; var exportSymbol = ts.Debug.checkDefined(exportSpecifier.symbol); var exportInfo = FindAllReferences.getExportInfo(exportSymbol, exportKind, state.checker); @@ -151899,7 +152053,7 @@ var ts; return getRenameInfoError(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library); } // Cannot rename `default` as in `import { default as foo } from "./someModule"; - if (ts.isIdentifier(node) && node.originalKeywordKind === 89 /* SyntaxKind.DefaultKeyword */ && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { + if (ts.isIdentifier(node) && node.escapedText === "default" && symbol.parent && symbol.parent.flags & 1536 /* SymbolFlags.Module */) { return undefined; } if (ts.isStringLiteralLike(node) && ts.tryGetImportFromModuleSpecifier(node)) { @@ -158301,7 +158455,6 @@ var ts; parent.parent : parent.parent.parent; jsDocNode.jsDoc = parent.jsDoc; - jsDocNode.jsDocCache = parent.jsDocCache; return jsDocNode; } function tryMergeJsdocTags(oldTag, newTag) { @@ -160956,8 +161109,8 @@ var ts; function collectExportRenames(sourceFile, checker, identifiers) { var res = new ts.Map(); forEachExportReference(sourceFile, function (node) { - var _a = node.name, text = _a.text, originalKeywordKind = _a.originalKeywordKind; - if (!res.has(text) && (originalKeywordKind !== undefined && ts.isNonContextualKeyword(originalKeywordKind) + var text = node.name.text; + if (!res.has(text) && (ts.isIdentifierANonContextualKeyword(node.name) || checker.resolveName(text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ true))) { // Unconditionally add an underscore in case `text` is a keyword. res.set(text, makeUniqueName("_".concat(text), identifiers)); @@ -170192,7 +170345,7 @@ var ts; var checker = context.program.getTypeChecker(); // Make a unique name for the extracted variable var file = scope.getSourceFile(); - var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.isKeyword(node.name.originalKeywordKind) + var localNameText = ts.isPropertyAccessExpression(node) && !ts.isClassLike(scope) && !checker.resolveName(node.name.text, node, 111551 /* SymbolFlags.Value */, /*excludeGlobals*/ false) && !ts.isPrivateIdentifier(node.name) && !ts.identifierToKeywordKind(node.name) ? node.name.text : ts.getUniqueName(ts.isClassLike(scope) ? "newProperty" : "newLocal", file); var isJS = ts.isInJSFile(scope); @@ -177840,7 +177993,7 @@ var ts; }, factoryDeprecation); /** @deprecated Use `factory.createIdentifier` or the factory supplied by your transformation context instead. */ ts.createIdentifier = ts.Debug.deprecate(function createIdentifier(text) { - return ts.factory.createIdentifier(text, /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined); + return ts.factory.createIdentifier(text, /*originalKeywordKind*/ undefined); }, factoryDeprecation); /** @deprecated Use `factory.createTempVariable` or the factory supplied by your transformation context instead. */ ts.createTempVariable = ts.Debug.deprecate(function createTempVariable(recordTempVariable) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 0f22525e48..64f3f431c6 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -4799,6 +4799,9 @@ var ts; // never cleared on SourceFiles which get re-used in between incremental parses. // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`. /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags"; + // The following flags repurpose other NodeFlags as different meanings for Identifier nodes + /** @internal */ NodeFlags[NodeFlags["IdentifierHasExtendedUnicodeEscape"] = 128] = "IdentifierHasExtendedUnicodeEscape"; + /** @internal */ NodeFlags[NodeFlags["IdentifierIsInJSDocNamespace"] = 2048] = "IdentifierIsInJSDocNamespace"; })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {})); var EtsFlags; (function (EtsFlags) { @@ -13191,6 +13194,15 @@ var ts; return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } ts.idText = idText; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node) { + var token = ts.stringToToken(node.escapedText); + return token ? ts.tryCast(token, ts.isKeyword) : undefined; + } + ts.identifierToKeywordKind = identifierToKeywordKind; function symbolName(symbol) { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -13595,14 +13607,18 @@ var ts; } ts.getJSDocReturnType = getJSDocReturnType; function getJSDocTagsWorker(node, noCache) { - var tags = node.jsDocCache; + var _a, _b; + if (!ts.canHaveJSDoc(node)) + return ts.emptyArray; + var tags = (_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. if (tags === undefined || noCache) { var comments = ts.getJSDocCommentsAndTags(node, noCache); ts.Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = ts.flatMap(comments, function (j) { return ts.isJSDoc(j) ? j.tags : j; }); if (!noCache) { - node.jsDocCache = tags; + (_b = node.jsDoc) !== null && _b !== void 0 ? _b : (node.jsDoc = []); + node.jsDoc.jsDocCache = tags; } } return tags; @@ -15970,6 +15986,13 @@ var ts; return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + /** @internal */ + function scanTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + ts.scanTokenAtPosition = scanTokenAtPosition; function getErrorSpanForArrowFunction(sourceFile, node) { var pos = ts.skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === 242 /* SyntaxKind.Block */) { @@ -17584,6 +17607,83 @@ var ts; ? node.body : undefined; } + /** @internal */ + function canHaveJSDoc(node) { + switch (node.kind) { + case 219 /* SyntaxKind.ArrowFunction */: + case 266 /* SyntaxKind.AnnotationDeclaration */: + case 172 /* SyntaxKind.AnnotationPropertyDeclaration */: + case 227 /* SyntaxKind.BinaryExpression */: + case 242 /* SyntaxKind.Block */: + case 253 /* SyntaxKind.BreakStatement */: + case 179 /* SyntaxKind.CallSignature */: + case 298 /* SyntaxKind.CaseClause */: + case 264 /* SyntaxKind.ClassDeclaration */: + case 232 /* SyntaxKind.ClassExpression */: + case 175 /* SyntaxKind.ClassStaticBlockDeclaration */: + case 176 /* SyntaxKind.Constructor */: + case 185 /* SyntaxKind.ConstructorType */: + case 180 /* SyntaxKind.ConstructSignature */: + case 252 /* SyntaxKind.ContinueStatement */: + case 260 /* SyntaxKind.DebuggerStatement */: + case 247 /* SyntaxKind.DoStatement */: + case 212 /* SyntaxKind.ElementAccessExpression */: + case 243 /* SyntaxKind.EmptyStatement */: + case 1 /* SyntaxKind.EndOfFileToken */: + case 269 /* SyntaxKind.EnumDeclaration */: + case 308 /* SyntaxKind.EnumMember */: + case 280 /* SyntaxKind.ExportAssignment */: + case 281 /* SyntaxKind.ExportDeclaration */: + case 284 /* SyntaxKind.ExportSpecifier */: + case 245 /* SyntaxKind.ExpressionStatement */: + case 250 /* SyntaxKind.ForInStatement */: + case 251 /* SyntaxKind.ForOfStatement */: + case 249 /* SyntaxKind.ForStatement */: + case 263 /* SyntaxKind.FunctionDeclaration */: + case 218 /* SyntaxKind.FunctionExpression */: + case 184 /* SyntaxKind.FunctionType */: + case 177 /* SyntaxKind.GetAccessor */: + case 79 /* SyntaxKind.Identifier */: + case 246 /* SyntaxKind.IfStatement */: + case 275 /* SyntaxKind.ImportDeclaration */: + case 274 /* SyntaxKind.ImportEqualsDeclaration */: + case 181 /* SyntaxKind.IndexSignature */: + case 267 /* SyntaxKind.InterfaceDeclaration */: + case 326 /* SyntaxKind.JSDocFunctionType */: + case 332 /* SyntaxKind.JSDocSignature */: + case 257 /* SyntaxKind.LabeledStatement */: + case 174 /* SyntaxKind.MethodDeclaration */: + case 173 /* SyntaxKind.MethodSignature */: + case 270 /* SyntaxKind.ModuleDeclaration */: + case 202 /* SyntaxKind.NamedTupleMember */: + case 273 /* SyntaxKind.NamespaceExportDeclaration */: + case 210 /* SyntaxKind.ObjectLiteralExpression */: + case 168 /* SyntaxKind.Parameter */: + case 217 /* SyntaxKind.ParenthesizedExpression */: + case 211 /* SyntaxKind.PropertyAccessExpression */: + case 305 /* SyntaxKind.PropertyAssignment */: + case 171 /* SyntaxKind.PropertyDeclaration */: + case 170 /* SyntaxKind.PropertySignature */: + case 254 /* SyntaxKind.ReturnStatement */: + case 241 /* SyntaxKind.SemicolonClassElement */: + case 178 /* SyntaxKind.SetAccessor */: + case 306 /* SyntaxKind.ShorthandPropertyAssignment */: + case 307 /* SyntaxKind.SpreadAssignment */: + case 256 /* SyntaxKind.SwitchStatement */: + case 258 /* SyntaxKind.ThrowStatement */: + case 259 /* SyntaxKind.TryStatement */: + case 268 /* SyntaxKind.TypeAliasDeclaration */: + case 167 /* SyntaxKind.TypeParameter */: + case 261 /* SyntaxKind.VariableDeclaration */: + case 244 /* SyntaxKind.VariableStatement */: + case 248 /* SyntaxKind.WhileStatement */: + case 255 /* SyntaxKind.WithStatement */: + return true; + default: + return false; + } + } + ts.canHaveJSDoc = canHaveJSDoc; function getJSDocCommentsAndTags(hostNode, noCache) { var result; // Pull parameter comments from declaring function as well @@ -18155,8 +18255,8 @@ var ts; return token !== undefined && isKeyword(token); } ts.isStringAKeyword = isStringAKeyword; - function isIdentifierANonContextualKeyword(_a) { - var originalKeywordKind = _a.originalKeywordKind; + function isIdentifierANonContextualKeyword(node) { + var originalKeywordKind = ts.identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } ts.isIdentifierANonContextualKeyword = isIdentifierANonContextualKeyword; @@ -19208,7 +19308,7 @@ var ts; } ts.isThisInTypeQuery = isThisInTypeQuery; function identifierIsThisKeyword(id) { - return id.originalKeywordKind === 109 /* SyntaxKind.ThisKeyword */; + return id.escapedText === "this"; } ts.identifierIsThisKeyword = identifierIsThisKeyword; function getAllAccessorDeclarations(declarations, accessor) { @@ -19632,7 +19732,7 @@ var ts; */ function getSyntacticModifierFlagsNoCache(node) { var flags = ts.canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0 /* ModifierFlags.None */; - if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.isInJSDocNamespace)) { + if (node.flags & 4 /* NodeFlags.NestedNamespace */ || (node.kind === 79 /* SyntaxKind.Identifier */ && node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */)) { flags |= 1 /* ModifierFlags.Export */; } return flags; @@ -20565,7 +20665,6 @@ var ts; this.transformFlags = 0 /* TransformFlags.None */; this.parent = undefined; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(fileName, text, skipTrivia) { this.fileName = fileName; @@ -20584,8 +20683,19 @@ var ts; getSignatureConstructor: function () { return Signature; }, getSourceMapSourceConstructor: function () { return SourceMapSource; }, }; + var objectAllocatorPatchers = []; + /** + * Used by `deprecatedCompat` to patch the object allocator to apply deprecations. + * @internal + */ + function addObjectAllocatorPatcher(fn) { + objectAllocatorPatchers.push(fn); + fn(ts.objectAllocator); + } + ts.addObjectAllocatorPatcher = addObjectAllocatorPatcher; function setObjectAllocator(alloc) { Object.assign(ts.objectAllocator, alloc); + ts.forEach(objectAllocatorPatchers, function (fn) { return fn(ts.objectAllocator); }); } ts.setObjectAllocator = setObjectAllocator; function formatStringFromArgs(text, args, baseIndex) { @@ -23062,7 +23172,6 @@ var ts; createRegularExpressionLiteral: createRegularExpressionLiteral, createLiteralLikeNode: createLiteralLikeNode, createIdentifier: createIdentifier, - updateIdentifier: updateIdentifier, createTempVariable: createTempVariable, createLoopVariable: createLoopVariable, createUniqueName: createUniqueName, @@ -23754,20 +23863,13 @@ var ts; // // Identifiers // - function createBaseIdentifier(text, originalKeywordKind) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = ts.stringToToken(text); - } - if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text) { var node = baseFactory.createBaseIdentifierNode(79 /* SyntaxKind.Identifier */); - node.originalKeywordKind = originalKeywordKind; node.escapedText = ts.escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) { - var node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined); + var node = createBaseIdentifier(text); node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -23776,28 +23878,25 @@ var ts; return node; } // @api - function createIdentifier(text, typeArguments, originalKeywordKind, hasExtendedUnicodeEscape) { - var node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = ts.stringToToken(text); + } + if (originalKeywordKind === 79 /* SyntaxKind.Identifier */) { + originalKeywordKind = undefined; } - if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + var node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) + node.flags |= 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */; + if (node.escapedText === "await") { node.transformFlags |= 67108864 /* TransformFlags.ContainsPossibleTopLevelAwait */; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { node.transformFlags |= 1024 /* TransformFlags.ContainsES2015 */; } return node; } // @api - function updateIdentifier(node, typeArguments) { - return node.typeArguments !== typeArguments - ? update(createIdentifier(ts.idText(node), typeArguments), node) - : node; - } - // @api function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) { var flags = 1 /* GeneratedIdentifierFlags.Auto */; if (reservedInNestedScopes) @@ -29058,6 +29157,30 @@ var ts; return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.typeNode; } ts.getTypeNode = getTypeNode; + /** @internal */ + function setIdentifierTypeArguments(node, typeArguments) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + ts.setIdentifierTypeArguments = setIdentifierTypeArguments; + /** @internal */ + function getIdentifierTypeArguments(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.identifierTypeArguments; + } + ts.getIdentifierTypeArguments = getIdentifierTypeArguments; + /** @internal */ + function setIdentifierGeneratedImportReference(node, value) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + ts.setIdentifierGeneratedImportReference = setIdentifierGeneratedImportReference; + /** @internal */ + function getIdentifierGeneratedImportReference(node) { + var _a; + return (_a = node.emitNode) === null || _a === void 0 ? void 0 : _a.generatedImportReference; + } + ts.getIdentifierGeneratedImportReference = getIdentifierGeneratedImportReference; })(ts || (ts = {})); /* @internal */ var ts; @@ -33948,7 +34071,7 @@ var ts; parseErrorAtCurrentToken(diagnosticMessage, arg0); } var pos = getNodePos(); - var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined) : + var result = kind === 79 /* SyntaxKind.Identifier */ ? factory.createIdentifier("", /*originalKeywordKind*/ undefined) : ts.isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === 8 /* SyntaxKind.NumericLiteral */ ? factory.createNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === 10 /* SyntaxKind.StringLiteral */ ? factory.createStringLiteral("", /*isSingleQuote*/ undefined) : @@ -33975,7 +34098,7 @@ var ts; var text = internIdentifier(scanner.getTokenValue()); var hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === 80 /* SyntaxKind.PrivateIdentifier */) { parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage || ts.Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); @@ -33988,7 +34111,7 @@ var ts; if (stateStylesRootNode && inEtsStateStylesContext() && token() === 24 /* SyntaxKind.DotToken */) { identifierCount++; var pos = getNodePos(); - return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + return finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } identifierCount++; // Only for end of file because the error gets reported incorrectly on embedded script tags. @@ -34382,6 +34505,7 @@ var ts; return parseElement(); } function currentNode(parsingContext, pos) { + var _a; // If we don't have a cursor or the parsing context isn't reusable, there's nothing to reuse. // // If there is an outstanding parse error that we've encountered, but not attached to @@ -34422,9 +34546,9 @@ var ts; if (!canReuseNode(node, parsingContext)) { return undefined; } - if (node.jsDocCache) { + if (ts.canHaveJSDoc(node) && ((_a = node.jsDoc) === null || _a === void 0 ? void 0 : _a.jsDocCache)) { // jsDocCache may include tags from parent nodes, which might have been modified. - node.jsDocCache = undefined; + node.jsDoc.jsDocCache = undefined; } return node; } @@ -34528,7 +34652,7 @@ var ts; // into an actual .ConstructorDeclaration. var methodDeclaration = node; var nameIsConstructor = methodDeclaration.name.kind === 79 /* SyntaxKind.Identifier */ && - methodDeclaration.name.originalKeywordKind === 136 /* SyntaxKind.ConstructorKeyword */; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } } @@ -34759,14 +34883,12 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var pos = getNodePos(); var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - var dotPos = getNodePos(); while (parseOptional(24 /* SyntaxKind.DotToken */)) { if (token() === 29 /* SyntaxKind.LessThanToken */) { - // the entity is part of a JSDoc-style generic, so record the trailing dot for later error reporting - entity.jsdocDotPos = dotPos; + // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and + // `typeArguments` to report it as a grammar error in the checker. break; } - dotPos = getNodePos(); entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos); } return entity; @@ -36887,13 +37009,13 @@ var ts; var pos = getNodePos(); var expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, 79 /* SyntaxKind.Identifier */), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === 24 /* SyntaxKind.DotToken */) { - expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), /*typeArguments*/ undefined, 79 /* SyntaxKind.Identifier */), pos, pos); + expression = finishVirtualNode(factory.createIdentifier("".concat(stateStylesRootNode, "Instance"), 79 /* SyntaxKind.Identifier */), pos, pos); } else { expression = parsePrimaryExpression(); @@ -40356,7 +40478,7 @@ var ts; return finishNode(jsDocNamespaceNode, pos); } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + typeNameOrNamespaceName.flags |= 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */; } return typeNameOrNamespaceName; } @@ -40547,7 +40669,7 @@ var ts; var end = scanner.getTextPos(); var originalKeywordKind = token(); var text = internIdentifier(scanner.getTokenValue()); - var result = finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos, end); + var result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } @@ -48308,7 +48430,7 @@ var ts; case 79 /* SyntaxKind.Identifier */: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { return 0 /* ModuleInstanceState.NonInstantiated */; } } @@ -48878,6 +49000,7 @@ var ts; else if (containerFlags & 64 /* ContainerFlags.IsInterface */) { seenThisKeyword = false; bindChildren(node); + ts.Debug.assertNotNode(node, ts.isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier node.flags = seenThisKeyword ? node.flags | 128 /* NodeFlags.ContainsThis */ : node.flags & ~128 /* NodeFlags.ContainsThis */; } else { @@ -50265,12 +50388,13 @@ var ts; !(node.flags & 8388608 /* NodeFlags.JSDoc */) && !ts.isIdentifierName(node)) { // strict mode identifiers + var originalKeywordKind = ts.identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && - node.originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { + originalKeywordKind >= 118 /* SyntaxKind.FirstFutureReservedWord */ && + originalKeywordKind <= 126 /* SyntaxKind.LastFutureReservedWord */) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } - else if (node.originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { + else if (originalKeywordKind === 134 /* SyntaxKind.AwaitKeyword */) { if (ts.isExternalModule(file) && ts.isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, ts.declarationNameToString(node))); } @@ -50278,7 +50402,7 @@ var ts; file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } - else if (node.originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { + else if (originalKeywordKind === 126 /* SyntaxKind.YieldKeyword */ && node.flags & 8192 /* NodeFlags.YieldContext */) { file.bindDiagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, ts.declarationNameToString(node))); } } @@ -50536,7 +50660,7 @@ var ts; // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. - if (node.isInJSDocNamespace) { + if (node.flags & 2048 /* NodeFlags.IdentifierIsInJSDocNamespace */) { var parentNode = node.parent; while (parentNode && !ts.isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; @@ -57077,10 +57201,14 @@ var ts; var qualifier = root.qualifier; if (qualifier) { if (ts.isIdentifier(qualifier)) { - qualifier = ts.factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier)) { + qualifier = ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(qualifier.right)) { + qualifier = ts.factory.updateQualifiedName(qualifier, qualifier.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -57097,10 +57225,14 @@ var ts; var typeArguments = root.typeArguments; var typeName = root.typeName; if (ts.isIdentifier(typeName)) { - typeName = ts.factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName)) { + typeName = ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName), typeArguments); + } } else { - typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== ts.getIdentifierTypeArguments(typeName.right)) { + typeName = ts.factory.updateQualifiedName(typeName, typeName.left, ts.setIdentifierTypeArguments(ts.factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; // then move qualifiers @@ -57761,7 +57893,7 @@ var ts; if (!nonRootParts || ts.isEntityName(nonRootParts)) { if (nonRootParts) { var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); } return ts.factory.createImportTypeNode(lit, assertion, nonRootParts, typeParameterNodes, isTypeOf); } @@ -57780,8 +57912,8 @@ var ts; } else { var lastId = ts.isIdentifier(entityName) ? entityName : entityName.right; - var lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + var lastTypeArgs = ts.getIdentifierTypeArguments(lastId); + ts.setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); return ts.factory.createTypeReferenceNode(entityName, lastTypeArgs); } function createAccessFromSymbolChain(chain, index, stopper) { @@ -57830,7 +57962,9 @@ var ts; return ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode(LHS, typeParameterNodes), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(symbolName))); } } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { var LHS = createAccessFromSymbolChain(chain, index - 1, stopper); @@ -57873,7 +58007,9 @@ var ts; text = "".concat(rawtext, "_").concat(i); } if (text !== rawtext) { - result = ts.factory.createIdentifier(text, result.typeArguments); + var typeArguments = ts.getIdentifierTypeArguments(result); + result = ts.factory.createIdentifier(text); + ts.setIdentifierTypeArguments(result, typeArguments); } // avoiding iterations of the above loop turns out to be worth it when `i` starts to get large, so we cache the max // `i` we've used thus far, to save work later @@ -57901,7 +58037,9 @@ var ts; if (index === 0) { context.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */; } - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57927,7 +58065,9 @@ var ts; symbolName.length > 1 && ts.isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : ts.isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? ts.factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; } @@ -57944,8 +58084,11 @@ var ts; expression = ts.factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = ts.setEmitFlags(ts.factory.createIdentifier(symbolName, typeParameterNodes), 16777216 /* EmitFlags.NoAsciiEscaping */); - expression.symbol = symbol; + var identifier = ts.setEmitFlags(ts.factory.createIdentifier(symbolName), 16777216 /* EmitFlags.NoAsciiEscaping */); + if (typeParameterNodes) + ts.setIdentifierTypeArguments(identifier, ts.factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return ts.factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -72244,15 +72387,17 @@ var ts; break; case 168 /* SyntaxKind.Parameter */: var param = declaration; - if (ts.isIdentifier(param.name) && - (ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || - param.name.originalKeywordKind && ts.isTypeNodeKind(param.name.originalKeywordKind))) { - var newName = "arg" + param.parent.parameters.indexOf(param); - var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (ts.isIdentifier(param.name)) { + var originalKeywordKind = ts.identifierToKeywordKind(param.name); + if ((ts.isCallSignatureDeclaration(param.parent) || ts.isMethodSignature(param.parent) || ts.isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, 788968 /* SymbolFlags.Type */, undefined, param.name.escapedText, /*isUse*/ true) || + originalKeywordKind && ts.isTypeNodeKind(originalKeywordKind))) { + var newName = "arg" + param.parent.parameters.indexOf(param); + var typeName = ts.declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = declaration.dotDotDotToken ? noImplicitAny ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -86128,8 +86273,12 @@ var ts; } function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === 183 /* SyntaxKind.TypeReference */ && node.typeName.jsdocDotPos !== undefined && !ts.isInJSFile(node) && !ts.isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === 183 /* SyntaxKind.TypeReference */ && !ts.isInJSFile(node) && !ts.isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + // If there was a token between the type name and the type arguments, check if it was a DotToken + var sourceFile = ts.getSourceFileOfNode(node); + if (ts.scanTokenAtPosition(sourceFile, node.typeName.end) === 24 /* SyntaxKind.DotToken */) { + grammarErrorAtPos(node, ts.skipTrivia(sourceFile.text, node.typeName.end), 1, ts.Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } ts.forEach(node.typeArguments, checkSourceElement); var type = getTypeFromTypeReference(node); @@ -87339,7 +87488,8 @@ var ts; if (!ident) { return undefined; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -91359,7 +91509,8 @@ var ts; if (!ident) { return; } - var symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + var symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -92182,7 +92333,7 @@ var ts; } return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name, ignoreErrors) { + function getSymbolOfNameOrPropertyAccessExpression(name) { if (ts.isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -92261,11 +92412,11 @@ var ts; var symbol = getIntrinsicTagSymbol(name.parent); return symbol === unknownSymbol ? undefined : symbol; } - var result = resolveEntityName(name, meaning, /*ignoreErrors*/ ignoreErrors, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); + var result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, ts.getHostSignatureFromJSDoc(name)); if (!result && isJSDoc_1) { var container = ts.findAncestor(name, ts.or(ts.isClassLike, ts.isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfNode(container)); } } if (result && isJSDoc_1) { @@ -92330,11 +92481,11 @@ var ts; } else if (isTypeReferenceIdentifier(name)) { var meaning = name.parent.kind === 183 /* SyntaxKind.TypeReference */ ? 788968 /* SymbolFlags.Type */ : 1920 /* SymbolFlags.Namespace */; - var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); + var symbol = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name); } if (name.parent.kind === 182 /* SyntaxKind.TypePredicate */) { - return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */); + return resolveEntityName(name, /*meaning*/ 1 /* SymbolFlags.FunctionScopedVariable */, /*ignoreErrors*/ true); } return undefined; } @@ -92500,7 +92651,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 306 /* SyntaxKind.ShorthandPropertyAssignment */) { - return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(location.name, 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } return undefined; } @@ -92509,10 +92660,10 @@ var ts; if (ts.isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + resolveEntityName(node.propertyName || node.name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } else { - return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */); + return resolveEntityName(node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, /*ignoreErrors*/ true); } } function getTypeOfNode(node) { @@ -92797,8 +92948,9 @@ var ts; // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(nodeIn) { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + var specifier = ts.getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } var node = ts.getParseTreeNode(nodeIn, ts.isIdentifier); if (node) { @@ -94928,7 +95080,7 @@ var ts; } function checkGrammarNameInLetOrConstDeclarations(name) { if (name.kind === 79 /* SyntaxKind.Identifier */) { - if (name.originalKeywordKind === 120 /* SyntaxKind.LetKeyword */) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } @@ -95662,9 +95814,6 @@ var ts; // NOTE: Before you can add a new method to `visitEachChildTable`, you must first ensure the `Node` subtype you // wish to add is defined in the `HasChildren` union in types.ts. var visitEachChildTable = (_a = {}, - _a[79 /* SyntaxKind.Identifier */] = function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, ts.isTypeNodeOrTypeParameterDeclaration)); - }, _a[165 /* SyntaxKind.QualifiedName */] = function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, ts.isEntityName), nodeVisitor(node.right, visitor, ts.isIdentifier)); }, @@ -104481,7 +104630,7 @@ var ts; } var generatedName = factory.createUniqueName("_".concat(name), 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */ | 64 /* GeneratedIdentifierFlags.AllowNameSubstitution */); var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + ts.setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } @@ -105606,7 +105755,7 @@ var ts; return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & 128 /* NodeFlags.IdentifierHasExtendedUnicodeEscape */) { return ts.setOriginalNode(ts.setTextRange(factory.createIdentifier(ts.unescapeLeadingUnderscores(node.escapedText)), node), node); } return node; @@ -108518,7 +108667,7 @@ var ts; * @param name An Identifier */ function trySubstituteReservedName(name) { - var token = name.originalKeywordKind || (ts.nodeIsSynthesized(name) ? ts.stringToToken(ts.idText(name)) : undefined); + var token = ts.identifierToKeywordKind(name); if (token !== undefined && token >= 81 /* SyntaxKind.FirstReservedWord */ && token <= 117 /* SyntaxKind.LastReservedWord */) { return ts.setTextRange(factory.createStringLiteralFromNode(name), name); } @@ -118661,7 +118810,7 @@ var ts; function emitIdentifier(node) { var writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol); - emitList(node, node.typeArguments, 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments + emitList(node, ts.getIdentifierTypeArguments(node), 53776 /* ListFormat.TypeParameters */); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments } // // Names diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 3730bedc96..7bff1d67f3 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -100,7 +100,7 @@ namespace ts { case SyntaxKind.Identifier: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias - if ((node as Identifier).isInJSDocNamespace) { + if (node.flags & NodeFlags.IdentifierIsInJSDocNamespace) { return ModuleInstanceState.NonInstantiated; } } @@ -717,6 +717,7 @@ namespace ts { else if (containerFlags & ContainerFlags.IsInterface) { seenThisKeyword = false; bindChildren(node); + Debug.assertNotNode(node, isIdentifier); // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier node.flags = seenThisKeyword ? node.flags | NodeFlags.ContainsThis : node.flags & ~NodeFlags.ContainsThis; } else { @@ -2223,13 +2224,14 @@ namespace ts { !isIdentifierName(node)) { // strict mode identifiers + const originalKeywordKind = identifierToKeywordKind(node); if (inStrictMode && - node.originalKeywordKind! >= SyntaxKind.FirstFutureReservedWord && - node.originalKeywordKind! <= SyntaxKind.LastFutureReservedWord) { + originalKeywordKind! >= SyntaxKind.FirstFutureReservedWord && + originalKeywordKind! <= SyntaxKind.LastFutureReservedWord) { file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), declarationNameToString(node))); } - else if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) { + else if (originalKeywordKind === SyntaxKind.AwaitKeyword) { if (isExternalModule(file) && isInTopLevelContext(node)) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, @@ -2241,7 +2243,7 @@ namespace ts { declarationNameToString(node))); } } - else if (node.originalKeywordKind === SyntaxKind.YieldKeyword && node.flags & NodeFlags.YieldContext) { + else if (originalKeywordKind === SyntaxKind.YieldKeyword && node.flags & NodeFlags.YieldContext) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, declarationNameToString(node))); @@ -2534,7 +2536,7 @@ namespace ts { // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. - if ((node as Identifier).isInJSDocNamespace) { + if (node.flags & NodeFlags.IdentifierIsInJSDocNamespace) { let parentNode = node.parent; while (parentNode && !isJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0338d9ef18..b51c7dc4e5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5890,12 +5890,16 @@ namespace ts { let qualifier = root.qualifier; if (qualifier) { if (isIdentifier(qualifier)) { - qualifier = factory.updateIdentifier(qualifier, typeArguments); + if (typeArguments !== getIdentifierTypeArguments(qualifier)) { + qualifier = setIdentifierTypeArguments(factory.cloneNode(qualifier), typeArguments); + } } else { - qualifier = factory.updateQualifiedName(qualifier, - qualifier.left, - factory.updateIdentifier(qualifier.right, typeArguments)); + if (typeArguments !== getIdentifierTypeArguments(qualifier.right)) { + qualifier = factory.updateQualifiedName(qualifier, + qualifier.left, + setIdentifierTypeArguments(factory.cloneNode(qualifier.right), typeArguments)); + } } } typeArguments = ref.typeArguments; @@ -5917,12 +5921,16 @@ namespace ts { let typeArguments = root.typeArguments; let typeName = root.typeName; if (isIdentifier(typeName)) { - typeName = factory.updateIdentifier(typeName, typeArguments); + if (typeArguments !== getIdentifierTypeArguments(typeName)) { + typeName = setIdentifierTypeArguments(factory.cloneNode(typeName), typeArguments); + } } else { - typeName = factory.updateQualifiedName(typeName, - typeName.left, - factory.updateIdentifier(typeName.right, typeArguments)); + if (typeArguments !== getIdentifierTypeArguments(typeName.right)) { + typeName = factory.updateQualifiedName(typeName, + typeName.left, + setIdentifierTypeArguments(factory.cloneNode(typeName.right), typeArguments)); + } } typeArguments = ref.typeArguments; // then move qualifiers @@ -6656,7 +6664,7 @@ namespace ts { if (!nonRootParts || isEntityName(nonRootParts)) { if (nonRootParts) { const lastId = isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right; - lastId.typeArguments = undefined; + setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); } return factory.createImportTypeNode(lit, assertion, nonRootParts as EntityName, typeParameterNodes as readonly TypeNode[], isTypeOf); } @@ -6676,8 +6684,8 @@ namespace ts { } else { const lastId = isIdentifier(entityName) ? entityName : entityName.right; - const lastTypeArgs = lastId.typeArguments; - lastId.typeArguments = undefined; + const lastTypeArgs = getIdentifierTypeArguments(lastId); + setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined); return factory.createTypeReferenceNode(entityName, lastTypeArgs as NodeArray); } @@ -6731,7 +6739,8 @@ namespace ts { } } - const identifier = setEmitFlags(factory.createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping); + const identifier = setEmitFlags(factory.createIdentifier(symbolName), EmitFlags.NoAsciiEscaping); + if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; if (index > stopper) { @@ -6776,7 +6785,9 @@ namespace ts { text = `${rawtext}_${i}`; } if (text !== rawtext) { - result = factory.createIdentifier(text, result.typeArguments); + const typeArguments = getIdentifierTypeArguments(result); + result = factory.createIdentifier(text); + setIdentifierTypeArguments(result, typeArguments); } // avoiding iterations of the above loop turns out to be worth it when `i` starts to get large, so we cache the max // `i` we've used thus far, to save work later @@ -6811,7 +6822,8 @@ namespace ts { context.flags ^= NodeBuilderFlags.InInitialEntityName; } - const identifier = setEmitFlags(factory.createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping); + const identifier = setEmitFlags(factory.createIdentifier(symbolName), EmitFlags.NoAsciiEscaping); + if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? factory.createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1), identifier) : identifier; @@ -6843,7 +6855,8 @@ namespace ts { symbolName.length > 1 && isIdentifierStart(symbolName.charCodeAt(1), languageVersion) : isIdentifierStart(firstChar, languageVersion); if (index === 0 || canUsePropertyAccess) { - const identifier = setEmitFlags(factory.createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping); + const identifier = setEmitFlags(factory.createIdentifier(symbolName), EmitFlags.NoAsciiEscaping); + if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray(typeParameterNodes)); identifier.symbol = symbol; return index > 0 ? factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier; @@ -6861,8 +6874,10 @@ namespace ts { expression = factory.createNumericLiteral(+symbolName); } if (!expression) { - expression = setEmitFlags(factory.createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping); - expression.symbol = symbol; + const identifier = setEmitFlags(factory.createIdentifier(symbolName), EmitFlags.NoAsciiEscaping); + if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray(typeParameterNodes)); + identifier.symbol = symbol; + expression = identifier; } return factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression); } @@ -22307,15 +22322,17 @@ namespace ts { break; case SyntaxKind.Parameter: const param = declaration as ParameterDeclaration; - if (isIdentifier(param.name) && - (isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) && - param.parent.parameters.indexOf(param) > -1 && - (resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) || - param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) { - const newName = "arg" + param.parent.parameters.indexOf(param); - const typeName = declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); - errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); - return; + if (isIdentifier(param.name)) { + const originalKeywordKind = identifierToKeywordKind(param.name); + if ((isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) && + param.parent.parameters.indexOf(param) > -1 && + (resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) || + originalKeywordKind && isTypeNodeKind(originalKeywordKind))) { + const newName = "arg" + param.parent.parameters.indexOf(param); + const typeName = declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : ""); + errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName); + return; + } } diagnostic = (declaration as ParameterDeclaration).dotDotDotToken ? noImplicitAny ? Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage : @@ -37428,8 +37445,12 @@ namespace ts { function checkTypeReferenceNode(node: TypeReferenceNode | ExpressionWithTypeArguments) { checkGrammarTypeArguments(node, node.typeArguments); - if (node.kind === SyntaxKind.TypeReference && node.typeName.jsdocDotPos !== undefined && !isInJSFile(node) && !isInJSDoc(node)) { - grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + if (node.kind === SyntaxKind.TypeReference && !isInJSFile(node) && !isInJSDoc(node) && node.typeArguments && node.typeName.end !== node.typeArguments.pos) { + // If there was a token between the type name and the type arguments, check if it was a DotToken + const sourceFile = getSourceFileOfNode(node); + if (scanTokenAtPosition(sourceFile, node.typeName.end) === SyntaxKind.DotToken) { + grammarErrorAtPos(node, skipTrivia(sourceFile.text, node.typeName.end), 1, Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments); + } } forEach(node.typeArguments, checkSourceElement); const type = getTypeFromTypeReference(node); @@ -38786,7 +38807,8 @@ namespace ts { if (!ident) { return undefined; } - const symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + const symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return undefined; } @@ -43273,7 +43295,8 @@ namespace ts { if (!ident) { return; } - const symbol = getSymbolOfNameOrPropertyAccessExpression(ident, /*ignoreErrors*/ true); + // The default value of ignoreErrors in getSymbolOfNameOrPropertyAccessExpression is true. + const symbol = getSymbolOfNameOrPropertyAccessExpression(ident); if (!symbol) { return; } @@ -44179,7 +44202,7 @@ namespace ts { return undefined; } - function getSymbolOfNameOrPropertyAccessExpression(name: EntityName | PrivateIdentifier | PropertyAccessExpression | JSDocMemberName, ignoreErrors?: boolean): Symbol | undefined { + function getSymbolOfNameOrPropertyAccessExpression(name: EntityName | PrivateIdentifier | PropertyAccessExpression | JSDocMemberName): Symbol | undefined { if (isDeclarationName(name)) { return getSymbolOfNode(name.parent); } @@ -44269,11 +44292,11 @@ namespace ts { const symbol = getIntrinsicTagSymbol(name.parent as JsxOpeningLikeElement); return symbol === unknownSymbol ? undefined : symbol; } - const result = resolveEntityName(name, meaning, /*ignoreErrors*/ ignoreErrors, /* dontResolveAlias */ true, getHostSignatureFromJSDoc(name)); + const result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /* dontResolveAlias */ true, getHostSignatureFromJSDoc(name)); if (!result && isJSDoc) { const container = findAncestor(name, or(isClassLike, isInterfaceDeclaration)); if (container) { - return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfNode(container)); + return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfNode(container)); } } if (result && isJSDoc) { @@ -44339,11 +44362,11 @@ namespace ts { } else if (isTypeReferenceIdentifier(name as EntityName)) { const meaning = name.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace; - const symbol = resolveEntityName(name as EntityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true); + const symbol = resolveEntityName(name as EntityName, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); return symbol && symbol !== unknownSymbol ? symbol : getUnresolvedSymbolForEntityName(name as EntityName); } if (name.parent.kind === SyntaxKind.TypePredicate) { - return resolveEntityName(name as Identifier, /*meaning*/ SymbolFlags.FunctionScopedVariable); + return resolveEntityName(name as Identifier, /*meaning*/ SymbolFlags.FunctionScopedVariable, /*ignoreErrors*/ true); } return undefined; @@ -44530,7 +44553,7 @@ namespace ts { function getShorthandAssignmentValueSymbol(location: Node | undefined): Symbol | undefined { if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) { - return resolveEntityName((location as ShorthandPropertyAssignment).name, SymbolFlags.Value | SymbolFlags.Alias); + return resolveEntityName((location as ShorthandPropertyAssignment).name, SymbolFlags.Value | SymbolFlags.Alias, /*ignoreErrors*/ true); } return undefined; } @@ -44540,10 +44563,10 @@ namespace ts { if (isExportSpecifier(node)) { return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); + resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*ignoreErrors*/ true); } else { - return resolveEntityName(node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); + return resolveEntityName(node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*ignoreErrors*/ true); } } @@ -44860,8 +44883,9 @@ namespace ts { // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(nodeIn: Identifier): Declaration | undefined { - if (nodeIn.generatedImportReference) { - return nodeIn.generatedImportReference; + const specifier = getIdentifierGeneratedImportReference(nodeIn); + if (specifier) { + return specifier; } const node = getParseTreeNode(nodeIn, isIdentifier); if (node) { @@ -47170,7 +47194,7 @@ namespace ts { function checkGrammarNameInLetOrConstDeclarations(name: Identifier | BindingPattern): boolean { if (name.kind === SyntaxKind.Identifier) { - if (name.originalKeywordKind === SyntaxKind.LetKeyword) { + if (name.escapedText === "let") { return grammarErrorOnNode(name, Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0580988630..eab5368520 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2081,7 +2081,7 @@ namespace ts { function emitIdentifier(node: Identifier) { const writeText = node.symbol ? writeSymbol : write; writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol); - emitList(node, node.typeArguments, ListFormat.TypeParameters); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments + emitList(node, getIdentifierTypeArguments(node), ListFormat.TypeParameters); // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments } // diff --git a/src/compiler/factory/emitNode.ts b/src/compiler/factory/emitNode.ts index 19ebfd53ba..3cef25a44a 100644 --- a/src/compiler/factory/emitNode.ts +++ b/src/compiler/factory/emitNode.ts @@ -291,4 +291,26 @@ namespace ts { export function getTypeNode(node: T): TypeNode | undefined { return node.emitNode?.typeNode; } + + /** @internal */ + export function setIdentifierTypeArguments(node: T, typeArguments: NodeArray | undefined) { + getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; + return node; + } + + /** @internal */ + export function getIdentifierTypeArguments(node: Identifier): NodeArray | undefined { + return node.emitNode?.identifierTypeArguments; + } + + /** @internal */ + export function setIdentifierGeneratedImportReference(node: T, value: ImportSpecifier | undefined) { + getOrCreateEmitNode(node).generatedImportReference = value; + return node; + } + + /** @internal */ + export function getIdentifierGeneratedImportReference(node: Identifier | PrivateIdentifier): ImportSpecifier | undefined { + return node.emitNode?.generatedImportReference; + } } diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 42fae339cf..98d1486654 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -54,7 +54,6 @@ namespace ts { createRegularExpressionLiteral, createLiteralLikeNode, createIdentifier, - updateIdentifier, createTempVariable, createLoopVariable, createUniqueName, @@ -859,21 +858,14 @@ namespace ts { // Identifiers // - function createBaseIdentifier(text: string, originalKeywordKind: SyntaxKind | undefined) { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = stringToToken(text); - } - if (originalKeywordKind === SyntaxKind.Identifier) { - originalKeywordKind = undefined; - } + function createBaseIdentifier(text: string) { const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable; - node.originalKeywordKind = originalKeywordKind; node.escapedText = escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { - const node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined) as Mutable; + const node = createBaseIdentifier(text) as Mutable; node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; node.autoGeneratePrefix = prefix; @@ -883,29 +875,24 @@ namespace ts { } // @api - function createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier { - const node = createBaseIdentifier(text, originalKeywordKind); - if (typeArguments) { - // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations - node.typeArguments = createNodeArray(typeArguments); + function createIdentifier(text: string, originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier { + if (originalKeywordKind === undefined && text) { + originalKeywordKind = stringToToken(text); + } + if (originalKeywordKind === SyntaxKind.Identifier) { + originalKeywordKind = undefined; } - if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) { + const node = createBaseIdentifier(text); + if (hasExtendedUnicodeEscape) node.flags |= NodeFlags.IdentifierHasExtendedUnicodeEscape; + if (node.escapedText === "await") { node.transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait; } - if (hasExtendedUnicodeEscape) { - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + if (node.flags & NodeFlags.IdentifierHasExtendedUnicodeEscape) { node.transformFlags |= TransformFlags.ContainsES2015; } return node; } - // @api - function updateIdentifier(node: Identifier, typeArguments?: NodeArray | undefined): Identifier { - return node.typeArguments !== typeArguments - ? update(createIdentifier(idText(node), typeArguments), node) - : node; - } - // @api function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean, prefix?: string | GeneratedNamePart, suffix?: string): GeneratedIdentifier { let flags = GeneratedIdentifierFlags.Auto; @@ -1006,7 +993,8 @@ namespace ts { function createToken(token: TKind): KeywordTypeNode; function createToken(token: TKind): ModifierToken; function createToken(token: TKind): KeywordToken; - function createToken(token: TKind): Token; + function createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + function createToken(token: SyntaxKind.Unknown): Token; function createToken(token: TKind): Token; function createToken(token: TKind) { Debug.assert(token >= SyntaxKind.FirstToken && token <= SyntaxKind.LastToken, "Invalid token"); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b935e9a9fc..5aafcd3931 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1288,7 +1288,7 @@ namespace ts { const statement = factory.createExpressionStatement(expression) as JsonObjectExpressionStatement; finishNode(statement, pos); statements = createNodeArray([statement], pos); - endOfFileToken = parseExpectedToken(SyntaxKind.EndOfFileToken, Diagnostics.Unexpected_token); + endOfFileToken = parseExpectedToken(SyntaxKind.EndOfFileToken, Diagnostics.Unexpected_token) as EndOfFileToken; } // Set source file so that errors will be reported with this file name @@ -2335,7 +2335,7 @@ namespace ts { const pos = getNodePos(); const result = - kind === SyntaxKind.Identifier ? factory.createIdentifier("", /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined) : + kind === SyntaxKind.Identifier ? factory.createIdentifier("", /*originalKeywordKind*/ undefined) : isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === SyntaxKind.NumericLiteral ? factory.createNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === SyntaxKind.StringLiteral ? factory.createStringLiteral("", /*isSingleQuote*/ undefined) : @@ -2364,7 +2364,7 @@ namespace ts { const text = internIdentifier(scanner.getTokenValue()); const hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factory.createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); } if (token() === SyntaxKind.PrivateIdentifier) { @@ -2381,7 +2381,7 @@ namespace ts { identifierCount++; const pos = getNodePos(); return finishVirtualNode( - factory.createIdentifier(`${stateStylesRootNode}Instance`, /*typeArguments*/ undefined, SyntaxKind.Identifier), + factory.createIdentifier(`${stateStylesRootNode}Instance`, SyntaxKind.Identifier), pos, pos ); @@ -2876,9 +2876,9 @@ namespace ts { return undefined; } - if ((node as JSDocContainer).jsDocCache) { + if (canHaveJSDoc(node) && node.jsDoc?.jsDocCache) { // jsDocCache may include tags from parent nodes, which might have been modified. - (node as JSDocContainer).jsDocCache = undefined; + node.jsDoc.jsDocCache = undefined; } return node; @@ -3004,7 +3004,7 @@ namespace ts { // into an actual .ConstructorDeclaration. const methodDeclaration = node as MethodDeclaration; const nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier && - methodDeclaration.name.originalKeywordKind === SyntaxKind.ConstructorKeyword; + methodDeclaration.name.escapedText === "constructor"; return !nameIsConstructor; } @@ -3273,14 +3273,12 @@ namespace ts { function parseEntityName(allowReservedWords: boolean, diagnosticMessage?: DiagnosticMessage): EntityName { const pos = getNodePos(); let entity: EntityName = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); - let dotPos = getNodePos(); while (parseOptional(SyntaxKind.DotToken)) { if (token() === SyntaxKind.LessThanToken) { - // the entity is part of a JSDoc-style generic, so record the trailing dot for later error reporting - entity.jsdocDotPos = dotPos; + // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and + // `typeArguments` to report it as a grammar error in the checker. break; } - dotPos = getNodePos(); entity = finishNode( factory.createQualifiedName( entity, @@ -5735,13 +5733,13 @@ namespace ts { let expression; if (inEtsExtendComponentsContext() && extendEtsComponentDeclaration && token() === SyntaxKind.DotToken) { - expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, /*typeArguments*/ undefined, SyntaxKind.Identifier), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(extendEtsComponentDeclaration.instance, SyntaxKind.Identifier), pos, pos); } else if (inEtsStylesComponentsContext() && stylesEtsComponentDeclaration && token() === SyntaxKind.DotToken) { - expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, /*typeArguments*/ undefined, SyntaxKind.Identifier), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(stylesEtsComponentDeclaration.instance, SyntaxKind.Identifier), pos, pos); } else if (inEtsStateStylesContext() && stateStylesRootNode && token() === SyntaxKind.DotToken) { - expression = finishVirtualNode(factory.createIdentifier(`${stateStylesRootNode}Instance`, /*typeArguments*/ undefined, SyntaxKind.Identifier), pos, pos); + expression = finishVirtualNode(factory.createIdentifier(`${stateStylesRootNode}Instance`, SyntaxKind.Identifier), pos, pos); } else { expression = parsePrimaryExpression(); @@ -9641,7 +9639,7 @@ namespace ts { } if (nested) { - typeNameOrNamespaceName.isInJSDocNamespace = true; + (typeNameOrNamespaceName as Mutable).flags |= NodeFlags.IdentifierIsInJSDocNamespace; } return typeNameOrNamespaceName; } @@ -9849,7 +9847,7 @@ namespace ts { const end = scanner.getTextPos(); const originalKeywordKind = token(); const text = internIdentifier(scanner.getTokenValue()); - const result = finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos, end); + const result = finishNode(factory.createIdentifier(text, originalKeywordKind), pos, end); nextTokenJSDoc(); return result; } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 7feb0c09c8..29ac1c7a46 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -648,7 +648,7 @@ namespace ts { return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments")); } } - if (node.hasExtendedUnicodeEscape) { + if (node.flags & NodeFlags.IdentifierHasExtendedUnicodeEscape) { return setOriginalNode(setTextRange( factory.createIdentifier(unescapeLeadingUnderscores(node.escapedText)), node diff --git a/src/compiler/transformers/es5.ts b/src/compiler/transformers/es5.ts index e82ba20cf5..d7d2482299 100644 --- a/src/compiler/transformers/es5.ts +++ b/src/compiler/transformers/es5.ts @@ -112,7 +112,7 @@ namespace ts { * @param name An Identifier */ function trySubstituteReservedName(name: Identifier) { - const token = name.originalKeywordKind || (nodeIsSynthesized(name) ? stringToToken(idText(name)) : undefined); + const token = identifierToKeywordKind(name); if (token !== undefined && token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord) { return setTextRange(factory.createStringLiteralFromNode(name), name); } diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 83a7f70d15..866ee45af9 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -57,7 +57,7 @@ namespace ts { } const generatedName = factory.createUniqueName(`_${name}`, GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel | GeneratedIdentifierFlags.AllowNameSubstitution); const specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName); - generatedName.generatedImportReference = specifier; + setIdentifierGeneratedImportReference(generatedName, specifier); specifierSourceImports.set(name, specifier); return generatedName; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a31fcebda4..6158c8b3f4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -821,6 +821,10 @@ namespace ts { // never cleared on SourceFiles which get re-used in between incremental parses. // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`. /* @internal */ PermanentlySetIncrementalFlags = PossiblyContainsDynamicImport | PossiblyContainsImportMeta, + + // The following flags repurpose other NodeFlags as different meanings for Identifier nodes + /** @internal */ IdentifierHasExtendedUnicodeEscape = ContainsThis, // Indicates whether the identifier contains an extended unicode escape sequence + /** @internal */ IdentifierIsInJSDocNamespace = HasAsyncFunctions, // Indicates whether the identifier is part of a JSDoc namespace } export const enum EtsFlags { @@ -915,9 +919,14 @@ namespace ts { skipCheck?: boolean; } - export interface JSDocContainer { - /* @internal */ jsDoc?: JSDoc[]; // JSDoc that directly precedes this node - /* @internal */ jsDocCache?: readonly JSDocTag[]; // Cache for getJSDocTags + export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; + /** @internal */ jsDoc?: JSDocArray; // JSDoc that directly precedes this node + } + + /** @internal */ + export interface JSDocArray extends Array { + jsDocCache?: readonly JSDocTag[]; // Cache for getJSDocTags } // Ideally, `ForEachChildNodes` and `VisitEachChildNodes` would not differ. @@ -966,12 +975,6 @@ namespace ts { | JSDocOverrideTag ; - /* @internal */ - export type VisitEachChildNodes = - | HasChildren - | Identifier - ; - /* @internal */ export type HasChildren = | QualifiedName @@ -1114,66 +1117,66 @@ namespace ts { | CommaListExpression ; - export type HasJSDoc = - | ParameterDeclaration + export type HasJSDoc = + | AccessorDeclaration + | AnnotationDeclaration + | AnnotationPropertyDeclaration + | ArrowFunction + | Block + | BreakStatement | CallSignatureDeclaration + | CaseClause + | ClassLikeDeclaration | ClassStaticBlockDeclaration + | ConstructorDeclaration + | ConstructorTypeNode | ConstructSignatureDeclaration - | MethodSignature - | PropertySignature - | ArrowFunction - | ParenthesizedExpression - | SpreadAssignment - | ShorthandPropertyAssignment - | PropertyAssignment - | FunctionExpression - | EmptyStatement + | ContinueStatement | DebuggerStatement - | Block - | VariableStatement - | ExpressionStatement - | IfStatement | DoStatement - | WhileStatement - | ForStatement + | EmptyStatement + | EndOfFileToken + | EnumDeclaration + | EnumMember + | ExportAssignment + | ExportDeclaration + | ExportSpecifier + | ExpressionStatement | ForInStatement | ForOfStatement - | BreakStatement - | ContinueStatement - | ReturnStatement - | WithStatement - | SwitchStatement - | LabeledStatement - | ThrowStatement - | TryStatement + | ForStatement | FunctionDeclaration - | ConstructorDeclaration - | MethodDeclaration - | VariableDeclaration - | PropertyDeclaration - | AnnotationPropertyDeclaration - | AnnotationDeclaration - | AccessorDeclaration - | ClassLikeDeclaration - | InterfaceDeclaration - | TypeAliasDeclaration - | EnumMember - | EnumDeclaration - | ModuleDeclaration - | ImportEqualsDeclaration + | FunctionExpression + | FunctionTypeNode + | IfStatement | ImportDeclaration - | NamespaceExportDeclaration - | ExportAssignment + | ImportEqualsDeclaration | IndexSignatureDeclaration - | FunctionTypeNode - | ConstructorTypeNode + | InterfaceDeclaration | JSDocFunctionType - | ExportDeclaration + | LabeledStatement + | MethodDeclaration + | MethodSignature + | ModuleDeclaration | NamedTupleMember - | ExportSpecifier - | CaseClause - | EndOfFileToken - ; + | NamespaceExportDeclaration + | ParameterDeclaration + | ParenthesizedExpression + | PropertyAssignment + | PropertyDeclaration + | PropertySignature + | ReturnStatement + | ShorthandPropertyAssignment + | SpreadAssignment + | SwitchStatement + | ThrowStatement + | TryStatement + | TypeAliasDeclaration + | VariableDeclaration + | VariableStatement + | WhileStatement + | WithStatement + ; export type HasType = | SignatureDeclaration @@ -1457,16 +1460,10 @@ namespace ts { * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ readonly escapedText: __String; - readonly originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later /*@internal*/ readonly autoGenerateFlags?: GeneratedIdentifierFlags; // Specifies whether to auto-generate the text for an identifier. /*@internal*/ readonly autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name. /*@internal*/ readonly autoGeneratePrefix?: string | GeneratedNamePart; /*@internal*/ readonly autoGenerateSuffix?: string; - /*@internal*/ generatedImportReference?: ImportSpecifier; // Reference to the generated import specifier this identifier refers to - isInJSDocNamespace?: boolean; // if the node is a member in a JSDoc namespace - /*@internal*/ typeArguments?: NodeArray; // Only defined on synthesized nodes. Though not syntactically valid, used in emitting diagnostics, quickinfo, and signature help. - /*@internal*/ jsdocDotPos?: number; // Identifier occurs in JSDoc-style generic: Id. - /*@internal*/ hasExtendedUnicodeEscape?: boolean; } // Transient identifier node (marked by id === -1) @@ -1483,7 +1480,6 @@ namespace ts { readonly kind: SyntaxKind.QualifiedName; readonly left: EntityName; readonly right: Identifier; - /*@internal*/ jsdocDotPos?: number; // QualifiedName occurs in JSDoc-style generic: Id1.Id2. } export type EntityName = Identifier | QualifiedName; @@ -7606,6 +7602,8 @@ namespace ts { startsOnNewLine?: boolean; // If the node should begin on a new line snippetElement?: SnippetElement; // Snippet element of the node typeNode?: TypeNode; // VariableDeclaration type + identifierTypeArguments?: NodeArray; // Only defined on synthesized identifiers. Though not syntactically valid, used in emitting diagnostics, quickinfo, and signature help. + generatedImportReference?: ImportSpecifier; // Reference to the generated import specifier this identifier refers to } /* @internal */ @@ -7903,8 +7901,7 @@ namespace ts { // createIdentifier(text: string): Identifier; - /* @internal */ createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures - /* @internal */ updateIdentifier(node: Identifier, typeArguments: NodeArray | undefined): Identifier; + /** @internal */ createIdentifier(text: string, originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures /** * Create a unique temporary variable. @@ -7949,11 +7946,12 @@ namespace ts { createToken(token: SyntaxKind.NullKeyword): NullLiteral; createToken(token: SyntaxKind.TrueKeyword): TrueLiteral; createToken(token: SyntaxKind.FalseKeyword): FalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + createToken(token: SyntaxKind.Unknown): Token; createToken(token: TKind): PunctuationToken; createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - createToken(token: TKind): Token; /*@internal*/ createToken(token: TKind): Token; // diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 40534a86d6..b9732e47c7 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1168,6 +1168,13 @@ namespace ts { return createTextSpanFromBounds(start, scanner.getTextPos()); } + /** @internal */ + export function scanTokenAtPosition(sourceFile: SourceFile, pos: number) { + const scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos); + scanner.scan(); + return scanner.getToken(); + } + function getErrorSpanForArrowFunction(sourceFile: SourceFile, node: ArrowFunction): TextSpan { const pos = skipTrivia(sourceFile.text, node.pos); if (node.body && node.body.kind === SyntaxKind.Block) { @@ -2834,6 +2841,83 @@ namespace ts { : undefined; } + /** @internal */ + export function canHaveJSDoc(node: Node): node is HasJSDoc { + switch (node.kind) { + case SyntaxKind.ArrowFunction: + case SyntaxKind.AnnotationDeclaration: + case SyntaxKind.AnnotationPropertyDeclaration: + case SyntaxKind.BinaryExpression: + case SyntaxKind.Block: + case SyntaxKind.BreakStatement: + case SyntaxKind.CallSignature: + case SyntaxKind.CaseClause: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassStaticBlockDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.ConstructorType: + case SyntaxKind.ConstructSignature: + case SyntaxKind.ContinueStatement: + case SyntaxKind.DebuggerStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.EmptyStatement: + case SyntaxKind.EndOfFileToken: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.EnumMember: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.ExpressionStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionType: + case SyntaxKind.GetAccessor: + case SyntaxKind.Identifier: + case SyntaxKind.IfStatement: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.IndexSignature: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocSignature: + case SyntaxKind.LabeledStatement: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.NamedTupleMember: + case SyntaxKind.NamespaceExportDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.Parameter: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.ReturnStatement: + case SyntaxKind.SemicolonClassElement: + case SyntaxKind.SetAccessor: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.SpreadAssignment: + case SyntaxKind.SwitchStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.TypeParameter: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.VariableStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.WithStatement: + return true; + default: + return false; + } + } + export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[] { let result: (JSDoc | JSDocTag)[] | undefined; // Pull parameter comments from declaring function as well @@ -3436,7 +3520,8 @@ namespace ts { return token !== undefined && isKeyword(token); } - export function isIdentifierANonContextualKeyword({ originalKeywordKind }: Identifier): boolean { + export function isIdentifierANonContextualKeyword(node: Identifier): boolean { + const originalKeywordKind = identifierToKeywordKind(node); return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } @@ -4605,7 +4690,7 @@ namespace ts { } export function identifierIsThisKeyword(id: Identifier): boolean { - return id.originalKeywordKind === SyntaxKind.ThisKeyword; + return id.escapedText === "this"; } export function getAllAccessorDeclarations(declarations: readonly Declaration[], accessor: AccessorDeclaration): AllAccessorDeclarations { @@ -5059,7 +5144,7 @@ namespace ts { */ export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags { let flags = canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : ModifierFlags.None; - if (node.flags & NodeFlags.NestedNamespace || (node.kind === SyntaxKind.Identifier && (node as Identifier).isInJSDocNamespace)) { + if (node.flags & NodeFlags.NestedNamespace || (node.kind === SyntaxKind.Identifier && node.flags & NodeFlags.IdentifierIsInJSDocNamespace)) { flags |= ModifierFlags.Export; } return flags; @@ -6059,7 +6144,6 @@ namespace ts { this.transformFlags = TransformFlags.None; this.parent = undefined!; this.original = undefined; - this.flowNode = undefined; } function SourceMapSource(this: SourceMapSource, fileName: string, text: string, skipTrivia?: (pos: number) => number) { @@ -6081,8 +6165,21 @@ namespace ts { getSourceMapSourceConstructor: () => SourceMapSource as any, }; + const objectAllocatorPatchers: ((objectAllocator: ObjectAllocator) => void)[] = []; + + /** + * Used by `deprecatedCompat` to patch the object allocator to apply deprecations. + * @internal + */ + export function addObjectAllocatorPatcher(fn: (objectAllocator: ObjectAllocator) => void) { + objectAllocatorPatchers.push(fn); + fn(objectAllocator); + } + + export function setObjectAllocator(alloc: ObjectAllocator) { Object.assign(objectAllocator, alloc); + forEach(objectAllocatorPatchers, fn => fn(objectAllocator)); } export function formatStringFromArgs(text: string, args: ArrayLike, baseIndex = 0): string { diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 7ac4421775..f9264ce340 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -491,6 +491,17 @@ namespace ts { export function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string { return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } + + + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + export function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined { + const token = stringToToken(node.escapedText as string); + return token ? tryCast(token, isKeyword) : undefined; + } + export function symbolName(symbol: Symbol): string { if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); @@ -898,14 +909,16 @@ namespace ts { } function getJSDocTagsWorker(node: Node, noCache?: boolean): readonly JSDocTag[] { - let tags = (node as JSDocContainer).jsDocCache; + if (!canHaveJSDoc(node)) return emptyArray; + let tags = node.jsDoc?.jsDocCache; // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. if (tags === undefined || noCache) { const comments = getJSDocCommentsAndTags(node, noCache); Debug.assert(comments.length < 2 || comments[0] !== comments[1]); tags = flatMap(comments, j => isJSDoc(j) ? j.tags : j); if (!noCache) { - (node as JSDocContainer).jsDocCache = tags; + node.jsDoc ??= []; + node.jsDoc.jsDocCache = tags; } } return tags; diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 16025c1f27..0807a2bc6b 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -409,23 +409,17 @@ namespace ts { // This looks something like: // // { - // [SyntaxKind.Identifier]: VisitEachChildFunction; // [SyntaxKind.QualifiedName]: VisitEachChildFunction; // [SyntaxKind.ComputedPropertyName]: VisitEachChildFunction; // ... // } // // This is then used as the expected type for `visitEachChildTable`. - type VisitEachChildTable = { [TNode in VisitEachChildNodes as TNode["kind"]]: VisitEachChildFunction }; + type VisitEachChildTable = { [TNode in HasChildren as TNode["kind"]]: VisitEachChildFunction }; // NOTE: Before you can add a new method to `visitEachChildTable`, you must first ensure the `Node` subtype you // wish to add is defined in the `HasChildren` union in types.ts. const visitEachChildTable: VisitEachChildTable = { - [SyntaxKind.Identifier]: function visitEachChildOfIdentifier(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) { - return context.factory.updateIdentifier(node, - nodesVisitor(node.typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration)); - }, - [SyntaxKind.QualifiedName]: function visitEachChildOfQualifiedName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateQualifiedName(node, nodeVisitor(node.left, visitor, isEntityName), diff --git a/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts b/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts index 3bb201d1ec..a134a5c947 100644 --- a/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts +++ b/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts @@ -922,7 +922,7 @@ namespace ts { /** @deprecated Use `factory.createIdentifier` or the factory supplied by your transformation context instead. */ export const createIdentifier = Debug.deprecate(function createIdentifier(text: string) { - return factory.createIdentifier(text, /*typeArguments*/ undefined, /*originalKeywordKind*/ undefined); + return factory.createIdentifier(text, /*originalKeywordKind*/ undefined); }, factoryDeprecation); /** @deprecated Use `factory.createTempVariable` or the factory supplied by your transformation context instead. */ diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index 5ac9680353..6bd3ad8aa1 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -186,7 +186,7 @@ namespace Utils { o.containsParseError = true; } - for (const propertyName of Object.getOwnPropertyNames(n) as readonly (keyof ts.SourceFile | keyof ts.Identifier)[]) { + for (const propertyName of Object.getOwnPropertyNames(n) as readonly (keyof ts.SourceFile | keyof ts.Identifier | keyof ts.StringLiteral)[]) { switch (propertyName) { case "parent": case "symbol": @@ -201,15 +201,17 @@ namespace Utils { // Blocklist of items we never put in the baseline file. break; - case "originalKeywordKind": - o[propertyName] = getKindName((n as any)[propertyName]); - break; - case "flags": // Clear the flags that are produced by aggregating child values. That is ephemeral // data we don't care about in the dump. We only care what the parser set directly // on the AST. - const flags = n.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData); + let flags = n.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData); + if (ts.isIdentifier(n)) { + if (flags & ts.NodeFlags.IdentifierHasExtendedUnicodeEscape) { + o.hasExtendedUnicodeEscape = true; + flags &= ~ts.NodeFlags.IdentifierHasExtendedUnicodeEscape; + } + } if (flags) { o[propertyName] = getNodeFlagName(flags); } diff --git a/src/services/codefixes/convertToEsModule.ts b/src/services/codefixes/convertToEsModule.ts index c21ba7464f..aed000f56e 100644 --- a/src/services/codefixes/convertToEsModule.ts +++ b/src/services/codefixes/convertToEsModule.ts @@ -79,8 +79,8 @@ namespace ts.codefix { function collectExportRenames(sourceFile: SourceFile, checker: TypeChecker, identifiers: Identifiers): ExportRenames { const res = new Map(); forEachExportReference(sourceFile, node => { - const { text, originalKeywordKind } = node.name; - if (!res.has(text) && (originalKeywordKind !== undefined && isNonContextualKeyword(originalKeywordKind) + const { text } = node.name; + if (!res.has(text) && (isIdentifierANonContextualKeyword(node.name) || checker.resolveName(text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) { // Unconditionally add an underscore in case `text` is a keyword. res.set(text, makeUniqueName(`_${text}`, identifiers)); diff --git a/src/services/completions.ts b/src/services/completions.ts index ba2bb208f3..776b83c491 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1049,8 +1049,11 @@ namespace ts.Completions { if (isModifier(node)) { return node.kind; } - if (isIdentifier(node) && node.originalKeywordKind && isModifierKind(node.originalKeywordKind)) { - return node.originalKeywordKind; + if (isIdentifier(node)) { + const originalKeywordKind = identifierToKeywordKind(node); + if (originalKeywordKind && isModifierKind(originalKeywordKind)) { + return originalKeywordKind; + } } return undefined; } @@ -4116,7 +4119,7 @@ namespace ts.Completions { } function keywordForNode(node: Node): SyntaxKind { - return isIdentifier(node) ? node.originalKeywordKind || SyntaxKind.Unknown : node.kind; + return isIdentifier(node) ? identifierToKeywordKind(node) ?? SyntaxKind.Unknown : node.kind; } function getContextualKeywords( @@ -4219,8 +4222,8 @@ namespace ts.Completions { } break; case SyntaxKind.Identifier: { - const originalKeywordKind = (location as Identifier).originalKeywordKind; - if (originalKeywordKind && isKeyword(originalKeywordKind)) { + const originalKeywordKind = identifierToKeywordKind(location as Identifier); + if (originalKeywordKind) { return undefined; } // class c { public prop = c| } @@ -4265,7 +4268,7 @@ namespace ts.Completions { return undefined; } const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword; - return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(stringToToken(contextToken.text)!)) // TODO: GH#18217 + return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(identifierToKeywordKind(contextToken) ?? SyntaxKind.Unknown)) ? contextToken.parent.parent as ObjectTypeDeclaration : undefined; } } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 0ea223074a..f917b33ac5 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1655,8 +1655,8 @@ namespace ts.FindAllReferences { // For `export { foo as bar }`, rename `foo`, but not `bar`. if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) { - const isDefaultExport = referenceLocation.originalKeywordKind === SyntaxKind.DefaultKeyword - || exportSpecifier.name.originalKeywordKind === SyntaxKind.DefaultKeyword; + const isDefaultExport = referenceLocation.escapedText === "default" + || exportSpecifier.name.escapedText === "default"; const exportKind = isDefaultExport ? ExportKind.Default : ExportKind.Named; const exportSymbol = Debug.checkDefined(exportSpecifier.symbol); const exportInfo = getExportInfo(exportSymbol, exportKind, state.checker); diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 9f3a052114..87c75026a8 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -1173,7 +1173,7 @@ namespace ts.refactor.extractSymbol { // Make a unique name for the extracted variable const file = scope.getSourceFile(); - const localNameText = isPropertyAccessExpression(node) && !isClassLike(scope) && !checker.resolveName(node.name.text, node, SymbolFlags.Value, /*excludeGlobals*/ false) && !isPrivateIdentifier(node.name) && !isKeyword(node.name.originalKeywordKind!) + const localNameText = isPropertyAccessExpression(node) && !isClassLike(scope) && !checker.resolveName(node.name.text, node, SymbolFlags.Value, /*excludeGlobals*/ false) && !isPrivateIdentifier(node.name) && !identifierToKeywordKind(node.name) ? node.name.text : getUniqueName(isClassLike(scope) ? "newProperty" : "newLocal", file); const isJS = isInJSFile(scope); diff --git a/src/services/rename.ts b/src/services/rename.ts index e2aa01b311..4e93eef554 100644 --- a/src/services/rename.ts +++ b/src/services/rename.ts @@ -43,7 +43,7 @@ namespace ts.Rename { } // Cannot rename `default` as in `import { default as foo } from "./someModule"; - if (isIdentifier(node) && node.originalKeywordKind === SyntaxKind.DefaultKeyword && symbol.parent && symbol.parent.flags & SymbolFlags.Module) { + if (isIdentifier(node) && node.escapedText === "default" && symbol.parent && symbol.parent.flags & SymbolFlags.Module) { return undefined; } diff --git a/src/services/services.ts b/src/services/services.ts index b85f64b764..949d7132aa 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -284,7 +284,7 @@ namespace ts { } public getChildren(): Node[] { - return this.kind === SyntaxKind.EndOfFileToken ? (this as EndOfFileToken).jsDoc || emptyArray : emptyArray; + return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc || emptyArray : emptyArray; } public getFirstToken(): Node | undefined { diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index a842e37a50..8ec8c2e790 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -966,7 +966,6 @@ namespace ts.textChanges { parent.parent as HasJSDoc : parent.parent.parent as HasJSDoc; jsDocNode.jsDoc = parent.jsDoc; - jsDocNode.jsDocCache = parent.jsDocCache; return jsDocNode; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b86d15474f..572f9cdf9c 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -633,9 +633,10 @@ declare namespace ts { locals?: SymbolTable; skipCheck?: boolean; } - export interface JSDocContainer { + export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AnnotationPropertyDeclaration | AnnotationDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken; + export type HasJSDoc = AccessorDeclaration | AnnotationDeclaration | AnnotationPropertyDeclaration | ArrowFunction | Block | BreakStatement | CallSignatureDeclaration | CaseClause | ClassLikeDeclaration | ClassStaticBlockDeclaration | ConstructorDeclaration | ConstructorTypeNode | ConstructSignatureDeclaration | ContinueStatement | DebuggerStatement | DoStatement | EmptyStatement | EndOfFileToken | EnumDeclaration | EnumMember | ExportAssignment | ExportDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | FunctionTypeNode | IfStatement | ImportDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | InterfaceDeclaration | JSDocFunctionType | LabeledStatement | MethodDeclaration | MethodSignature | ModuleDeclaration | NamedTupleMember | NamespaceExportDeclaration | ParameterDeclaration | ParenthesizedExpression | PropertyAssignment | PropertyDeclaration | PropertySignature | ReturnStatement | ShorthandPropertyAssignment | SpreadAssignment | SwitchStatement | ThrowStatement | TryStatement | TypeAliasDeclaration | VariableDeclaration | VariableStatement | WhileStatement | WithStatement; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | AnnotationPropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -711,8 +712,6 @@ declare namespace ts { * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ readonly escapedText: __String; - readonly originalKeywordKind?: SyntaxKind; - isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; @@ -3711,11 +3710,12 @@ declare namespace ts { createToken(token: SyntaxKind.NullKeyword): NullLiteral; createToken(token: SyntaxKind.TrueKeyword): TrueLiteral; createToken(token: SyntaxKind.FalseKeyword): FalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + createToken(token: SyntaxKind.Unknown): Token; createToken(token: TKind): PunctuationToken; createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - createToken(token: TKind): Token; createSuper(): SuperExpression; createThis(): ThisExpression; createNull(): NullLiteral; @@ -4817,6 +4817,11 @@ declare namespace ts { */ function unescapeLeadingUnderscores(identifier: __String): string; function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; function symbolName(symbol: Symbol): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 6a74eb1412..20ad9bbae3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -633,9 +633,10 @@ declare namespace ts { locals?: SymbolTable; skipCheck?: boolean; } - export interface JSDocContainer { + export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AnnotationPropertyDeclaration | AnnotationDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken; + export type HasJSDoc = AccessorDeclaration | AnnotationDeclaration | AnnotationPropertyDeclaration | ArrowFunction | Block | BreakStatement | CallSignatureDeclaration | CaseClause | ClassLikeDeclaration | ClassStaticBlockDeclaration | ConstructorDeclaration | ConstructorTypeNode | ConstructSignatureDeclaration | ContinueStatement | DebuggerStatement | DoStatement | EmptyStatement | EndOfFileToken | EnumDeclaration | EnumMember | ExportAssignment | ExportDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | FunctionTypeNode | IfStatement | ImportDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | InterfaceDeclaration | JSDocFunctionType | LabeledStatement | MethodDeclaration | MethodSignature | ModuleDeclaration | NamedTupleMember | NamespaceExportDeclaration | ParameterDeclaration | ParenthesizedExpression | PropertyAssignment | PropertyDeclaration | PropertySignature | ReturnStatement | ShorthandPropertyAssignment | SpreadAssignment | SwitchStatement | ThrowStatement | TryStatement | TypeAliasDeclaration | VariableDeclaration | VariableStatement | WhileStatement | WithStatement; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | AnnotationPropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -711,8 +712,6 @@ declare namespace ts { * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ readonly escapedText: __String; - readonly originalKeywordKind?: SyntaxKind; - isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; @@ -3711,11 +3710,12 @@ declare namespace ts { createToken(token: SyntaxKind.NullKeyword): NullLiteral; createToken(token: SyntaxKind.TrueKeyword): TrueLiteral; createToken(token: SyntaxKind.FalseKeyword): FalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): EndOfFileToken; + createToken(token: SyntaxKind.Unknown): Token; createToken(token: TKind): PunctuationToken; createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - createToken(token: TKind): Token; createSuper(): SuperExpression; createThis(): ThisExpression; createNull(): NullLiteral; @@ -4817,6 +4817,11 @@ declare namespace ts { */ function unescapeLeadingUnderscores(identifier: __String): string; function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; function symbolName(symbol: Symbol): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; -- Gitee