Skip to content

Commit 9851d23

Browse files
committed
inferredTypeFromTransitiveModule tests
1 parent b8a3c8b commit 9851d23

File tree

202 files changed

+2759
-1552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+2759
-1552
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30272,7 +30272,7 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy
3027230272
// 4). type A = import("./f/*gotToDefinitionHere*/oo")
3027330273
if (ast.IsExternalModuleImportEqualsDeclaration(grandParent) && ast.GetExternalModuleImportEqualsDeclarationExpression(grandParent) == node) ||
3027430274
((parent.Kind == ast.KindImportDeclaration || parent.Kind == ast.KindJSImportDeclaration || parent.Kind == ast.KindExportDeclaration) && ast.GetExternalModuleName(parent) == node) ||
30275-
ast.IsVariableDeclarationInitializedToRequire(grandParent) ||
30275+
ast.IsVariableDeclarationInitializedToRequire(grandParent) || ast.IsImportCall(parent) ||
3027630276
(ast.IsLiteralTypeNode(parent) && ast.IsLiteralImportTypeNode(grandParent) && grandParent.AsImportTypeNode().Argument == parent) {
3027730277
return c.resolveExternalModuleName(node, node, ignoreErrors)
3027830278
}

internal/execute/tscbuild_test.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,88 @@ func TestBuildFileDelete(t *testing.T) {
390390
}
391391
}
392392

