Skip to content
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

const x = require("m") should create an alias symbol #25533

Closed
ghost opened this issue Jul 9, 2018 · 5 comments · Fixed by #25732 or #39770
Closed

const x = require("m") should create an alias symbol #25533

ghost opened this issue Jul 9, 2018 · 5 comments · Fixed by #25732 or #39770
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Fix Available A PR has been opened for this issue
Milestone

Comments

@ghost
Copy link

ghost commented Jul 9, 2018

TypeScript Version: 3.0.0-dev.20180707

Code

/// <reference path='fourslash.ts'/>

// @allowJs: true

// @Filename: /a.js
////function [|{| "isWriteAccess": true, "isDefinition": true |}x|]() {};
////module.exports = [|x|];

// @Filename: /b.js
////const [|x|] = require("./a");
////[|x|];

const [r0, r1, r2, r3] = test.ranges();
verify.referenceGroups(r2, [/*todo*/]);

Expected behavior:

x in const x is an alias of the x in function x() {}, so all references are found.

Actual behavior:

x is a variable that happens to be the same type as the other x. Only references in b.js are found.

@ghost ghost added Bug A bug in TypeScript Salsa checkJs Relates to checking JavaScript using TypeScript labels Jul 9, 2018
@ghost ghost assigned sandersn Jul 9, 2018
@mhegazy mhegazy added this to the TypeScript 3.0.1 milestone Jul 10, 2018
@ghost ghost modified the milestones: TypeScript 3.0.1, TypeScript 3.1 Jul 10, 2018
@sandersn
Copy link
Member

The in-file type of commonjs modules is usually wrong, so I'll have to fix bugs related to that before aliasing will really make sense. I will look at #25621 first.

@ghost ghost reopened this Jul 20, 2018
@ghost
Copy link
Author

ghost commented Jul 20, 2018

The test from the original post still isn't returning results in a.js.

@sandersn
Copy link
Member

Turns out github didn't recognise that the "fix #xxxx" syntax occurred in a conditional clause and unconditionally closed this issue. :) Thanks for re-opening.

@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Domain: JavaScript The issue relates to JavaScript specifically Salsa labels Nov 29, 2018
@Jessidhia
Copy link

Jessidhia commented Jan 17, 2019

That's only correct if the module.exports is never reassigned...... but that's the best we can do in ES modules. That is also a limitation of node's --experimentalModules.

@sandersn
Copy link
Member

Note that the type of module.exports inside a module is now correctly checked, which unblocks fixing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants