mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Unify types
This commit is contained in:
+84
-28
@@ -307,33 +307,61 @@ function symbolsConflict(s1, s2) {
|
||||
*/
|
||||
function verifyMatchingSymbols(decl, isInternal) {
|
||||
ts.visitEachChild(decl, /** @type {(node: ts.Node) => ts.Node} */ function visit(node) {
|
||||
if (ts.isIdentifier(node) && ts.isPartOfTypeNode(node)) {
|
||||
if (ts.isQualifiedName(node.parent) && node !== node.parent.left) {
|
||||
return node;
|
||||
}
|
||||
if (ts.isParameter(node.parent) && node === node.parent.name) {
|
||||
return node;
|
||||
}
|
||||
if (ts.isNamedTupleMember(node.parent) && node === node.parent.name) {
|
||||
return node;
|
||||
}
|
||||
|
||||
const symbolOfNode = typeChecker.getSymbolAtLocation(node);
|
||||
if (!symbolOfNode) {
|
||||
fail(`No symbol for node at ${nodeToLocation(node)}`);
|
||||
}
|
||||
const symbolInScope = findInScope(symbolOfNode.name);
|
||||
if (!symbolInScope) {
|
||||
if (symbolOfNode.declarations?.every(d => isLocalDeclaration(d) && d.getSourceFile() === decl.getSourceFile()) && !isSelfReference(node, symbolOfNode)) {
|
||||
// The symbol is a local that needs to be copied into the scope.
|
||||
scopeStack[scopeStack.length - 1].locals.set(symbolOfNode.name, { symbol: symbolOfNode, writeTarget: isInternal ? WriteTarget.Internal : WriteTarget.Both });
|
||||
if (ts.isIdentifier(node)) {
|
||||
let meaning = ts.SymbolFlags.None;
|
||||
if (ts.isPartOfTypeNode(node)) {
|
||||
if (ts.isQualifiedName(node.parent) && node !== node.parent.left) {
|
||||
return node;
|
||||
}
|
||||
// We didn't find the symbol in scope at all. Just allow it and we'll fail at test time.
|
||||
return node;
|
||||
if (ts.isParameter(node.parent) && node === node.parent.name) {
|
||||
return node;
|
||||
}
|
||||
if (ts.isNamedTupleMember(node.parent) && node === node.parent.name) {
|
||||
return node;
|
||||
}
|
||||
meaning = ts.SymbolFlags.Type;
|
||||
}
|
||||
else if (ts.isExpressionWithTypeArguments(node.parent) &&
|
||||
ts.isHeritageClause(node.parent.parent) &&
|
||||
ts.isClassLike(node.parent.parent.parent)) {
|
||||
meaning = ts.SymbolFlags.Value;
|
||||
}
|
||||
|
||||
if (symbolsConflict(symbolOfNode, symbolInScope)) {
|
||||
fail(`Declaration at ${nodeToLocation(decl)}\n references ${symbolOfNode.name} at ${symbolOfNode.declarations && nodeToLocation(symbolOfNode.declarations[0])},\n but containing scope contains a symbol with the same name declared at ${symbolInScope.declarations && nodeToLocation(symbolInScope.declarations[0])}`);
|
||||
if (meaning) {
|
||||
const symbolOfNode = typeChecker.getSymbolAtLocation(node);
|
||||
if (!symbolOfNode) {
|
||||
fail(`No symbol for node at ${nodeToLocation(node)}`);
|
||||
}
|
||||
const symbolInScope = findInScope(symbolOfNode.name);
|
||||
if (!symbolInScope) {
|
||||
/** @type {ts.Declaration[]} */
|
||||
const declarations = [];
|
||||
if (meaning === ts.SymbolFlags.Type && symbolOfNode.declarations) {
|
||||
declarations.push(...symbolOfNode.declarations);
|
||||
}
|
||||
else if (meaning === ts.SymbolFlags.Value && symbolOfNode.valueDeclaration) {
|
||||
declarations.push(symbolOfNode.valueDeclaration);
|
||||
}
|
||||
if (declarations.every(d => isLocalDeclaration(d) && d.getSourceFile() === decl.getSourceFile()) && !isSelfReference(node, symbolOfNode)) {
|
||||
// The symbol is a local that needs to be copied into the scope.
|
||||
const locals = scopeStack[scopeStack.length - 1].locals;
|
||||
if (!locals.has(symbolOfNode.name)) {
|
||||
locals.set(symbolOfNode.name, { symbol: symbolOfNode, writeTarget: isInternal ? WriteTarget.Internal : WriteTarget.Both });
|
||||
if (symbolOfNode.valueDeclaration) {
|
||||
const statement = getDeclarationStatement(symbolOfNode.valueDeclaration);
|
||||
if (statement) {
|
||||
verifyMatchingSymbols(statement, isInternal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// We didn't find the symbol in scope at all. Just allow it and we'll fail at test time.
|
||||
return node;
|
||||
}
|
||||
|
||||
if (symbolsConflict(symbolOfNode, symbolInScope)) {
|
||||
fail(`Declaration at ${nodeToLocation(decl)}\n references ${symbolOfNode.name} at ${symbolOfNode.declarations && nodeToLocation(symbolOfNode.declarations[0])},\n but containing scope contains a symbol with the same name declared at ${symbolInScope.declarations && nodeToLocation(symbolInScope.declarations[0])}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,9 +373,10 @@ function verifyMatchingSymbols(decl, isInternal) {
|
||||
* @param {ts.Declaration} decl
|
||||
*/
|
||||
function isLocalDeclaration(decl) {
|
||||
return ts.canHaveModifiers(decl)
|
||||
&& !ts.getModifiers(decl)?.some(m => m.kind === ts.SyntaxKind.ExportKeyword)
|
||||
&& !!getDeclarationStatement(decl);
|
||||
const statement = getDeclarationStatement(decl);
|
||||
return !!statement
|
||||
&& ts.canHaveModifiers(statement)
|
||||
&& !ts.getModifiers(statement)?.some(m => m.kind === ts.SyntaxKind.ExportKeyword);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -456,7 +485,34 @@ function emitAsNamespace(name, parent, moduleSymbol, needExportModifier) {
|
||||
symbol.declarations?.forEach(decl => {
|
||||
// We already checked that getDeclarationStatement(decl) works for each declaration.
|
||||
const statement = getDeclarationStatement(decl);
|
||||
writeNode(/** @type {ts.Statement} */ (statement), decl.getSourceFile(), writeTarget);
|
||||
if (!statement) return;
|
||||
|
||||
if (writeTarget & WriteTarget.Public) {
|
||||
if (!ts.isInternalDeclaration(statement)) {
|
||||
const publicStatement = ts.visitEachChild(statement, node => {
|
||||
// No @internal comments in the public API.
|
||||
if (ts.isInternalDeclaration(node)) {
|
||||
return undefined;
|
||||
}
|
||||
// TODO: remove after https://github.com/microsoft/TypeScript/pull/58187 is released
|
||||
if (ts.canHaveModifiers(node)) {
|
||||
for (const modifier of ts.getModifiers(node) ?? []) {
|
||||
if (modifier.kind === ts.SyntaxKind.PrivateKeyword) {
|
||||
removeAllComments(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return removeDeclareConstExport(node, /*needExportModifier*/ false);
|
||||
}, /*context*/ undefined);
|
||||
writeNode(/** @type {ts.Statement} */ (publicStatement), decl.getSourceFile(), WriteTarget.Public);
|
||||
}
|
||||
}
|
||||
|
||||
if (writeTarget & WriteTarget.Internal) {
|
||||
const updated = ts.visitEachChild(statement, node => removeDeclareConstExport(node, childrenNeedExportModifier), /*context*/ undefined);
|
||||
writeNode(/** @type {ts.Statement} */ (updated), decl.getSourceFile(), WriteTarget.Internal);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// /** @internal */
|
||||
// export * from "../nodes.js";
|
||||
/** @internal */
|
||||
export * from "../ast.js";
|
||||
/** @internal */
|
||||
|
||||
@@ -7,6 +7,7 @@ export * from "../semver.js";
|
||||
export * from "../performanceCore.js";
|
||||
export * from "../tracing.js";
|
||||
export * from "../types.js";
|
||||
export * from "../ast.js";
|
||||
export * from "../sys.js";
|
||||
export * from "../path.js";
|
||||
export * from "../diagnosticInformationMap.generated.js";
|
||||
@@ -14,16 +15,20 @@ export * from "../scanner.js";
|
||||
export * from "../utilitiesPublic.js";
|
||||
export * from "../utilities.js";
|
||||
export * from "../factory/parenthesizerRules.js";
|
||||
export * from "../factory/astParenthesizerRules.js";
|
||||
export * from "../factory/nodeConverters.js";
|
||||
export * from "../factory/nodeFactory.js";
|
||||
export * from "../factory/astNodeFactory.js";
|
||||
export * from "../factory/emitNode.js";
|
||||
export * from "../factory/astNodeTests.js";
|
||||
export * from "../factory/emitHelpers.js";
|
||||
export * from "../factory/nodeTests.js";
|
||||
export * from "../factory/nodeChildren.js";
|
||||
export * from "../factory/utilities.js";
|
||||
export * from "../factory/utilitiesPublic.js";
|
||||
export * from "../forEachChild.js";
|
||||
export * from "../parser.js";
|
||||
export * from "../forEachChild.js";
|
||||
export * from "../astForEachChild.js";
|
||||
export * from "../commandLineParser.js";
|
||||
export * from "../moduleNameResolver.js";
|
||||
export * from "../binder.js";
|
||||
@@ -76,7 +81,3 @@ import * as moduleSpecifiers from "./ts.moduleSpecifiers.js";
|
||||
export { moduleSpecifiers };
|
||||
import * as performance from "./ts.performance.js";
|
||||
export { performance };
|
||||
/** @internal */
|
||||
import * as ast from "./ts.ast.js";
|
||||
/** @internal */
|
||||
export { ast };
|
||||
+1429
-11408
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,7 @@ import {
|
||||
AstExpressionStatement,
|
||||
AstExpressionWithTypeArguments,
|
||||
AstExternalModuleReference,
|
||||
AstForEachChildNodes,
|
||||
AstForInStatement,
|
||||
AstForOfStatement,
|
||||
AstForStatement,
|
||||
@@ -174,12 +175,8 @@ import {
|
||||
AstWhileStatement,
|
||||
AstWithStatement,
|
||||
AstYieldExpression,
|
||||
AstForEachChildNodes
|
||||
} from "./_namespaces/ts.ast.js";
|
||||
import {
|
||||
forEach,
|
||||
SyntaxKind,
|
||||
isArray,
|
||||
} from "./_namespaces/ts.js";
|
||||
|
||||
function visitNode<T>(cbNode: (node: AstNode) => T, node: AstNode | undefined): T | undefined {
|
||||
|
||||
@@ -120,6 +120,7 @@ import {
|
||||
HasFlowNode,
|
||||
hasJSDocNodes,
|
||||
HasLocals,
|
||||
hasName,
|
||||
hasSyntacticModifier,
|
||||
Identifier,
|
||||
identifierToKeywordKind,
|
||||
@@ -1012,7 +1013,8 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
||||
const isImmediatelyInvoked = (
|
||||
containerFlags & ContainerFlags.IsFunctionExpression &&
|
||||
!hasSyntacticModifier(node, ModifierFlags.Async) &&
|
||||
!(node as FunctionLikeDeclaration).asteriskToken &&
|
||||
// TODO(rbuckton): unchecked cast can result in wrong map deopt due to missing `asteriskToken` property
|
||||
!(node as Extract<FunctionLikeDeclaration, { asteriskToken: any }>).asteriskToken &&
|
||||
!!getImmediatelyInvokedFunctionExpression(node)
|
||||
) || node.kind === SyntaxKind.ClassStaticBlockDeclaration;
|
||||
// A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
|
||||
@@ -2646,7 +2648,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
||||
function checkStrictModeFunctionName(node: FunctionLikeDeclaration) {
|
||||
if (inStrictMode && !(node.flags & NodeFlags.Ambient)) {
|
||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
|
||||
checkStrictModeEvalOrArguments(node, node.name);
|
||||
checkStrictModeEvalOrArguments(node, isNamedDeclaration(node) ? node.name : undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3720,7 +3722,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
||||
node.flowNode = currentFlow;
|
||||
}
|
||||
checkStrictModeFunctionName(node);
|
||||
const bindingName = node.name ? node.name.escapedText : InternalSymbolName.Function;
|
||||
const bindingName = hasName(node) ? node.name.escapedText : InternalSymbolName.Function;
|
||||
return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName);
|
||||
}
|
||||
|
||||
|
||||
+29
-22
@@ -1065,7 +1065,7 @@ import {
|
||||
TupleTypeReference,
|
||||
Type,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeChecker,
|
||||
TypeCheckerHost,
|
||||
TypeComparer,
|
||||
@@ -1121,6 +1121,10 @@ import {
|
||||
WideningContext,
|
||||
WithStatement,
|
||||
YieldExpression,
|
||||
canHaveName,
|
||||
hasName,
|
||||
canHaveQuestionToken,
|
||||
hasAsteriskToken,
|
||||
} from "./_namespaces/ts.js";
|
||||
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js";
|
||||
import * as performance from "./_namespaces/ts.performance.js";
|
||||
@@ -14639,7 +14643,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
function isTypeInvalidDueToUnionDiscriminant(contextualType: Type, obj: ObjectLiteralExpression | JsxAttributes): boolean {
|
||||
const list = obj.properties as NodeArray<ObjectLiteralElementLike | JsxAttributeLike>;
|
||||
return list.some(property => {
|
||||
const nameType = property.name && (isJsxNamespacedName(property.name) ? getStringLiteralType(getTextOfJsxAttributeName(property.name)) : getLiteralTypeFromPropertyName(property.name));
|
||||
const nameType = !isSpreadAssignment(property) && !isJsxSpreadAttribute(property) && (isJsxNamespacedName(property.name) ? getStringLiteralType(getTextOfJsxAttributeName(property.name)) : getLiteralTypeFromPropertyName(property.name));
|
||||
const name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
|
||||
const expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
|
||||
return !!expected && isLiteralType(expected) && !isTypeAssignableTo(getTypeOfNode(property), expected);
|
||||
@@ -22477,8 +22481,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration) && getSourceFileOfNode(objectLiteralDeclaration) === getSourceFileOfNode(errorNode)) {
|
||||
const propDeclaration = prop.valueDeclaration as ObjectLiteralElementLike;
|
||||
Debug.assertNode(propDeclaration, isObjectLiteralElementLike);
|
||||
Debug.assertNotNode(propDeclaration, isSpreadAssignment);
|
||||
Debug.assertNotNode(propDeclaration, isJsxSpreadAttribute);
|
||||
|
||||
const name = propDeclaration.name!;
|
||||
const name = propDeclaration.name;
|
||||
errorNode = name;
|
||||
|
||||
if (isIdentifier(name)) {
|
||||
@@ -31852,7 +31858,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (element.name) {
|
||||
if (!isSpreadAssignment(element) && !isJsxSpreadAttribute(element)) {
|
||||
const nameType = getLiteralTypeFromPropertyName(element.name);
|
||||
// We avoid calling getApplicableIndexInfo here because it performs potentially expensive intersection reduction.
|
||||
return mapType(type, t => findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType)?.type, /*noReductions*/ true);
|
||||
@@ -32847,7 +32853,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// As otherwise they may not be checked until exports for the type at this position are retrieved,
|
||||
// which may never occur.
|
||||
for (const elem of node.properties) {
|
||||
if (elem.name && isComputedPropertyName(elem.name)) {
|
||||
if (canHaveName(elem) && isComputedPropertyName(elem.name)) {
|
||||
checkComputedPropertyName(elem.name);
|
||||
}
|
||||
}
|
||||
@@ -32855,7 +32861,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
let offset = 0;
|
||||
for (const memberDecl of node.properties) {
|
||||
let member = getSymbolOfDeclaration(memberDecl);
|
||||
const computedNameType = memberDecl.name && memberDecl.name.kind === SyntaxKind.ComputedPropertyName ?
|
||||
const computedNameType = canHaveName(memberDecl) && memberDecl.name.kind === SyntaxKind.ComputedPropertyName ?
|
||||
checkComputedPropertyName(memberDecl.name) : undefined;
|
||||
if (
|
||||
memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
||||
@@ -34980,9 +34986,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// If the template didn't end in a backtick, or its beginning occurred right prior to EOF,
|
||||
// then this might actually turn out to be a TemplateHead in the future;
|
||||
// so we consider the call to be incomplete.
|
||||
const templateLiteral = node.template as LiteralExpression;
|
||||
Debug.assert(templateLiteral.kind === SyntaxKind.NoSubstitutionTemplateLiteral);
|
||||
callIsIncomplete = !!templateLiteral.isUnterminated;
|
||||
Debug.assert(node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral);
|
||||
callIsIncomplete = !!node.template.isUnterminated;
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.Decorator) {
|
||||
@@ -37989,9 +37994,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
function createClassMemberDecoratorContextTypeForNode(node: MethodDeclaration | AccessorDeclaration | PropertyDeclaration, thisType: Type, valueType: Type) {
|
||||
const name = node.name;
|
||||
const isStatic = hasStaticModifier(node);
|
||||
const isPrivate = isPrivateIdentifier(node.name);
|
||||
const nameType = isPrivate ? getStringLiteralType(idText(node.name)) : getLiteralTypeFromPropertyName(node.name);
|
||||
const isPrivate = isPrivateIdentifier(name);
|
||||
const nameType = isPrivate ? getStringLiteralType(idText(name)) : getLiteralTypeFromPropertyName(name);
|
||||
const contextType = isMethodDeclaration(node) ? createClassMethodDecoratorContextType(thisType, valueType) :
|
||||
isGetAccessorDeclaration(node) ? createClassGetterDecoratorContextType(thisType, valueType) :
|
||||
isSetAccessorDeclaration(node) ? createClassSetterDecoratorContextType(thisType, valueType) :
|
||||
@@ -40901,7 +40907,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
getReturnTypeOfSingleNonGenericCallSignature(checkNonNullExpression(expr.expression));
|
||||
}
|
||||
else if (isAssertionExpression(expr) && !isConstTypeReference(expr.type)) {
|
||||
return getTypeFromTypeNode((expr as TypeAssertion).type);
|
||||
return getTypeFromTypeNode((expr as TypeAssertionExpression).type);
|
||||
}
|
||||
else if (isLiteralExpression(node) || isBooleanLiteral(node)) {
|
||||
return checkExpression(node);
|
||||
@@ -42241,7 +42247,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0;
|
||||
|
||||
function reportImplementationExpectedError(node: SignatureDeclaration): void {
|
||||
if (node.name && nodeIsMissing(node.name)) {
|
||||
if (canHaveName(node) && node.name && nodeIsMissing(node.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -42258,10 +42264,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// In this case the subsequent node is not really consecutive (.pos !== node.end), and we must ignore it here.
|
||||
if (subsequentNode && subsequentNode.pos === node.end) {
|
||||
if (subsequentNode.kind === node.kind) {
|
||||
const errorNode: Node = (subsequentNode as FunctionLikeDeclaration).name || subsequentNode;
|
||||
const subsequentName = (subsequentNode as FunctionLikeDeclaration).name;
|
||||
const subsequentName = tryCast(subsequentNode, canHaveName)?.name;
|
||||
const errorNode: Node = subsequentName ?? subsequentNode;
|
||||
if (
|
||||
node.name && subsequentName && (
|
||||
hasName(node) && subsequentName && (
|
||||
// both are private identifiers
|
||||
isPrivateIdentifier(node.name) && isPrivateIdentifier(subsequentName) && node.name.escapedText === subsequentName.escapedText ||
|
||||
// Both are computed property names
|
||||
@@ -42284,12 +42290,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return;
|
||||
}
|
||||
if (nodeIsPresent((subsequentNode as FunctionLikeDeclaration).body)) {
|
||||
error(errorNode, Diagnostics.Function_implementation_name_must_be_0, declarationNameToString(node.name));
|
||||
error(errorNode, Diagnostics.Function_implementation_name_must_be_0, declarationNameToString(canHaveName(node) ? node.name : undefined));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
const errorNode: Node = node.name || node;
|
||||
const errorNode: Node = tryCast(node, canHaveName)?.name ?? node;
|
||||
if (isConstructor) {
|
||||
error(errorNode, Diagnostics.Constructor_implementation_is_missing);
|
||||
}
|
||||
@@ -42405,7 +42411,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// Abstract methods can't have an implementation -- in particular, they don't need one.
|
||||
if (
|
||||
lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
|
||||
!hasSyntacticModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken
|
||||
!hasSyntacticModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) &&
|
||||
!(canHaveQuestionToken(lastSeenNonAmbientDeclaration) && lastSeenNonAmbientDeclaration.questionToken)
|
||||
) {
|
||||
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
|
||||
}
|
||||
@@ -44221,7 +44228,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// Don't validate for-in initializer as it is already an error
|
||||
const widenedType = getWidenedTypeForVariableLikeDeclaration(node);
|
||||
if (needCheckInitializer) {
|
||||
const initializerType = checkExpressionCached(node.initializer);
|
||||
const initializerType = checkExpressionCached(node.initializer!);
|
||||
if (strictNullChecks && needCheckWidenedType) {
|
||||
checkNonNullNonVoidType(initializerType, node);
|
||||
}
|
||||
@@ -47634,7 +47641,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
|
||||
const validForTypeAttributes = isExclusivelyTypeOnlyImportOrExport(declaration);
|
||||
const override = getResolutionModeOverride(node, validForTypeAttributes ? grammarErrorOnNode : undefined);
|
||||
const isImportAttributes = declaration.attributes.token === SyntaxKind.WithKeyword;
|
||||
const isImportAttributes = node.token === SyntaxKind.WithKeyword;
|
||||
if (validForTypeAttributes && override) {
|
||||
return; // Other grammar checks do not apply to type-only imports with resolution mode assertions
|
||||
}
|
||||
@@ -51477,7 +51484,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
function checkGrammarForGenerator(node: FunctionLikeDeclaration) {
|
||||
if (node.asteriskToken) {
|
||||
if (hasAsteriskToken(node)) {
|
||||
Debug.assert(
|
||||
node.kind === SyntaxKind.FunctionDeclaration ||
|
||||
node.kind === SyntaxKind.FunctionExpression ||
|
||||
|
||||
@@ -401,7 +401,7 @@ import {
|
||||
TryStatement,
|
||||
TupleTypeNode,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeLiteralNode,
|
||||
TypeNode,
|
||||
TypeOfExpression,
|
||||
@@ -1935,7 +1935,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
return emitTaggedTemplateExpression(node as TaggedTemplateExpression);
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return emitTypeAssertionExpression(node as TypeAssertion);
|
||||
return emitTypeAssertionExpression(node as TypeAssertionExpression);
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return emitParenthesizedExpression(node as ParenthesizedExpression);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
@@ -2718,7 +2718,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
emitExpression(node.template);
|
||||
}
|
||||
|
||||
function emitTypeAssertionExpression(node: TypeAssertion) {
|
||||
function emitTypeAssertionExpression(node: TypeAssertionExpression) {
|
||||
writePunctuation("<");
|
||||
emit(node.type);
|
||||
writePunctuation(">");
|
||||
|
||||
@@ -59,7 +59,7 @@ import {
|
||||
SyntacticTypeNodeBuilderContext,
|
||||
SyntacticTypeNodeBuilderResolver,
|
||||
SyntaxKind,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeNode,
|
||||
TypeParameterDeclaration,
|
||||
UnionTypeNode,
|
||||
@@ -263,7 +263,7 @@ export function createSyntacticTypeNodeBuilder(
|
||||
return typeFromFunctionLikeExpression(node as ArrowFunction | FunctionExpression, context);
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.AsExpression:
|
||||
const asExpression = node as AsExpression | TypeAssertion;
|
||||
const asExpression = node as AsExpression | TypeAssertionExpression;
|
||||
return typeFromTypeAssertion(asExpression.expression, asExpression.type, context, requiresAddingUndefined);
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
const unaryExpression = node as PrefixUnaryExpression;
|
||||
|
||||
@@ -92,6 +92,7 @@ import {
|
||||
AstInferTypeNode,
|
||||
AstInterfaceDeclaration,
|
||||
AstIntersectionTypeNode,
|
||||
AstJSDoc,
|
||||
AstJSDocAllType,
|
||||
AstJSDocAugmentsTag,
|
||||
AstJSDocAuthorTag,
|
||||
@@ -111,7 +112,6 @@ import {
|
||||
AstJSDocNameReference,
|
||||
AstJSDocNamespaceBody,
|
||||
AstJSDocNamespaceDeclaration,
|
||||
AstJSDoc,
|
||||
AstJSDocNonNullableType,
|
||||
AstJSDocNullableType,
|
||||
AstJSDocOptionalType,
|
||||
@@ -277,7 +277,22 @@ import {
|
||||
AstWhileStatement,
|
||||
AstWithStatement,
|
||||
AstYieldExpression,
|
||||
BinaryOperator,
|
||||
cast,
|
||||
CharacterCodes,
|
||||
createAstParenthesizerRules,
|
||||
createScanner,
|
||||
Debug,
|
||||
EmitFlags,
|
||||
escapeLeadingUnderscores,
|
||||
FileReference,
|
||||
getCommentRange,
|
||||
getIdentifierAutoGenerate,
|
||||
getIdentifierTypeArguments,
|
||||
getSourceMapRange,
|
||||
getSyntheticLeadingComments,
|
||||
getSyntheticTrailingComments,
|
||||
identity,
|
||||
isAstBinaryExpression,
|
||||
isAstCallChain,
|
||||
isAstCommaListExpression,
|
||||
@@ -294,40 +309,22 @@ import {
|
||||
isAstPropertyAccessChain,
|
||||
isAstQuestionToken,
|
||||
isAstVariableDeclaration,
|
||||
LiteralToken,
|
||||
MetaProperty,
|
||||
Node,
|
||||
nullAstParenthesizerRules,
|
||||
SourceFile,
|
||||
} from "../_namespaces/ts.ast.js";
|
||||
import {
|
||||
BinaryOperator,
|
||||
cast,
|
||||
CharacterCodes,
|
||||
createScanner,
|
||||
Debug,
|
||||
EmitFlags,
|
||||
escapeLeadingUnderscores,
|
||||
FileReference,
|
||||
getCommentRange,
|
||||
getIdentifierAutoGenerate,
|
||||
getIdentifierTypeArguments,
|
||||
getSourceMapRange,
|
||||
getSyntheticLeadingComments,
|
||||
getSyntheticTrailingComments,
|
||||
identity,
|
||||
isParseTreeNode,
|
||||
KeywordSyntaxKind,
|
||||
KeywordTypeSyntaxKind,
|
||||
LanguageVariant,
|
||||
lastOrUndefined,
|
||||
LiteralToken,
|
||||
memoize,
|
||||
mergeEmitNode,
|
||||
MetaProperty,
|
||||
ModifierFlags,
|
||||
ModifierSyntaxKind,
|
||||
Node,
|
||||
NodeFactoryFlags,
|
||||
NodeFlags,
|
||||
nodeIsSynthesized,
|
||||
nullAstParenthesizerRules,
|
||||
OuterExpressionKinds,
|
||||
PostfixUnaryOperator,
|
||||
PrefixUnaryOperator,
|
||||
@@ -343,6 +340,7 @@ import {
|
||||
setIdentifierTypeArguments,
|
||||
setTextRange,
|
||||
some,
|
||||
SourceFile,
|
||||
startsWith,
|
||||
SyntaxKind,
|
||||
TokenFlags,
|
||||
|
||||
@@ -13,7 +13,9 @@ import {
|
||||
AstDeclareKeyword,
|
||||
AstElementAccessChain,
|
||||
AsteriskToken,
|
||||
AstHasDecorators,
|
||||
AstHasJSDoc,
|
||||
AstHasModifiers,
|
||||
AstLeftHandSideExpression,
|
||||
AstNode,
|
||||
AstNonNullChain,
|
||||
@@ -33,6 +35,7 @@ import {
|
||||
Bundle,
|
||||
CallExpression,
|
||||
CallSignatureDeclaration,
|
||||
canHaveJSDoc,
|
||||
CaseBlock,
|
||||
CaseClause,
|
||||
CaseKeyword,
|
||||
@@ -93,6 +96,8 @@ import {
|
||||
InferTypeNode,
|
||||
InterfaceDeclaration,
|
||||
IntersectionTypeNode,
|
||||
isLeftHandSideExpressionKind,
|
||||
JSDoc,
|
||||
JSDocAllType,
|
||||
JSDocAugmentsTag,
|
||||
JSDocAuthorTag,
|
||||
@@ -109,7 +114,6 @@ import {
|
||||
JSDocMemberName,
|
||||
JSDocNamepathType,
|
||||
JSDocNameReference,
|
||||
JSDoc,
|
||||
JSDocNonNullableType,
|
||||
JSDocNullableType,
|
||||
JSDocOptionalType,
|
||||
@@ -167,6 +171,7 @@ import {
|
||||
NamespaceImport,
|
||||
NewExpression,
|
||||
Node,
|
||||
NodeFlags,
|
||||
NonNullExpression,
|
||||
NoSubstitutionTemplateLiteral,
|
||||
NotEmittedStatement,
|
||||
@@ -175,6 +180,7 @@ import {
|
||||
ObjectLiteralExpression,
|
||||
OmittedExpression,
|
||||
OptionalTypeNode,
|
||||
OuterExpressionKinds,
|
||||
OverrideKeyword,
|
||||
ParameterDeclaration,
|
||||
ParenthesizedExpression,
|
||||
@@ -207,6 +213,7 @@ import {
|
||||
StringLiteral,
|
||||
SuperExpression,
|
||||
SwitchStatement,
|
||||
SyntaxKind,
|
||||
SyntaxList,
|
||||
SyntheticExpression,
|
||||
SyntheticReferenceExpression,
|
||||
@@ -224,7 +231,7 @@ import {
|
||||
TryStatement,
|
||||
TupleTypeNode,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeLiteralNode,
|
||||
TypeOfExpression,
|
||||
TypeOperatorNode,
|
||||
@@ -240,15 +247,6 @@ import {
|
||||
WhileStatement,
|
||||
WithStatement,
|
||||
YieldExpression,
|
||||
AstHasModifiers,
|
||||
AstHasDecorators,
|
||||
} from "../_namespaces/ts.ast.js";
|
||||
import {
|
||||
canHaveJSDoc,
|
||||
isLeftHandSideExpressionKind,
|
||||
NodeFlags,
|
||||
OuterExpressionKinds,
|
||||
SyntaxKind,
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
// Literals
|
||||
@@ -700,7 +698,7 @@ export function isAstTaggedTemplateExpression(node: AstNode): node is AstNode<Ta
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isAstTypeAssertionExpression(node: AstNode): node is AstNode<TypeAssertion> {
|
||||
export function isAstTypeAssertionExpression(node: AstNode): node is AstNode<TypeAssertionExpression> {
|
||||
return node.kind === SyntaxKind.TypeAssertionExpression;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,7 @@ import {
|
||||
isAstTypeOperatorNode,
|
||||
isAstUnionTypeNode,
|
||||
skipAstOuterExpressions,
|
||||
} from "../_namespaces/ts.ast.js";
|
||||
import {
|
||||
Associativity,
|
||||
ast,
|
||||
BinaryOperator,
|
||||
compareValues,
|
||||
Comparison,
|
||||
@@ -75,7 +72,7 @@ export interface AstParenthesizerRules {
|
||||
parenthesizeLeftSideOfAccess(expression: AstExpression, optionalChain?: boolean): AstLeftHandSideExpression;
|
||||
parenthesizeOperandOfPostfixUnary(operand: AstExpression): AstLeftHandSideExpression;
|
||||
parenthesizeOperandOfPrefixUnary(operand: AstExpression): AstUnaryExpression;
|
||||
parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike<AstExpression>): AstNodeArray<ast.AstExpression>;
|
||||
parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike<AstExpression>): AstNodeArray<AstExpression>;
|
||||
parenthesizeExpressionForDisallowedComma(expression: AstExpression): AstExpression;
|
||||
parenthesizeExpressionOfExpressionStatement(expression: AstExpression): AstExpression;
|
||||
parenthesizeConciseBodyOfArrowFunction(body: AstExpression): AstExpression;
|
||||
@@ -487,7 +484,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth
|
||||
emittedExpression,
|
||||
setTextRange(factory.createParenthesizedExpression(callee), callee),
|
||||
emittedExpression.data.typeArguments,
|
||||
emittedExpression.data.arguments!,
|
||||
emittedExpression.data.arguments,
|
||||
);
|
||||
return factory.restoreOuterExpressions(expression, updated, OuterExpressionKinds.PartiallyEmittedExpressions);
|
||||
}
|
||||
@@ -667,8 +664,8 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth
|
||||
if (isAstNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.data.type);
|
||||
if (isAstFunctionTypeNode(type) || isAstConstructorTypeNode(type) || isAstTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.data.type);
|
||||
if (isAstConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.data.falseType);
|
||||
if (isAstUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types!.items));
|
||||
if (isAstIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types!.items));
|
||||
if (isAstUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items));
|
||||
if (isAstIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items));
|
||||
if (isAstInferTypeNode(type)) return !!type.data.typeParameter.data.constraint && hasJSDocPostfixQuestion(type.data.typeParameter.data.constraint);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,16 @@ import {
|
||||
AccessExpression,
|
||||
append,
|
||||
appendIfUnique,
|
||||
ast,
|
||||
AstIdentifier,
|
||||
AstNode,
|
||||
AstPrivateIdentifier,
|
||||
AutoGenerateInfo,
|
||||
Debug,
|
||||
EmitFlags,
|
||||
EmitHelper,
|
||||
EmitNode,
|
||||
getAstParseTreeNode,
|
||||
getAstSourceFileNodeOfNode,
|
||||
getParseTreeNode,
|
||||
getSourceFileOfNode,
|
||||
Identifier,
|
||||
@@ -34,7 +38,7 @@ import {
|
||||
* various transient transformation properties.
|
||||
* @internal
|
||||
*/
|
||||
export function getOrCreateEmitNode(node: Node | ast.AstNode<ast.Node>): EmitNode {
|
||||
export function getOrCreateEmitNode(node: Node | AstNode): EmitNode {
|
||||
if (!node.emitNode) {
|
||||
if (isParseTreeNode(node)) {
|
||||
// To avoid holding onto transformation artifacts, we keep track of any
|
||||
@@ -44,8 +48,8 @@ export function getOrCreateEmitNode(node: Node | ast.AstNode<ast.Node>): EmitNod
|
||||
return node.emitNode = { annotatedNodes: [node] } as EmitNode;
|
||||
}
|
||||
|
||||
if (node instanceof ast.AstNode) {
|
||||
const sourceFile = ast.getAstSourceFileNodeOfNode(ast.getAstParseTreeNode(ast.getAstSourceFileNodeOfNode(node))) ?? Debug.fail("Could not determine parsed source file.");
|
||||
if (node instanceof AstNode) {
|
||||
const sourceFile = getAstSourceFileNodeOfNode(getAstParseTreeNode(getAstSourceFileNodeOfNode(node))) ?? Debug.fail("Could not determine parsed source file.");
|
||||
getOrCreateEmitNode(sourceFile).annotatedNodes!.push(node.node);
|
||||
}
|
||||
else {
|
||||
@@ -98,8 +102,8 @@ export function removeAllComments<T extends Node>(node: T): T {
|
||||
*/
|
||||
export function setEmitFlags<T extends Node>(node: T, emitFlags: EmitFlags): T;
|
||||
/** @internal */
|
||||
export function setEmitFlags<T extends Node | ast.AstNode<ast.Node>>(node: T, emitFlags: EmitFlags): T;
|
||||
export function setEmitFlags<T extends Node | ast.AstNode<ast.Node>>(node: T, emitFlags: EmitFlags) {
|
||||
export function setEmitFlags<T extends Node | AstNode>(node: T, emitFlags: EmitFlags): T;
|
||||
export function setEmitFlags<T extends Node | AstNode>(node: T, emitFlags: EmitFlags) {
|
||||
getOrCreateEmitNode(node).flags = emitFlags;
|
||||
return node;
|
||||
}
|
||||
@@ -141,8 +145,8 @@ export function addInternalEmitFlags<T extends Node>(node: T, emitFlags: Interna
|
||||
*/
|
||||
export function getSourceMapRange(node: Node): SourceMapRange;
|
||||
/** @internal */
|
||||
export function getSourceMapRange(node: Node | ast.AstNode): SourceMapRange; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getSourceMapRange(node: Node | ast.AstNode): SourceMapRange {
|
||||
export function getSourceMapRange(node: Node | AstNode): SourceMapRange; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getSourceMapRange(node: Node | AstNode): SourceMapRange {
|
||||
return node.emitNode?.sourceMapRange ?? node;
|
||||
}
|
||||
|
||||
@@ -195,8 +199,8 @@ export function setStartsOnNewLine<T extends Node>(node: T, newLine: boolean): T
|
||||
*/
|
||||
export function getCommentRange(node: Node): TextRange;
|
||||
/** @internal */
|
||||
export function getCommentRange(node: Node | ast.AstNode): TextRange; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getCommentRange(node: Node | ast.AstNode): TextRange {
|
||||
export function getCommentRange(node: Node | AstNode): TextRange; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getCommentRange(node: Node | AstNode): TextRange {
|
||||
return node.emitNode?.commentRange ?? node;
|
||||
}
|
||||
|
||||
@@ -210,8 +214,8 @@ export function setCommentRange<T extends Node>(node: T, range: TextRange): T {
|
||||
|
||||
export function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined;
|
||||
/** @internal */
|
||||
export function getSyntheticLeadingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getSyntheticLeadingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined {
|
||||
export function getSyntheticLeadingComments(node: Node | AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getSyntheticLeadingComments(node: Node | AstNode): SynthesizedComment[] | undefined {
|
||||
return node.emitNode?.leadingComments;
|
||||
}
|
||||
|
||||
@@ -226,8 +230,8 @@ export function addSyntheticLeadingComment<T extends Node>(node: T, kind: Syntax
|
||||
|
||||
export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined;
|
||||
/** @internal */
|
||||
export function getSyntheticTrailingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getSyntheticTrailingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined {
|
||||
export function getSyntheticTrailingComments(node: Node | AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function getSyntheticTrailingComments(node: Node | AstNode): SynthesizedComment[] | undefined {
|
||||
return node.emitNode?.trailingComments;
|
||||
}
|
||||
|
||||
@@ -370,24 +374,24 @@ export function getTypeNode<T extends Node>(node: T): TypeNode | undefined {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function setIdentifierTypeArguments<T extends Identifier | ast.AstIdentifier>(node: T, typeArguments: NodeArray<TypeNode | TypeParameterDeclaration> | undefined): T {
|
||||
export function setIdentifierTypeArguments<T extends Identifier | AstIdentifier>(node: T, typeArguments: NodeArray<TypeNode | TypeParameterDeclaration> | undefined): T {
|
||||
getOrCreateEmitNode(node).identifierTypeArguments = typeArguments;
|
||||
return node;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getIdentifierTypeArguments(node: Identifier | ast.AstIdentifier): NodeArray<TypeNode | TypeParameterDeclaration> | undefined {
|
||||
export function getIdentifierTypeArguments(node: Identifier | AstIdentifier): NodeArray<TypeNode | TypeParameterDeclaration> | undefined {
|
||||
return node.emitNode?.identifierTypeArguments;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function setIdentifierAutoGenerate<T extends Identifier | PrivateIdentifier | ast.AstIdentifier | ast.AstPrivateIdentifier>(node: T, autoGenerate: AutoGenerateInfo | undefined): T {
|
||||
export function setIdentifierAutoGenerate<T extends Identifier | PrivateIdentifier | AstIdentifier | AstPrivateIdentifier>(node: T, autoGenerate: AutoGenerateInfo | undefined): T {
|
||||
getOrCreateEmitNode(node).autoGenerate = autoGenerate;
|
||||
return node;
|
||||
}
|
||||
|
||||
/** @internal @knipignore */
|
||||
export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier | ast.AstIdentifier | ast.AstPrivateIdentifier): AutoGenerateInfo | undefined {
|
||||
export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier | AstIdentifier | AstPrivateIdentifier): AutoGenerateInfo | undefined {
|
||||
return node.emitNode?.autoGenerate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
import {
|
||||
AstNode,
|
||||
createScanner,
|
||||
Debug,
|
||||
emptyArray,
|
||||
forEach,
|
||||
forEachChild,
|
||||
getSourceFileOfNode,
|
||||
hasTabstop,
|
||||
isJSDocCommentContainingNode,
|
||||
isNodeKind,
|
||||
isTokenKind,
|
||||
JSDocContainer,
|
||||
Node,
|
||||
NodeArray,
|
||||
NodeFlags,
|
||||
Scanner,
|
||||
ScriptTarget,
|
||||
SourceFileLike,
|
||||
SyntaxKind,
|
||||
SyntaxList,
|
||||
TokenSyntaxKind,
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
const sourceFileToNodeChildren = new WeakMap<SourceFileLike, WeakMap<Node, readonly Node[] | undefined>>();
|
||||
@@ -59,3 +73,96 @@ export function transferSourceFileChildren(sourceFile: SourceFileLike, targetSou
|
||||
sourceFileToNodeChildren.set(targetSourceFile, map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// copied form services/services.ts
|
||||
let _scanner: Scanner | undefined;
|
||||
|
||||
function scanner() {
|
||||
_scanner ??= createScanner(ScriptTarget.Latest, /*skipTrivia*/ true);
|
||||
return _scanner;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function createChildren(node: Node, sourceFile: SourceFileLike | undefined): readonly Node[] {
|
||||
const children: Node[] = [];
|
||||
|
||||
if (isJSDocCommentContainingNode(node)) {
|
||||
/** Don't add trivia for "tokens" since this is in a comment. */
|
||||
forEachChild(node, child => {
|
||||
children.push(child);
|
||||
});
|
||||
return children;
|
||||
}
|
||||
|
||||
scanner().setText((sourceFile || getSourceFileOfNode(node)).text);
|
||||
let pos = node.pos;
|
||||
const processNode = (child: Node) => {
|
||||
addSyntheticNodes(children, pos, child.pos, node);
|
||||
children.push(child);
|
||||
pos = child.end;
|
||||
};
|
||||
const processNodes = (nodes: NodeArray<Node>) => {
|
||||
addSyntheticNodes(children, pos, nodes.pos, node);
|
||||
children.push(createSyntaxList(nodes, node));
|
||||
pos = nodes.end;
|
||||
};
|
||||
// jsDocComments need to be the first children
|
||||
forEach((node as JSDocContainer).jsDoc, processNode);
|
||||
// For syntactic classifications, all trivia are classified together, including jsdoc comments.
|
||||
// For that to work, the jsdoc comments should still be the leading trivia of the first child.
|
||||
// Restoring the scanner position ensures that.
|
||||
pos = node.pos;
|
||||
forEachChild(node, processNode, processNodes);
|
||||
addSyntheticNodes(children, pos, node.end, node);
|
||||
scanner().setText(undefined);
|
||||
return children;
|
||||
}
|
||||
|
||||
function createNode<TKind extends TokenSyntaxKind>(kind: TKind, pos: number, end: number, parent: Node): Node {
|
||||
const astNode = kind === SyntaxKind.StringLiteral ? AstNode.StringLiteral() : AstNode.Token(kind);
|
||||
astNode.pos = pos;
|
||||
astNode.end = end;
|
||||
astNode.parent = parent.ast;
|
||||
astNode.flags = parent.flags & NodeFlags.ContextFlags;
|
||||
return astNode.node;
|
||||
}
|
||||
|
||||
function addSyntheticNodes(nodes: Node[], pos: number, end: number, parent: Node): void {
|
||||
scanner().resetTokenState(pos);
|
||||
while (pos < end) {
|
||||
const token = scanner().scan();
|
||||
const textPos = scanner().getTokenEnd();
|
||||
if (textPos <= end) {
|
||||
Debug.assert(isTokenKind(token));
|
||||
if (token === SyntaxKind.Identifier) {
|
||||
if (hasTabstop(parent)) {
|
||||
continue;
|
||||
}
|
||||
Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent.kind)} to have an ${Debug.formatSyntaxKind(token)} in its trivia`);
|
||||
}
|
||||
nodes.push(createNode(token as TokenSyntaxKind, pos, textPos, parent));
|
||||
}
|
||||
pos = textPos;
|
||||
if (token === SyntaxKind.EndOfFileToken) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createSyntaxList(nodes: NodeArray<Node>, parent: Node): Node {
|
||||
const list = AstNode.SyntaxList();
|
||||
list.pos = nodes.pos;
|
||||
list.end = nodes.end;
|
||||
list.parent = parent.ast;
|
||||
const children: Node[] = [];
|
||||
let pos = nodes.pos;
|
||||
for (const node of nodes) {
|
||||
addSyntheticNodes(children, pos, node.pos, parent);
|
||||
children.push(node);
|
||||
pos = node.end;
|
||||
}
|
||||
addSyntheticNodes(children, pos, nodes.end, parent);
|
||||
list.data._children = children;
|
||||
return list.node;
|
||||
}
|
||||
|
||||
+369
-394
File diff suppressed because it is too large
Load Diff
@@ -212,7 +212,7 @@ import {
|
||||
TryStatement,
|
||||
TupleTypeNode,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeLiteralNode,
|
||||
TypeOfExpression,
|
||||
TypeOperatorNode,
|
||||
@@ -601,7 +601,7 @@ export function isTaggedTemplateExpression(node: Node): node is TaggedTemplateEx
|
||||
return node.kind === SyntaxKind.TaggedTemplateExpression;
|
||||
}
|
||||
|
||||
export function isTypeAssertionExpression(node: Node): node is TypeAssertion {
|
||||
export function isTypeAssertionExpression(node: Node): node is TypeAssertionExpression {
|
||||
return node.kind === SyntaxKind.TypeAssertionExpression;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,21 @@
|
||||
import {
|
||||
ast,
|
||||
BinaryOperator,
|
||||
CallChain,
|
||||
cast,
|
||||
ClassElement,
|
||||
ConciseBody,
|
||||
ElementAccessChain,
|
||||
Expression,
|
||||
identity,
|
||||
isLeftHandSideExpression,
|
||||
isNodeArray,
|
||||
isUnaryExpression,
|
||||
JSDocClassReference,
|
||||
JSDocNamespaceDeclaration,
|
||||
JSDocPropertyLikeTag,
|
||||
JsxNamespacedName,
|
||||
LeftHandSideExpression,
|
||||
LiteralExpression,
|
||||
ModuleBody,
|
||||
NamedTupleMember,
|
||||
Node,
|
||||
NodeArray,
|
||||
NodeFactory,
|
||||
NonNullChain,
|
||||
ObjectLiteralElement,
|
||||
ParenthesizerRules,
|
||||
PropertyAccessChain,
|
||||
Statement,
|
||||
SyntaxKind,
|
||||
TypeElement,
|
||||
TypeNode,
|
||||
UnaryExpression,
|
||||
UnaryExpression
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
/** @internal */
|
||||
@@ -94,43 +79,43 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul
|
||||
}
|
||||
|
||||
function parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression): Expression {
|
||||
return astRules.parenthesizeLeftSideOfBinary(binaryOperator, asNode(leftSide).ast).node;
|
||||
return astRules.parenthesizeLeftSideOfBinary(binaryOperator, leftSide.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression | undefined, rightSide: Expression): Expression {
|
||||
return astRules.parenthesizeRightSideOfBinary(binaryOperator, asNode(leftSide)?.ast, asNode(rightSide).ast).node;
|
||||
return astRules.parenthesizeRightSideOfBinary(binaryOperator, leftSide?.ast, rightSide.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeExpressionOfComputedPropertyName(expression: Expression): Expression {
|
||||
return astRules.parenthesizeExpressionOfComputedPropertyName(asNode(expression).ast).node;
|
||||
return astRules.parenthesizeExpressionOfComputedPropertyName(expression.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeConditionOfConditionalExpression(condition: Expression): Expression {
|
||||
return astRules.parenthesizeConditionOfConditionalExpression(asNode(condition).ast).node;
|
||||
return astRules.parenthesizeConditionOfConditionalExpression(condition.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeBranchOfConditionalExpression(branch: Expression): Expression {
|
||||
return astRules.parenthesizeBranchOfConditionalExpression(asNode(branch).ast).node;
|
||||
return astRules.parenthesizeBranchOfConditionalExpression(branch.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeExpressionOfExportDefault(expression: Expression): Expression {
|
||||
return astRules.parenthesizeExpressionOfExportDefault(asNode(expression).ast).node;
|
||||
return astRules.parenthesizeExpressionOfExportDefault(expression.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeExpressionOfNew(expression: Expression): LeftHandSideExpression {
|
||||
return astRules.parenthesizeExpressionOfNew(asNode(expression).ast).node;
|
||||
return astRules.parenthesizeExpressionOfNew(expression.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeLeftSideOfAccess(expression: Expression, optionalChain?: boolean): LeftHandSideExpression {
|
||||
return astRules.parenthesizeLeftSideOfAccess(asNode(expression).ast, optionalChain).node;
|
||||
return astRules.parenthesizeLeftSideOfAccess(expression.ast, optionalChain).node;
|
||||
}
|
||||
|
||||
function parenthesizeOperandOfPostfixUnary(operand: Expression): LeftHandSideExpression {
|
||||
return astRules.parenthesizeOperandOfPostfixUnary(asNode(operand).ast).node;
|
||||
return astRules.parenthesizeOperandOfPostfixUnary(operand.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeOperandOfPrefixUnary(operand: Expression): UnaryExpression {
|
||||
return astRules.parenthesizeOperandOfPrefixUnary(asNode(operand).ast).node;
|
||||
return astRules.parenthesizeOperandOfPrefixUnary(operand.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeExpressionsOfCommaDelimitedList(elements: NodeArray<Expression>): NodeArray<Expression> {
|
||||
@@ -138,29 +123,29 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul
|
||||
}
|
||||
|
||||
function parenthesizeExpressionForDisallowedComma(expression: Expression): Expression {
|
||||
return astRules.parenthesizeExpressionForDisallowedComma(asNode(expression).ast).node;
|
||||
return astRules.parenthesizeExpressionForDisallowedComma(expression.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeExpressionOfExpressionStatement(expression: Expression): Expression {
|
||||
return astRules.parenthesizeExpressionOfExpressionStatement(asNode(expression).ast).node;
|
||||
return astRules.parenthesizeExpressionOfExpressionStatement(expression.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeConciseBodyOfArrowFunction(body: Expression): Expression;
|
||||
function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody;
|
||||
function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody {
|
||||
return astRules.parenthesizeConciseBodyOfArrowFunction(asNode(body).ast).node;
|
||||
return astRules.parenthesizeConciseBodyOfArrowFunction(body.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeCheckTypeOfConditionalType(checkType: TypeNode): TypeNode {
|
||||
return astRules.parenthesizeCheckTypeOfConditionalType(asNode(checkType).ast).node;
|
||||
return astRules.parenthesizeCheckTypeOfConditionalType(checkType.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeExtendsTypeOfConditionalType(extendsType: TypeNode): TypeNode {
|
||||
return astRules.parenthesizeExtendsTypeOfConditionalType(asNode(extendsType).ast).node;
|
||||
return astRules.parenthesizeExtendsTypeOfConditionalType(extendsType.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeConstituentTypeOfUnionType(type: TypeNode): TypeNode {
|
||||
return astRules.parenthesizeConstituentTypeOfUnionType(asNode(type).ast).node;
|
||||
return astRules.parenthesizeConstituentTypeOfUnionType(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeConstituentTypesOfUnionType(members: readonly TypeNode[]): NodeArray<TypeNode> {
|
||||
@@ -168,7 +153,7 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul
|
||||
}
|
||||
|
||||
function parenthesizeConstituentTypeOfIntersectionType(type: TypeNode): TypeNode {
|
||||
return astRules.parenthesizeConstituentTypeOfIntersectionType(asNode(type).ast).node;
|
||||
return astRules.parenthesizeConstituentTypeOfIntersectionType(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeConstituentTypesOfIntersectionType(members: readonly TypeNode[]): NodeArray<TypeNode> {
|
||||
@@ -176,15 +161,15 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul
|
||||
}
|
||||
|
||||
function parenthesizeOperandOfTypeOperator(type: TypeNode) {
|
||||
return astRules.parenthesizeOperandOfTypeOperator(asNode(type).ast).node;
|
||||
return astRules.parenthesizeOperandOfTypeOperator(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeOperandOfReadonlyTypeOperator(type: TypeNode) {
|
||||
return astRules.parenthesizeOperandOfReadonlyTypeOperator(asNode(type).ast).node;
|
||||
return astRules.parenthesizeOperandOfReadonlyTypeOperator(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeNonArrayTypeOfPostfixType(type: TypeNode) {
|
||||
return astRules.parenthesizeNonArrayTypeOfPostfixType(asNode(type).ast).node;
|
||||
return astRules.parenthesizeNonArrayTypeOfPostfixType(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeElementTypesOfTupleType(types: readonly (TypeNode | NamedTupleMember)[]): NodeArray<TypeNode> {
|
||||
@@ -192,49 +177,25 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul
|
||||
}
|
||||
|
||||
function parenthesizeElementTypeOfTupleType(type: TypeNode | NamedTupleMember): TypeNode {
|
||||
return astRules.parenthesizeElementTypeOfTupleType(asNode(type).ast).node;
|
||||
return astRules.parenthesizeElementTypeOfTupleType(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeTypeOfOptionalType(type: TypeNode): TypeNode {
|
||||
return astRules.parenthesizeTypeOfOptionalType(asNode(type).ast).node;
|
||||
return astRules.parenthesizeTypeOfOptionalType(type.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeLeadingTypeArgument(node: TypeNode) {
|
||||
return astRules.parenthesizeLeadingTypeArgument(asNode(node).ast).node;
|
||||
return astRules.parenthesizeLeadingTypeArgument(node.ast).node;
|
||||
}
|
||||
|
||||
function parenthesizeTypeArguments(typeArguments: NodeArray<TypeNode> | undefined): NodeArray<TypeNode> | undefined {
|
||||
return astRules.parenthesizeTypeArguments(asNodeArray(typeArguments)?.ast)?.nodes;
|
||||
}
|
||||
|
||||
type ToNode<T extends Node> = Expression extends T ? ast.Expression :
|
||||
Statement extends T ? ast.Statement :
|
||||
TypeNode extends T ? ast.TypeNode :
|
||||
TypeElement extends T ? ast.TypeElement :
|
||||
ClassElement extends T ? ast.ClassElement :
|
||||
ObjectLiteralElement extends T ? ast.ObjectLiteralElement :
|
||||
PropertyAccessChain extends T ? ast.PropertyAccessChain :
|
||||
ElementAccessChain extends T ? ast.ElementAccessChain :
|
||||
CallChain extends T ? ast.CallChain :
|
||||
NonNullChain extends T ? ast.NonNullChain :
|
||||
ModuleBody extends T ? ast.ModuleBody :
|
||||
LiteralExpression extends T ? ast.LiteralExpression :
|
||||
JSDocNamespaceDeclaration extends T ? ast.JSDocNamespaceDeclaration :
|
||||
JSDocPropertyLikeTag extends T ? ast.JSDocPropertyLikeTag :
|
||||
JSDocClassReference extends T ? ast.JSDocClassReference :
|
||||
JsxNamespacedName extends T ? ast.JsxNamespacedName :
|
||||
ast.NodeType[T["kind"]];
|
||||
|
||||
function asNode<T extends Node>(node: T): ToNode<T>;
|
||||
function asNode<T extends Node>(node: T | undefined): ToNode<T> | undefined;
|
||||
function asNode(node: Node | undefined): ast.Node | undefined {
|
||||
return node as ast.Node | undefined;
|
||||
}
|
||||
|
||||
function asNodeArray<T extends Node>(array: readonly T[]): ast.NodeArray<ToNode<T>>;
|
||||
function asNodeArray<T extends Node>(array: readonly T[] | undefined): ast.NodeArray<ToNode<T>> | undefined;
|
||||
function asNodeArray(array: readonly Node[] | undefined): ast.NodeArray<ast.Node> | undefined {
|
||||
return array ? factory.createNodeArray(array) as ast.NodeArray<ast.Node> : undefined;
|
||||
function asNodeArray<T extends Node>(array: readonly T[]): NodeArray<T>;
|
||||
function asNodeArray<T extends Node>(array: readonly T[] | undefined): NodeArray<T> | undefined;
|
||||
function asNodeArray(array: readonly Node[] | undefined): NodeArray<Node> | undefined {
|
||||
return array ? factory.createNodeArray(array) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,6 @@ import {
|
||||
MethodDeclaration,
|
||||
MinusToken,
|
||||
Modifier,
|
||||
ModifiersArray,
|
||||
ModuleKind,
|
||||
ModuleName,
|
||||
MultiplicativeOperator,
|
||||
@@ -463,7 +462,7 @@ function createExpressionForMethodDeclaration(factory: NodeFactory, method: Meth
|
||||
|
||||
/** @internal */
|
||||
export function createExpressionForObjectLiteralElementLike(factory: NodeFactory, node: ObjectLiteralExpression, property: ObjectLiteralElementLike, receiver: Expression): Expression | undefined {
|
||||
if (property.name && isPrivateIdentifier(property.name)) {
|
||||
if (!isSpreadAssignment(property) && property.name && isPrivateIdentifier(property.name)) {
|
||||
Debug.failBadSyntaxKind(property.name, "Private identifiers are not allowed in object literals.");
|
||||
}
|
||||
switch (property.kind) {
|
||||
@@ -1048,10 +1047,13 @@ export function tryGetPropertyNameOfBindingOrAssignmentElement(bindingElement: B
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
// `a` in `({ ...a } = ...)`
|
||||
if (bindingElement.name && isPrivateIdentifier(bindingElement.name)) {
|
||||
return Debug.failBadSyntaxKind(bindingElement.name);
|
||||
if (isPropertyName(bindingElement.expression)) {
|
||||
if (isPrivateIdentifier(bindingElement.expression)) {
|
||||
return Debug.failBadSyntaxKind(bindingElement.expression);
|
||||
}
|
||||
return bindingElement.expression;
|
||||
}
|
||||
return bindingElement.name;
|
||||
break;
|
||||
}
|
||||
|
||||
const target = getTargetOfBindingOrAssignmentElement(bindingElement);
|
||||
@@ -1606,7 +1608,7 @@ export function formatGeneratedName(privateName: boolean, prefix: string | Gener
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function createAccessorPropertyBackingField(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, initializer: Expression | undefined): PropertyDeclaration {
|
||||
export function createAccessorPropertyBackingField(factory: NodeFactory, node: PropertyDeclaration, modifiers: NodeArray<Modifier> | undefined, initializer: Expression | undefined): PropertyDeclaration {
|
||||
return factory.updatePropertyDeclaration(
|
||||
node,
|
||||
modifiers,
|
||||
|
||||
@@ -162,7 +162,7 @@ import {
|
||||
TryStatement,
|
||||
TupleTypeNode,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeLiteralNode,
|
||||
TypeOfExpression,
|
||||
TypeOperatorNode,
|
||||
@@ -307,7 +307,6 @@ const forEachChildTable: ForEachChildTable = {
|
||||
},
|
||||
[SyntaxKind.Constructor]: function forEachChildInConstructor<T>(node: ConstructorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
|
||||
return visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, node.name) ||
|
||||
visitNodes(cbNode, cbNodes, node.typeParameters) ||
|
||||
visitNodes(cbNode, cbNodes, node.parameters) ||
|
||||
visitNode(cbNode, node.type) ||
|
||||
@@ -450,7 +449,7 @@ const forEachChildTable: ForEachChildTable = {
|
||||
visitNodes(cbNode, cbNodes, node.typeArguments) ||
|
||||
visitNode(cbNode, node.template);
|
||||
},
|
||||
[SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression<T>(node: TypeAssertion, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
|
||||
[SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression<T>(node: TypeAssertionExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
|
||||
return visitNode(cbNode, node.type) ||
|
||||
visitNode(cbNode, node.expression);
|
||||
},
|
||||
|
||||
@@ -100,6 +100,7 @@ import {
|
||||
NodeModulePathParts,
|
||||
normalizePath,
|
||||
PackageJsonPathFields,
|
||||
PartialSourceFile,
|
||||
pathContainsNodeModules,
|
||||
pathIsBareSpecifier,
|
||||
pathIsRelative,
|
||||
@@ -183,7 +184,7 @@ export function getModuleSpecifierPreferences(
|
||||
{ importModuleSpecifierPreference, importModuleSpecifierEnding, autoImportSpecifierExcludeRegexes }: UserPreferences,
|
||||
host: Pick<ModuleSpecifierResolutionHost, "getDefaultResolutionModeForFile">,
|
||||
compilerOptions: CompilerOptions,
|
||||
importingSourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat">,
|
||||
importingSourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">,
|
||||
oldImportSpecifier?: string,
|
||||
): ModuleSpecifierPreferences {
|
||||
const filePreferredEnding = getPreferredEnding();
|
||||
@@ -431,7 +432,7 @@ export function getModuleSpecifiersWithCacheInfo(
|
||||
|
||||
/** @internal */
|
||||
export function getLocalModuleSpecifierBetweenFileNames(
|
||||
importingFile: Pick<SourceFile, "fileName" | "impliedNodeFormat">,
|
||||
importingFile: PartialSourceFile<"impliedNodeFormat">,
|
||||
targetFileName: string,
|
||||
compilerOptions: CompilerOptions,
|
||||
host: ModuleSpecifierResolutionHost,
|
||||
@@ -1459,7 +1460,7 @@ function isPathRelativeToParent(path: string): boolean {
|
||||
return startsWith(path, "..");
|
||||
}
|
||||
|
||||
function getDefaultResolutionModeForFile(file: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, host: Pick<ModuleSpecifierResolutionHost, "getDefaultResolutionModeForFile">, compilerOptions: CompilerOptions) {
|
||||
function getDefaultResolutionModeForFile(file: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, host: Pick<ModuleSpecifierResolutionHost, "getDefaultResolutionModeForFile">, compilerOptions: CompilerOptions) {
|
||||
return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,613 @@
|
||||
import {
|
||||
ArrayBindingPattern,
|
||||
ArrayLiteralExpression,
|
||||
ArrayTypeNode,
|
||||
ArrowFunction,
|
||||
AsExpression,
|
||||
AstTokenData,
|
||||
AwaitExpression,
|
||||
BigIntLiteral,
|
||||
BinaryExpression,
|
||||
BindingElement,
|
||||
Block,
|
||||
BreakStatement,
|
||||
Bundle,
|
||||
CallExpression,
|
||||
CallSignatureDeclaration,
|
||||
CaseBlock,
|
||||
CaseClause,
|
||||
CatchClause,
|
||||
ClassDeclaration,
|
||||
ClassExpression,
|
||||
ClassStaticBlockDeclaration,
|
||||
CommaListExpression,
|
||||
ComputedPropertyName,
|
||||
ConditionalExpression,
|
||||
ConditionalTypeNode,
|
||||
ConstructorDeclaration,
|
||||
ConstructorTypeNode,
|
||||
ConstructSignatureDeclaration,
|
||||
ContinueStatement,
|
||||
DebuggerStatement,
|
||||
Decorator,
|
||||
DefaultClause,
|
||||
DeleteExpression,
|
||||
DoStatement,
|
||||
ElementAccessExpression,
|
||||
EmptyStatement,
|
||||
EndOfFileToken,
|
||||
EnumDeclaration,
|
||||
EnumMember,
|
||||
ExportAssignment,
|
||||
ExportDeclaration,
|
||||
ExportSpecifier,
|
||||
ExpressionStatement,
|
||||
ExpressionWithTypeArguments,
|
||||
ExternalModuleReference,
|
||||
FalseLiteral,
|
||||
ForInStatement,
|
||||
ForOfStatement,
|
||||
ForStatement,
|
||||
FunctionDeclaration,
|
||||
FunctionExpression,
|
||||
FunctionTypeNode,
|
||||
GetAccessorDeclaration,
|
||||
HasLocals,
|
||||
HasName,
|
||||
HeritageClause,
|
||||
Identifier,
|
||||
IfStatement,
|
||||
ImportAttribute,
|
||||
ImportClause,
|
||||
ImportDeclaration,
|
||||
ImportEqualsDeclaration,
|
||||
ImportExpression,
|
||||
ImportSpecifier,
|
||||
ImportTypeAssertionContainer,
|
||||
ImportTypeNode,
|
||||
IndexedAccessTypeNode,
|
||||
IndexSignatureDeclaration,
|
||||
InferTypeNode,
|
||||
InterfaceDeclaration,
|
||||
IntersectionTypeNode,
|
||||
IsFunctionLike,
|
||||
JSDoc,
|
||||
JSDocAllType,
|
||||
JSDocAugmentsTag,
|
||||
JSDocAuthorTag,
|
||||
JSDocCallbackTag,
|
||||
JSDocClassTag,
|
||||
JSDocDeprecatedTag,
|
||||
JSDocEnumTag,
|
||||
JSDocFunctionType,
|
||||
JSDocImplementsTag,
|
||||
JSDocImportTag,
|
||||
JSDocLink,
|
||||
JSDocLinkCode,
|
||||
JSDocLinkPlain,
|
||||
JSDocMemberName,
|
||||
JSDocNamepathType,
|
||||
JSDocNameReference,
|
||||
JSDocNonNullableType,
|
||||
JSDocNullableType,
|
||||
JSDocOptionalType,
|
||||
JSDocOverloadTag,
|
||||
JSDocOverrideTag,
|
||||
JSDocParameterTag,
|
||||
JSDocPrivateTag,
|
||||
JSDocPropertyTag,
|
||||
JSDocProtectedTag,
|
||||
JSDocPublicTag,
|
||||
JSDocReadonlyTag,
|
||||
JSDocReturnTag,
|
||||
JSDocSatisfiesTag,
|
||||
JSDocSeeTag,
|
||||
JSDocSignature,
|
||||
JSDocTemplateTag,
|
||||
JSDocText,
|
||||
JSDocThisTag,
|
||||
JSDocThrowsTag,
|
||||
JSDocTypedefTag,
|
||||
JSDocTypeExpression,
|
||||
JSDocTypeLiteral,
|
||||
JSDocTypeTag,
|
||||
JSDocUnknownTag,
|
||||
JSDocUnknownType,
|
||||
JSDocVariadicType,
|
||||
JsxAttribute,
|
||||
JsxAttributes,
|
||||
JsxClosingElement,
|
||||
JsxClosingFragment,
|
||||
JsxElement,
|
||||
JsxExpression,
|
||||
JsxFragment,
|
||||
JsxNamespacedName,
|
||||
JsxOpeningElement,
|
||||
JsxOpeningFragment,
|
||||
JsxSelfClosingElement,
|
||||
JsxSpreadAttribute,
|
||||
JsxText,
|
||||
LabeledStatement,
|
||||
LiteralTypeNode,
|
||||
MappedTypeNode,
|
||||
MetaProperty,
|
||||
MethodDeclaration,
|
||||
MethodSignature,
|
||||
MissingDeclaration,
|
||||
ModuleBlock,
|
||||
ModuleDeclaration,
|
||||
NamedExports,
|
||||
NamedImports,
|
||||
NamedTupleMember,
|
||||
NamespaceExport,
|
||||
NamespaceExportDeclaration,
|
||||
NamespaceImport,
|
||||
NewExpression,
|
||||
NonNullExpression,
|
||||
NoSubstitutionTemplateLiteral,
|
||||
NotEmittedStatement,
|
||||
NotEmittedTypeElement,
|
||||
NullLiteral,
|
||||
NumericLiteral,
|
||||
ObjectBindingPattern,
|
||||
ObjectLiteralExpression,
|
||||
OmittedExpression,
|
||||
OptionalTypeNode,
|
||||
ParameterDeclaration,
|
||||
ParenthesizedExpression,
|
||||
ParenthesizedTypeNode,
|
||||
PartiallyEmittedExpression,
|
||||
PostfixUnaryExpression,
|
||||
PrefixUnaryExpression,
|
||||
PrivateIdentifier,
|
||||
PropertyAccessExpression,
|
||||
PropertyAssignment,
|
||||
PropertyDeclaration,
|
||||
PropertySignature,
|
||||
QualifiedName,
|
||||
RegularExpressionLiteral,
|
||||
RestTypeNode,
|
||||
ReturnStatement,
|
||||
SatisfiesExpression,
|
||||
SemicolonClassElement,
|
||||
SetAccessorDeclaration,
|
||||
ShorthandPropertyAssignment,
|
||||
SourceFile,
|
||||
SpreadAssignment,
|
||||
SpreadElement,
|
||||
StringLiteral,
|
||||
SuperExpression,
|
||||
SwitchStatement,
|
||||
SyntaxKind,
|
||||
SyntaxList,
|
||||
SyntheticExpression,
|
||||
SyntheticReferenceExpression,
|
||||
TaggedTemplateExpression,
|
||||
TemplateExpression,
|
||||
TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail,
|
||||
ThisExpression,
|
||||
ThisTypeNode,
|
||||
ThrowStatement,
|
||||
Token,
|
||||
TrueLiteral,
|
||||
TryStatement,
|
||||
TupleTypeNode,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertionExpression,
|
||||
TypeLiteralNode,
|
||||
TypeOfExpression,
|
||||
TypeOperatorNode,
|
||||
TypeParameterDeclaration,
|
||||
TypePredicateNode,
|
||||
TypeQueryNode,
|
||||
TypeReferenceNode,
|
||||
UnionTypeNode,
|
||||
VariableDeclaration,
|
||||
VariableDeclarationList,
|
||||
VariableStatement,
|
||||
VoidExpression,
|
||||
WhileStatement,
|
||||
WithStatement,
|
||||
YieldExpression
|
||||
} from "./_namespaces/ts.js";
|
||||
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
type _ = [
|
||||
__Expect<IsFunctionLike, Extract<Nodes, { _signatureDeclarationBrand: any }>>,
|
||||
__Expect<Extract<Nodes, { _signatureDeclarationBrand: any }>, IsFunctionLike>,
|
||||
];
|
||||
}
|
||||
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
type _ = [
|
||||
__Expect<HasLocals, Extract<Nodes, { _localsContainerBrand: any }>>,
|
||||
__Expect<Extract<Nodes, { _localsContainerBrand: any }>, HasLocals>,
|
||||
];
|
||||
}
|
||||
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
type _ = [
|
||||
__Expect<HasName, Extract<Nodes, { name: any }>>,
|
||||
__Expect<Extract<Nodes, { name: any }>, HasName>,
|
||||
];
|
||||
}
|
||||
|
||||
// Registry
|
||||
|
||||
/**
|
||||
* A mapping of all `SyntaxKind` values to their associated `Node` subtypes.
|
||||
*/
|
||||
export interface NodeMap {
|
||||
[SyntaxKind.Unknown]: Token<SyntaxKind.Unknown, AstTokenData>;
|
||||
[SyntaxKind.EndOfFileToken]: EndOfFileToken;
|
||||
[SyntaxKind.SingleLineCommentTrivia]: Token<SyntaxKind.SingleLineCommentTrivia, AstTokenData>;
|
||||
[SyntaxKind.MultiLineCommentTrivia]: Token<SyntaxKind.MultiLineCommentTrivia, AstTokenData>;
|
||||
[SyntaxKind.NewLineTrivia]: Token<SyntaxKind.NewLineTrivia, AstTokenData>;
|
||||
[SyntaxKind.WhitespaceTrivia]: Token<SyntaxKind.WhitespaceTrivia, AstTokenData>;
|
||||
[SyntaxKind.ShebangTrivia]: Token<SyntaxKind.ShebangTrivia, AstTokenData>;
|
||||
[SyntaxKind.ConflictMarkerTrivia]: Token<SyntaxKind.ConflictMarkerTrivia, AstTokenData>;
|
||||
[SyntaxKind.NonTextFileMarkerTrivia]: never;
|
||||
[SyntaxKind.NumericLiteral]: NumericLiteral;
|
||||
[SyntaxKind.BigIntLiteral]: BigIntLiteral;
|
||||
[SyntaxKind.StringLiteral]: StringLiteral;
|
||||
[SyntaxKind.JsxText]: JsxText;
|
||||
[SyntaxKind.JsxTextAllWhiteSpaces]: never;
|
||||
[SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral;
|
||||
[SyntaxKind.NoSubstitutionTemplateLiteral]: NoSubstitutionTemplateLiteral;
|
||||
[SyntaxKind.TemplateHead]: TemplateHead;
|
||||
[SyntaxKind.TemplateMiddle]: TemplateMiddle;
|
||||
[SyntaxKind.TemplateTail]: TemplateTail;
|
||||
[SyntaxKind.OpenBraceToken]: Token<SyntaxKind.OpenBraceToken, AstTokenData>;
|
||||
[SyntaxKind.CloseBraceToken]: Token<SyntaxKind.CloseBraceToken, AstTokenData>;
|
||||
[SyntaxKind.OpenParenToken]: Token<SyntaxKind.OpenParenToken, AstTokenData>;
|
||||
[SyntaxKind.CloseParenToken]: Token<SyntaxKind.CloseParenToken, AstTokenData>;
|
||||
[SyntaxKind.OpenBracketToken]: Token<SyntaxKind.OpenBracketToken, AstTokenData>;
|
||||
[SyntaxKind.CloseBracketToken]: Token<SyntaxKind.CloseBracketToken, AstTokenData>;
|
||||
[SyntaxKind.DotToken]: Token<SyntaxKind.DotToken, AstTokenData>;
|
||||
[SyntaxKind.DotDotDotToken]: Token<SyntaxKind.DotDotDotToken, AstTokenData>;
|
||||
[SyntaxKind.SemicolonToken]: Token<SyntaxKind.SemicolonToken, AstTokenData>;
|
||||
[SyntaxKind.CommaToken]: Token<SyntaxKind.CommaToken, AstTokenData>;
|
||||
[SyntaxKind.QuestionDotToken]: Token<SyntaxKind.QuestionDotToken, AstTokenData>;
|
||||
[SyntaxKind.LessThanToken]: Token<SyntaxKind.LessThanToken, AstTokenData>;
|
||||
[SyntaxKind.LessThanSlashToken]: Token<SyntaxKind.LessThanSlashToken, AstTokenData>;
|
||||
[SyntaxKind.GreaterThanToken]: Token<SyntaxKind.GreaterThanToken, AstTokenData>;
|
||||
[SyntaxKind.LessThanEqualsToken]: Token<SyntaxKind.LessThanEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.GreaterThanEqualsToken]: Token<SyntaxKind.GreaterThanEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.EqualsEqualsToken]: Token<SyntaxKind.EqualsEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.ExclamationEqualsToken]: Token<SyntaxKind.ExclamationEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.EqualsEqualsEqualsToken]: Token<SyntaxKind.EqualsEqualsEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.ExclamationEqualsEqualsToken]: Token<SyntaxKind.ExclamationEqualsEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.EqualsGreaterThanToken]: Token<SyntaxKind.EqualsGreaterThanToken, AstTokenData>;
|
||||
[SyntaxKind.PlusToken]: Token<SyntaxKind.PlusToken, AstTokenData>;
|
||||
[SyntaxKind.MinusToken]: Token<SyntaxKind.MinusToken, AstTokenData>;
|
||||
[SyntaxKind.AsteriskToken]: Token<SyntaxKind.AsteriskToken, AstTokenData>;
|
||||
[SyntaxKind.AsteriskAsteriskToken]: Token<SyntaxKind.AsteriskAsteriskToken, AstTokenData>;
|
||||
[SyntaxKind.SlashToken]: Token<SyntaxKind.SlashToken, AstTokenData>;
|
||||
[SyntaxKind.PercentToken]: Token<SyntaxKind.PercentToken, AstTokenData>;
|
||||
[SyntaxKind.PlusPlusToken]: Token<SyntaxKind.PlusPlusToken, AstTokenData>;
|
||||
[SyntaxKind.MinusMinusToken]: Token<SyntaxKind.MinusMinusToken, AstTokenData>;
|
||||
[SyntaxKind.LessThanLessThanToken]: Token<SyntaxKind.LessThanLessThanToken, AstTokenData>;
|
||||
[SyntaxKind.GreaterThanGreaterThanToken]: Token<SyntaxKind.GreaterThanGreaterThanToken, AstTokenData>;
|
||||
[SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: Token<SyntaxKind.GreaterThanGreaterThanGreaterThanToken, AstTokenData>;
|
||||
[SyntaxKind.AmpersandToken]: Token<SyntaxKind.AmpersandToken, AstTokenData>;
|
||||
[SyntaxKind.BarToken]: Token<SyntaxKind.BarToken, AstTokenData>;
|
||||
[SyntaxKind.CaretToken]: Token<SyntaxKind.CaretToken, AstTokenData>;
|
||||
[SyntaxKind.ExclamationToken]: Token<SyntaxKind.ExclamationToken, AstTokenData>;
|
||||
[SyntaxKind.TildeToken]: Token<SyntaxKind.TildeToken, AstTokenData>;
|
||||
[SyntaxKind.AmpersandAmpersandToken]: Token<SyntaxKind.AmpersandAmpersandToken, AstTokenData>;
|
||||
[SyntaxKind.BarBarToken]: Token<SyntaxKind.BarBarToken, AstTokenData>;
|
||||
[SyntaxKind.QuestionToken]: Token<SyntaxKind.QuestionToken, AstTokenData>;
|
||||
[SyntaxKind.ColonToken]: Token<SyntaxKind.ColonToken, AstTokenData>;
|
||||
[SyntaxKind.AtToken]: Token<SyntaxKind.AtToken, AstTokenData>;
|
||||
[SyntaxKind.QuestionQuestionToken]: Token<SyntaxKind.QuestionQuestionToken, AstTokenData>;
|
||||
[SyntaxKind.BacktickToken]: Token<SyntaxKind.BacktickToken, AstTokenData>;
|
||||
[SyntaxKind.HashToken]: Token<SyntaxKind.HashToken, AstTokenData>;
|
||||
[SyntaxKind.EqualsToken]: Token<SyntaxKind.EqualsToken, AstTokenData>;
|
||||
[SyntaxKind.PlusEqualsToken]: Token<SyntaxKind.PlusEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.MinusEqualsToken]: Token<SyntaxKind.MinusEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.AsteriskEqualsToken]: Token<SyntaxKind.AsteriskEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.AsteriskAsteriskEqualsToken]: Token<SyntaxKind.AsteriskAsteriskEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.SlashEqualsToken]: Token<SyntaxKind.SlashEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.PercentEqualsToken]: Token<SyntaxKind.PercentEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.LessThanLessThanEqualsToken]: Token<SyntaxKind.LessThanLessThanEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.GreaterThanGreaterThanEqualsToken]: Token<SyntaxKind.GreaterThanGreaterThanEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: Token<SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.AmpersandEqualsToken]: Token<SyntaxKind.AmpersandEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.BarEqualsToken]: Token<SyntaxKind.BarEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.BarBarEqualsToken]: Token<SyntaxKind.BarBarEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.AmpersandAmpersandEqualsToken]: Token<SyntaxKind.AmpersandAmpersandEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.QuestionQuestionEqualsToken]: Token<SyntaxKind.QuestionQuestionEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.CaretEqualsToken]: Token<SyntaxKind.CaretEqualsToken, AstTokenData>;
|
||||
[SyntaxKind.Identifier]: Identifier;
|
||||
[SyntaxKind.PrivateIdentifier]: PrivateIdentifier;
|
||||
/** @internal */
|
||||
[SyntaxKind.JSDocCommentTextToken]: never;
|
||||
[SyntaxKind.BreakKeyword]: Token<SyntaxKind.BreakKeyword, AstTokenData>;
|
||||
[SyntaxKind.CaseKeyword]: Token<SyntaxKind.CaseKeyword, AstTokenData>;
|
||||
[SyntaxKind.CatchKeyword]: Token<SyntaxKind.CatchKeyword, AstTokenData>;
|
||||
[SyntaxKind.ClassKeyword]: Token<SyntaxKind.ClassKeyword, AstTokenData>;
|
||||
[SyntaxKind.ConstKeyword]: Token<SyntaxKind.ConstKeyword, AstTokenData>;
|
||||
[SyntaxKind.ContinueKeyword]: Token<SyntaxKind.ContinueKeyword, AstTokenData>;
|
||||
[SyntaxKind.DebuggerKeyword]: Token<SyntaxKind.DebuggerKeyword, AstTokenData>;
|
||||
[SyntaxKind.DefaultKeyword]: Token<SyntaxKind.DefaultKeyword, AstTokenData>;
|
||||
[SyntaxKind.DeleteKeyword]: Token<SyntaxKind.DeleteKeyword, AstTokenData>;
|
||||
[SyntaxKind.DoKeyword]: Token<SyntaxKind.DoKeyword, AstTokenData>;
|
||||
[SyntaxKind.ElseKeyword]: Token<SyntaxKind.ElseKeyword, AstTokenData>;
|
||||
[SyntaxKind.EnumKeyword]: Token<SyntaxKind.EnumKeyword, AstTokenData>;
|
||||
[SyntaxKind.ExportKeyword]: Token<SyntaxKind.ExportKeyword, AstTokenData>;
|
||||
[SyntaxKind.ExtendsKeyword]: Token<SyntaxKind.ExtendsKeyword, AstTokenData>;
|
||||
[SyntaxKind.FalseKeyword]: FalseLiteral;
|
||||
[SyntaxKind.FinallyKeyword]: Token<SyntaxKind.FinallyKeyword, AstTokenData>;
|
||||
[SyntaxKind.ForKeyword]: Token<SyntaxKind.ForKeyword, AstTokenData>;
|
||||
[SyntaxKind.FunctionKeyword]: Token<SyntaxKind.FunctionKeyword, AstTokenData>;
|
||||
[SyntaxKind.IfKeyword]: Token<SyntaxKind.IfKeyword, AstTokenData>;
|
||||
[SyntaxKind.ImportKeyword]: ImportExpression;
|
||||
[SyntaxKind.InKeyword]: Token<SyntaxKind.InKeyword, AstTokenData>;
|
||||
[SyntaxKind.InstanceOfKeyword]: Token<SyntaxKind.InstanceOfKeyword, AstTokenData>;
|
||||
[SyntaxKind.NewKeyword]: Token<SyntaxKind.NewKeyword, AstTokenData>;
|
||||
[SyntaxKind.NullKeyword]: NullLiteral;
|
||||
[SyntaxKind.ReturnKeyword]: Token<SyntaxKind.ReturnKeyword, AstTokenData>;
|
||||
[SyntaxKind.SuperKeyword]: SuperExpression;
|
||||
[SyntaxKind.SwitchKeyword]: Token<SyntaxKind.SwitchKeyword, AstTokenData>;
|
||||
[SyntaxKind.ThisKeyword]: ThisExpression;
|
||||
[SyntaxKind.ThrowKeyword]: Token<SyntaxKind.ThrowKeyword, AstTokenData>;
|
||||
[SyntaxKind.TrueKeyword]: TrueLiteral;
|
||||
[SyntaxKind.TryKeyword]: Token<SyntaxKind.TryKeyword, AstTokenData>;
|
||||
[SyntaxKind.TypeOfKeyword]: Token<SyntaxKind.TypeOfKeyword, AstTokenData>;
|
||||
[SyntaxKind.VarKeyword]: Token<SyntaxKind.VarKeyword, AstTokenData>;
|
||||
[SyntaxKind.VoidKeyword]: Token<SyntaxKind.VoidKeyword, AstTokenData>;
|
||||
[SyntaxKind.WhileKeyword]: Token<SyntaxKind.WhileKeyword, AstTokenData>;
|
||||
[SyntaxKind.WithKeyword]: Token<SyntaxKind.WithKeyword, AstTokenData>;
|
||||
[SyntaxKind.ImplementsKeyword]: Token<SyntaxKind.ImplementsKeyword, AstTokenData>;
|
||||
[SyntaxKind.InterfaceKeyword]: Token<SyntaxKind.InterfaceKeyword, AstTokenData>;
|
||||
[SyntaxKind.LetKeyword]: Token<SyntaxKind.LetKeyword, AstTokenData>;
|
||||
[SyntaxKind.PackageKeyword]: Token<SyntaxKind.PackageKeyword, AstTokenData>;
|
||||
[SyntaxKind.PrivateKeyword]: Token<SyntaxKind.PrivateKeyword, AstTokenData>;
|
||||
[SyntaxKind.ProtectedKeyword]: Token<SyntaxKind.ProtectedKeyword, AstTokenData>;
|
||||
[SyntaxKind.PublicKeyword]: Token<SyntaxKind.PublicKeyword, AstTokenData>;
|
||||
[SyntaxKind.StaticKeyword]: Token<SyntaxKind.StaticKeyword, AstTokenData>;
|
||||
[SyntaxKind.YieldKeyword]: Token<SyntaxKind.YieldKeyword, AstTokenData>;
|
||||
[SyntaxKind.AbstractKeyword]: Token<SyntaxKind.AbstractKeyword, AstTokenData>;
|
||||
[SyntaxKind.AccessorKeyword]: Token<SyntaxKind.AccessorKeyword, AstTokenData>;
|
||||
[SyntaxKind.AsKeyword]: Token<SyntaxKind.AsKeyword, AstTokenData>;
|
||||
[SyntaxKind.AssertsKeyword]: Token<SyntaxKind.AssertsKeyword, AstTokenData>;
|
||||
[SyntaxKind.AssertKeyword]: Token<SyntaxKind.AssertKeyword, AstTokenData>;
|
||||
[SyntaxKind.AnyKeyword]: Token<SyntaxKind.AnyKeyword, AstTokenData>;
|
||||
[SyntaxKind.AsyncKeyword]: Token<SyntaxKind.AsyncKeyword, AstTokenData>;
|
||||
[SyntaxKind.AwaitKeyword]: Token<SyntaxKind.AwaitKeyword, AstTokenData>;
|
||||
[SyntaxKind.BooleanKeyword]: Token<SyntaxKind.BooleanKeyword, AstTokenData>;
|
||||
[SyntaxKind.ConstructorKeyword]: Token<SyntaxKind.ConstructorKeyword, AstTokenData>;
|
||||
[SyntaxKind.DeclareKeyword]: Token<SyntaxKind.DeclareKeyword, AstTokenData>;
|
||||
[SyntaxKind.GetKeyword]: Token<SyntaxKind.GetKeyword, AstTokenData>;
|
||||
[SyntaxKind.InferKeyword]: Token<SyntaxKind.InferKeyword, AstTokenData>;
|
||||
[SyntaxKind.IntrinsicKeyword]: Token<SyntaxKind.IntrinsicKeyword, AstTokenData>;
|
||||
[SyntaxKind.IsKeyword]: Token<SyntaxKind.IsKeyword, AstTokenData>;
|
||||
[SyntaxKind.KeyOfKeyword]: Token<SyntaxKind.KeyOfKeyword, AstTokenData>;
|
||||
[SyntaxKind.ModuleKeyword]: Token<SyntaxKind.ModuleKeyword, AstTokenData>;
|
||||
[SyntaxKind.NamespaceKeyword]: Token<SyntaxKind.NamespaceKeyword, AstTokenData>;
|
||||
[SyntaxKind.NeverKeyword]: Token<SyntaxKind.NeverKeyword, AstTokenData>;
|
||||
[SyntaxKind.OutKeyword]: Token<SyntaxKind.OutKeyword, AstTokenData>;
|
||||
[SyntaxKind.ReadonlyKeyword]: Token<SyntaxKind.ReadonlyKeyword, AstTokenData>;
|
||||
[SyntaxKind.RequireKeyword]: Token<SyntaxKind.RequireKeyword, AstTokenData>;
|
||||
[SyntaxKind.NumberKeyword]: Token<SyntaxKind.NumberKeyword, AstTokenData>;
|
||||
[SyntaxKind.ObjectKeyword]: Token<SyntaxKind.ObjectKeyword, AstTokenData>;
|
||||
[SyntaxKind.SatisfiesKeyword]: Token<SyntaxKind.SatisfiesKeyword, AstTokenData>;
|
||||
[SyntaxKind.SetKeyword]: Token<SyntaxKind.SetKeyword, AstTokenData>;
|
||||
[SyntaxKind.StringKeyword]: Token<SyntaxKind.StringKeyword, AstTokenData>;
|
||||
[SyntaxKind.SymbolKeyword]: Token<SyntaxKind.SymbolKeyword, AstTokenData>;
|
||||
[SyntaxKind.TypeKeyword]: Token<SyntaxKind.TypeKeyword, AstTokenData>;
|
||||
[SyntaxKind.UndefinedKeyword]: Token<SyntaxKind.UndefinedKeyword, AstTokenData>;
|
||||
[SyntaxKind.UniqueKeyword]: Token<SyntaxKind.UniqueKeyword, AstTokenData>;
|
||||
[SyntaxKind.UnknownKeyword]: Token<SyntaxKind.UnknownKeyword, AstTokenData>;
|
||||
[SyntaxKind.UsingKeyword]: Token<SyntaxKind.UsingKeyword, AstTokenData>;
|
||||
[SyntaxKind.FromKeyword]: Token<SyntaxKind.FromKeyword, AstTokenData>;
|
||||
[SyntaxKind.GlobalKeyword]: Token<SyntaxKind.GlobalKeyword, AstTokenData>;
|
||||
[SyntaxKind.BigIntKeyword]: Token<SyntaxKind.BigIntKeyword, AstTokenData>;
|
||||
[SyntaxKind.OverrideKeyword]: Token<SyntaxKind.OverrideKeyword, AstTokenData>;
|
||||
[SyntaxKind.OfKeyword]: Token<SyntaxKind.OfKeyword, AstTokenData>;
|
||||
[SyntaxKind.QualifiedName]: QualifiedName;
|
||||
[SyntaxKind.ComputedPropertyName]: ComputedPropertyName;
|
||||
[SyntaxKind.Decorator]: Decorator;
|
||||
[SyntaxKind.TypeParameter]: TypeParameterDeclaration;
|
||||
[SyntaxKind.CallSignature]: CallSignatureDeclaration;
|
||||
[SyntaxKind.ConstructSignature]: ConstructSignatureDeclaration;
|
||||
[SyntaxKind.VariableDeclaration]: VariableDeclaration;
|
||||
[SyntaxKind.VariableDeclarationList]: VariableDeclarationList;
|
||||
[SyntaxKind.Parameter]: ParameterDeclaration;
|
||||
[SyntaxKind.BindingElement]: BindingElement;
|
||||
[SyntaxKind.PropertySignature]: PropertySignature;
|
||||
[SyntaxKind.PropertyDeclaration]: PropertyDeclaration;
|
||||
[SyntaxKind.PropertyAssignment]: PropertyAssignment;
|
||||
[SyntaxKind.ShorthandPropertyAssignment]: ShorthandPropertyAssignment;
|
||||
[SyntaxKind.SpreadAssignment]: SpreadAssignment;
|
||||
[SyntaxKind.ObjectBindingPattern]: ObjectBindingPattern;
|
||||
[SyntaxKind.ArrayBindingPattern]: ArrayBindingPattern;
|
||||
[SyntaxKind.FunctionDeclaration]: FunctionDeclaration;
|
||||
[SyntaxKind.MethodSignature]: MethodSignature;
|
||||
[SyntaxKind.MethodDeclaration]: MethodDeclaration;
|
||||
[SyntaxKind.Constructor]: ConstructorDeclaration;
|
||||
[SyntaxKind.SemicolonClassElement]: SemicolonClassElement;
|
||||
[SyntaxKind.GetAccessor]: GetAccessorDeclaration;
|
||||
[SyntaxKind.SetAccessor]: SetAccessorDeclaration;
|
||||
[SyntaxKind.IndexSignature]: IndexSignatureDeclaration;
|
||||
[SyntaxKind.ClassStaticBlockDeclaration]: ClassStaticBlockDeclaration;
|
||||
[SyntaxKind.ImportTypeAssertionContainer]: ImportTypeAssertionContainer;
|
||||
[SyntaxKind.ImportType]: ImportTypeNode;
|
||||
[SyntaxKind.ThisType]: ThisTypeNode;
|
||||
[SyntaxKind.FunctionType]: FunctionTypeNode;
|
||||
[SyntaxKind.ConstructorType]: ConstructorTypeNode;
|
||||
[SyntaxKind.TypeReference]: TypeReferenceNode;
|
||||
[SyntaxKind.TypePredicate]: TypePredicateNode;
|
||||
[SyntaxKind.TypeQuery]: TypeQueryNode;
|
||||
[SyntaxKind.TypeLiteral]: TypeLiteralNode;
|
||||
[SyntaxKind.ArrayType]: ArrayTypeNode;
|
||||
[SyntaxKind.TupleType]: TupleTypeNode;
|
||||
[SyntaxKind.NamedTupleMember]: NamedTupleMember;
|
||||
[SyntaxKind.OptionalType]: OptionalTypeNode;
|
||||
[SyntaxKind.RestType]: RestTypeNode;
|
||||
[SyntaxKind.UnionType]: UnionTypeNode;
|
||||
[SyntaxKind.IntersectionType]: IntersectionTypeNode;
|
||||
[SyntaxKind.ConditionalType]: ConditionalTypeNode;
|
||||
[SyntaxKind.InferType]: InferTypeNode;
|
||||
[SyntaxKind.ParenthesizedType]: ParenthesizedTypeNode;
|
||||
[SyntaxKind.TypeOperator]: TypeOperatorNode;
|
||||
[SyntaxKind.IndexedAccessType]: IndexedAccessTypeNode;
|
||||
[SyntaxKind.MappedType]: MappedTypeNode;
|
||||
[SyntaxKind.LiteralType]: LiteralTypeNode;
|
||||
[SyntaxKind.TemplateLiteralType]: TemplateLiteralTypeNode;
|
||||
[SyntaxKind.TemplateLiteralTypeSpan]: TemplateLiteralTypeSpan;
|
||||
[SyntaxKind.OmittedExpression]: OmittedExpression;
|
||||
[SyntaxKind.PrefixUnaryExpression]: PrefixUnaryExpression;
|
||||
[SyntaxKind.PostfixUnaryExpression]: PostfixUnaryExpression;
|
||||
[SyntaxKind.DeleteExpression]: DeleteExpression;
|
||||
[SyntaxKind.TypeOfExpression]: TypeOfExpression;
|
||||
[SyntaxKind.VoidExpression]: VoidExpression;
|
||||
[SyntaxKind.AwaitExpression]: AwaitExpression;
|
||||
[SyntaxKind.YieldExpression]: YieldExpression;
|
||||
[SyntaxKind.BinaryExpression]: BinaryExpression;
|
||||
[SyntaxKind.ConditionalExpression]: ConditionalExpression;
|
||||
[SyntaxKind.FunctionExpression]: FunctionExpression;
|
||||
[SyntaxKind.ArrowFunction]: ArrowFunction;
|
||||
[SyntaxKind.TemplateExpression]: TemplateExpression;
|
||||
[SyntaxKind.TemplateSpan]: TemplateSpan;
|
||||
[SyntaxKind.ParenthesizedExpression]: ParenthesizedExpression;
|
||||
[SyntaxKind.ArrayLiteralExpression]: ArrayLiteralExpression;
|
||||
[SyntaxKind.SpreadElement]: SpreadElement;
|
||||
[SyntaxKind.ObjectLiteralExpression]: ObjectLiteralExpression;
|
||||
[SyntaxKind.PropertyAccessExpression]: PropertyAccessExpression;
|
||||
[SyntaxKind.ElementAccessExpression]: ElementAccessExpression;
|
||||
[SyntaxKind.CallExpression]: CallExpression;
|
||||
[SyntaxKind.ExpressionWithTypeArguments]: ExpressionWithTypeArguments;
|
||||
[SyntaxKind.NewExpression]: NewExpression;
|
||||
[SyntaxKind.TaggedTemplateExpression]: TaggedTemplateExpression;
|
||||
[SyntaxKind.AsExpression]: AsExpression;
|
||||
[SyntaxKind.TypeAssertionExpression]: TypeAssertionExpression;
|
||||
[SyntaxKind.SyntheticExpression]: SyntheticExpression;
|
||||
[SyntaxKind.SatisfiesExpression]: SatisfiesExpression;
|
||||
[SyntaxKind.NonNullExpression]: NonNullExpression;
|
||||
[SyntaxKind.MetaProperty]: MetaProperty;
|
||||
[SyntaxKind.JsxElement]: JsxElement;
|
||||
[SyntaxKind.JsxAttributes]: JsxAttributes;
|
||||
[SyntaxKind.JsxNamespacedName]: JsxNamespacedName;
|
||||
[SyntaxKind.JsxOpeningElement]: JsxOpeningElement;
|
||||
[SyntaxKind.JsxSelfClosingElement]: JsxSelfClosingElement;
|
||||
[SyntaxKind.JsxFragment]: JsxFragment;
|
||||
[SyntaxKind.JsxOpeningFragment]: JsxOpeningFragment;
|
||||
[SyntaxKind.JsxClosingFragment]: JsxClosingFragment;
|
||||
[SyntaxKind.JsxAttribute]: JsxAttribute;
|
||||
[SyntaxKind.JsxSpreadAttribute]: JsxSpreadAttribute;
|
||||
[SyntaxKind.JsxClosingElement]: JsxClosingElement;
|
||||
[SyntaxKind.JsxExpression]: JsxExpression;
|
||||
[SyntaxKind.EmptyStatement]: EmptyStatement;
|
||||
[SyntaxKind.DebuggerStatement]: DebuggerStatement;
|
||||
[SyntaxKind.MissingDeclaration]: MissingDeclaration;
|
||||
[SyntaxKind.Block]: Block;
|
||||
[SyntaxKind.VariableStatement]: VariableStatement;
|
||||
[SyntaxKind.ExpressionStatement]: ExpressionStatement;
|
||||
[SyntaxKind.IfStatement]: IfStatement;
|
||||
[SyntaxKind.DoStatement]: DoStatement;
|
||||
[SyntaxKind.WhileStatement]: WhileStatement;
|
||||
[SyntaxKind.ForStatement]: ForStatement;
|
||||
[SyntaxKind.ForInStatement]: ForInStatement;
|
||||
[SyntaxKind.ForOfStatement]: ForOfStatement;
|
||||
[SyntaxKind.BreakStatement]: BreakStatement;
|
||||
[SyntaxKind.ContinueStatement]: ContinueStatement;
|
||||
[SyntaxKind.ReturnStatement]: ReturnStatement;
|
||||
[SyntaxKind.WithStatement]: WithStatement;
|
||||
[SyntaxKind.SwitchStatement]: SwitchStatement;
|
||||
[SyntaxKind.CaseBlock]: CaseBlock;
|
||||
[SyntaxKind.CaseClause]: CaseClause;
|
||||
[SyntaxKind.DefaultClause]: DefaultClause;
|
||||
[SyntaxKind.LabeledStatement]: LabeledStatement;
|
||||
[SyntaxKind.ThrowStatement]: ThrowStatement;
|
||||
[SyntaxKind.TryStatement]: TryStatement;
|
||||
[SyntaxKind.CatchClause]: CatchClause;
|
||||
[SyntaxKind.ClassDeclaration]: ClassDeclaration;
|
||||
[SyntaxKind.ClassExpression]: ClassExpression;
|
||||
[SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration;
|
||||
[SyntaxKind.HeritageClause]: HeritageClause;
|
||||
[SyntaxKind.TypeAliasDeclaration]: TypeAliasDeclaration;
|
||||
[SyntaxKind.EnumMember]: EnumMember;
|
||||
[SyntaxKind.EnumDeclaration]: EnumDeclaration;
|
||||
[SyntaxKind.ModuleDeclaration]: ModuleDeclaration;
|
||||
[SyntaxKind.ModuleBlock]: ModuleBlock;
|
||||
[SyntaxKind.ImportEqualsDeclaration]: ImportEqualsDeclaration;
|
||||
[SyntaxKind.ExternalModuleReference]: ExternalModuleReference;
|
||||
[SyntaxKind.ImportDeclaration]: ImportDeclaration;
|
||||
[SyntaxKind.ImportClause]: ImportClause;
|
||||
[SyntaxKind.ImportAttribute]: ImportAttribute;
|
||||
[SyntaxKind.ImportAttributes]: ImportAttributes;
|
||||
[SyntaxKind.NamespaceImport]: NamespaceImport;
|
||||
[SyntaxKind.NamespaceExport]: NamespaceExport;
|
||||
[SyntaxKind.NamespaceExportDeclaration]: NamespaceExportDeclaration;
|
||||
[SyntaxKind.ExportDeclaration]: ExportDeclaration;
|
||||
[SyntaxKind.NamedImports]: NamedImports;
|
||||
[SyntaxKind.NamedExports]: NamedExports;
|
||||
[SyntaxKind.ImportSpecifier]: ImportSpecifier;
|
||||
[SyntaxKind.ExportSpecifier]: ExportSpecifier;
|
||||
[SyntaxKind.ExportAssignment]: ExportAssignment;
|
||||
[SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression;
|
||||
[SyntaxKind.JSDocNameReference]: JSDocNameReference;
|
||||
[SyntaxKind.JSDocMemberName]: JSDocMemberName;
|
||||
[SyntaxKind.JSDocAllType]: JSDocAllType;
|
||||
[SyntaxKind.JSDocUnknownType]: JSDocUnknownType;
|
||||
[SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType;
|
||||
[SyntaxKind.JSDocNullableType]: JSDocNullableType;
|
||||
[SyntaxKind.JSDocOptionalType]: JSDocOptionalType;
|
||||
[SyntaxKind.JSDocFunctionType]: JSDocFunctionType;
|
||||
[SyntaxKind.JSDocVariadicType]: JSDocVariadicType;
|
||||
[SyntaxKind.JSDocNamepathType]: JSDocNamepathType;
|
||||
[SyntaxKind.JSDoc]: JSDoc;
|
||||
[SyntaxKind.JSDocLink]: JSDocLink;
|
||||
[SyntaxKind.JSDocLinkCode]: JSDocLinkCode;
|
||||
[SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain;
|
||||
[SyntaxKind.JSDocText]: JSDocText;
|
||||
[SyntaxKind.JSDocTag]: JSDocUnknownTag;
|
||||
[SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag;
|
||||
[SyntaxKind.JSDocImplementsTag]: JSDocImplementsTag;
|
||||
[SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag;
|
||||
[SyntaxKind.JSDocDeprecatedTag]: JSDocDeprecatedTag;
|
||||
[SyntaxKind.JSDocClassTag]: JSDocClassTag;
|
||||
[SyntaxKind.JSDocPublicTag]: JSDocPublicTag;
|
||||
[SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag;
|
||||
[SyntaxKind.JSDocProtectedTag]: JSDocProtectedTag;
|
||||
[SyntaxKind.JSDocReadonlyTag]: JSDocReadonlyTag;
|
||||
[SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag;
|
||||
[SyntaxKind.JSDocEnumTag]: JSDocEnumTag;
|
||||
[SyntaxKind.JSDocThisTag]: JSDocThisTag;
|
||||
[SyntaxKind.JSDocTemplateTag]: JSDocTemplateTag;
|
||||
[SyntaxKind.JSDocSeeTag]: JSDocSeeTag;
|
||||
[SyntaxKind.JSDocReturnTag]: JSDocReturnTag;
|
||||
[SyntaxKind.JSDocTypeTag]: JSDocTypeTag;
|
||||
[SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag;
|
||||
[SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag;
|
||||
[SyntaxKind.JSDocOverloadTag]: JSDocOverloadTag;
|
||||
[SyntaxKind.JSDocThrowsTag]: JSDocThrowsTag;
|
||||
[SyntaxKind.JSDocSignature]: JSDocSignature;
|
||||
[SyntaxKind.JSDocPropertyTag]: JSDocPropertyTag;
|
||||
[SyntaxKind.JSDocParameterTag]: JSDocParameterTag;
|
||||
[SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral;
|
||||
[SyntaxKind.JSDocSatisfiesTag]: JSDocSatisfiesTag;
|
||||
[SyntaxKind.JSDocImportTag]: JSDocImportTag;
|
||||
[SyntaxKind.SourceFile]: SourceFile;
|
||||
[SyntaxKind.Bundle]: Bundle;
|
||||
[SyntaxKind.SyntaxList]: SyntaxList;
|
||||
[SyntaxKind.NotEmittedStatement]: NotEmittedStatement;
|
||||
[SyntaxKind.NotEmittedTypeElement]: NotEmittedTypeElement;
|
||||
[SyntaxKind.PartiallyEmittedExpression]: PartiallyEmittedExpression;
|
||||
[SyntaxKind.CommaListExpression]: CommaListExpression;
|
||||
/** @internal */
|
||||
[SyntaxKind.SyntheticReferenceExpression]: SyntheticReferenceExpression;
|
||||
[SyntaxKind.Count]: never;
|
||||
[SyntaxKind.NonTextFileMarkerTrivia]: never;
|
||||
}
|
||||
|
||||
/**
|
||||
* The set of all `Node` subtypes.
|
||||
*/
|
||||
export type Nodes = NodeMap[keyof NodeMap];
|
||||
|
||||
type __Expect<T, _ extends T> = never; // eslint-disable-line @typescript-eslint/naming-convention
|
||||
+47
-60
@@ -1,4 +1,8 @@
|
||||
import {
|
||||
addRange,
|
||||
addRelatedInfo,
|
||||
append,
|
||||
AssertionLevel,
|
||||
AstAccessorDeclaration,
|
||||
AstArrayBindingElement,
|
||||
AstArrayBindingPattern,
|
||||
@@ -17,6 +21,7 @@ import {
|
||||
AstBooleanLiteral,
|
||||
AstBreakOrContinueStatement,
|
||||
AstCallSignatureDeclaration,
|
||||
astCanHaveModifiers,
|
||||
AstCaseBlock,
|
||||
AstCaseClause,
|
||||
AstCaseOrDefaultClause,
|
||||
@@ -46,6 +51,7 @@ import {
|
||||
AstExpression,
|
||||
AstExpressionStatement,
|
||||
AstExpressionWithTypeArguments,
|
||||
astForEachChild,
|
||||
AstForInitializer,
|
||||
AstForInOrOfStatement,
|
||||
AstForStatement,
|
||||
@@ -53,6 +59,8 @@ import {
|
||||
AstFunctionExpression,
|
||||
AstFunctionOrConstructorTypeNode,
|
||||
AstHasJSDoc,
|
||||
astHasJSDocNodes,
|
||||
AstHasModifiers,
|
||||
AstHeritageClause,
|
||||
AstIdentifier,
|
||||
AstIfStatement,
|
||||
@@ -67,6 +75,7 @@ import {
|
||||
AstInferTypeNode,
|
||||
AstInterfaceDeclaration,
|
||||
AstIterationStatement,
|
||||
AstJSDoc,
|
||||
AstJSDocAllType,
|
||||
AstJSDocAugmentsTag,
|
||||
AstJSDocAuthorTag,
|
||||
@@ -80,7 +89,6 @@ import {
|
||||
AstJSDocMemberName,
|
||||
AstJSDocNameReference,
|
||||
AstJSDocNamespaceDeclaration,
|
||||
AstJSDoc,
|
||||
AstJSDocNullableType,
|
||||
AstJSDocOptionalType,
|
||||
AstJSDocOverloadTag,
|
||||
@@ -213,47 +221,8 @@ import {
|
||||
AstWhileStatement,
|
||||
AstWithStatement,
|
||||
AstYieldExpression,
|
||||
createAstNodeFactory,
|
||||
astHasJSDocNodes,
|
||||
isAstAsyncModifier,
|
||||
isAstDeclareKeyword,
|
||||
isAstExportModifier,
|
||||
isAstExpressionWithTypeArguments,
|
||||
isAstFunctionTypeNode,
|
||||
isAstIdentifier,
|
||||
isAstJSDocFunctionType,
|
||||
isAstJSDocNullableType,
|
||||
isAstJSDocReturnTag,
|
||||
isAstJSDocTypeTag,
|
||||
isAstJsxNamespacedName,
|
||||
isAstJsxOpeningElement,
|
||||
isAstJsxOpeningFragment,
|
||||
isAstLeftHandSideExpression,
|
||||
isAstNonNullExpression,
|
||||
isAstPrivateIdentifier,
|
||||
isAstSetAccessorDeclaration,
|
||||
isAstStringOrNumericLiteralLike,
|
||||
isAstTaggedTemplateExpression,
|
||||
isAstTypeReferenceNode,
|
||||
astForEachChild,
|
||||
isAstMetaProperty,
|
||||
astCanHaveModifiers,
|
||||
AstHasModifiers,
|
||||
isAstImportEqualsDeclaration,
|
||||
isAstImportDeclaration,
|
||||
isAstExportAssignment,
|
||||
isAstExportDeclaration,
|
||||
isAstExternalModuleReference,
|
||||
} from "./_namespaces/ts.ast.js";
|
||||
import {
|
||||
addRange,
|
||||
addRelatedInfo,
|
||||
append,
|
||||
AssertionLevel,
|
||||
ast,
|
||||
attachFileToDiagnostics,
|
||||
canHaveJSDoc,
|
||||
canHaveModifiers,
|
||||
CharacterCodes,
|
||||
CommentDirective,
|
||||
commentPragmas,
|
||||
@@ -261,6 +230,7 @@ import {
|
||||
concatenate,
|
||||
containsParseError,
|
||||
convertToJson,
|
||||
createAstNodeFactory,
|
||||
createDetachedDiagnostic,
|
||||
createNodeFactory,
|
||||
createScanner,
|
||||
@@ -281,7 +251,6 @@ import {
|
||||
findIndex,
|
||||
firstOrUndefined,
|
||||
forEach,
|
||||
forEachChild,
|
||||
getAnyExtensionFromPath,
|
||||
getBaseFileName,
|
||||
getBinaryOperatorPrecedence,
|
||||
@@ -292,21 +261,40 @@ import {
|
||||
getLeadingCommentRanges,
|
||||
getSpellingSuggestion,
|
||||
getTextOfNodeFromSourceText,
|
||||
HasModifiers,
|
||||
identity,
|
||||
isArray,
|
||||
isAssignmentOperator,
|
||||
isAstAsyncModifier,
|
||||
isAstDeclareKeyword,
|
||||
isAstExportAssignment,
|
||||
isAstExportDeclaration,
|
||||
isAstExportModifier,
|
||||
isAstExpressionWithTypeArguments,
|
||||
isAstExternalModuleReference,
|
||||
isAstFunctionTypeNode,
|
||||
isAstIdentifier,
|
||||
isAstImportDeclaration,
|
||||
isAstImportEqualsDeclaration,
|
||||
isAstJSDocFunctionType,
|
||||
isAstJSDocNullableType,
|
||||
isAstJSDocReturnTag,
|
||||
isAstJSDocTypeTag,
|
||||
isAstJsxNamespacedName,
|
||||
isAstJsxOpeningElement,
|
||||
isAstJsxOpeningFragment,
|
||||
isAstLeftHandSideExpression,
|
||||
isAstMetaProperty,
|
||||
isAstNonNullExpression,
|
||||
isAstPrivateIdentifier,
|
||||
isAstSetAccessorDeclaration,
|
||||
isAstStringOrNumericLiteralLike,
|
||||
isAstTaggedTemplateExpression,
|
||||
isAstTypeReferenceNode,
|
||||
isClassMemberModifier,
|
||||
isExportAssignment,
|
||||
isExportDeclaration,
|
||||
isExternalModuleReference,
|
||||
isIdentifierText,
|
||||
isImportDeclaration,
|
||||
isImportEqualsDeclaration,
|
||||
isKeyword,
|
||||
isKeywordOrPunctuation,
|
||||
isLiteralKind,
|
||||
isMetaProperty,
|
||||
isModifierKind,
|
||||
isTemplateLiteralKind,
|
||||
JSDoc,
|
||||
@@ -325,7 +313,6 @@ import {
|
||||
ModuleKind,
|
||||
Mutable,
|
||||
Node,
|
||||
NodeArray,
|
||||
NodeFactory,
|
||||
NodeFactoryFlags,
|
||||
NodeFlags,
|
||||
@@ -411,7 +398,7 @@ export function isFileProbablyExternalModule(sourceFile: SourceFile): Node | und
|
||||
// Try to use the first top-level import/export when available, then
|
||||
// fall back to looking for an 'import.meta' somewhere in the tree if necessary.
|
||||
// TODO(rbuckton): do not instantiate .node
|
||||
return forEach((sourceFile as AstSourceFile["node"]).ast.data.statements.items, isAnExternalModuleIndicatorNode)?.node ||
|
||||
return forEach(sourceFile.ast.data.statements.items, isAnExternalModuleIndicatorNode)?.node ||
|
||||
getImportMetaIfNecessary(sourceFile)?.node;
|
||||
}
|
||||
|
||||
@@ -425,7 +412,7 @@ function isAnExternalModuleIndicatorNode(node: AstNode) {
|
||||
|
||||
function getImportMetaIfNecessary(sourceFile: SourceFile) {
|
||||
return sourceFile.flags & NodeFlags.PossiblyContainsImportMeta ?
|
||||
walkTreeForImportMeta((sourceFile as AstSourceFile["node"]).ast) :
|
||||
walkTreeForImportMeta(sourceFile.ast) :
|
||||
undefined;
|
||||
}
|
||||
|
||||
@@ -521,7 +508,7 @@ export function isExternalModule(file: SourceFile): boolean {
|
||||
// becoming detached from any SourceFile). It is recommended that this SourceFile not
|
||||
// be used once 'update' is called on it.
|
||||
export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks = false): SourceFile {
|
||||
const newSourceFile = IncrementalParser.updateSourceFile((sourceFile as AstSourceFile["node"]).ast, newText, textChangeRange, aggressiveChecks);
|
||||
const newSourceFile = IncrementalParser.updateSourceFile(sourceFile.ast, newText, textChangeRange, aggressiveChecks);
|
||||
// Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import.
|
||||
// We will manually port the flag to the new source file.
|
||||
newSourceFile.flags |= sourceFile.flags & NodeFlags.PermanentlySetIncrementalFlags;
|
||||
@@ -540,7 +527,7 @@ export function parseIsolatedJSDocComment(content: string, start?: number, lengt
|
||||
if (result && result.jsDoc) {
|
||||
// because the jsDocComment was parsed out of the source file, it might
|
||||
// not be covered by the fixupParentReferences.
|
||||
Parser.fixupParentReferences((result.jsDoc as AstJSDoc["node"]).ast);
|
||||
Parser.fixupParentReferences(result.jsDoc.ast);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -9173,7 +9160,7 @@ namespace IncrementalParser {
|
||||
astForEachChild(node, visitNode, visitArray);
|
||||
if (astHasJSDocNodes(node)) {
|
||||
for (const jsDocComment of node.data.jsDoc!) {
|
||||
visitNode((jsDocComment as AstJSDoc["node"]).ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries
|
||||
visitNode(jsDocComment.ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries
|
||||
}
|
||||
}
|
||||
checkNodePositions(node, aggressiveChecks);
|
||||
@@ -9283,7 +9270,7 @@ namespace IncrementalParser {
|
||||
};
|
||||
if (astHasJSDocNodes(node)) {
|
||||
for (const jsDocComment of node.data.jsDoc!) {
|
||||
visitNode((jsDocComment as AstJSDoc["node"]).ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries
|
||||
visitNode(jsDocComment.ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries
|
||||
}
|
||||
}
|
||||
astForEachChild(node, visitNode);
|
||||
@@ -9326,7 +9313,7 @@ namespace IncrementalParser {
|
||||
astForEachChild(child, visitNode, visitArray);
|
||||
if (astHasJSDocNodes(child)) {
|
||||
for (const jsDocComment of child.data.jsDoc!) {
|
||||
visitNode((jsDocComment as AstJSDoc["node"]).ast);
|
||||
visitNode(jsDocComment.ast);
|
||||
}
|
||||
}
|
||||
checkNodePositions(child, aggressiveChecks);
|
||||
@@ -9417,7 +9404,7 @@ namespace IncrementalParser {
|
||||
while (true) {
|
||||
const lastChild = getLastChild(node.node); // TODO(rbuckton): do not instantiate .node
|
||||
if (lastChild) {
|
||||
node = (lastChild as AstNode["node"]).ast;
|
||||
node = lastChild.ast;
|
||||
}
|
||||
else {
|
||||
return node;
|
||||
@@ -9858,9 +9845,9 @@ function getNamedPragmaArguments(pragma: PragmaDefinition, text: string | undefi
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function tagNamesAreEquivalent(lhs: JsxTagNameExpression | ast.AstJsxTagNameExpression, rhs: JsxTagNameExpression | ast.AstJsxTagNameExpression): boolean {
|
||||
if (!(lhs instanceof AstNode)) lhs = (lhs as AstJsxTagNameExpression["node"]).ast;
|
||||
if (!(rhs instanceof AstNode)) rhs = (rhs as AstJsxTagNameExpression["node"]).ast;
|
||||
export function tagNamesAreEquivalent(lhs: JsxTagNameExpression | AstJsxTagNameExpression, rhs: JsxTagNameExpression | AstJsxTagNameExpression): boolean {
|
||||
if (!(lhs instanceof AstNode)) lhs = lhs.ast;
|
||||
if (!(rhs instanceof AstNode)) rhs = rhs.ast;
|
||||
if (lhs.kind !== rhs.kind) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -333,6 +333,7 @@ import {
|
||||
WriteFileCallback,
|
||||
WriteFileCallbackData,
|
||||
writeFileEnsuringDirectories,
|
||||
PartialSourceFile,
|
||||
} from "./_namespaces/ts.js";
|
||||
import * as performance from "./_namespaces/ts.performance.js";
|
||||
|
||||
@@ -888,7 +889,7 @@ export function getModeForResolutionAtIndex(file: SourceFileImportsList, index:
|
||||
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number, compilerOptions?: CompilerOptions): ResolutionMode {
|
||||
// we ensure all elements of file.imports and file.moduleAugmentations have the relevant parent pointers set during program setup,
|
||||
// so it's safe to use them even pre-bind
|
||||
return getModeForUsageLocationWorker(file, getModuleNameStringLiteralAt(file, index), compilerOptions);
|
||||
return getModeForUsageLocationWorker(file as PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, getModuleNameStringLiteralAt(file, index), compilerOptions);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -944,7 +945,7 @@ export function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLi
|
||||
return getModeForUsageLocationWorker(file, usage, compilerOptions);
|
||||
}
|
||||
|
||||
function getModeForUsageLocationWorker(file: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions) {
|
||||
function getModeForUsageLocationWorker(file: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions) {
|
||||
if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent) || isJSDocImportTag(usage.parent)) {
|
||||
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
|
||||
if (isTypeOnly) {
|
||||
@@ -966,7 +967,7 @@ function getModeForUsageLocationWorker(file: Pick<SourceFile, "fileName" | "impl
|
||||
}
|
||||
}
|
||||
|
||||
function getEmitSyntaxForUsageLocationWorker(file: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions): ResolutionMode {
|
||||
function getEmitSyntaxForUsageLocationWorker(file: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions): ResolutionMode {
|
||||
if (!compilerOptions) {
|
||||
// This should always be provided, but we try to fail somewhat
|
||||
// gracefully to allow projects like ts-node time to update.
|
||||
@@ -5204,7 +5205,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
}
|
||||
}
|
||||
|
||||
function shouldTransformImportCallWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): boolean {
|
||||
function shouldTransformImportCallWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): boolean {
|
||||
const moduleKind = getEmitModuleKind(options);
|
||||
if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext || moduleKind === ModuleKind.Preserve) {
|
||||
return false;
|
||||
@@ -5212,11 +5213,11 @@ function shouldTransformImportCallWorker(sourceFile: Pick<SourceFile, "fileName"
|
||||
return getEmitModuleFormatOfFileWorker(sourceFile, options) < ModuleKind.ES2015;
|
||||
}
|
||||
/** @internal Prefer `program.getEmitModuleFormatOfFile` when possible. */
|
||||
export function getEmitModuleFormatOfFileWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ModuleKind {
|
||||
export function getEmitModuleFormatOfFileWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ModuleKind {
|
||||
return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options);
|
||||
}
|
||||
/** @internal Prefer `program.getImpliedNodeFormatForEmit` when possible. */
|
||||
export function getImpliedNodeFormatForEmitWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
|
||||
export function getImpliedNodeFormatForEmitWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
|
||||
const moduleKind = getEmitModuleKind(options);
|
||||
if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) {
|
||||
return sourceFile.impliedNodeFormat;
|
||||
@@ -5238,7 +5239,7 @@ export function getImpliedNodeFormatForEmitWorker(sourceFile: Pick<SourceFile, "
|
||||
return undefined;
|
||||
}
|
||||
/** @internal Prefer `program.getDefaultResolutionModeForFile` when possible. */
|
||||
export function getDefaultResolutionModeForFileWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
|
||||
export function getDefaultResolutionModeForFileWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
|
||||
return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
BindingElement,
|
||||
Bundle,
|
||||
CallExpression,
|
||||
canHaveAsteriskToken,
|
||||
chainBundle,
|
||||
ClassDeclaration,
|
||||
ClassElement,
|
||||
@@ -851,7 +852,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
|
||||
functionName,
|
||||
factory.createFunctionExpression(
|
||||
filter(node.modifiers, (m): m is Modifier => isModifier(m) && !isStaticModifier(m) && !isAccessorModifier(m)),
|
||||
node.asteriskToken,
|
||||
tryCast(node, canHaveAsteriskToken)?.asteriskToken,
|
||||
functionName,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
@@ -3300,7 +3301,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
|
||||
// constructor references in static property initializers.
|
||||
const declaration = resolver.getReferencedValueDeclaration(node);
|
||||
if (declaration) {
|
||||
const classAlias = classAliases[declaration.id!]; // TODO: GH#18217
|
||||
const classAlias = classAliases[declaration.id]; // TODO: GH#18217
|
||||
if (classAlias) {
|
||||
const clone = factory.cloneNode(classAlias);
|
||||
setSourceMapRange(clone, node);
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Bundle,
|
||||
CallSignatureDeclaration,
|
||||
canHaveModifiers,
|
||||
canHaveName,
|
||||
canProduceDiagnostics,
|
||||
ClassDeclaration,
|
||||
compact,
|
||||
@@ -683,7 +684,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
return visitNode(type, visitDeclarationSubtree, isTypeNode);
|
||||
}
|
||||
|
||||
errorNameNode = node.name;
|
||||
errorNameNode = canHaveName(node) ? node.name : undefined;
|
||||
let oldDiag: typeof getSymbolAccessibilityDiagnostic;
|
||||
if (!suppressNewDiagnosticContexts) {
|
||||
oldDiag = getSymbolAccessibilityDiagnostic;
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
getAllAccessorDeclarations,
|
||||
getNameOfDeclaration,
|
||||
getTextOfNode,
|
||||
hasName,
|
||||
hasSyntacticModifier,
|
||||
ImportEqualsDeclaration,
|
||||
IndexSignatureDeclaration,
|
||||
@@ -733,7 +734,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod
|
||||
function addParentDeclarationRelatedInfo(node: Node, diag: DiagnosticWithLocation) {
|
||||
const parentDeclaration = findNearestDeclaration(node);
|
||||
if (parentDeclaration) {
|
||||
const targetStr = isExportAssignment(parentDeclaration) || !parentDeclaration.name ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false);
|
||||
const targetStr = isExportAssignment(parentDeclaration) || !hasName(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false);
|
||||
addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr));
|
||||
}
|
||||
return diag;
|
||||
@@ -791,7 +792,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod
|
||||
const parentDeclaration = findNearestDeclaration(node);
|
||||
let diag: DiagnosticWithLocation;
|
||||
if (parentDeclaration) {
|
||||
const targetStr = isExportAssignment(parentDeclaration) || !parentDeclaration.name ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false);
|
||||
const targetStr = isExportAssignment(parentDeclaration) || !hasName(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false);
|
||||
const parent = findAncestor(node.parent, n => isExportAssignment(n) || (isStatement(n) ? "quit" : !isParenthesizedExpression(n) && !isTypeAssertionExpression(n) && !isAsExpression(n)));
|
||||
|
||||
if (parentDeclaration === parent) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
BreakOrContinueStatement,
|
||||
Bundle,
|
||||
CallExpression,
|
||||
canHaveAsteriskToken,
|
||||
CaseBlock,
|
||||
CaseClause,
|
||||
cast,
|
||||
@@ -76,6 +77,7 @@ import {
|
||||
getSourceMapRange,
|
||||
getSuperCallFromStatement,
|
||||
getUseDefineForClassFields,
|
||||
hasName,
|
||||
hasStaticModifier,
|
||||
hasSyntacticModifier,
|
||||
Identifier,
|
||||
@@ -2527,7 +2529,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
|
||||
setTextRange(
|
||||
factory.createFunctionExpression(
|
||||
/*modifiers*/ undefined,
|
||||
node.asteriskToken,
|
||||
tryCast(node, canHaveAsteriskToken)?.asteriskToken,
|
||||
name,
|
||||
/*typeParameters*/ undefined,
|
||||
parameters,
|
||||
@@ -3318,7 +3320,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
|
||||
if (
|
||||
(property.transformFlags & TransformFlags.ContainsYield &&
|
||||
hierarchyFacts & HierarchyFacts.AsyncFunctionBody)
|
||||
|| (hasComputed = Debug.checkDefined(property.name).kind === SyntaxKind.ComputedPropertyName)
|
||||
|| (hasComputed = cast(property, hasName).name.kind === SyntaxKind.ComputedPropertyName)
|
||||
) {
|
||||
numInitialProperties = i;
|
||||
break;
|
||||
|
||||
@@ -131,7 +131,6 @@ import {
|
||||
Modifier,
|
||||
ModifierFlags,
|
||||
ModifierLike,
|
||||
ModifiersArray,
|
||||
moveRangePastDecorators,
|
||||
moveRangePastModifiers,
|
||||
Node,
|
||||
@@ -1238,7 +1237,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
>(
|
||||
member: TNode,
|
||||
classInfo: ClassInfo | undefined,
|
||||
createDescriptor?: (node: TNode & { readonly name: PrivateIdentifier; }, modifiers: ModifiersArray | undefined) => Expression,
|
||||
createDescriptor?: (node: TNode & { readonly name: PrivateIdentifier; }, modifiers: NodeArray<Modifier> | undefined) => Expression,
|
||||
) {
|
||||
let referencedName: Expression | undefined;
|
||||
let name: PropertyName | undefined;
|
||||
@@ -2273,7 +2272,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
/**
|
||||
* Creates a `value`, `get`, or `set` method for a pseudo-{@link PropertyDescriptor} object created for a private element.
|
||||
*/
|
||||
function createDescriptorMethod(original: Node, name: PrivateIdentifier, modifiers: ModifiersArray | undefined, asteriskToken: AsteriskToken | undefined, kind: "value" | "get" | "set", parameters: readonly ParameterDeclaration[], body: Block | undefined) {
|
||||
function createDescriptorMethod(original: Node, name: PrivateIdentifier, modifiers: NodeArray<Modifier> | undefined, asteriskToken: AsteriskToken | undefined, kind: "value" | "get" | "set", parameters: readonly ParameterDeclaration[], body: Block | undefined) {
|
||||
const func = factory.createFunctionExpression(
|
||||
modifiers,
|
||||
asteriskToken,
|
||||
@@ -2300,7 +2299,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
/**
|
||||
* Creates a pseudo-{@link PropertyDescriptor} object used when decorating a private {@link MethodDeclaration}.
|
||||
*/
|
||||
function createMethodDescriptorObject(node: PrivateIdentifierMethodDeclaration, modifiers: ModifiersArray | undefined) {
|
||||
function createMethodDescriptorObject(node: PrivateIdentifierMethodDeclaration, modifiers: NodeArray<Modifier> | undefined) {
|
||||
return factory.createObjectLiteralExpression([
|
||||
createDescriptorMethod(
|
||||
node,
|
||||
@@ -2317,7 +2316,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
/**
|
||||
* Creates a pseudo-{@link PropertyDescriptor} object used when decorating a private {@link GetAccessorDeclaration}.
|
||||
*/
|
||||
function createGetAccessorDescriptorObject(node: PrivateIdentifierGetAccessorDeclaration, modifiers: ModifiersArray | undefined) {
|
||||
function createGetAccessorDescriptorObject(node: PrivateIdentifierGetAccessorDeclaration, modifiers: NodeArray<Modifier> | undefined) {
|
||||
return factory.createObjectLiteralExpression([
|
||||
createDescriptorMethod(
|
||||
node,
|
||||
@@ -2334,7 +2333,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
/**
|
||||
* Creates a pseudo-{@link PropertyDescriptor} object used when decorating a private {@link SetAccessorDeclaration}.
|
||||
*/
|
||||
function createSetAccessorDescriptorObject(node: PrivateIdentifierSetAccessorDeclaration, modifiers: ModifiersArray | undefined) {
|
||||
function createSetAccessorDescriptorObject(node: PrivateIdentifierSetAccessorDeclaration, modifiers: NodeArray<Modifier> | undefined) {
|
||||
return factory.createObjectLiteralExpression([
|
||||
createDescriptorMethod(
|
||||
node,
|
||||
@@ -2351,7 +2350,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
/**
|
||||
* Creates a pseudo-{@link PropertyDescriptor} object used when decorating an `accessor` {@link PropertyDeclaration} with a private name.
|
||||
*/
|
||||
function createAccessorPropertyDescriptorObject(node: PrivateIdentifierPropertyDeclaration, modifiers: ModifiersArray | undefined) {
|
||||
function createAccessorPropertyDescriptorObject(node: PrivateIdentifierPropertyDeclaration, modifiers: NodeArray<Modifier> | undefined) {
|
||||
// {
|
||||
// get() { return this.${privateName}; },
|
||||
// set(value) { this.${privateName} = value; },
|
||||
@@ -2406,7 +2405,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
* @param name The name for the resulting declaration.
|
||||
* @param descriptorName The name of the descriptor variable.
|
||||
*/
|
||||
function createMethodDescriptorForwarder(modifiers: ModifiersArray | undefined, name: PropertyName, descriptorName: Identifier) {
|
||||
function createMethodDescriptorForwarder(modifiers: NodeArray<Modifier> | undefined, name: PropertyName, descriptorName: Identifier) {
|
||||
// strip off all but the `static` modifier
|
||||
modifiers = visitNodes(modifiers, node => isStaticModifier(node) ? node : undefined, isModifier);
|
||||
return factory.createGetAccessorDeclaration(
|
||||
@@ -2431,7 +2430,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
* @param name The name for the resulting declaration.
|
||||
* @param descriptorName The name of the descriptor variable.
|
||||
*/
|
||||
function createGetAccessorDescriptorForwarder(modifiers: ModifiersArray | undefined, name: PropertyName, descriptorName: Identifier) {
|
||||
function createGetAccessorDescriptorForwarder(modifiers: NodeArray<Modifier> | undefined, name: PropertyName, descriptorName: Identifier) {
|
||||
// strip off all but the `static` modifier
|
||||
modifiers = visitNodes(modifiers, node => isStaticModifier(node) ? node : undefined, isModifier);
|
||||
return factory.createGetAccessorDeclaration(
|
||||
@@ -2460,7 +2459,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
* @param name The name for the resulting declaration.
|
||||
* @param descriptorName The name of the descriptor variable.
|
||||
*/
|
||||
function createSetAccessorDescriptorForwarder(modifiers: ModifiersArray | undefined, name: PropertyName, descriptorName: Identifier) {
|
||||
function createSetAccessorDescriptorForwarder(modifiers: NodeArray<Modifier> | undefined, name: PropertyName, descriptorName: Identifier) {
|
||||
// strip off all but the `static` modifier
|
||||
modifiers = visitNodes(modifiers, node => isStaticModifier(node) ? node : undefined, isModifier);
|
||||
return factory.createSetAccessorDeclaration(
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
getNonAssignmentOperatorForCompoundAssignment,
|
||||
getOriginalNode,
|
||||
getOriginalNodeId,
|
||||
hasAsteriskToken,
|
||||
Identifier,
|
||||
idText,
|
||||
IfStatement,
|
||||
@@ -422,7 +423,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
||||
else if (inGeneratorFunctionBody) {
|
||||
return visitJavaScriptInGeneratorFunctionBody(node);
|
||||
}
|
||||
else if (isFunctionLikeDeclaration(node) && node.asteriskToken) {
|
||||
else if (isFunctionLikeDeclaration(node) && hasAsteriskToken(node)) {
|
||||
return visitGenerator(node);
|
||||
}
|
||||
else if (transformFlags & TransformFlags.ContainsGenerator) {
|
||||
|
||||
@@ -314,7 +314,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
|
||||
function visitJsxOpeningLikeElementJSX(node: JsxOpeningLikeElement, children: readonly JsxChild[] | undefined, isChild: boolean, location: TextRange) {
|
||||
const tagName = getTagName(node);
|
||||
const childrenProp = children && children.length ? convertJsxChildrenToChildrenPropAssignment(children) : undefined;
|
||||
const keyAttr = find(node.attributes.properties, p => !!p.name && isIdentifier(p.name) && p.name.escapedText === "key") as JsxAttribute | undefined;
|
||||
const keyAttr = find(node.attributes.properties, p => !isJsxSpreadAttribute(p) && isIdentifier(p.name) && p.name.escapedText === "key") as JsxAttribute | undefined;
|
||||
const attrs = keyAttr ? filter(node.attributes.properties, p => p !== keyAttr) : node.attributes.properties;
|
||||
const objectProperties = length(attrs) ? transformJsxAttributesToObjectProps(attrs, childrenProp) :
|
||||
factory.createObjectLiteralExpression(childrenProp ? [childrenProp] : emptyArray); // When there are no attributes, React wants {}
|
||||
|
||||
+4816
-1098
File diff suppressed because it is too large
Load Diff
+53
-35
@@ -24,7 +24,14 @@ import {
|
||||
AssignmentDeclarationKind,
|
||||
AssignmentExpression,
|
||||
AssignmentOperatorToken,
|
||||
ast,
|
||||
AstBinaryExpression,
|
||||
AstExpression,
|
||||
AstHasJSDoc,
|
||||
AstModifierLike,
|
||||
AstNewExpression,
|
||||
AstNode,
|
||||
AstPostfixUnaryExpression,
|
||||
AstPrefixUnaryExpression,
|
||||
BarBarEqualsToken,
|
||||
BinaryExpression,
|
||||
binarySearch,
|
||||
@@ -253,6 +260,7 @@ import {
|
||||
isArrayLiteralExpression,
|
||||
isArrowFunction,
|
||||
isAssertionExpression,
|
||||
isAstJSDocTypeExpression,
|
||||
isAutoAccessorPropertyDeclaration,
|
||||
isBigIntLiteral,
|
||||
isBinaryExpression,
|
||||
@@ -488,6 +496,7 @@ import {
|
||||
QuestionQuestionEqualsToken,
|
||||
ReadonlyCollection,
|
||||
ReadonlyTextRange,
|
||||
RegularExpressionLiteral,
|
||||
removeTrailingDirectorySeparator,
|
||||
RequireOrImportCall,
|
||||
RequireVariableStatement,
|
||||
@@ -508,6 +517,7 @@ import {
|
||||
shouldAllowImportingTsExtension,
|
||||
Signature,
|
||||
SignatureDeclaration,
|
||||
SignatureDeclarationBase,
|
||||
SignatureFlags,
|
||||
singleElementArray,
|
||||
singleOrUndefined,
|
||||
@@ -525,6 +535,7 @@ import {
|
||||
Statement,
|
||||
StringLiteral,
|
||||
StringLiteralLike,
|
||||
StringLiteralLikeNode,
|
||||
StringLiteralType,
|
||||
stringToToken,
|
||||
SuperCall,
|
||||
@@ -561,7 +572,7 @@ import {
|
||||
TupleTypeNode,
|
||||
Type,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeChecker,
|
||||
TypeCheckerHost,
|
||||
TypeElement,
|
||||
@@ -777,7 +788,7 @@ export function usingSingleLineStringWriter(action: (writer: EmitTextWriter) =>
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getFullWidth(node: Node | ast.AstNode): number {
|
||||
export function getFullWidth(node: Node | AstNode): number {
|
||||
return node.end - node.pos;
|
||||
}
|
||||
|
||||
@@ -933,8 +944,8 @@ export function hasChangesInResolutions<K, V>(
|
||||
|
||||
// Returns true if this node contains a parse error anywhere underneath it.
|
||||
/** @internal */
|
||||
export function containsParseError(node: Node | ast.AstNode): boolean {
|
||||
aggregateChildData(node instanceof ast.AstNode ? node.node : node); // TODO(rbuckton): do not instantiate node
|
||||
export function containsParseError(node: Node | AstNode): boolean {
|
||||
aggregateChildData(node instanceof AstNode ? node.node : node); // TODO(rbuckton): do not instantiate node
|
||||
return (node.flags & NodeFlags.ThisNodeOrAnySubNodesHasError) !== 0;
|
||||
}
|
||||
|
||||
@@ -1058,7 +1069,7 @@ export function isFileLevelUniqueName(sourceFile: SourceFile, name: string, hasG
|
||||
// However, this node will be 'missing' in the sense that no actual source-code/tokens are
|
||||
// contained within it.
|
||||
/** @internal */
|
||||
export function nodeIsMissing(node: Node | ast.AstNode | undefined): boolean {
|
||||
export function nodeIsMissing(node: Node | AstNode | undefined): boolean {
|
||||
if (node === undefined) {
|
||||
return true;
|
||||
}
|
||||
@@ -1067,7 +1078,7 @@ export function nodeIsMissing(node: Node | ast.AstNode | undefined): boolean {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function nodeIsPresent(node: Node | ast.AstNode | undefined): boolean {
|
||||
export function nodeIsPresent(node: Node | AstNode | undefined): boolean {
|
||||
return !nodeIsMissing(node);
|
||||
}
|
||||
|
||||
@@ -1279,9 +1290,9 @@ export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node:
|
||||
return getTextOfNodeFromSourceText(sourceFile.text, node, includeTrivia);
|
||||
}
|
||||
|
||||
function isJSDocTypeExpressionOrChild(node: Node | ast.AstNode): boolean {
|
||||
return node instanceof ast.AstNode ?
|
||||
!!findAncestor(node, ast.isAstJSDocTypeExpression) :
|
||||
function isJSDocTypeExpressionOrChild(node: Node | AstNode): boolean {
|
||||
return node instanceof AstNode ?
|
||||
!!findAncestor(node, isAstJSDocTypeExpression) :
|
||||
!!findAncestor(node, isJSDocTypeExpression);
|
||||
}
|
||||
|
||||
@@ -1312,7 +1323,7 @@ export function moduleExportNameIsDefault(node: ModuleExportName): boolean {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getTextOfNodeFromSourceText(sourceText: string, node: Node | ast.AstNode, includeTrivia = false): string {
|
||||
export function getTextOfNodeFromSourceText(sourceText: string, node: Node | AstNode, includeTrivia = false): string {
|
||||
if (nodeIsMissing(node)) {
|
||||
return "";
|
||||
}
|
||||
@@ -1880,7 +1891,7 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u
|
||||
case SyntaxKind.BigIntLiteral:
|
||||
return node.text;
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && node.isUnterminated) {
|
||||
if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as RegularExpressionLiteral).isUnterminated) {
|
||||
return node.text + (node.text.charCodeAt(node.text.length - 1) === CharacterCodes.backslash ? " /" : "/");
|
||||
}
|
||||
return node.text;
|
||||
@@ -1890,7 +1901,7 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u
|
||||
}
|
||||
|
||||
function canUseOriginalText(node: LiteralLikeNode, flags: GetLiteralTextFlags): boolean {
|
||||
if (nodeIsSynthesized(node) || !node.parent || (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && node.isUnterminated)) {
|
||||
if (nodeIsSynthesized(node) || !node.parent || (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as StringLiteralLikeNode).isUnterminated)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2610,7 +2621,7 @@ export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: Sour
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getJSDocCommentRanges(node: Node | ast.AstNode, text: string): CommentRange[] | undefined {
|
||||
export function getJSDocCommentRanges(node: Node | AstNode, text: string): CommentRange[] | undefined {
|
||||
const commentRanges = (node.kind === SyntaxKind.Parameter ||
|
||||
node.kind === SyntaxKind.TypeParameter ||
|
||||
node.kind === SyntaxKind.FunctionExpression ||
|
||||
@@ -2719,7 +2730,7 @@ export function isPartOfTypeNode(node: Node): boolean {
|
||||
case SyntaxKind.IndexSignature:
|
||||
return node === (parent as SignatureDeclaration).type;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return node === (parent as TypeAssertion).type;
|
||||
return node === (parent as TypeAssertionExpression).type;
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
@@ -2789,7 +2800,7 @@ export function forEachYieldExpression(body: Block, visitor: (expr: YieldExpress
|
||||
return;
|
||||
default:
|
||||
if (isFunctionLike(node)) {
|
||||
if (node.name && node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
// Note that we will not include methods/accessors of a class because they would require
|
||||
// first descending into the class. This is by design.
|
||||
traverse(node.name.expression);
|
||||
@@ -4394,8 +4405,8 @@ export function canHaveFlowNode(node: Node): node is HasFlowNode {
|
||||
/** @internal */
|
||||
export function canHaveJSDoc(node: Node): node is HasJSDoc;
|
||||
/** @internal */
|
||||
export function canHaveJSDoc(node: ast.AstNode): node is ast.AstHasJSDoc;
|
||||
export function canHaveJSDoc(node: Node | ast.AstNode) {
|
||||
export function canHaveJSDoc(node: AstNode): node is AstHasJSDoc;
|
||||
export function canHaveJSDoc(node: Node | AstNode) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
@@ -4672,6 +4683,7 @@ export function getTypeParameterFromJsDoc(node: TypeParameterDeclaration & { par
|
||||
|
||||
/** @internal @knipignore */
|
||||
export function hasTypeArguments(node: Node): node is HasTypeArguments {
|
||||
// TODO: switch on kind
|
||||
return !!(node as HasTypeArguments).typeArguments;
|
||||
}
|
||||
|
||||
@@ -5183,13 +5195,16 @@ export function getFunctionFlags(node: SignatureDeclaration | undefined): Functi
|
||||
|
||||
/** @internal */
|
||||
export function isAsyncFunction(node: Node): boolean {
|
||||
Debug.type<FunctionLikeDeclaration>(node);
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return (node as FunctionLikeDeclaration).body !== undefined
|
||||
&& (node as FunctionLikeDeclaration).asteriskToken === undefined
|
||||
return node.body !== undefined
|
||||
&& node.asteriskToken === undefined
|
||||
&& hasSyntacticModifier(node, ModifierFlags.Async);
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return node.body !== undefined
|
||||
&& hasSyntacticModifier(node, ModifierFlags.Async);
|
||||
}
|
||||
return false;
|
||||
@@ -5471,9 +5486,9 @@ export const enum Associativity {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getExpressionAssociativity(expression: Expression | ast.AstExpression): Associativity {
|
||||
export function getExpressionAssociativity(expression: Expression | AstExpression): Associativity {
|
||||
const operator = getOperator(expression);
|
||||
const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof ast.AstNode ? (expression as ast.AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined);
|
||||
const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof AstNode ? (expression as AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined);
|
||||
return getOperatorAssociativity(expression.kind, operator, hasArguments);
|
||||
}
|
||||
|
||||
@@ -5518,18 +5533,18 @@ export function getOperatorAssociativity(kind: SyntaxKind, operator: SyntaxKind,
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getExpressionPrecedence(expression: Expression | ast.AstExpression): OperatorPrecedence {
|
||||
export function getExpressionPrecedence(expression: Expression | AstExpression): OperatorPrecedence {
|
||||
const operator = getOperator(expression);
|
||||
const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof ast.AstNode ? (expression as ast.AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined);
|
||||
const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof AstNode ? (expression as AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined);
|
||||
return getOperatorPrecedence(expression.kind, operator, hasArguments);
|
||||
}
|
||||
|
||||
function getOperator(expression: Expression | ast.AstExpression): SyntaxKind {
|
||||
function getOperator(expression: Expression | AstExpression): SyntaxKind {
|
||||
if (expression.kind === SyntaxKind.BinaryExpression) {
|
||||
return expression instanceof ast.AstNode ? (expression as ast.AstBinaryExpression).data.operatorToken.kind : (expression as BinaryExpression).operatorToken.kind;
|
||||
return expression instanceof AstNode ? (expression as AstBinaryExpression).data.operatorToken.kind : (expression as BinaryExpression).operatorToken.kind;
|
||||
}
|
||||
else if (expression.kind === SyntaxKind.PrefixUnaryExpression || expression.kind === SyntaxKind.PostfixUnaryExpression) {
|
||||
return expression instanceof ast.AstNode ? (expression as ast.AstPrefixUnaryExpression | ast.AstPostfixUnaryExpression).data.operator : (expression as PrefixUnaryExpression | PostfixUnaryExpression).operator;
|
||||
return expression instanceof AstNode ? (expression as AstPrefixUnaryExpression | AstPostfixUnaryExpression).data.operator : (expression as PrefixUnaryExpression | PostfixUnaryExpression).operator;
|
||||
}
|
||||
else {
|
||||
return expression.kind;
|
||||
@@ -7172,7 +7187,7 @@ export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function modifiersToFlags(modifiers: readonly ModifierLike[] | readonly ast.AstModifierLike[] | undefined): ModifierFlags {
|
||||
export function modifiersToFlags(modifiers: readonly ModifierLike[] | readonly AstModifierLike[] | undefined): ModifierFlags {
|
||||
let flags = ModifierFlags.None;
|
||||
if (modifiers) {
|
||||
for (const modifier of modifiers) {
|
||||
@@ -10424,11 +10439,11 @@ export function setNodeFlags<T extends Node>(node: T | undefined, newFlags: Node
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function setParent<T extends Node | ast.AstNode>(child: T, parent: T["parent"] | undefined): T;
|
||||
export function setParent<T extends Node | AstNode>(child: T, parent: T["parent"] | undefined): T;
|
||||
/** @internal */
|
||||
export function setParent<T extends Node | ast.AstNode>(child: T | undefined, parent: T["parent"] | undefined): T | undefined;
|
||||
export function setParent<T extends Node | AstNode>(child: T | undefined, parent: T["parent"] | undefined): T | undefined;
|
||||
/** @internal */
|
||||
export function setParent<T extends Node | ast.AstNode>(child: T | undefined, parent: T["parent"] | undefined): T | undefined {
|
||||
export function setParent<T extends Node | AstNode>(child: T | undefined, parent: T["parent"] | undefined): T | undefined {
|
||||
if (child && parent) {
|
||||
(child as Mutable<T>).parent = parent;
|
||||
}
|
||||
@@ -11700,13 +11715,16 @@ export function createNameResolver({
|
||||
return isTypeQueryNode(location) || ((
|
||||
isFunctionLikeDeclaration(location) ||
|
||||
(location.kind === SyntaxKind.PropertyDeclaration && !isStatic(location))
|
||||
) && (!lastLocation || lastLocation !== (location as SignatureDeclaration | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred
|
||||
// TODO(rbuckton): unchecked cast can result in wrong map deopt for missing `name` property
|
||||
) && (!lastLocation || lastLocation !== (location as SignatureDeclarationBase | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred
|
||||
}
|
||||
if (lastLocation && lastLocation === (location as FunctionExpression | ArrowFunction).name) {
|
||||
// TODO(rbuckton): unchecked cast can result in wrong map deopt for missing `name` property
|
||||
if (lastLocation && lastLocation === (location as FunctionExpression).name) {
|
||||
return false;
|
||||
}
|
||||
// generator functions and async functions are not inlined in control flow when immediately invoked
|
||||
if ((location as FunctionExpression | ArrowFunction).asteriskToken || hasSyntacticModifier(location, ModifierFlags.Async)) {
|
||||
// TODO(rbuckton): unchecked cast can result in wrong map deopt for missing `asteriskToken` property
|
||||
if ((location as FunctionExpression).asteriskToken || hasSyntacticModifier(location, ModifierFlags.Async)) {
|
||||
return true;
|
||||
}
|
||||
return !getImmediatelyInvokedFunctionExpression(location);
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
AssertionExpression,
|
||||
AssignmentDeclarationKind,
|
||||
AssignmentPattern,
|
||||
ast,
|
||||
AutoAccessorPropertyDeclaration,
|
||||
BinaryExpression,
|
||||
BindableObjectDefinePropertyCall,
|
||||
@@ -227,6 +226,7 @@ import {
|
||||
ModuleDeclaration,
|
||||
ModuleReference,
|
||||
NamedDeclaration,
|
||||
HasName,
|
||||
NamedExportBindings,
|
||||
NamedImportBindings,
|
||||
NamespaceBody,
|
||||
@@ -291,6 +291,10 @@ import {
|
||||
TypeReferenceType,
|
||||
UnaryExpression,
|
||||
VariableDeclaration,
|
||||
HasQuestionToken,
|
||||
HasAsteriskToken,
|
||||
AsteriskToken,
|
||||
AstNode,
|
||||
} from "./_namespaces/ts.js";
|
||||
|
||||
export function isExternalModuleNameRelative(moduleName: string): boolean {
|
||||
@@ -780,7 +784,7 @@ interface AncestorTraversable<T extends AncestorTraversable<T>> {
|
||||
* At that point findAncestor returns undefined.
|
||||
* @internal
|
||||
*/
|
||||
export function findAncestor<T extends ast.AstNode>(node: ast.AstNode | undefined, callback: (element: ast.AstNode) => element is T): T | undefined;
|
||||
export function findAncestor<T extends AstNode>(node: AstNode | undefined, callback: (element: AstNode) => element is T): T | undefined;
|
||||
/**
|
||||
* Iterates through the parent chain of a node and performs the callback on each parent until the callback
|
||||
* returns a truthy value, then returns that value.
|
||||
@@ -789,7 +793,7 @@ export function findAncestor<T extends ast.AstNode>(node: ast.AstNode | undefine
|
||||
*/
|
||||
export function findAncestor<T extends Node>(node: Node | undefined, callback: (element: Node) => element is T): T | undefined;
|
||||
/** @internal */
|
||||
export function findAncestor(node: ast.AstNode | undefined, callback: (element: ast.AstNode) => boolean | "quit"): ast.AstNode | undefined;
|
||||
export function findAncestor(node: AstNode | undefined, callback: (element: AstNode) => boolean | "quit"): AstNode | undefined;
|
||||
export function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined;
|
||||
export function findAncestor<T extends AncestorTraversable<T>>(node: T | T | undefined, callback: (element: T) => boolean | "quit"): T | undefined {
|
||||
while (node) {
|
||||
@@ -812,8 +816,8 @@ export function findAncestor<T extends AncestorTraversable<T>>(node: T | T | und
|
||||
*/
|
||||
export function isParseTreeNode(node: Node): boolean;
|
||||
/** @internal */
|
||||
export function isParseTreeNode(node: Node | ast.AstNode<ast.Node>): boolean; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function isParseTreeNode(node: Node | ast.AstNode<ast.Node>): boolean {
|
||||
export function isParseTreeNode(node: Node | AstNode<Node>): boolean; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
export function isParseTreeNode(node: Node | AstNode<Node>): boolean {
|
||||
return (node.flags & NodeFlags.Synthesized) === 0;
|
||||
}
|
||||
|
||||
@@ -956,6 +960,98 @@ export function isNamedDeclaration(node: Node): node is NamedDeclaration & { nam
|
||||
return !!(node as NamedDeclaration).name; // A 'name' property should always be a DeclarationName.
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function canHaveName(node: Node): node is HasName {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.ImportAttribute:
|
||||
case SyntaxKind.ImportClause:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.JSDocCallbackTag:
|
||||
case SyntaxKind.JSDocLink:
|
||||
case SyntaxKind.JSDocLinkCode:
|
||||
case SyntaxKind.JSDocLinkPlain:
|
||||
case SyntaxKind.JSDocNameReference:
|
||||
case SyntaxKind.JSDocParameterTag:
|
||||
case SyntaxKind.JSDocPropertyTag:
|
||||
case SyntaxKind.JSDocSeeTag:
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
case SyntaxKind.JsxAttribute:
|
||||
case SyntaxKind.JsxNamespacedName:
|
||||
case SyntaxKind.MetaProperty:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.MissingDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.NamedTupleMember:
|
||||
case SyntaxKind.NamespaceExport:
|
||||
case SyntaxKind.NamespaceExportDeclaration:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.TypeParameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function hasName(node: Node): node is HasName & { name: DeclarationName } {
|
||||
return canHaveName(node) && !!node.name;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function canHaveQuestionToken(node: Node): node is HasQuestionToken {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.NamedTupleMember:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function canHaveAsteriskToken(node: Node): node is HasAsteriskToken {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.YieldExpression:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function hasAsteriskToken(node: Node): node is HasAsteriskToken & { asteriskToken: AsteriskToken } {
|
||||
return canHaveAsteriskToken(node) && !!node.asteriskToken;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getNonAssignedNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined {
|
||||
switch (declaration.kind) {
|
||||
@@ -1494,7 +1590,7 @@ export function isToken(n: Node): boolean {
|
||||
|
||||
/** @internal */
|
||||
export function isNodeArray<T extends Node>(array: readonly T[]): array is NodeArray<T> {
|
||||
return hasProperty(array, "pos") && hasProperty(array, "end") || array instanceof ast.NodeArray;
|
||||
return hasProperty(array, "pos") && hasProperty(array, "end") || array instanceof NodeArray;
|
||||
}
|
||||
|
||||
// Literals
|
||||
@@ -2558,6 +2654,7 @@ export function hasJSDocNodes(node: Node): node is HasJSDoc {
|
||||
* @internal
|
||||
*/
|
||||
export function hasType(node: Node): node is HasType {
|
||||
// TODO: switch on kind
|
||||
return !!(node as HasType).type;
|
||||
}
|
||||
|
||||
@@ -2567,6 +2664,7 @@ export function hasType(node: Node): node is HasType {
|
||||
* @internal
|
||||
*/
|
||||
export function hasInitializer(node: Node): node is HasInitializer {
|
||||
// TODO: switch on kind
|
||||
return !!(node as HasInitializer).initializer;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,8 +175,8 @@ function convertDiagnostic(diagnostic: ts.Diagnostic) {
|
||||
|
||||
export function sourceFileToJSON(file: ts.Node): string {
|
||||
const s = JSON.stringify(file, (_, v) => {
|
||||
if (v instanceof ts.ast.AstNode) v = v.node;
|
||||
if (v instanceof ts.ast.AstNodeArray) v = v.nodes;
|
||||
if (v instanceof ts.AstNode) v = v.node;
|
||||
if (v instanceof ts.AstNodeArray) v = v.nodes;
|
||||
return isNodeOrArray(v) ? serializeNode(v) : v;
|
||||
}, " ");
|
||||
return s;
|
||||
@@ -267,8 +267,8 @@ export function sourceFileToJSON(file: ts.Node): string {
|
||||
|
||||
default: {
|
||||
let value = obj[propertyName];
|
||||
if (value instanceof ts.ast.AstNode) value = value.node;
|
||||
if (value instanceof ts.ast.AstNodeArray) value = value.nodes;
|
||||
if (value instanceof ts.AstNode) value = value.node;
|
||||
if (value instanceof ts.AstNodeArray) value = value.nodes;
|
||||
o[propertyName] = value;
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ export function sourceFileToJSON(file: ts.Node): string {
|
||||
if (ts.containsParseError(n)) {
|
||||
o.containsParseError = true;
|
||||
}
|
||||
if (n instanceof ts.ast.Node) {
|
||||
if (n instanceof ts.Node) {
|
||||
serializeProperties(o, n, n, ["pos", "end", "flags", "modifierFlagsCache", "transformFlags"]);
|
||||
serializeProperties(o, n, n.ast.data, Object.getOwnPropertyNames(n.ast.data));
|
||||
}
|
||||
@@ -292,7 +292,7 @@ export function sourceFileToJSON(file: ts.Node): string {
|
||||
}
|
||||
else {
|
||||
serializeProperties(o, /*n*/ undefined, n, Object.getOwnPropertyNames(n));
|
||||
if (n instanceof ts.ast.NodeArray) {
|
||||
if (n instanceof ts.NodeArray) {
|
||||
serializeProperties(o, /*n*/ undefined, n, ["pos", "end", "hasTrailingComma", "transformFlags"]);
|
||||
}
|
||||
}
|
||||
@@ -376,10 +376,10 @@ function assertArrayStructuralEquals(array1: ts.NodeArray<ts.Node>, array2: ts.N
|
||||
}
|
||||
|
||||
function findChildName(parent: any, child: any) {
|
||||
if (parent instanceof ts.ast.Node) {
|
||||
if (parent instanceof ts.Node) {
|
||||
parent = parent.ast.data;
|
||||
}
|
||||
if (child instanceof ts.ast.Node || child instanceof ts.ast.NodeArray) {
|
||||
if (child instanceof ts.Node || child instanceof ts.NodeArray) {
|
||||
child = child.ast;
|
||||
}
|
||||
for (const name in parent) {
|
||||
|
||||
@@ -64,7 +64,7 @@ import {
|
||||
TextSpan,
|
||||
ThrowStatement,
|
||||
TryStatement,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
VariableDeclaration,
|
||||
VariableDeclarationList,
|
||||
VariableStatement,
|
||||
@@ -423,8 +423,8 @@ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: num
|
||||
break;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
// Breakpoint in type assertion goes to its operand
|
||||
if ((node.parent as TypeAssertion).type === node) {
|
||||
return spanInNextNode((node.parent as TypeAssertion).type);
|
||||
if ((node.parent as TypeAssertionExpression).type === node) {
|
||||
return spanInNextNode((node.parent as TypeAssertionExpression).type);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
|
||||
@@ -101,7 +101,7 @@ import {
|
||||
TaggedTemplateExpression,
|
||||
TextRange,
|
||||
TextSpan,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeChecker,
|
||||
usingSingleLineStringWriter,
|
||||
VariableDeclaration,
|
||||
@@ -538,7 +538,7 @@ function createCallSiteCollector(program: Program, callSites: CallSite[]): (node
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.AsExpression:
|
||||
// do not descend into the type side of an assertion
|
||||
collect((node as TypeAssertion | AsExpression).expression);
|
||||
collect((node as TypeAssertionExpression | AsExpression).expression);
|
||||
return;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
SourceFile,
|
||||
SyntaxKind,
|
||||
textChanges,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
const fixId = "addConvertToUnknownForNonOverlappingTypes";
|
||||
@@ -38,14 +38,14 @@ registerCodeFix({
|
||||
}),
|
||||
});
|
||||
|
||||
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, assertion: AsExpression | TypeAssertion) {
|
||||
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, assertion: AsExpression | TypeAssertionExpression) {
|
||||
const replacement = isAsExpression(assertion)
|
||||
? factory.createAsExpression(assertion.expression, factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword))
|
||||
: factory.createTypeAssertion(factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword), assertion.expression);
|
||||
changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
|
||||
}
|
||||
|
||||
function getAssertion(sourceFile: SourceFile, pos: number): AsExpression | TypeAssertion | undefined {
|
||||
function getAssertion(sourceFile: SourceFile, pos: number): AsExpression | TypeAssertionExpression | undefined {
|
||||
if (isInJSFile(sourceFile)) return undefined;
|
||||
return findAncestor(getTokenAtPosition(sourceFile, pos), (n): n is AsExpression | TypeAssertion => isAsExpression(n) || isTypeAssertionExpression(n));
|
||||
return findAncestor(getTokenAtPosition(sourceFile, pos), (n): n is AsExpression | TypeAssertionExpression => isAsExpression(n) || isTypeAssertionExpression(n));
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
getNameOfDeclaration,
|
||||
getQuotePreference,
|
||||
getTokenAtPosition,
|
||||
hasName,
|
||||
idText,
|
||||
isAccessExpression,
|
||||
isArrowFunction,
|
||||
@@ -315,7 +316,7 @@ function getModifierKindFromSource(source: Node, kind: Modifier["kind"]): readon
|
||||
}
|
||||
|
||||
function isConstructorAssignment(x: ObjectLiteralElementLike | PropertyAccessExpression) {
|
||||
if (!x.name) return false;
|
||||
if (!hasName(x)) return false;
|
||||
if (isIdentifier(x.name) && x.name.text === "constructor") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
BinaryExpression,
|
||||
BindingElement,
|
||||
BindingName,
|
||||
canHaveAsteriskToken,
|
||||
ClassDeclaration,
|
||||
ClassExpression,
|
||||
concatenate,
|
||||
@@ -35,6 +36,7 @@ import {
|
||||
getSynthesizedDeepClones,
|
||||
getSynthesizedDeepClonesWithReplacements,
|
||||
getSynthesizedDeepCloneWithReplacements,
|
||||
hasName,
|
||||
Identifier,
|
||||
ImportDeclaration,
|
||||
importFromModuleSpecifier,
|
||||
@@ -77,6 +79,7 @@ import {
|
||||
SymbolFlags,
|
||||
SyntaxKind,
|
||||
textChanges,
|
||||
tryCast,
|
||||
TypeChecker,
|
||||
VariableStatement,
|
||||
} from "../_namespaces/ts.js";
|
||||
@@ -411,11 +414,11 @@ function reExportDefault(moduleSpecifier: string): ExportDeclaration {
|
||||
|
||||
function convertExportsPropertyAssignment({ left, right, parent }: BinaryExpression & { left: PropertyAccessExpression; }, sourceFile: SourceFile, changes: textChanges.ChangeTracker): void {
|
||||
const name = left.name.text;
|
||||
if ((isFunctionExpression(right) || isArrowFunction(right) || isClassExpression(right)) && (!right.name || right.name.text === name)) {
|
||||
if ((isFunctionExpression(right) || isArrowFunction(right) || isClassExpression(right)) && (!hasName(right) || right.name.text === name)) {
|
||||
// `exports.f = function() {}` -> `export function f() {}` -- Replace `exports.f = ` with `export `, and insert the name after `function`.
|
||||
changes.replaceRange(sourceFile, { pos: left.getStart(sourceFile), end: right.getStart(sourceFile) }, factory.createToken(SyntaxKind.ExportKeyword), { suffix: " " });
|
||||
|
||||
if (!right.name) changes.insertName(sourceFile, right, name);
|
||||
if (!hasName(right)) changes.insertName(sourceFile, right, name);
|
||||
|
||||
const semi = findChildOfKind(parent, SyntaxKind.SemicolonToken, sourceFile);
|
||||
if (semi) changes.delete(sourceFile, semi);
|
||||
@@ -631,7 +634,7 @@ function isFreeIdentifier(node: Identifier): boolean {
|
||||
function functionExpressionToDeclaration(name: string | undefined, additionalModifiers: readonly Modifier[], fn: FunctionExpression | ArrowFunction | MethodDeclaration, useSitesToUnqualify: Map<Node, Node> | undefined): FunctionDeclaration {
|
||||
return factory.createFunctionDeclaration(
|
||||
concatenate(additionalModifiers, getSynthesizedDeepClones(fn.modifiers)),
|
||||
getSynthesizedDeepClone(fn.asteriskToken),
|
||||
getSynthesizedDeepClone(tryCast(fn, canHaveAsteriskToken)?.asteriskToken),
|
||||
name,
|
||||
getSynthesizedDeepClones(fn.typeParameters),
|
||||
getSynthesizedDeepClones(fn.parameters),
|
||||
|
||||
@@ -79,7 +79,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, {
|
||||
hasEffectiveReadonlyModifier(indexSignature) ? factory.createModifier(SyntaxKind.ReadonlyKeyword) : undefined,
|
||||
mappedTypeParameter,
|
||||
/*nameType*/ undefined,
|
||||
indexSignature.questionToken,
|
||||
/*questionToken*/ undefined,
|
||||
indexSignature.type,
|
||||
/*members*/ undefined,
|
||||
);
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
textChanges,
|
||||
Type,
|
||||
TypeAliasDeclaration,
|
||||
TypeAssertion,
|
||||
TypeAssertionExpression,
|
||||
TypeChecker,
|
||||
TypeFlags,
|
||||
TypeNode,
|
||||
@@ -92,7 +92,7 @@ function getInfo(sourceFile: SourceFile, pos: number, checker: TypeChecker): { r
|
||||
}
|
||||
|
||||
// TODO: GH#19856 Node & { type: TypeNode }
|
||||
type TypeContainer = AsExpression | CallSignatureDeclaration | ConstructSignatureDeclaration | FunctionDeclaration | GetAccessorDeclaration | IndexSignatureDeclaration | MappedTypeNode | MethodDeclaration | MethodSignature | ParameterDeclaration | PropertyDeclaration | PropertySignature | SetAccessorDeclaration | TypeAliasDeclaration | TypeAssertion | VariableDeclaration;
|
||||
type TypeContainer = AsExpression | CallSignatureDeclaration | ConstructSignatureDeclaration | FunctionDeclaration | GetAccessorDeclaration | IndexSignatureDeclaration | MappedTypeNode | MethodDeclaration | MethodSignature | ParameterDeclaration | PropertyDeclaration | PropertySignature | SetAccessorDeclaration | TypeAliasDeclaration | TypeAssertionExpression | VariableDeclaration;
|
||||
function isTypeContainer(node: Node): node is TypeContainer {
|
||||
// NOTE: Some locations are not handled yet:
|
||||
// MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ArrowFunction,
|
||||
Block,
|
||||
CallExpression,
|
||||
canHaveAsteriskToken,
|
||||
CharacterCodes,
|
||||
CheckFlags,
|
||||
ClassLikeDeclaration,
|
||||
@@ -469,7 +470,7 @@ export function createSignatureDeclarationFromSignature(
|
||||
}
|
||||
|
||||
const questionToken = optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined;
|
||||
const asteriskToken = signatureDeclaration.asteriskToken;
|
||||
const asteriskToken = tryCast(signatureDeclaration, canHaveAsteriskToken)?.asteriskToken;
|
||||
if (isFunctionExpression(signatureDeclaration)) {
|
||||
return factory.updateFunctionExpression(signatureDeclaration, modifiers, signatureDeclaration.asteriskToken, tryCast(name, isIdentifier), typeParameters, parameters, type, body ?? signatureDeclaration.body);
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ function getFunctionReferences(containingFunction: SignatureDeclaration, sourceF
|
||||
const parent = containingFunction.parent;
|
||||
searchToken = (isVariableDeclaration(parent) || isPropertyDeclaration(parent)) && isIdentifier(parent.name) ?
|
||||
parent.name :
|
||||
containingFunction.name;
|
||||
isFunctionExpression(containingFunction) ? containingFunction.name : undefined;
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
|
||||
@@ -96,6 +96,7 @@ import {
|
||||
GoToDefinition,
|
||||
hasEffectiveModifier,
|
||||
hasInitializer,
|
||||
hasName,
|
||||
hasSyntacticModifier,
|
||||
hasType,
|
||||
HighlightSpan,
|
||||
@@ -389,9 +390,9 @@ function getContextNodeForNodeEntry(node: Node): ContextNode | undefined {
|
||||
}
|
||||
|
||||
if (
|
||||
node.parent.name === node || // node is name of declaration, use parent
|
||||
isConstructorDeclaration(node.parent) ||
|
||||
isExportAssignment(node.parent) ||
|
||||
isConstructorDeclaration(node.parent) ||
|
||||
node.parent.name === node || // node is name of declaration, use parent
|
||||
// Property name of the import export specifier or binding pattern, use parent
|
||||
((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent))
|
||||
&& node.parent.propertyName === node) ||
|
||||
@@ -1752,7 +1753,7 @@ export namespace Core {
|
||||
checker: TypeChecker,
|
||||
cb: (name: Identifier, call?: CallExpression) => boolean,
|
||||
): boolean {
|
||||
if (!signature.name || !isIdentifier(signature.name)) return false;
|
||||
if (!hasName(signature) || !isIdentifier(signature.name)) return false;
|
||||
|
||||
const symbol = Debug.checkDefined(checker.getSymbolAtLocation(signature.name));
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
getTextOfPropertyName,
|
||||
getTouchingPropertyName,
|
||||
getTouchingToken,
|
||||
hasAsteriskToken,
|
||||
hasEffectiveModifier,
|
||||
hasInitializer,
|
||||
hasStaticModifier,
|
||||
@@ -167,7 +168,7 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
|
||||
|
||||
if (node.kind === SyntaxKind.YieldKeyword) {
|
||||
const functionDeclaration = findAncestor(node, n => isFunctionLikeDeclaration(n));
|
||||
const isGeneratorFunction = functionDeclaration && functionDeclaration.asteriskToken;
|
||||
const isGeneratorFunction = functionDeclaration && hasAsteriskToken(functionDeclaration);
|
||||
return isGeneratorFunction ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ export const enum ImportExport {
|
||||
}
|
||||
|
||||
interface AmbientModuleDeclaration extends ModuleDeclaration {
|
||||
body?: ModuleBlock;
|
||||
body: ModuleBlock | undefined;
|
||||
}
|
||||
type SourceFileLike = SourceFile | AmbientModuleDeclaration;
|
||||
// Identifier for the case of `const x = require("y")`.
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
getTextOfIdentifierOrLiteral,
|
||||
getTextOfNode,
|
||||
hasJSDocNodes,
|
||||
hasName,
|
||||
Identifier,
|
||||
ImportClause,
|
||||
InterfaceDeclaration,
|
||||
@@ -407,12 +408,12 @@ function addChildrenRecursively(node: Node | undefined): void {
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
const nameNode = (node as FunctionLikeDeclaration).name;
|
||||
const nameNode = (node as FunctionDeclaration).name;
|
||||
// If we see a function declaration track as a possible ES5 class
|
||||
if (nameNode && isIdentifier(nameNode)) {
|
||||
addTrackedEs5Class(nameNode.text);
|
||||
}
|
||||
addNodeWithRecursiveChild(node, (node as FunctionLikeDeclaration).body);
|
||||
addNodeWithRecursiveChild(node, (node as FunctionDeclaration).body);
|
||||
break;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
@@ -1027,7 +1028,7 @@ function getModifiers(node: Node): string {
|
||||
|
||||
function getFunctionOrClassName(node: FunctionExpression | FunctionDeclaration | ArrowFunction | ClassLikeDeclaration): string {
|
||||
const { parent } = node;
|
||||
if (node.name && getFullWidth(node.name) > 0) {
|
||||
if (hasName(node) && getFullWidth(node.name) > 0) {
|
||||
return cleanText(declarationNameToString(node.name));
|
||||
}
|
||||
// See if it is a var initializer. If so, use the var name.
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
ApplicableRefactorInfo,
|
||||
ArrowFunction,
|
||||
Block,
|
||||
canHaveAsteriskToken,
|
||||
ConciseBody,
|
||||
copyComments,
|
||||
copyTrailingAsLeadingComments,
|
||||
@@ -48,6 +49,7 @@ import {
|
||||
suppressLeadingTrivia,
|
||||
SyntaxKind,
|
||||
textChanges,
|
||||
tryCast,
|
||||
TypeChecker,
|
||||
VariableDeclaration,
|
||||
VariableDeclarationList,
|
||||
@@ -261,7 +263,7 @@ function getVariableInfo(func: FunctionExpression | ArrowFunction): VariableInfo
|
||||
function getEditInfoForConvertToAnonymousFunction(context: RefactorContext, func: FunctionExpression | ArrowFunction): FileTextChanges[] {
|
||||
const { file } = context;
|
||||
const body = convertToBlock(func.body);
|
||||
const newNode = factory.createFunctionExpression(func.modifiers, func.asteriskToken, /*name*/ undefined, func.typeParameters, func.parameters, func.type, body);
|
||||
const newNode = factory.createFunctionExpression(func.modifiers, tryCast(func, canHaveAsteriskToken)?.asteriskToken, /*name*/ undefined, func.typeParameters, func.parameters, func.type, body);
|
||||
return textChanges.ChangeTracker.with(context, t => t.replaceNode(file, func, newNode));
|
||||
}
|
||||
|
||||
@@ -274,7 +276,7 @@ function getEditInfoForConvertToNamedFunction(context: RefactorContext, func: Fu
|
||||
|
||||
const modifiersFlags = (getCombinedModifierFlags(variableDeclaration) & ModifierFlags.Export) | getEffectiveModifierFlags(func);
|
||||
const modifiers = factory.createModifiersFromModifierFlags(modifiersFlags);
|
||||
const newNode = factory.createFunctionDeclaration(length(modifiers) ? modifiers : undefined, func.asteriskToken, name, func.typeParameters, func.parameters, func.type, body);
|
||||
const newNode = factory.createFunctionDeclaration(length(modifiers) ? modifiers : undefined, tryCast(func, canHaveAsteriskToken)?.asteriskToken, name, func.typeParameters, func.parameters, func.type, body);
|
||||
|
||||
if (variableDeclarationList.declarations.length === 1) {
|
||||
return textChanges.ChangeTracker.with(context, t => t.replaceNode(file, statement, newNode));
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
BreakStatement,
|
||||
CancellationToken,
|
||||
canHaveModifiers,
|
||||
cast,
|
||||
CharacterCodes,
|
||||
ClassElement,
|
||||
ClassLikeDeclaration,
|
||||
@@ -59,6 +60,7 @@ import {
|
||||
getThisContainer,
|
||||
getUniqueName,
|
||||
hasEffectiveModifier,
|
||||
hasName,
|
||||
hasSyntacticModifier,
|
||||
Identifier,
|
||||
InternalNodeBuilderFlags,
|
||||
@@ -1646,7 +1648,7 @@ function transformFunctionBody(body: Node, exposedVariableDeclarations: readonly
|
||||
assignments.unshift(factory.createPropertyAssignment(returnValueProperty, visitNode(node.expression, visitor, isExpression)));
|
||||
}
|
||||
if (assignments.length === 1) {
|
||||
return factory.createReturnStatement(assignments[0].name as Expression);
|
||||
return factory.createReturnStatement(cast(assignments[0], hasName).name as Expression);
|
||||
}
|
||||
else {
|
||||
return factory.createReturnStatement(factory.createObjectLiteralExpression(assignments));
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
Block,
|
||||
CallExpression,
|
||||
CancellationToken,
|
||||
canHaveName,
|
||||
codefix,
|
||||
compilerOptionsIndicateEsModules,
|
||||
createDiagnosticForNode,
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
getAssignmentDeclarationKind,
|
||||
getFunctionFlags,
|
||||
hasInitializer,
|
||||
hasName,
|
||||
hasPropertyAccessExpressionWithName,
|
||||
Identifier,
|
||||
importFromModuleSpecifier,
|
||||
@@ -55,6 +57,7 @@ import {
|
||||
some,
|
||||
SourceFile,
|
||||
SyntaxKind,
|
||||
tryCast,
|
||||
TypeChecker,
|
||||
VariableStatement,
|
||||
} from "./_namespaces/ts.js";
|
||||
@@ -125,7 +128,7 @@ export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Pr
|
||||
}
|
||||
|
||||
if (codefix.parameterShouldGetTypeFromJSDoc(node)) {
|
||||
diags.push(createDiagnosticForNode(node.name || node, Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types));
|
||||
diags.push(createDiagnosticForNode(tryCast(node, canHaveName)?.name ?? node, Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +179,7 @@ function addConvertToAsyncFunctionDiagnostics(node: FunctionLikeDeclaration, che
|
||||
// need to check function before checking map so that deeper levels of nested callbacks are checked
|
||||
if (isConvertibleFunction(node, checker) && !visitedNestedConvertibleFunctions.has(getKeyFromNode(node))) {
|
||||
diags.push(createDiagnosticForNode(
|
||||
!node.name && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node,
|
||||
!hasName(node) && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node,
|
||||
Diagnostics.This_may_be_converted_to_an_async_function,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
getTextOfConstantValue,
|
||||
getTextOfIdentifierOrLiteral,
|
||||
getTextOfNode,
|
||||
hasName,
|
||||
hasSyntacticModifier,
|
||||
idText,
|
||||
ImportEqualsDeclaration,
|
||||
@@ -509,7 +510,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker: Type
|
||||
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
|
||||
displayParts.push(spacePart());
|
||||
}
|
||||
else if (declaration.kind !== SyntaxKind.CallSignature && declaration.name) {
|
||||
else if (declaration.kind !== SyntaxKind.CallSignature && hasName(declaration)) {
|
||||
addFullSymbolName(declaration.symbol);
|
||||
}
|
||||
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
addToSeen,
|
||||
ArrowFunction,
|
||||
ast,
|
||||
BindingElement,
|
||||
CharacterCodes,
|
||||
ClassElement,
|
||||
@@ -67,6 +66,7 @@ import {
|
||||
group,
|
||||
HasJSDoc,
|
||||
hasJSDocNodes,
|
||||
hasName,
|
||||
ImportClause,
|
||||
ImportSpecifier,
|
||||
indexOfNode,
|
||||
@@ -163,6 +163,7 @@ import {
|
||||
TextRange,
|
||||
textSpanEnd,
|
||||
Token,
|
||||
TokenSyntaxKind,
|
||||
tokenToString,
|
||||
toSorted,
|
||||
TransformationContext,
|
||||
@@ -681,11 +682,11 @@ export class ChangeTracker {
|
||||
this.insertNodesAt(sourceFile, getAdjustedStartPosition(sourceFile, before, options), newNodes, this.getOptionsForInsertNodeBefore(before, first(newNodes), blankLineBetween));
|
||||
}
|
||||
|
||||
public insertModifierAt(sourceFile: SourceFile, pos: number, modifier: SyntaxKind, options: InsertNodeOptions = {}): void {
|
||||
public insertModifierAt(sourceFile: SourceFile, pos: number, modifier: TokenSyntaxKind, options: InsertNodeOptions = {}): void {
|
||||
this.insertNodeAt(sourceFile, pos, factory.createToken(modifier), options);
|
||||
}
|
||||
|
||||
public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void {
|
||||
public insertModifierBefore(sourceFile: SourceFile, modifier: TokenSyntaxKind, before: Node): void {
|
||||
return this.insertModifierAt(sourceFile, before.getStart(sourceFile), modifier, { suffix: " " });
|
||||
}
|
||||
|
||||
@@ -980,7 +981,7 @@ export class ChangeTracker {
|
||||
}
|
||||
|
||||
public insertName(sourceFile: SourceFile, node: FunctionExpression | ClassExpression | ArrowFunction, name: string): void {
|
||||
Debug.assert(!node.name);
|
||||
Debug.assert(!hasName(node));
|
||||
if (node.kind === SyntaxKind.ArrowFunction) {
|
||||
const arrow = findChildOfKind(node, SyntaxKind.EqualsGreaterThanToken, sourceFile)!;
|
||||
const lparen = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile);
|
||||
@@ -1384,7 +1385,7 @@ const textChangesTransformationContext: TransformationContext = {
|
||||
export function assignPositionsToNode(node: Node): Node {
|
||||
const visited = visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
|
||||
// create proxy node for non synthesized nodes
|
||||
const newNode = nodeIsSynthesized(visited) ? visited : (visited as ast.Node).ast.shadow().node;
|
||||
const newNode = nodeIsSynthesized(visited) ? visited : visited.ast.shadow().node;
|
||||
setTextRangePosEnd(newNode, getPos(node), getEnd(node));
|
||||
return newNode;
|
||||
}
|
||||
|
||||
+1
-89
@@ -14,6 +14,7 @@ import {
|
||||
GetEffectiveTypeRootsHost,
|
||||
HasChangedAutomaticTypeDirectiveNames,
|
||||
HasInvalidatedResolutions,
|
||||
IScriptSnapshot,
|
||||
JSDocParsingMode,
|
||||
LineAndCharacter,
|
||||
MinimalResolutionCacheHost,
|
||||
@@ -43,50 +44,6 @@ import {
|
||||
UserPreferences,
|
||||
} from "./_namespaces/ts.js";
|
||||
|
||||
declare module "../compiler/types.js" {
|
||||
// Module transform: converted from interface augmentation
|
||||
export interface Node {
|
||||
getSourceFile(): SourceFile;
|
||||
getChildCount(sourceFile?: SourceFile): number;
|
||||
getChildAt(index: number, sourceFile?: SourceFile): Node;
|
||||
getChildren(sourceFile?: SourceFile): readonly Node[];
|
||||
/** @internal */
|
||||
getChildren(sourceFile?: SourceFileLike): readonly Node[]; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number;
|
||||
/** @internal */
|
||||
getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
getFullStart(): number;
|
||||
getEnd(): number;
|
||||
getWidth(sourceFile?: SourceFileLike): number;
|
||||
getFullWidth(): number;
|
||||
getLeadingTriviaWidth(sourceFile?: SourceFile): number;
|
||||
getFullText(sourceFile?: SourceFile): string;
|
||||
getText(sourceFile?: SourceFile): string;
|
||||
getFirstToken(sourceFile?: SourceFile): Node | undefined;
|
||||
/** @internal */
|
||||
getFirstToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
getLastToken(sourceFile?: SourceFile): Node | undefined;
|
||||
/** @internal */
|
||||
getLastToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
// See ts.forEachChild for documentation.
|
||||
forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "../compiler/types.js" {
|
||||
// Module transform: converted from interface augmentation
|
||||
export interface Identifier {
|
||||
readonly text: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "../compiler/types.js" {
|
||||
// Module transform: converted from interface augmentation
|
||||
export interface PrivateIdentifier {
|
||||
readonly text: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "../compiler/types.js" {
|
||||
// Module transform: converted from interface augmentation
|
||||
export interface Symbol {
|
||||
@@ -156,25 +113,6 @@ declare module "../compiler/types.js" {
|
||||
}
|
||||
}
|
||||
|
||||
declare module "../compiler/types.js" {
|
||||
// Module transform: converted from interface augmentation
|
||||
export interface SourceFile {
|
||||
/** @internal */ version: string;
|
||||
/** @internal */ scriptSnapshot: IScriptSnapshot | undefined;
|
||||
/** @internal */ nameTable: Map<__String, number> | undefined;
|
||||
|
||||
/** @internal */ getNamedDeclarations(): Map<string, readonly Declaration[]>;
|
||||
|
||||
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
|
||||
getLineEndOfPosition(pos: number): number;
|
||||
getLineStarts(): readonly number[];
|
||||
getPositionOfLineAndCharacter(line: number, character: number): number;
|
||||
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
|
||||
|
||||
/** @internal */ sourceMapper?: DocumentPositionMapper;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "../compiler/types.js" {
|
||||
// Module transform: converted from interface augmentation
|
||||
export interface SourceFileLike {
|
||||
@@ -189,32 +127,6 @@ declare module "../compiler/types.js" {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
|
||||
* snapshot is observably immutable. i.e. the same calls with the same parameters will return
|
||||
* the same values.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export interface IScriptSnapshot {
|
||||
/** Gets a portion of the script snapshot specified by [start, end). */
|
||||
getText(start: number, end: number): string;
|
||||
|
||||
/** Gets the length of this script snapshot. */
|
||||
getLength(): number;
|
||||
|
||||
/**
|
||||
* Gets the TextChangeRange that describe how the text changed between this text and
|
||||
* an older version. This information is used by the incremental parser to determine
|
||||
* what sections of the script need to be re-parsed. 'undefined' can be returned if the
|
||||
* change range cannot be determined. However, in that case, incremental parsing will
|
||||
* not happen and the entire document will be re - parsed.
|
||||
*/
|
||||
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined;
|
||||
|
||||
/** Releases all resources held by this script snapshot */
|
||||
dispose?(): void;
|
||||
}
|
||||
|
||||
export namespace ScriptSnapshot {
|
||||
class StringScriptSnapshot implements IScriptSnapshot {
|
||||
constructor(private text: string) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
BreakOrContinueStatement,
|
||||
CallExpression,
|
||||
canHaveModifiers,
|
||||
canHaveName,
|
||||
CaseClause,
|
||||
cast,
|
||||
CatchClause,
|
||||
@@ -279,7 +280,6 @@ import {
|
||||
LanguageServiceHost,
|
||||
last,
|
||||
lastOrUndefined,
|
||||
LiteralExpression,
|
||||
map,
|
||||
maybeBind,
|
||||
Modifier,
|
||||
@@ -347,6 +347,7 @@ import {
|
||||
startsWith,
|
||||
StringLiteral,
|
||||
StringLiteralLike,
|
||||
StringLiteralLikeNode,
|
||||
stringToToken,
|
||||
stripQuotes,
|
||||
Symbol,
|
||||
@@ -715,7 +716,7 @@ export function isNameOfModuleDeclaration(node: Node): boolean {
|
||||
|
||||
/** @internal */
|
||||
export function isNameOfFunctionDeclaration(node: Node): boolean {
|
||||
return isIdentifier(node) && tryCast(node.parent, isFunctionLike)?.name === node;
|
||||
return isIdentifier(node) && tryCast(tryCast(node.parent, isFunctionLike), canHaveName)?.name === node;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -1863,7 +1864,7 @@ export function isInString(sourceFile: SourceFile, position: number, previousTok
|
||||
}
|
||||
|
||||
if (position === end) {
|
||||
return !!(previousToken as LiteralExpression).isUnterminated;
|
||||
return !!(previousToken as StringLiteralLikeNode).isUnterminated;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4399
-2024
File diff suppressed because it is too large
Load Diff
@@ -24,4 +24,4 @@ var _a, _b;
|
||||
var _c = { x: 1 }, x = _c.x; // Error, rest must be last property
|
||||
(_a = { x: 1 }, x = _a.x); // Error, rest must be last property
|
||||
var _d = { x: 1 }, x = _d.x, b = __rest(_d, ["a", "x"]); // Error, rest must be last property
|
||||
(_b = { x: 1 }, x = _b.x, b = __rest(_b, ["x"])); // Error, rest must be last property
|
||||
(_b = { x: 1 }, x = _b.x, b = __rest(_b, ["a", "x"])); // Error, rest must be last property
|
||||
|
||||
Reference in New Issue
Block a user