Skip to content

Commit

Permalink
Preserve type nodes which resolve to errors in declaration emit output (
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham authored May 8, 2024
1 parent bc14459 commit fece7f1
Show file tree
Hide file tree
Showing 71 changed files with 1,260 additions and 1,245 deletions.
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8160,7 +8160,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function serializeTypeForDeclaration(context: NodeBuilderContext, declaration: Declaration | undefined, type: Type, symbol: Symbol) {
const addUndefined = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration);
const enclosingDeclaration = context.enclosingDeclaration;
if (!isErrorType(type) && enclosingDeclaration) {
if (enclosingDeclaration && (!isErrorType(type) || (context.flags & NodeBuilderFlags.AllowUnresolvedNames))) {
const declWithExistingAnnotation = declaration && getNonlocalEffectiveTypeAnnotationNode(declaration)
? declaration
: getDeclarationWithTypeAnnotation(symbol, getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration));
Expand Down Expand Up @@ -8460,7 +8460,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName && !isLateBindableName(node.name)) {
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedComputedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
return undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const declarationEmitNodeBuilderFlags = NodeBuilderFlags.MultilineObjectLiterals
NodeBuilderFlags.UseTypeOfFunction |
NodeBuilderFlags.UseStructuralFallback |
NodeBuilderFlags.AllowEmptyTuple |
NodeBuilderFlags.AllowUnresolvedComputedNames |
NodeBuilderFlags.AllowUnresolvedNames |
NodeBuilderFlags.GenerateNamesForShadowedTypeParams |
NodeBuilderFlags.NoTruncation;

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5432,7 +5432,7 @@ export const enum NodeBuilderFlags {
// Errors (cont.)
AllowNodeModulesRelativePaths = 1 << 26,
/** @internal */ DoNotIncludeSymbolChain = 1 << 27, // Skip looking up and printing an accessible symbol chain
/** @internal */ AllowUnresolvedComputedNames = 1 << 32,
/** @internal */ AllowUnresolvedNames = 1 << 32,

IgnoreErrors = AllowThisInObjectLiteral | AllowQualifiedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths,

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/ArrowFunction1.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
=== ArrowFunction1.ts ===
var v = (a: ) => {
>v : (a: any) => void
> : ^ ^^^^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^^
>(a: ) => { } : (a: any) => void
> : ^ ^^^^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^^
>a : any
> : ^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module clodule1 {

function f(x: T) { }
>f : (x: T) => void
> : ^ ^^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^^
>x : T
> : ^
}
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/arguments.types
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ function f() {

interface I {
method(args: typeof arguments): void;
>method : (args: any) => void
> : ^ ^^^^^^^^^^
>method : (args: typeof arguments) => void
> : ^ ^^ ^^^^^
>args : any
> : ^^^
>arguments : any
> : ^^^

fn: (args: typeof arguments) => void;
>fn : (args: any) => void
> : ^ ^^^^^^^^^^
>fn : (args: typeof arguments) => void
> : ^ ^^ ^^^^^
>args : any
> : ^^^
>arguments : any
Expand All @@ -66,8 +66,8 @@ interface I {
> : ^^^

construct: new (args: typeof arguments) => void;
>construct : new (args: any) => void
> : ^^^^^ ^^^^^^^^^^
>construct : new (args: typeof arguments) => void
> : ^^^^^ ^^ ^^^^^
>args : any
> : ^^^
>arguments : any
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayReferenceWithoutTypeArgs.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class X {
> : ^

public f(a: Array) { }
>f : (a: any) => void
> : ^ ^^^^^^^^^^^^^^
>f : (a: Array) => void
> : ^ ^^ ^^^^^^^^^
>a : any
> : ^^^
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/badExternalModuleReference.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import a1 = require("garbage");

export declare var a: {
>a : { (): a1.connectExport; test1: a1.connectModule; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^

test1: a1.connectModule;
>test1 : a1.connectModule
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/circularBaseTypes.types
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type M3 = M2[keyof M2]; // Error
> : ^^^

function f(m: M3) {
>f : (m: any) => any
> : ^ ^^^^^^^^^^^^^
>f : (m: M3) => any
> : ^ ^^ ^^^^^^^^
>m : any
> : ^^^

Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/errorsInGenericTypeReference.types
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class testClass2<T> {
}
var tc2 = new testClass2<{ x: V }>(); // error: could not find symbol V
>tc2 : testClass2<{ x: V; }>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^ ^^^^
>new testClass2<{ x: V }>() : testClass2<{ x: V; }>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^ ^^^^
>testClass2 : typeof testClass2
> : ^^^^^^^^^^^^^^^^^
>x : V
Expand All @@ -73,15 +73,15 @@ class testClass3 {

set a(value: Foo<{ x: V }>) { } // error: could not find symbol V
>a : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>value : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^

property: Foo<{ x: V }>; // error: could not find symbol V
>property : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^
}
Expand All @@ -100,15 +100,15 @@ function testFunction2(p: Foo<{ x: V }>) { }// error: could not find symbol V
>testFunction2 : (p: Foo<{ x: V; }>) => void
> : ^ ^^ ^^^^^^^^^
>p : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^


// in var type annotation
var f: Foo<{ x: V }>; // error: could not find symbol V
>f : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^

Expand All @@ -130,7 +130,7 @@ class testClass6<T> {

method<M extends { x: V }>(): void { } // error: could not find symbol V
>method : <M extends { x: V; }>() => void
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^
>x : V
> : ^
}
Expand All @@ -149,7 +149,7 @@ class testClass7 extends Foo<{ x: V }> { } // error: could not find symbol V
>testClass7 : testClass7
> : ^^^^^^^^^^
>Foo : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^

Expand All @@ -166,7 +166,7 @@ class testClass8 implements IFoo<{ x: V }> { } // error: could not find symbol V
interface testInterface2 {
new (a: Foo<{ x: V }>): Foo<{ x: V }>; //2x: error: could not find symbol V
>a : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^
>x : V
Expand All @@ -182,15 +182,15 @@ interface testInterface2 {
>method : (a: Foo<{ x: V; }>) => Foo<{ x: V; }>
> : ^ ^^ ^^^^^
>a : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^
>x : V
> : ^

property: Foo<{ x: V }>; // error: could not find symbol V
>property : Foo<{ x: V; }>
> : ^^^^^^^^^^^^^^
> : ^^^^^^^^^ ^^^^
>x : V
> : ^
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Foo {

f(@decorate user: A.B.C.D.E): void {}
>f : (user: A.B.C.D.E) => void
> : ^ ^^^^^^^^^^^^^^^^
> : ^ ^^ ^^^^^
>decorate : any
> : ^^^
>user : A.B.C.D.E
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/extendArray.types
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare module _Core {
>collect : (fn: (e: _element) => _element[]) => any[]
> : ^ ^^ ^^^^^
>fn : (e: _element) => _element[]
> : ^ ^^^^^^^^^^^^^^^
> : ^ ^^ ^^^^^
>e : _element
> : ^^^^^^^^
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ module TU {
>x : T
> : ^
>b : (x: U) => U
> : ^ ^^^^^^^^^
> : ^ ^^ ^^^^^^
>x : U
> : ^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class Foo<T> {

static a = (n: T) => { };
>a : (n: T) => void
> : ^ ^^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^^
>(n: T) => { } : (n: T) => void
> : ^ ^^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^^
>n : T
> : ^

Expand All @@ -34,9 +34,9 @@ class Foo<T> {
>((x: T) => x || undefined)(null) : any
> : ^^^
>((x: T) => x || undefined) : (x: T) => any
> : ^ ^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^
>(x: T) => x || undefined : (x: T) => any
> : ^ ^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^
>x : T
> : ^
>x || undefined : any
Expand All @@ -48,9 +48,9 @@ class Foo<T> {

static e = function (x: T) { return null; }
>e : (x: T) => any
> : ^ ^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^
>function (x: T) { return null; } : (x: T) => any
> : ^ ^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^
>x : T
> : ^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ foo((arg: Foo) => { return arg.x; });
> : ^^^
>foo : (a: any) => any
> : ^ ^^^^^^^^^^^^^
>(arg: Foo) => { return arg.x; } : (arg: any) => any
> : ^ ^^^^^^^^^^^^^
>(arg: Foo) => { return arg.x; } : (arg: Foo) => any
> : ^ ^^ ^^^^^^^^
>arg : any
> : ^^^
>arg.x : any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ module TypeScript {
> : ^^^

public toString<A,B,C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean) {
>toString : <A, B, C>(scopeSymbol?: any, useConstraintInName?: boolean) => any
> : ^^^^^^^^^^ ^^^^^^^^ ^^^ ^^^^^^^^
>toString : <A, B, C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean) => any
> : ^^^^^^^^^^ ^^^ ^^ ^^^ ^^^^^^^^
>scopeSymbol : any
> : ^^^
>useConstraintInName : boolean
Expand All @@ -61,12 +61,12 @@ module TypeScript {
> : ^^^
>this.getScopedNameEx(scopeSymbol, useConstraintInName) : any
> : ^^^
>this.getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: any, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>this.getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
> : ^^^^^^^^^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>this : this
> : ^^^^
>getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: any, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
> : ^^^^^^^^^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>scopeSymbol : any
> : ^^^
>useConstraintInName : boolean
Expand All @@ -79,8 +79,8 @@ module TypeScript {
> : ^^^
}
public getScopedNameEx<A,B,C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) {
>getScopedNameEx : <A, B, C>(scopeSymbol?: any, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
> : ^^^^^^^^^^ ^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>getScopedNameEx : <A, B, C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
> : ^^^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>scopeSymbol : any
> : ^^^
>useConstraintInName : boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ declare var c: C;
> : ^^^

declare var a: { x: C };
>a : { x: any; }
> : ^^^^^^^^^^^
>a : { x: C; }
> : ^^^^^ ^^^
>x : any
> : ^^^

declare var b: { (x: C): C };
>b : (x: any) => any
> : ^ ^^^^^^^^^^^^^
>b : (x: C) => any
> : ^ ^^ ^^^^^^^^
>x : any
> : ^^^

Expand All @@ -36,8 +36,8 @@ declare var d: { [x: C]: C };
> : ^^^

declare function f(x: C): C;
>f : (x: any) => any
> : ^ ^^^^^^^^^^^^^
>f : (x: C) => any
> : ^ ^^ ^^^^^^^^
>x : any
> : ^^^

Expand Down
Loading

0 comments on commit fece7f1

Please sign in to comment.