393+
func TestBuildInferredTypeFromTransitiveModule(t *testing.T) {
394+
t.Parallel()
395+
testCases := []*tscInput{
396+
{
397+
subScenario: "inferred type from transitive module",
398+
files: getBuildInferredTypeFromTransitiveModuleMap(false, ""),
399+
commandLineArgs: []string{"--b", "--verbose"},
400+
edits: []*tscEdit{
401+
{
402+
caption: "incremental-declaration-changes",
403+
edit: func(sys *testSys) {
404+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "param: string", "")
405+
},
406+
},
407+
{
408+
caption: "incremental-declaration-changes",
409+
edit: func(sys *testSys) {
410+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "foobar()", "foobar(param: string)")
411+
},
412+
},
413+
},
414+
},
415+
{
416+
subScenario: "inferred type from transitive module with isolatedModules",
417+
files: getBuildInferredTypeFromTransitiveModuleMap(true, ""),
418+
commandLineArgs: []string{"--b", "--verbose"},
419+
edits: []*tscEdit{
420+
{
421+
caption: "incremental-declaration-changes",
422+
edit: func(sys *testSys) {
423+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "param: string", "")
424+
},
425+
},
426+
{
427+
caption: "incremental-declaration-changes",
428+
edit: func(sys *testSys) {
429+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "foobar()", "foobar(param: string)")
430+
},
431+
},
432+
},
433+
},
434+
{
435+
subScenario: "reports errors in files affected by change in signature with isolatedModules",
436+
files: getBuildInferredTypeFromTransitiveModuleMap(true, stringtestutil.Dedent(`
437+
import { default as bar } from './bar';
438+
bar("hello");
439+
`)),
440+
commandLineArgs: []string{"--b", "--verbose"},
441+
edits: []*tscEdit{
442+
{
443+
caption: "incremental-declaration-changes",
444+
edit: func(sys *testSys) {
445+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "param: string", "")
446+
},
447+
},
448+
{
449+
caption: "incremental-declaration-changes",
450+
edit: func(sys *testSys) {
451+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "foobar()", "foobar(param: string)")
452+
},
453+
},
454+
{
455+
caption: "incremental-declaration-changes",
456+
edit: func(sys *testSys) {
457+
sys.replaceFileText("/home/src/workspaces/project/bar.ts", "param: string", "")
458+
},
459+
},
460+
{
461+
caption: "Fix Error",
462+
edit: func(sys *testSys) {
463+
sys.replaceFileText("/home/src/workspaces/project/lazyIndex.ts", `bar("hello")`, "bar()")
464+
},
465+
},
466+
},
467+
},
468+
}
469+
470+
for _, test := range testCases {
471+
test.run(t, "inferredTypeFromTransitiveModule")
472+
}
473+
}
474+
393475
func TestBuildSolutionProject(t *testing.T) {
394476
t.Parallel()
395477
testCases := []*tscInput{
@@ -756,3 +838,60 @@ func getBuildEmitDeclarationOnlyTestCase(declarationMap bool) *tscInput {
756838
},
757839
}
758840
}
841+
842+
func getBuildInferredTypeFromTransitiveModuleMap(isolatedModules bool, lazyExtraContents string) FileMap {
843+
return FileMap{
844+
"/home/src/workspaces/project/bar.ts": stringtestutil.Dedent(`
845+
interface RawAction {
846+
(...args: any[]): Promise<any> | void;
847+
}
848+
interface ActionFactory {
849+
<T extends RawAction>(target: T): T;
850+
}
851+
declare function foo<U extends any[] = any[]>(): ActionFactory;
852+
export default foo()(function foobar(param: string): void {
853+
});
854+
`),
855+
"/home/src/workspaces/project/bundling.ts": stringtestutil.Dedent(`
856+
export class LazyModule<TModule> {
857+
constructor(private importCallback: () => Promise<TModule>) {}
858+
}
859+
860+
export class LazyAction<
861+
TAction extends (...args: any[]) => any,
862+
TModule
863+
> {
864+
constructor(_lazyModule: LazyModule<TModule>, _getter: (module: TModule) => TAction) {
865+
}
866+
}
867+
`),
868+
"/home/src/workspaces/project/global.d.ts": stringtestutil.Dedent(`
869+
interface PromiseConstructor {
870+
new <T>(): Promise<T>;
871+
}
872+
declare var Promise: PromiseConstructor;
873+
interface Promise<T> {
874+
}
875+
`),
876+
"/home/src/workspaces/project/index.ts": stringtestutil.Dedent(`
877+
import { LazyAction, LazyModule } from './bundling';
878+
const lazyModule = new LazyModule(() =>
879+
import('./lazyIndex')
880+
);
881+
export const lazyBar = new LazyAction(lazyModule, m => m.bar);
882+
`),
883+
"/home/src/workspaces/project/lazyIndex.ts": stringtestutil.Dedent(`
884+
export { default as bar } from './bar';
885+
`) + lazyExtraContents,
886+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(fmt.Sprintf(`
887+
{
888+
"compilerOptions": {
889+
"target": "es5",
890+
"declaration": true,
891+
"outDir": "obj",
892+
"incremental": true,
893+
"isolatedModules": %t,
894+
},
895+
}`, isolatedModules)),
896+
}
897+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// === goToDefinition ===
22
// === /foo.ts ===
33

4-
// export function foo() { return "foo"; }
4+
// [|export function foo() { return "foo"; }
55
// import("./f/*GO TO DEFINITION*/oo")
6-
// var x = import("./foo")
6+
// var x = import("./foo")|]
77

88

99

1010

1111
// === goToDefinition ===
1212
// === /foo.ts ===
1313

14-
// export function foo() { return "foo"; }
14+
// [|export function foo() { return "foo"; }
1515
// import("./foo")
16-
// var x = import("./fo/*GO TO DEFINITION*/o")
16+
// var x = import("./fo/*GO TO DEFINITION*/o")|]

testdata/baselines/reference/submodule/compiler/declarationEmitDoesNotUseReexportedNamespaceAsLocal.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function a() {}
88
export const x = add(import("./sub"));
99
>x : Symbol(x, Decl(index.ts, 0, 12))
1010
>add : Symbol(add, Decl(index.ts, 1, 27))
11+
>"./sub" : Symbol("sub", Decl(sub.ts, 0, 0))
1112

1213
export * as Q from "./sub";
1314
>Q : Symbol(Q, Decl(index.ts, 1, 6))

testdata/baselines/reference/submodule/compiler/declarationEmitDoesNotUseReexportedNamespaceAsLocal.symbols.diff

Lines changed: 0 additions & 10 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/declarationEmitExportAliasVisibiilityMarking.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default (suit: Suit, rank: Rank) => ({suit, rank});
2828
export let lazyCard = () => import('./Card').then(a => a.default);
2929
>lazyCard : Symbol(lazyCard, Decl(index.ts, 0, 10))
3030
>import('./Card').then : Symbol(then, Decl(lib.es5.d.ts, --, --))
31+
>'./Card' : Symbol("Card", Decl(Card.ts, 0, 0))
3132
>then : Symbol(then, Decl(lib.es5.d.ts, --, --))
3233
>a : Symbol(a, Decl(index.ts, 0, 50))
3334
>a.default : Symbol(default, Decl(Card.ts, 0, 37))

testdata/baselines/reference/submodule/compiler/declarationEmitExportAliasVisibiilityMarking.symbols.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
export let lazyCard = () => import('./Card').then(a => a.default);
66
>lazyCard : Symbol(lazyCard, Decl(index.ts, 0, 10))
77
->import('./Card').then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
8-
->'./Card' : Symbol("Card", Decl(Card.ts, 0, 0))
9-
->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
108
+>import('./Card').then : Symbol(then, Decl(lib.es5.d.ts, --, --))
9+
>'./Card' : Symbol("Card", Decl(Card.ts, 0, 0))
10+
->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1111
+>then : Symbol(then, Decl(lib.es5.d.ts, --, --))
1212
>a : Symbol(a, Decl(index.ts, 0, 50))
1313
>a.default : Symbol(default, Decl(Card.ts, 0, 37))

testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.symbols

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ export const mod = await (async () => {
2424

2525
case 0:
2626
return await import("./case0.js");
27+
>"./case0.js" : Symbol("/case0", Decl(case0.ts, 0, 0))
28+
2729
case 1:
2830
return await import("./case1.js");
31+
>"./case1.js" : Symbol("/case1", Decl(case1.ts, 0, 0))
32+
2933
default:
3034
return await import("./caseFallback.js");
35+
>"./caseFallback.js" : Symbol("/caseFallback", Decl(caseFallback.ts, 0, 0))
3136
}
3237
})();

testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.symbols.diff

Lines changed: 0 additions & 17 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/errorForConflictingExportEqualsValue.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export = x;
88
>x : Symbol(x, Decl(a.ts, 0, 10))
99

1010
import("./a");
11+
>"./a" : Symbol("/a", Decl(a.ts, 0, 0))
1112

0 commit comments

Comments
 (0)