mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Extract node type printer (#59282)
This commit is contained in:
+381
-810
File diff suppressed because it is too large
Load Diff
@@ -6998,7 +6998,7 @@
|
||||
"category": "Error",
|
||||
"code": 9008
|
||||
},
|
||||
"At least one accessor must have an explicit return type annotation with --isolatedDeclarations.": {
|
||||
"At least one accessor must have an explicit type annotation with --isolatedDeclarations.": {
|
||||
"category": "Error",
|
||||
"code": 9009
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1668,7 +1668,7 @@ export function createAccessorPropertySetRedirector(factory: NodeFactory, node:
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function findComputedPropertyNameCacheAssignment(name: ComputedPropertyName) {
|
||||
export function findComputedPropertyNameCacheAssignment(name: ComputedPropertyName): AssignmentExpression<EqualsToken> & { readonly left: GeneratedIdentifier; } | undefined {
|
||||
let node = name.expression;
|
||||
while (true) {
|
||||
node = skipOuterExpressions(node);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
AccessorDeclaration,
|
||||
addRelatedInfo,
|
||||
AllAccessorDeclarations,
|
||||
append,
|
||||
ArrayBindingElement,
|
||||
BindingElement,
|
||||
@@ -53,7 +52,6 @@ import {
|
||||
FunctionTypeNode,
|
||||
GeneratedIdentifierFlags,
|
||||
GetAccessorDeclaration,
|
||||
getAllAccessorDeclarations,
|
||||
getCommentRange,
|
||||
getDirectoryPath,
|
||||
getEffectiveBaseTypeNode,
|
||||
@@ -77,6 +75,7 @@ import {
|
||||
getThisParameter,
|
||||
hasDynamicName,
|
||||
hasEffectiveModifier,
|
||||
hasInferredType,
|
||||
hasJSDocNodes,
|
||||
HasModifiers,
|
||||
hasSyntacticModifier,
|
||||
@@ -128,6 +127,7 @@ import {
|
||||
isModuleDeclaration,
|
||||
isObjectLiteralExpression,
|
||||
isOmittedExpression,
|
||||
isParameter,
|
||||
isPrimitiveLiteralValue,
|
||||
isPrivateIdentifier,
|
||||
isSemicolonClassElement,
|
||||
@@ -186,6 +186,7 @@ import {
|
||||
setOriginalNode,
|
||||
setParent,
|
||||
setTextRange,
|
||||
SignatureDeclaration,
|
||||
some,
|
||||
SourceFile,
|
||||
Statement,
|
||||
@@ -632,7 +633,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
}
|
||||
}
|
||||
|
||||
function ensureParameter(p: ParameterDeclaration, modifierMask?: ModifierFlags, type?: TypeNode): ParameterDeclaration {
|
||||
function ensureParameter(p: ParameterDeclaration, modifierMask?: ModifierFlags): ParameterDeclaration {
|
||||
let oldDiag: typeof getSymbolAccessibilityDiagnostic | undefined;
|
||||
if (!suppressNewDiagnosticContexts) {
|
||||
oldDiag = getSymbolAccessibilityDiagnostic;
|
||||
@@ -644,7 +645,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
p.dotDotDotToken,
|
||||
filterBindingPatternInitializers(p.name),
|
||||
resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined,
|
||||
ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
|
||||
ensureType(p, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
|
||||
ensureNoInitializer(p),
|
||||
);
|
||||
if (!suppressNewDiagnosticContexts) {
|
||||
@@ -669,21 +670,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
type HasInferredType =
|
||||
| FunctionDeclaration
|
||||
| MethodDeclaration
|
||||
| GetAccessorDeclaration
|
||||
| BindingElement
|
||||
| ConstructSignatureDeclaration
|
||||
| VariableDeclaration
|
||||
| MethodSignature
|
||||
| CallSignatureDeclaration
|
||||
| ParameterDeclaration
|
||||
| PropertyDeclaration
|
||||
| PropertySignature;
|
||||
|
||||
function ensureType(node: HasInferredType, type: TypeNode | undefined, ignorePrivate?: boolean): TypeNode | undefined {
|
||||
function ensureType(node: VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertySignature | ExportAssignment | SignatureDeclaration, ignorePrivate?: boolean): TypeNode | undefined {
|
||||
if (!ignorePrivate && hasEffectiveModifier(node, ModifierFlags.Private)) {
|
||||
// Private nodes emit no types (except private parameter properties, whose parameter types are actually visible)
|
||||
return;
|
||||
@@ -692,39 +679,38 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
// Literal const declarations will have an initializer ensured rather than a type
|
||||
return;
|
||||
}
|
||||
const shouldAddImplicitUndefined = node.kind === SyntaxKind.Parameter && resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration);
|
||||
if (type && !shouldAddImplicitUndefined) {
|
||||
return visitNode(type, visitDeclarationSubtree, isTypeNode);
|
||||
// Should be removed createTypeOfDeclaration will actually now reuse the existing annotation so there is no real need to duplicate type walking
|
||||
// Left in for now to minimize diff during syntactic type node builder refactor
|
||||
if (
|
||||
!isExportAssignment(node)
|
||||
&& !isBindingElement(node)
|
||||
&& node.type
|
||||
&& (!isParameter(node) || !resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration))
|
||||
) {
|
||||
return visitNode(node.type, visitDeclarationSubtree, isTypeNode);
|
||||
}
|
||||
|
||||
const oldErrorNameNode = errorNameNode;
|
||||
errorNameNode = node.name;
|
||||
let oldDiag: typeof getSymbolAccessibilityDiagnostic;
|
||||
if (!suppressNewDiagnosticContexts) {
|
||||
oldDiag = getSymbolAccessibilityDiagnostic;
|
||||
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node);
|
||||
if (canProduceDiagnostics(node)) {
|
||||
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node);
|
||||
}
|
||||
}
|
||||
let typeNode;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
typeNode = resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.CallSignature:
|
||||
typeNode = resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
||||
break;
|
||||
default:
|
||||
Debug.assertNever(node);
|
||||
if (hasInferredType(node)) {
|
||||
typeNode = resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
||||
}
|
||||
else if (isFunctionLike(node)) {
|
||||
typeNode = resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
||||
}
|
||||
else {
|
||||
Debug.assertNever(node);
|
||||
}
|
||||
|
||||
errorNameNode = undefined;
|
||||
errorNameNode = oldErrorNameNode;
|
||||
if (!suppressNewDiagnosticContexts) {
|
||||
getSymbolAccessibilityDiagnostic = oldDiag!;
|
||||
}
|
||||
@@ -802,8 +788,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
if (!isPrivate) {
|
||||
const valueParameter = getSetAccessorValueParameter(input);
|
||||
if (valueParameter) {
|
||||
const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, getAllAccessorDeclarations(isObjectLiteralExpression(input.parent) ? input.parent.properties : input.parent.members, input));
|
||||
newValueParameter = ensureParameter(valueParameter, /*modifierMask*/ undefined, accessorType);
|
||||
newValueParameter = ensureParameter(valueParameter);
|
||||
}
|
||||
}
|
||||
if (!newValueParameter) {
|
||||
@@ -1103,7 +1088,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
input,
|
||||
ensureTypeParams(input, input.typeParameters),
|
||||
updateParamsList(input, input.parameters),
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
));
|
||||
case SyntaxKind.Constructor: {
|
||||
// A constructor declaration may not have a type annotation
|
||||
@@ -1125,7 +1110,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
input.questionToken,
|
||||
ensureTypeParams(input, input.typeParameters),
|
||||
updateParamsList(input, input.parameters),
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
/*body*/ undefined,
|
||||
);
|
||||
return cleanup(sig);
|
||||
@@ -1134,13 +1119,12 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
if (isPrivateIdentifier(input.name)) {
|
||||
return cleanup(/*returnValue*/ undefined);
|
||||
}
|
||||
const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, getAllAccessorDeclarations(isObjectLiteralExpression(input.parent) ? input.parent.properties : input.parent.members, input));
|
||||
return cleanup(factory.updateGetAccessorDeclaration(
|
||||
input,
|
||||
ensureModifiers(input),
|
||||
input.name,
|
||||
updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)),
|
||||
ensureType(input, accessorType),
|
||||
ensureType(input),
|
||||
/*body*/ undefined,
|
||||
));
|
||||
}
|
||||
@@ -1165,7 +1149,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
ensureModifiers(input),
|
||||
input.name,
|
||||
input.questionToken,
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
ensureNoInitializer(input),
|
||||
));
|
||||
case SyntaxKind.PropertySignature:
|
||||
@@ -1177,7 +1161,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
ensureModifiers(input),
|
||||
input.name,
|
||||
input.questionToken,
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
));
|
||||
case SyntaxKind.MethodSignature: {
|
||||
if (isPrivateIdentifier(input.name)) {
|
||||
@@ -1190,7 +1174,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
input.questionToken,
|
||||
ensureTypeParams(input, input.typeParameters),
|
||||
updateParamsList(input, input.parameters),
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
));
|
||||
}
|
||||
case SyntaxKind.CallSignature: {
|
||||
@@ -1199,7 +1183,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
input,
|
||||
ensureTypeParams(input, input.typeParameters),
|
||||
updateParamsList(input, input.parameters),
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1217,7 +1201,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
}
|
||||
shouldEnterSuppressNewDiagnosticsContextContext = true;
|
||||
suppressNewDiagnosticContexts = true; // Variable declaration types also suppress new diagnostic contexts, provided the contexts wouldn't be made for binding pattern types
|
||||
return cleanup(factory.updateVariableDeclaration(input, input.name, /*exclamationToken*/ undefined, ensureType(input, input.type), ensureNoInitializer(input)));
|
||||
return cleanup(factory.updateVariableDeclaration(input, input.name, /*exclamationToken*/ undefined, ensureType(input), ensureNoInitializer(input)));
|
||||
}
|
||||
case SyntaxKind.TypeParameter: {
|
||||
if (isPrivateMethodTypeParameter(input) && (input.default || input.constraint)) {
|
||||
@@ -1343,7 +1327,8 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
errorNode: input,
|
||||
});
|
||||
errorFallbackNode = input;
|
||||
const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker), /*initializer*/ undefined);
|
||||
const type = ensureType(input);
|
||||
const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, type, /*initializer*/ undefined);
|
||||
errorFallbackNode = undefined;
|
||||
const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const));
|
||||
|
||||
@@ -1461,7 +1446,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
input.name,
|
||||
ensureTypeParams(input, input.typeParameters),
|
||||
updateParamsList(input, input.parameters),
|
||||
ensureType(input, input.type),
|
||||
ensureType(input),
|
||||
/*body*/ undefined,
|
||||
));
|
||||
if (clean && resolver.isExpandoFunctionDeclaration(input) && shouldEmitFunctionProperties(input)) {
|
||||
@@ -1621,7 +1606,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
ensureModifiers(param),
|
||||
param.name,
|
||||
param.questionToken,
|
||||
ensureType(param, param.type),
|
||||
ensureType(param),
|
||||
ensureNoInitializer(param),
|
||||
),
|
||||
param,
|
||||
@@ -1644,7 +1629,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
ensureModifiers(param),
|
||||
elem.name as Identifier,
|
||||
/*questionOrExclamationToken*/ undefined,
|
||||
ensureType(elem, /*type*/ undefined),
|
||||
ensureType(elem),
|
||||
/*initializer*/ undefined,
|
||||
));
|
||||
}
|
||||
@@ -1801,7 +1786,7 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
return recreateBindingPattern(e.name);
|
||||
}
|
||||
else {
|
||||
return factory.createVariableDeclaration(e.name, /*exclamationToken*/ undefined, ensureType(e, /*type*/ undefined), /*initializer*/ undefined);
|
||||
return factory.createVariableDeclaration(e.name, /*exclamationToken*/ undefined, ensureType(e), /*initializer*/ undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1855,21 +1840,6 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
return maskModifierFlags(node, mask, additions);
|
||||
}
|
||||
|
||||
function getTypeAnnotationFromAllAccessorDeclarations(node: AccessorDeclaration, accessors: AllAccessorDeclarations) {
|
||||
let accessorType = getTypeAnnotationFromAccessor(node);
|
||||
if (!accessorType && node !== accessors.firstAccessor) {
|
||||
accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor);
|
||||
// If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message
|
||||
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.firstAccessor);
|
||||
}
|
||||
if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) {
|
||||
accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor);
|
||||
// If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message
|
||||
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor);
|
||||
}
|
||||
return accessorType;
|
||||
}
|
||||
|
||||
function transformHeritageClauses(nodes: NodeArray<HeritageClause> | undefined) {
|
||||
return factory.createNodeArray(filter(
|
||||
map(nodes, clause =>
|
||||
@@ -1913,16 +1883,6 @@ function maskModifierFlags(node: Node, modifierMask: ModifierFlags = ModifierFla
|
||||
return flags;
|
||||
}
|
||||
|
||||
function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | undefined {
|
||||
if (accessor) {
|
||||
return accessor.kind === SyntaxKind.GetAccessor
|
||||
? accessor.type // Getter - return type
|
||||
: accessor.parameters.length > 0
|
||||
? accessor.parameters[0].type // Setter parameter type
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
|
||||
type CanHaveLiteralInitializer = VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration;
|
||||
function canHaveLiteralInitializer(node: Node): node is CanHaveLiteralInitializer {
|
||||
switch (node.kind) {
|
||||
|
||||
@@ -625,8 +625,8 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod
|
||||
[SyntaxKind.ArrowFunction]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.MethodDeclaration]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.ConstructSignature]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.GetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.SetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.GetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.SetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.Parameter]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.VariableDeclaration]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
||||
[SyntaxKind.PropertyDeclaration]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
||||
|
||||
+43
-14
@@ -5849,7 +5849,7 @@ export interface EmitResolver {
|
||||
requiresAddingImplicitUndefined(node: ParameterDeclaration, enclosingDeclaration: Node | undefined): boolean;
|
||||
isExpandoFunctionDeclaration(node: FunctionDeclaration | VariableDeclaration): boolean;
|
||||
getPropertiesOfContainerFunction(node: Declaration): Symbol[];
|
||||
createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression | ElementAccessExpression | BinaryExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, internalFlags: InternalNodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined;
|
||||
createTypeOfDeclaration(declaration: HasInferredType, enclosingDeclaration: Node, flags: NodeBuilderFlags, internalFlags: InternalNodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined;
|
||||
createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, internalFlags: InternalNodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined;
|
||||
createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, internalFlags: InternalNodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined;
|
||||
createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker): Expression;
|
||||
@@ -10504,37 +10504,66 @@ export interface EvaluationResolver {
|
||||
|
||||
/** @internal */
|
||||
export type HasInferredType =
|
||||
| PropertyAssignment
|
||||
| Exclude<VariableLikeDeclaration, JsxAttribute | EnumMember>
|
||||
| PropertyAccessExpression
|
||||
| BinaryExpression
|
||||
| ElementAccessExpression
|
||||
| VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| BindingElement
|
||||
| PropertyDeclaration
|
||||
| PropertySignature
|
||||
| BinaryExpression
|
||||
| ExportAssignment;
|
||||
|
||||
/** @internal */
|
||||
export interface SyntacticTypeNodeBuilderContext {
|
||||
flags: NodeBuilderFlags;
|
||||
tracker: Required<Pick<SymbolTracker, "reportInferenceFallback">>;
|
||||
enclosingFile: SourceFile | undefined;
|
||||
enclosingDeclaration: Node | undefined;
|
||||
approximateLength: number;
|
||||
noInferenceFallback?: boolean;
|
||||
suppressReportInferenceFallback: boolean;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export interface SyntacticTypeNodeBuilderResolver {
|
||||
isOptionalParameter(p: ParameterDeclaration): boolean;
|
||||
isUndefinedIdentifierExpression(name: Identifier): boolean;
|
||||
isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean;
|
||||
getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations;
|
||||
isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult;
|
||||
requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag, enclosingDeclaration: Node | undefined): boolean;
|
||||
requiresAddingImplicitUndefined(declaration: ParameterDeclaration | PropertySignature | JSDocParameterTag | JSDocPropertyTag | PropertyDeclaration, symbol: Symbol | undefined, enclosingDeclaration: Node | undefined): boolean;
|
||||
isDefinitelyReferenceToGlobalSymbolObject(node: Node): boolean;
|
||||
isEntityNameVisible(context: SyntacticTypeNodeBuilderContext, entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult;
|
||||
serializeExistingTypeNode(context: SyntacticTypeNodeBuilderContext, node: TypeNode, addUndefined?: boolean): TypeNode | undefined;
|
||||
serializeReturnTypeForSignature(context: SyntacticTypeNodeBuilderContext, signatureDeclaration: SignatureDeclaration | JSDocSignature): TypeNode | undefined;
|
||||
serializeTypeOfExpression(context: SyntacticTypeNodeBuilderContext, expr: Expression): TypeNode;
|
||||
serializeTypeOfDeclaration(context: SyntacticTypeNodeBuilderContext, node: HasInferredType | GetAccessorDeclaration | SetAccessorDeclaration, symbol: Symbol | undefined): TypeNode | undefined;
|
||||
serializeNameOfParameter(context: SyntacticTypeNodeBuilderContext, parameter: ParameterDeclaration): BindingName | string;
|
||||
serializeTypeName(context: SyntacticTypeNodeBuilderContext, node: EntityName, isTypeOf?: boolean, typeArguments?: readonly TypeNode[]): TypeNode | undefined;
|
||||
serializeEntityName(context: SyntacticTypeNodeBuilderContext, node: EntityNameExpression): Expression | undefined;
|
||||
getJsDocPropertyOverride(context: SyntacticTypeNodeBuilderContext, jsDocTypeLiteral: JSDocTypeLiteral, jsDocProperty: JSDocPropertyLikeTag): TypeNode | undefined;
|
||||
enterNewScope(context: SyntacticTypeNodeBuilderContext, node: IntroducesNewScopeNode | ConditionalTypeNode): () => void;
|
||||
markNodeReuse<T extends Node>(context: SyntacticTypeNodeBuilderContext, range: T, location: Node | undefined): T;
|
||||
trackExistingEntityName<T extends EntityNameOrEntityNameExpression>(context: SyntacticTypeNodeBuilderContext, node: T): { introducesError: boolean; node: T; };
|
||||
trackComputedName(context: SyntacticTypeNodeBuilderContext, accessExpression: EntityNameOrEntityNameExpression): void;
|
||||
evaluateEntityNameExpression(expression: EntityNameExpression): EvaluatorResult;
|
||||
getModuleSpecifierOverride(context: SyntacticTypeNodeBuilderContext, parent: ImportTypeNode, lit: StringLiteral): string | undefined;
|
||||
canReuseTypeNode(context: SyntacticTypeNodeBuilderContext, existing: TypeNode): boolean;
|
||||
canReuseTypeNodeAnnotation(context: SyntacticTypeNodeBuilderContext, node: Declaration, existing: TypeNode, symbol: Symbol | undefined, requiresAddingUndefined?: boolean): boolean;
|
||||
shouldRemoveDeclaration(context: SyntacticTypeNodeBuilderContext, node: DynamicNamedDeclaration): boolean;
|
||||
hasLateBindableName(node: Declaration): node is LateBoundDeclaration | LateBoundBinaryExpressionDeclaration;
|
||||
createRecoveryBoundary(context: SyntacticTypeNodeBuilderContext): {
|
||||
startRecoveryScope(): () => void;
|
||||
finalizeBoundary(): boolean;
|
||||
markError(): void;
|
||||
hadError(): boolean;
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export interface SyntacticNodeBuilder {
|
||||
typeFromExpression: (node: Expression, context: SyntacticTypeNodeBuilderContext, isConstContext?: boolean, requiresAddingUndefined?: boolean, preserveLiterals?: boolean) => boolean | undefined;
|
||||
serializeTypeOfDeclaration: (node: HasInferredType, context: SyntacticTypeNodeBuilderContext) => boolean | undefined;
|
||||
serializeReturnTypeForSignature: (node: SignatureDeclaration | JSDocSignature, context: SyntacticTypeNodeBuilderContext) => boolean | undefined;
|
||||
serializeTypeOfExpression: (expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) => boolean;
|
||||
serializeTypeOfDeclaration: (node: HasInferredType, symbol: Symbol, context: SyntacticTypeNodeBuilderContext) => TypeNode | undefined;
|
||||
serializeReturnTypeForSignature: (signature: SignatureDeclaration | JSDocSignature, symbol: Symbol, context: SyntacticTypeNodeBuilderContext) => TypeNode | undefined;
|
||||
serializeTypeOfExpression: (expr: Expression | JsxAttributeValue, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) => TypeNode;
|
||||
tryReuseExistingTypeNode: (context: SyntacticTypeNodeBuilderContext, existing: TypeNode) => TypeNode | undefined;
|
||||
serializeTypeOfAccessor: (accessor: AccessorDeclaration, symbol: Symbol, context: SyntacticTypeNodeBuilderContext) => TypeNode | undefined;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export type IntroducesNewScopeNode = SignatureDeclaration | JSDocSignature | MappedTypeNode;
|
||||
|
||||
@@ -246,6 +246,7 @@ import {
|
||||
InterfaceDeclaration,
|
||||
InternalEmitFlags,
|
||||
InternalSymbolName,
|
||||
IntroducesNewScopeNode,
|
||||
isAccessor,
|
||||
isAnyDirectorySeparator,
|
||||
isArray,
|
||||
@@ -322,6 +323,7 @@ import {
|
||||
isLeftHandSideExpression,
|
||||
isLineBreak,
|
||||
isLiteralTypeNode,
|
||||
isMappedTypeNode,
|
||||
isMemberName,
|
||||
isMetaProperty,
|
||||
isMethodDeclaration,
|
||||
@@ -2920,11 +2922,6 @@ export function isVariableLike(node: Node): node is VariableLikeDeclaration {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isVariableLikeOrAccessor(node: Node): node is AccessorDeclaration | VariableLikeDeclaration {
|
||||
return isVariableLike(node) || isAccessor(node);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isVariableDeclarationInVariableStatement(node: VariableDeclaration): boolean {
|
||||
return node.parent.kind === SyntaxKind.VariableDeclarationList
|
||||
@@ -11938,6 +11935,9 @@ export function hasInferredType(node: Node): node is HasInferredType {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.JSDocParameterTag:
|
||||
case SyntaxKind.JSDocPropertyTag:
|
||||
return true;
|
||||
default:
|
||||
assertType<never>(node);
|
||||
@@ -12077,3 +12077,9 @@ function getNodeAtPosition(sourceFile: SourceFile, position: number, includeJSDo
|
||||
current = child;
|
||||
}
|
||||
}
|
||||
/** @internal */
|
||||
export function isNewScopeNode(node: Node): node is IntroducesNewScopeNode {
|
||||
return isFunctionLike(node)
|
||||
|| isJSDocSignature(node)
|
||||
|| isMappedTypeNode(node);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ const extractExpression = "extract-expression";
|
||||
const errorCodes = [
|
||||
Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
||||
Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
||||
Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
||||
Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
||||
Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
||||
Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
||||
Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
||||
|
||||
Reference in New Issue
Block a user