-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Dont look for properties of Object and Function type when looking to resolve named import from module with export=
#37964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8c9128a
Add tests
sheetalkamat 5af482c
Dont look at object or function type when looking for members of `exp…
sheetalkamat fd9c2ea
Merge branch 'master' into importMerge
sheetalkamat a252ef9
Create separate cache when skipping function and object property augm…
sheetalkamat 5a964bd
Lookup in both cache if not skipObjectFunctionPropertyAugment
sheetalkamat 55ed718
Merge branch 'master' into importMerge
sheetalkamat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/moduleAugmentationWithNonExistentNamedImport.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
tests/cases/compiler/bar.d.ts(1,10): error TS2305: Module '"./foo"' has no exported member 'Bar'. | ||
|
||
|
||
==== tests/cases/compiler/foo.d.ts (0 errors) ==== | ||
export = Foo; | ||
export as namespace Foo; | ||
|
||
declare namespace Foo { | ||
function foo(); | ||
} | ||
|
||
declare global { | ||
namespace Bar { } | ||
} | ||
|
||
==== tests/cases/compiler/bar.d.ts (1 errors) ==== | ||
import { Bar } from './foo'; | ||
~~~ | ||
!!! error TS2305: Module '"./foo"' has no exported member 'Bar'. | ||
export = Bar; | ||
export as namespace Bar; |
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/moduleAugmentationWithNonExistentNamedImport.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== tests/cases/compiler/foo.d.ts === | ||
export = Foo; | ||
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 24)) | ||
|
||
export as namespace Foo; | ||
>Foo : Symbol(Foo, Decl(foo.d.ts, 0, 13)) | ||
|
||
declare namespace Foo { | ||
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 24)) | ||
|
||
function foo(); | ||
>foo : Symbol(foo, Decl(foo.d.ts, 3, 23)) | ||
} | ||
|
||
declare global { | ||
>global : Symbol(global, Decl(foo.d.ts, 5, 1)) | ||
|
||
namespace Bar { } | ||
>Bar : Symbol(Bar, Decl(foo.d.ts, 7, 16)) | ||
} | ||
|
||
=== tests/cases/compiler/bar.d.ts === | ||
import { Bar } from './foo'; | ||
>Bar : Symbol(Bar, Decl(bar.d.ts, 0, 8)) | ||
|
||
export = Bar; | ||
>Bar : Symbol(Bar, Decl(bar.d.ts, 0, 8)) | ||
|
||
export as namespace Bar; | ||
>Bar : Symbol(Bar, Decl(bar.d.ts, 1, 13)) | ||
|
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/moduleAugmentationWithNonExistentNamedImport.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
=== tests/cases/compiler/foo.d.ts === | ||
export = Foo; | ||
>Foo : typeof Foo | ||
|
||
export as namespace Foo; | ||
>Foo : typeof Foo | ||
|
||
declare namespace Foo { | ||
>Foo : typeof Foo | ||
|
||
function foo(); | ||
>foo : () => any | ||
} | ||
|
||
declare global { | ||
>global : any | ||
|
||
namespace Bar { } | ||
} | ||
|
||
=== tests/cases/compiler/bar.d.ts === | ||
import { Bar } from './foo'; | ||
>Bar : any | ||
|
||
export = Bar; | ||
>Bar : any | ||
|
||
export as namespace Bar; | ||
>Bar : any | ||
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/namedImportNonExistentName.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
tests/cases/compiler/bar.ts(1,10): error TS2305: Module '"./foo"' has no exported member 'Bar'. | ||
tests/cases/compiler/bar.ts(1,15): error TS2305: Module '"./foo"' has no exported member 'toString'. | ||
tests/cases/compiler/bar.ts(3,10): error TS2305: Module '"./foo2"' has no exported member 'a'. | ||
tests/cases/compiler/bar.ts(3,13): error TS2305: Module '"./foo2"' has no exported member 'b'. | ||
tests/cases/compiler/bar.ts(3,19): error TS2305: Module '"./foo2"' has no exported member 'd'. | ||
tests/cases/compiler/bar.ts(3,22): error TS2305: Module '"./foo2"' has no exported member 'toString'. | ||
|
||
|
||
==== tests/cases/compiler/foo.d.ts (0 errors) ==== | ||
export = Foo; | ||
export as namespace Foo; | ||
|
||
declare namespace Foo { | ||
function foo(); | ||
} | ||
|
||
==== tests/cases/compiler/foo2.ts (0 errors) ==== | ||
let x: { a: string; c: string; } | { b: number; c: number; }; | ||
export = x | ||
|
||
==== tests/cases/compiler/bar.ts (6 errors) ==== | ||
import { Bar, toString, foo } from './foo'; | ||
~~~ | ||
!!! error TS2305: Module '"./foo"' has no exported member 'Bar'. | ||
~~~~~~~~ | ||
!!! error TS2305: Module '"./foo"' has no exported member 'toString'. | ||
foo(); | ||
import { a, b, c, d, toString as foo2String } from './foo2'; | ||
~ | ||
!!! error TS2305: Module '"./foo2"' has no exported member 'a'. | ||
~ | ||
!!! error TS2305: Module '"./foo2"' has no exported member 'b'. | ||
~ | ||
!!! error TS2305: Module '"./foo2"' has no exported member 'd'. | ||
~~~~~~~~ | ||
!!! error TS2305: Module '"./foo2"' has no exported member 'toString'. | ||
c; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//// [tests/cases/compiler/namedImportNonExistentName.ts] //// | ||
|
||
//// [foo.d.ts] | ||
export = Foo; | ||
export as namespace Foo; | ||
|
||
declare namespace Foo { | ||
function foo(); | ||
} | ||
|
||
//// [foo2.ts] | ||
let x: { a: string; c: string; } | { b: number; c: number; }; | ||
export = x | ||
|
||
//// [bar.ts] | ||
import { Bar, toString, foo } from './foo'; | ||
foo(); | ||
import { a, b, c, d, toString as foo2String } from './foo2'; | ||
c; | ||
|
||
//// [foo2.js] | ||
"use strict"; | ||
var x; | ||
module.exports = x; | ||
//// [bar.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
var foo_1 = require("./foo"); | ||
foo_1.foo(); | ||
var foo2_1 = require("./foo2"); | ||
foo2_1.c; |
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/namedImportNonExistentName.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
=== tests/cases/compiler/foo.d.ts === | ||
export = Foo; | ||
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 24)) | ||
|
||
export as namespace Foo; | ||
>Foo : Symbol(Foo, Decl(foo.d.ts, 0, 13)) | ||
|
||
declare namespace Foo { | ||
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 24)) | ||
|
||
function foo(); | ||
>foo : Symbol(foo, Decl(foo.d.ts, 3, 23)) | ||
} | ||
|
||
=== tests/cases/compiler/foo2.ts === | ||
let x: { a: string; c: string; } | { b: number; c: number; }; | ||
>x : Symbol(x, Decl(foo2.ts, 0, 3)) | ||
>a : Symbol(a, Decl(foo2.ts, 0, 8)) | ||
>c : Symbol(c, Decl(foo2.ts, 0, 19)) | ||
>b : Symbol(b, Decl(foo2.ts, 0, 36)) | ||
>c : Symbol(c, Decl(foo2.ts, 0, 47)) | ||
|
||
export = x | ||
>x : Symbol(x, Decl(foo2.ts, 0, 3)) | ||
|
||
=== tests/cases/compiler/bar.ts === | ||
import { Bar, toString, foo } from './foo'; | ||
>Bar : Symbol(Bar, Decl(bar.ts, 0, 8)) | ||
>toString : Symbol(toString, Decl(bar.ts, 0, 13)) | ||
>foo : Symbol(foo, Decl(bar.ts, 0, 23)) | ||
|
||
foo(); | ||
>foo : Symbol(foo, Decl(bar.ts, 0, 23)) | ||
|
||
import { a, b, c, d, toString as foo2String } from './foo2'; | ||
>a : Symbol(a, Decl(bar.ts, 2, 8)) | ||
>b : Symbol(b, Decl(bar.ts, 2, 11)) | ||
>c : Symbol(c, Decl(bar.ts, 2, 14)) | ||
>d : Symbol(d, Decl(bar.ts, 2, 17)) | ||
>foo2String : Symbol(foo2String, Decl(bar.ts, 2, 20)) | ||
|
||
c; | ||
>c : Symbol(c, Decl(bar.ts, 2, 14)) | ||
|
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/namedImportNonExistentName.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
=== tests/cases/compiler/foo.d.ts === | ||
export = Foo; | ||
>Foo : typeof Foo | ||
|
||
export as namespace Foo; | ||
>Foo : typeof Foo | ||
|
||
declare namespace Foo { | ||
>Foo : typeof Foo | ||
|
||
function foo(); | ||
>foo : () => any | ||
} | ||
|
||
=== tests/cases/compiler/foo2.ts === | ||
let x: { a: string; c: string; } | { b: number; c: number; }; | ||
>x : { a: string; c: string; } | { b: number; c: number; } | ||
>a : string | ||
>c : string | ||
>b : number | ||
>c : number | ||
|
||
export = x | ||
>x : { a: string; c: string; } | { b: number; c: number; } | ||
|
||
=== tests/cases/compiler/bar.ts === | ||
import { Bar, toString, foo } from './foo'; | ||
>Bar : any | ||
>toString : any | ||
>foo : () => any | ||
|
||
foo(); | ||
>foo() : any | ||
>foo : () => any | ||
|
||
import { a, b, c, d, toString as foo2String } from './foo2'; | ||
>a : any | ||
>b : any | ||
>c : string | number | ||
>d : any | ||
>toString : any | ||
>foo2String : any | ||
|
||
c; | ||
>c : string | number | ||
|
16 changes: 16 additions & 0 deletions
16
tests/cases/compiler/moduleAugmentationWithNonExistentNamedImport.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @filename: foo.d.ts | ||
export = Foo; | ||
export as namespace Foo; | ||
|
||
declare namespace Foo { | ||
function foo(); | ||
} | ||
|
||
declare global { | ||
namespace Bar { } | ||
} | ||
|
||
// @filename: bar.d.ts | ||
import { Bar } from './foo'; | ||
export = Bar; | ||
export as namespace Bar; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @filename: foo.d.ts | ||
export = Foo; | ||
export as namespace Foo; | ||
|
||
declare namespace Foo { | ||
function foo(); | ||
} | ||
|
||
// @filename: foo2.ts | ||
let x: { a: string; c: string; } | { b: number; c: number; }; | ||
export = x | ||
|
||
// @filename: bar.ts | ||
import { Bar, toString, foo } from './foo'; | ||
foo(); | ||
import { a, b, c, d, toString as foo2String } from './foo2'; | ||
c; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, rather than threading through this flag, and worrying about the safety of caching it and have two differently calculated symbols for a property lookup, couldn't we
globalFunctionType
andglobalObjectType
each to a unique empty type (which should naturally cause property lookups that ultimately may have depended on them to fail during global initialization).symbolFromVariable.parent
here isglobalObjectType
orglobalFunctionType
and, if so, discard the result? (to ensure consistency with the initialization phase)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.