-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix values and types merging in JS module exports #37896
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c6f7c82
Fix values and types merging in JS module exports
andrewbranch 4d8f63f
Fix everything
andrewbranch 4ff811b
Share `setValueDeclaration` between binder (local merge) and checker …
andrewbranch fccaaf6
Revert accidental changes to baselines
andrewbranch d59e9ca
Merge branch 'master' into bug/37833
andrewbranch 6a004bc
Update baseline from master merge
andrewbranch 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
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
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
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
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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation.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,43 @@ | ||
=== /test.js === | ||
class Abcde { | ||
>Abcde : Symbol(Abcde, Decl(test.js, 0, 0)) | ||
|
||
/** @type {string} */ | ||
x; | ||
>x : Symbol(Abcde.x, Decl(test.js, 0, 13)) | ||
} | ||
|
||
module.exports = { | ||
>module.exports : Symbol("/test", Decl(test.js, 0, 0)) | ||
>module : Symbol("/test.js", Decl(test.js, 3, 1), Decl(index.ts, 0, 31)) | ||
>exports : Symbol("/test.js", Decl(test.js, 3, 1), Decl(index.ts, 0, 31)) | ||
|
||
Abcde | ||
>Abcde : Symbol(Abcde, Decl(test.js, 5, 18)) | ||
|
||
}; | ||
|
||
=== /index.ts === | ||
import { Abcde } from "./test"; | ||
>Abcde : Symbol(Abcde, Decl(index.ts, 0, 8)) | ||
|
||
declare module "./test" { | ||
>"./test" : Symbol("/test.js", Decl(test.js, 3, 1), Decl(index.ts, 0, 31)) | ||
|
||
interface Abcde { b: string } | ||
>Abcde : Symbol(Abcde, Decl(index.ts, 2, 25), Decl(test.js, 5, 18)) | ||
>b : Symbol(Abcde.b, Decl(index.ts, 3, 19)) | ||
} | ||
|
||
new Abcde().x; | ||
>new Abcde().x : Symbol(Abcde.x, Decl(test.js, 0, 13)) | ||
>Abcde : Symbol(Abcde, Decl(index.ts, 0, 8)) | ||
>x : Symbol(Abcde.x, Decl(test.js, 0, 13)) | ||
|
||
// Bug: the type meaning from /test.js does not | ||
// propagate through the object literal export. | ||
const x: Abcde = { b: "" }; | ||
>x : Symbol(x, Decl(index.ts, 10, 5)) | ||
>Abcde : Symbol(Abcde, Decl(index.ts, 0, 8)) | ||
>b : Symbol(b, Decl(index.ts, 10, 18)) | ||
|
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation.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 @@ | ||
=== /test.js === | ||
class Abcde { | ||
>Abcde : Abcde | ||
|
||
/** @type {string} */ | ||
x; | ||
>x : string | ||
} | ||
|
||
module.exports = { | ||
>module.exports = { Abcde} : { Abcde: typeof Abcde; } | ||
>module.exports : { Abcde: typeof Abcde; } | ||
>module : { "\"/test\"": { Abcde: typeof Abcde; }; } | ||
>exports : { Abcde: typeof Abcde; } | ||
>{ Abcde} : { Abcde: typeof Abcde; } | ||
|
||
Abcde | ||
>Abcde : typeof Abcde | ||
|
||
}; | ||
|
||
=== /index.ts === | ||
import { Abcde } from "./test"; | ||
>Abcde : typeof Abcde | ||
|
||
declare module "./test" { | ||
>"./test" : { Abcde: typeof Abcde; } | ||
|
||
interface Abcde { b: string } | ||
>b : string | ||
} | ||
|
||
new Abcde().x; | ||
>new Abcde().x : string | ||
>new Abcde() : Abcde | ||
>Abcde : typeof Abcde | ||
>x : string | ||
|
||
// Bug: the type meaning from /test.js does not | ||
// propagate through the object literal export. | ||
const x: Abcde = { b: "" }; | ||
>x : Abcde | ||
>{ b: "" } : { b: string; } | ||
>b : string | ||
>"" : "" | ||
|
27 changes: 27 additions & 0 deletions
27
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation2.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,27 @@ | ||
/index.ts(4,16): error TS2300: Duplicate identifier 'a'. | ||
/index.ts(7,3): error TS2339: Property 'toFixed' does not exist on type 'string'. | ||
/test.js(2,3): error TS2300: Duplicate identifier 'a'. | ||
|
||
|
||
==== /test.js (1 errors) ==== | ||
module.exports = { | ||
a: "ok" | ||
~ | ||
!!! error TS2300: Duplicate identifier 'a'. | ||
!!! related TS6203 /index.ts:4:16: 'a' was also declared here. | ||
}; | ||
|
||
==== /index.ts (2 errors) ==== | ||
import { a } from "./test"; | ||
|
||
declare module "./test" { | ||
export const a: number; | ||
~ | ||
!!! error TS2300: Duplicate identifier 'a'. | ||
!!! related TS6203 /test.js:2:3: 'a' was also declared here. | ||
} | ||
|
||
a.toFixed(); | ||
~~~~~~~ | ||
!!! error TS2339: Property 'toFixed' does not exist on type 'string'. | ||
|
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation2.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,25 @@ | ||
=== /test.js === | ||
module.exports = { | ||
>module.exports : Symbol("/test", Decl(test.js, 0, 0)) | ||
>module : Symbol("/test.js", Decl(test.js, 0, 0), Decl(index.ts, 0, 27)) | ||
>exports : Symbol("/test.js", Decl(test.js, 0, 0), Decl(index.ts, 0, 27)) | ||
|
||
a: "ok" | ||
>a : Symbol(a, Decl(test.js, 0, 18)) | ||
|
||
}; | ||
|
||
=== /index.ts === | ||
import { a } from "./test"; | ||
>a : Symbol(a, Decl(index.ts, 0, 8)) | ||
|
||
declare module "./test" { | ||
>"./test" : Symbol("/test.js", Decl(test.js, 0, 0), Decl(index.ts, 0, 27)) | ||
|
||
export const a: number; | ||
>a : Symbol(a, Decl(index.ts, 3, 14)) | ||
} | ||
|
||
a.toFixed(); | ||
>a : Symbol(a, Decl(index.ts, 0, 8)) | ||
|
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation2.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,31 @@ | ||
=== /test.js === | ||
module.exports = { | ||
>module.exports = { a: "ok"} : { a: string | number; } | ||
>module.exports : { a: string | number; } | ||
>module : { "\"/test\"": { a: string | number; }; } | ||
>exports : { a: string | number; } | ||
>{ a: "ok"} : { a: string; } | ||
|
||
a: "ok" | ||
>a : string | ||
>"ok" : "ok" | ||
|
||
}; | ||
|
||
=== /index.ts === | ||
import { a } from "./test"; | ||
>a : string | ||
|
||
declare module "./test" { | ||
>"./test" : { a: string | number; } | ||
|
||
export const a: number; | ||
>a : number | ||
} | ||
|
||
a.toFixed(); | ||
>a.toFixed() : any | ||
>a.toFixed : any | ||
>a : string | ||
>toFixed : any | ||
|
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
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
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
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
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
Oops, something went wrong.
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.
does this need a fix in the binder too? It probably only applies to code that is js-only (assignment declarations) and ts-only (ambient declarations) so 99.9% of the time it'll be in different files, but for the 0.01%, we do understand ambient declarations in .js as well -- we just put an error on them.
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.
Hmm, how would you end up with an ambient declaration in a JavaScript file? Off the top of my head I didn’t think that was possible.
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.
Well, we'll parse and understand this in JS:
Just with lots of errors saying "please don't use this".
More practically, I think it would be better if this code and the check inside declareSymbol in the binder were the same -- if they haven't already diverged too far.
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.
The logic in those two places was identical, so it was safe and easy to move to a utility. That said, I couldn’t actually trigger the same crash by writing ambient code in a JS file, I think because an ambient module declaration is only a module augmentation if the file is an ES module, and if it’s an ES module,
module.exports
is ignored.