Repository navigation
Don’t recognize non-top-level module.exports as special assignments #34805
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
Closed
Andrew Branch (andrewbranch)
wants to merge
1
commit into
microsoft:master
from
andrewbranch:bug/33765-part-2
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| tests/cases/conformance/jsdoc/not-iife.js(5,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. | ||
| tests/cases/conformance/jsdoc/not-iife.js(6,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. | ||
| tests/cases/conformance/jsdoc/not-iife.js(8,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. | ||
| tests/cases/conformance/jsdoc/test.js(2,1): error TS2304: Cannot find name 'ShouldNotBeGlobal'. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/jsdoc/not-iife.js (3 errors) ==== | ||
| var ShouldBeGlobal = 0; | ||
| function f(type, ctor, exports) { | ||
| if (typeof exports !== "undefined") { | ||
| exports.a = ctor; | ||
| module.exports.b = ctor; | ||
| ~~~~~~ | ||
| !!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. | ||
| module.exports = { ctor }; | ||
| ~~~~~~ | ||
| !!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. | ||
| exports = { ctor }; | ||
| module.exports["c"] = type; | ||
| ~~~~~~ | ||
| !!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. | ||
| } | ||
| } | ||
|
|
||
| ==== tests/cases/conformance/jsdoc/iife.js (0 errors) ==== | ||
| var ShouldNotBeGlobal = 0; | ||
| (function () { | ||
| exports.a = "b"; | ||
| })(); | ||
|
|
||
| ==== tests/cases/conformance/jsdoc/test.js (1 errors) ==== | ||
| ShouldBeGlobal; | ||
| ShouldNotBeGlobal; | ||
| ~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2304: Cannot find name 'ShouldNotBeGlobal'. | ||
|
|
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,50 @@ | ||
| === tests/cases/conformance/jsdoc/not-iife.js === | ||
| var ShouldBeGlobal = 0; | ||
| >ShouldBeGlobal : Symbol(ShouldBeGlobal, Decl(not-iife.js, 0, 3)) | ||
|
|
||
| function f(type, ctor, exports) { | ||
| >f : Symbol(f, Decl(not-iife.js, 0, 23)) | ||
| >type : Symbol(type, Decl(not-iife.js, 1, 11)) | ||
| >ctor : Symbol(ctor, Decl(not-iife.js, 1, 16)) | ||
| >exports : Symbol(exports, Decl(not-iife.js, 1, 22)) | ||
|
|
||
| if (typeof exports !== "undefined") { | ||
| >exports : Symbol(exports, Decl(not-iife.js, 1, 22)) | ||
|
|
||
| exports.a = ctor; | ||
| >exports : Symbol(exports, Decl(not-iife.js, 1, 22)) | ||
| >ctor : Symbol(ctor, Decl(not-iife.js, 1, 16)) | ||
|
|
||
| module.exports.b = ctor; | ||
| >ctor : Symbol(ctor, Decl(not-iife.js, 1, 16)) | ||
|
|
||
| module.exports = { ctor }; | ||
| >ctor : Symbol(ctor, Decl(not-iife.js, 5, 26)) | ||
|
|
||
| exports = { ctor }; | ||
| >exports : Symbol(exports, Decl(not-iife.js, 1, 22)) | ||
| >ctor : Symbol(ctor, Decl(not-iife.js, 6, 19)) | ||
|
|
||
| module.exports["c"] = type; | ||
| >type : Symbol(type, Decl(not-iife.js, 1, 11)) | ||
| } | ||
| } | ||
|
|
||
| === tests/cases/conformance/jsdoc/iife.js === | ||
| var ShouldNotBeGlobal = 0; | ||
| >ShouldNotBeGlobal : Symbol(ShouldNotBeGlobal, Decl(iife.js, 0, 3)) | ||
|
|
||
| (function () { | ||
| exports.a = "b"; | ||
| >exports.a : Symbol(a, Decl(iife.js, 1, 14)) | ||
| >exports : Symbol(a, Decl(iife.js, 1, 14)) | ||
| >a : Symbol(a, Decl(iife.js, 1, 14)) | ||
|
|
||
| })(); | ||
|
|
||
| === tests/cases/conformance/jsdoc/test.js === | ||
| ShouldBeGlobal; | ||
| >ShouldBeGlobal : Symbol(ShouldBeGlobal, Decl(not-iife.js, 0, 3)) | ||
|
|
||
| ShouldNotBeGlobal; | ||
|
|
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,84 @@ | ||
| === tests/cases/conformance/jsdoc/not-iife.js === | ||
| var ShouldBeGlobal = 0; | ||
| >ShouldBeGlobal : number | ||
| >0 : 0 | ||
|
|
||
| function f(type, ctor, exports) { | ||
| >f : (type: any, ctor: any, exports: any) => void | ||
| >type : any | ||
| >ctor : any | ||
| >exports : any | ||
|
|
||
| if (typeof exports !== "undefined") { | ||
| >typeof exports !== "undefined" : boolean | ||
| >typeof exports : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
| >exports : any | ||
| >"undefined" : "undefined" | ||
|
|
||
| exports.a = ctor; | ||
| >exports.a = ctor : any | ||
| >exports.a : any | ||
| >exports : any | ||
| >a : any | ||
| >ctor : any | ||
|
|
||
| module.exports.b = ctor; | ||
| >module.exports.b = ctor : any | ||
| >module.exports.b : any | ||
| >module.exports : any | ||
| >module : any | ||
| >exports : any | ||
| >b : any | ||
| >ctor : any | ||
|
|
||
| module.exports = { ctor }; | ||
| >module.exports = { ctor } : { ctor: any; } | ||
| >module.exports : any | ||
| >module : any | ||
| >exports : any | ||
| >{ ctor } : { ctor: any; } | ||
| >ctor : any | ||
|
|
||
| exports = { ctor }; | ||
| >exports = { ctor } : { ctor: any; } | ||
| >exports : any | ||
| >{ ctor } : { ctor: any; } | ||
| >ctor : any | ||
|
|
||
| module.exports["c"] = type; | ||
| >module.exports["c"] = type : any | ||
| >module.exports["c"] : any | ||
| >module.exports : any | ||
| >module : any | ||
| >exports : any | ||
| >"c" : "c" | ||
| >type : any | ||
| } | ||
| } | ||
|
|
||
| === tests/cases/conformance/jsdoc/iife.js === | ||
| var ShouldNotBeGlobal = 0; | ||
| >ShouldNotBeGlobal : number | ||
| >0 : 0 | ||
|
|
||
| (function () { | ||
| >(function () { exports.a = "b";})() : void | ||
| >(function () { exports.a = "b";}) : () => void | ||
| >function () { exports.a = "b";} : () => void | ||
|
|
||
| exports.a = "b"; | ||
| >exports.a = "b" : "b" | ||
| >exports.a : string | ||
| >exports : typeof import("tests/cases/conformance/jsdoc/iife") | ||
| >a : string | ||
| >"b" : "b" | ||
|
|
||
| })(); | ||
|
|
||
| === tests/cases/conformance/jsdoc/test.js === | ||
| ShouldBeGlobal; | ||
| >ShouldBeGlobal : number | ||
|
|
||
| ShouldNotBeGlobal; | ||
| >ShouldNotBeGlobal : 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // @noEmit: true | ||
| // @checkJs: true | ||
| // @allowJs: true | ||
|
|
||
| // @Filename: not-iife.js | ||
| var ShouldBeGlobal = 0; | ||
| function f(type, ctor, exports) { | ||
| if (typeof exports !== "undefined") { | ||
| exports.a = ctor; | ||
| module.exports.b = ctor; | ||
| module.exports = { ctor }; | ||
| exports = { ctor }; | ||
| module.exports["c"] = type; | ||
| } | ||
| } | ||
|
|
||
| // @Filename: iife.js | ||
| var ShouldNotBeGlobal = 0; | ||
| (function () { | ||
| exports.a = "b"; | ||
| })(); | ||
|
|
||
| // @Filename: test.js | ||
| ShouldBeGlobal; | ||
| ShouldNotBeGlobal; |
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.
previously, isTopLevel calls occurred outside getAssignmentDeclarationKind, mostly [1] so that we could call that once in the binder and not have to walk up the tree too much elsewhere -- at least at one point, getAssignmentDeclarationKind checked fairly local syntax.
So, three questions:
[1] it was partly chance. But lots of things are partly chance.
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.
exports. But you’re right, we don’t have metrics on this.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.
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.
Ah, yeah, this is the first time we look way up the tree.