-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Improve JavaScript type from constructor imported via require #16686
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
=== tests/cases/conformance/salsa/node.d.ts === | ||
declare function require(id: string): any; | ||
>require : Symbol(require, Decl(node.d.ts, 0, 0)) | ||
>id : Symbol(id, Decl(node.d.ts, 0, 25)) | ||
|
||
declare var module: any, exports: any; | ||
>module : Symbol(module, Decl(node.d.ts, 1, 11)) | ||
>exports : Symbol(exports, Decl(node.d.ts, 1, 24)) | ||
|
||
=== tests/cases/conformance/salsa/index.js === | ||
const A = require("./other"); | ||
>A : Symbol(A, Decl(index.js, 0, 5)) | ||
>require : Symbol(require, Decl(node.d.ts, 0, 0)) | ||
>"./other" : Symbol("tests/cases/conformance/salsa/other", Decl(other.js, 0, 0)) | ||
|
||
const a = new A().id; | ||
>a : Symbol(a, Decl(index.js, 1, 5)) | ||
>new A().id : Symbol(A.id, Decl(other.js, 0, 14)) | ||
>A : Symbol(A, Decl(index.js, 0, 5)) | ||
>id : Symbol(A.id, Decl(other.js, 0, 14)) | ||
|
||
const B = function() { this.id = 1; } | ||
>B : Symbol(B, Decl(index.js, 3, 5)) | ||
>id : Symbol(B.id, Decl(index.js, 3, 22)) | ||
|
||
const b = new B().id; | ||
>b : Symbol(b, Decl(index.js, 4, 5)) | ||
>new B().id : Symbol(B.id, Decl(index.js, 3, 22)) | ||
>B : Symbol(B, Decl(index.js, 3, 5)) | ||
>id : Symbol(B.id, Decl(index.js, 3, 22)) | ||
|
||
=== tests/cases/conformance/salsa/other.js === | ||
function A() { this.id = 1; } | ||
>A : Symbol(A, Decl(other.js, 0, 0)) | ||
>id : Symbol(A.id, Decl(other.js, 0, 14)) | ||
|
||
module.exports = A; | ||
>module : Symbol(export=, Decl(other.js, 0, 29)) | ||
>exports : Symbol(export=, Decl(other.js, 0, 29)) | ||
>A : Symbol(A, Decl(other.js, 0, 0)) | ||
|
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,55 @@ | ||
=== tests/cases/conformance/salsa/node.d.ts === | ||
declare function require(id: string): any; | ||
>require : (id: string) => any | ||
>id : string | ||
|
||
declare var module: any, exports: any; | ||
>module : any | ||
>exports : any | ||
|
||
=== tests/cases/conformance/salsa/index.js === | ||
const A = require("./other"); | ||
>A : () => void | ||
>require("./other") : () => void | ||
>require : (id: string) => any | ||
>"./other" : "./other" | ||
|
||
const a = new A().id; | ||
>a : number | ||
>new A().id : number | ||
>new A() : { id: number; } | ||
>A : () => void | ||
>id : number | ||
|
||
const B = function() { this.id = 1; } | ||
>B : () => void | ||
>function() { this.id = 1; } : () => void | ||
>this.id = 1 : 1 | ||
>this.id : any | ||
>this : any | ||
>id : any | ||
>1 : 1 | ||
|
||
const b = new B().id; | ||
>b : number | ||
>new B().id : number | ||
>new B() : { id: number; } | ||
>B : () => void | ||
>id : number | ||
|
||
=== tests/cases/conformance/salsa/other.js === | ||
function A() { this.id = 1; } | ||
>A : () => void | ||
>this.id = 1 : 1 | ||
>this.id : any | ||
>this : any | ||
>id : any | ||
>1 : 1 | ||
|
||
module.exports = A; | ||
>module.exports = A : () => void | ||
>module.exports : any | ||
>module : any | ||
>exports : any | ||
>A : () => void | ||
|
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,18 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
// @module: commonjs | ||
// @filename: node.d.ts | ||
declare function require(id: string): any; | ||
declare var module: any, exports: any; | ||
|
||
// @filename: index.js | ||
const A = require("./other"); | ||
const a = new A().id; | ||
|
||
const B = function() { this.id = 1; } | ||
const b = new B().id; | ||
|
||
// @filename: other.js | ||
function A() { this.id = 1; } | ||
module.exports = A; |
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.
what's an example for this case? it looks like the
const B = function ...
case in the new test file, but I expected that to be imported from a new, third file instead of just being in the original file.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
const A =
case tests the from an external file, while theconst B =
case tests the use locally. Both cases are relevant. Are you talking about a third case where we import something re-exported from a third file?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 line 16096 handle the
const A =
test (external) and 16099 handle theconst B =
test (local)? The two tests differ in syntax, so I thought the difference in the two cases in getJavascriptClassType was syntactic, and that both needed to come from external files. I guess that's wrong, and the difference is external vs local?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.
Line 16096 handles the case where
symbol
refers directly (globally or within the same file) to a function or a variable declaration whose initializer is a function.Line 16099 handles the case where
symbol
refers indirectly to a function or variable declaration whose initializer is a function. This is usually the case for imports likeconst C = require("./c")
orconst { C } = require("./c")
, but also cases likeconst C = B
whereB
is also local and is a function or variable declaration whose initializer is a function.