-
Notifications
You must be signed in to change notification settings - Fork 747
Fix typedef binding with CJS exports=
#826
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 14 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6f540b2
Fix typedef binding with CJS `exports=`
sandersn b8bc147
remove TODO that is now done
sandersn 5d2d999
Merge branch 'main' into fix-typedef-export
sandersn 8021e94
fallback-resolve namespace members on the export= symbol
sandersn 689d0e7
Merge branch 'main' into fix-typedef-export
sandersn 1cffb6e
Add JSExportDeclaration
sandersn 3c5ec18
Revert "Add JSExportDeclaration"
sandersn 1ba2be7
Merge branch 'main' into fix-typedef-export
sandersn b9ab451
Merge branch 'main' into fix-typedef-export
sandersn a14ebdd
Merge branch 'main' into fix-typedef-export
sandersn c713ea5
Merge branch 'main' into fix-typedef-export
sandersn b1b5eaa
npm run updatefailing
sandersn e61cea5
make hack more like old hack
sandersn f20bd78
update test names and checker comments
sandersn 34cbad6
revert code from previous attempt
sandersn c64de86
update internal test filenames too
sandersn 41d412d
move hack into resolveEntityName
sandersn b5e8a24
Only export typedefs if there are no conflicts
sandersn 8b6fef2
Merge branch 'main' into fix-typedef-export
sandersn 8205ffa
npm run updatefailing
sandersn 4728500
Merge branch 'main' into fix-typedef-export
sandersn 6350c42
update baselines
sandersn 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
14 changes: 14 additions & 0 deletions
14
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.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,14 @@ | ||
| use.js(1,22): error TS2307: Cannot find module './controlFlowJSClassProperty' or its corresponding type declarations. | ||
|
|
||
|
|
||
| ==== typedefModuleExportsIndirect1.js (0 errors) ==== | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const dummy = 0; | ||
| module.exports = dummy; | ||
| ==== use.js (1 errors) ==== | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2307: Cannot find module './controlFlowJSClassProperty' or its corresponding type declarations. | ||
| /** @type {C} */ | ||
| var c | ||
|
|
35 changes: 35 additions & 0 deletions
35
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.js
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,35 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect1.ts] //// | ||
|
|
||
| //// [typedefModuleExportsIndirect1.js] | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const dummy = 0; | ||
| module.exports = dummy; | ||
| //// [use.js] | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
|
|
||
|
|
||
| //// [typedefModuleExportsIndirect1.js] | ||
| "use strict"; | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const dummy = 0; | ||
| module.exports = dummy; | ||
| //// [use.js] | ||
| "use strict"; | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c; | ||
|
|
||
|
|
||
| //// [typedefModuleExportsIndirect1.d.ts] | ||
| export type C = { | ||
| a: 1; | ||
| m: 1; | ||
| }; | ||
| export = dummy; | ||
| //// [use.d.ts] | ||
| type C = import('./controlFlowJSClassProperty').C; | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| declare var c: C; |
19 changes: 19 additions & 0 deletions
19
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.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,19 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect1.ts] //// | ||
|
|
||
| === typedefModuleExportsIndirect1.js === | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const dummy = 0; | ||
| >dummy : Symbol(dummy, Decl(typedefModuleExportsIndirect1.js, 1, 5)) | ||
|
|
||
| module.exports = dummy; | ||
| >module.exports : Symbol(dummy, Decl(typedefModuleExportsIndirect1.js, 1, 5)) | ||
| >module : Symbol(module.exports) | ||
| >exports : Symbol(dummy, Decl(typedefModuleExportsIndirect1.js, 1, 5)) | ||
| >dummy : Symbol(dummy, Decl(typedefModuleExportsIndirect1.js, 1, 5)) | ||
|
|
||
| === use.js === | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
| >c : Symbol(c, Decl(use.js, 2, 3)) | ||
|
|
21 changes: 21 additions & 0 deletions
21
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.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,21 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect1.ts] //// | ||
|
|
||
| === typedefModuleExportsIndirect1.js === | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const dummy = 0; | ||
| >dummy : 0 | ||
| >0 : 0 | ||
|
|
||
| module.exports = dummy; | ||
| >module.exports = dummy : 0 | ||
| >module.exports : 0 | ||
| >module : { readonly dummy: 0; } | ||
| >exports : 0 | ||
| >dummy : 0 | ||
|
|
||
| === use.js === | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
| >c : any | ||
|
|
14 changes: 14 additions & 0 deletions
14
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.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,14 @@ | ||
| use.js(1,22): error TS2307: Cannot find module './controlFlowJSClassProperty' or its corresponding type declarations. | ||
|
|
||
|
|
||
| ==== typedefModuleExportsIndirect2.js (0 errors) ==== | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const f = function() {}; | ||
| module.exports = f; | ||
| ==== use.js (1 errors) ==== | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2307: Cannot find module './controlFlowJSClassProperty' or its corresponding type declarations. | ||
| /** @type {C} */ | ||
| var c | ||
|
|
35 changes: 35 additions & 0 deletions
35
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.js
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,35 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect2.ts] //// | ||
|
|
||
| //// [typedefModuleExportsIndirect2.js] | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const f = function() {}; | ||
| module.exports = f; | ||
| //// [use.js] | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
|
|
||
|
|
||
| //// [typedefModuleExportsIndirect2.js] | ||
| "use strict"; | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const f = function () { }; | ||
| module.exports = f; | ||
| //// [use.js] | ||
| "use strict"; | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c; | ||
|
|
||
|
|
||
| //// [typedefModuleExportsIndirect2.d.ts] | ||
| export type C = { | ||
| a: 1; | ||
| m: 1; | ||
| }; | ||
| export = f; | ||
| //// [use.d.ts] | ||
| type C = import('./controlFlowJSClassProperty').C; | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| declare var c: C; |
19 changes: 19 additions & 0 deletions
19
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.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,19 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect2.ts] //// | ||
|
|
||
| === typedefModuleExportsIndirect2.js === | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const f = function() {}; | ||
| >f : Symbol(f, Decl(typedefModuleExportsIndirect2.js, 1, 5)) | ||
|
|
||
| module.exports = f; | ||
| >module.exports : Symbol(f, Decl(typedefModuleExportsIndirect2.js, 1, 5)) | ||
| >module : Symbol(module.exports) | ||
| >exports : Symbol(f, Decl(typedefModuleExportsIndirect2.js, 1, 5)) | ||
| >f : Symbol(f, Decl(typedefModuleExportsIndirect2.js, 1, 5)) | ||
|
|
||
| === use.js === | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
| >c : Symbol(c, Decl(use.js, 2, 3)) | ||
|
|
21 changes: 21 additions & 0 deletions
21
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.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,21 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect2.ts] //// | ||
|
|
||
| === typedefModuleExportsIndirect2.js === | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const f = function() {}; | ||
| >f : () => void | ||
| >function() {} : () => void | ||
|
|
||
| module.exports = f; | ||
| >module.exports = f : () => void | ||
| >module.exports : () => void | ||
| >module : { readonly f: () => void; } | ||
| >exports : () => void | ||
| >f : () => void | ||
|
|
||
| === use.js === | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
| >c : any | ||
|
|
14 changes: 14 additions & 0 deletions
14
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.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,14 @@ | ||
| use.js(1,22): error TS2307: Cannot find module './controlFlowJSClassProperty' or its corresponding type declarations. | ||
|
|
||
|
|
||
| ==== typedefModuleExportsIndirect3.js (0 errors) ==== | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const o = {}; | ||
| module.exports = o; | ||
| ==== use.js (1 errors) ==== | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2307: Cannot find module './controlFlowJSClassProperty' or its corresponding type declarations. | ||
| /** @type {C} */ | ||
| var c | ||
|
|
35 changes: 35 additions & 0 deletions
35
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.js
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,35 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect3.ts] //// | ||
|
|
||
| //// [typedefModuleExportsIndirect3.js] | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const o = {}; | ||
| module.exports = o; | ||
| //// [use.js] | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
|
|
||
|
|
||
| //// [typedefModuleExportsIndirect3.js] | ||
| "use strict"; | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const o = {}; | ||
| module.exports = o; | ||
| //// [use.js] | ||
| "use strict"; | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c; | ||
|
|
||
|
|
||
| //// [typedefModuleExportsIndirect3.d.ts] | ||
| export type C = { | ||
| a: 1; | ||
| m: 1; | ||
| }; | ||
| export = o; | ||
| //// [use.d.ts] | ||
| type C = import('./controlFlowJSClassProperty').C; | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| declare var c: C; |
19 changes: 19 additions & 0 deletions
19
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.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,19 @@ | ||
| //// [tests/cases/conformance/salsa/typedefModuleExportsIndirect3.ts] //// | ||
|
|
||
| === typedefModuleExportsIndirect3.js === | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const o = {}; | ||
| >o : Symbol(o, Decl(typedefModuleExportsIndirect3.js, 1, 5)) | ||
|
|
||
| module.exports = o; | ||
| >module.exports : Symbol(o, Decl(typedefModuleExportsIndirect3.js, 1, 5)) | ||
| >module : Symbol(module.exports) | ||
| >exports : Symbol(o, Decl(typedefModuleExportsIndirect3.js, 1, 5)) | ||
| >o : Symbol(o, Decl(typedefModuleExportsIndirect3.js, 1, 5)) | ||
|
|
||
| === use.js === | ||
| /** @typedef {import('./controlFlowJSClassProperty').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
| >c : Symbol(c, Decl(use.js, 2, 3)) | ||
|
|
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.
this is a driveby fix--dontResolveAlias wasn't used even before this PR
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.
In Strada I see
dontResolveAliasbeing given both true and false all over the place. Are you sure we should remove it?Uh oh!
There was an error while loading. Please reload this page.
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.
Yes. As best I can tell, it's a translation artifact--resolveQualifiedName is a function extracted from resolveEntityName -- it reads way better in Go and probably would in TS too -- but its code never actually refers to dontResolveAlias, even in Strada. It's only checked once in resolveEntityName, actually, right at the end, when deciding whether to resolveAlias on the symbol we just resolved.