You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Go to definition shows Node require statement as definition #39895
Nathan Shively-Sanders (@sandersn), this could be impacted by your explorations into making CommonJS requires actual alias symbols. Is that still something you’re looking at?
Duplicate of #25533; this bug has a plainer explanation of the problem, and that one has a ready-made repro. #39770 is definitely a pre-requisite for fixing this, and I hope to get this fix in at the same time.
Reacted by Markus Waas, Andrew Branch and ExE Boss
Well, on digging into the code, I found two things:
We actually have quite different code for goto-def.
For goto-def to work the same way as with ES imports, both const = require AND module.exports= need to create aliases. Alias for commonjs require in JS #39770 only does the former. (Alternatively, we could add more ad-hoc resolution code in gotoDefinition.ts.)
#39770 does fix find-all-refs and improves goto-def -- it jumps to the module.exports -- but it still doesn't jump all the way to the original declaration like ES exports to. So, although the OP's screenshot is a dupe of #25533 for find-all-refs, the title requests a goto-def fix. Let's use this bug to track that now.
both const = require AND module.exports= need to create aliases.... (Alternatively, we could add more ad-hoc resolution code in gotoDefinition.ts.)
Nathan Shively-Sanders (@sandersn) do you have an opinion on which of these is a better solution? I.e., is making module.exports aliases valuable beyond the benefits to go-to-definition? I have a feeling that might be a bit risky for this post-beta period, but is it something we should be aiming for otherwise?
As of 4.0, both module.exports.x= and module.exports= create an alias for entity names and class expressions, although not for other expressions. So the rest of this fix is likely in gotoDefinition.ts -- but it's hopefully less ad-hoc than before.
Changes in goto-def are less core to the compiler, but might be more complex. It's hard to guess whether this should ship in the RC without making the fix first. If turns out to be simple, I think it would be fine.
I actually don’t know if this need be specific to module.exports or even to JavaScript. I kind of feel like we should always just jump past shorthand property assignments... maybe? They feel very alias-y, not very declaration-y.
There’s really not a lot of user feedback on this, and offering too-granular definitions is generally better than making a non-obvious leap past the definition the user was interested in (skipping past an uninteresting declaration is usually as simple as an additional ⌘-click). So, I’ll limit this to skipping past the shorthand property assignments in module.exports = { one, two, three, ... } as I feel confident from personal experience that those are a nuisance when they show up in go-to-definition.
Activity
andrewbranch commentedon Aug 5, 2020
Nathan Shively-Sanders (@sandersn), this could be impacted by your explorations into making CommonJS requires actual alias symbols. Is that still something you’re looking at?
sandersn commentedon Aug 5, 2020
Yes, I've been distracted by other JS prototypes for 4.1, but I'll get back to it pretty soon. I'll add this bug to the list of ones to check on.
sandersn commentedon Aug 11, 2020
Duplicate of #25533; this bug has a plainer explanation of the problem, and that one has a ready-made repro. #39770 is definitely a pre-requisite for fixing this, and I hope to get this fix in at the same time.
sandersn commentedon Aug 12, 2020
Well, on digging into the code, I found two things:
const = requireANDmodule.exports=need to create aliases. Alias for commonjs require in JS #39770 only does the former. (Alternatively, we could add more ad-hoc resolution code in gotoDefinition.ts.)#39770 does fix find-all-refs and improves goto-def -- it jumps to the
module.exports-- but it still doesn't jump all the way to the original declaration like ES exports to. So, although the OP's screenshot is a dupe of #25533 for find-all-refs, the title requests a goto-def fix. Let's use this bug to track that now.andrewbranch commentedon Sep 21, 2020
Nathan Shively-Sanders (@sandersn) do you have an opinion on which of these is a better solution? I.e., is making
module.exportsaliases valuable beyond the benefits to go-to-definition? I have a feeling that might be a bit risky for this post-beta period, but is it something we should be aiming for otherwise?sandersn commentedon Sep 24, 2020
As of 4.0, both
module.exports.x=andmodule.exports=create an alias for entity names and class expressions, although not for other expressions. So the rest of this fix is likely in gotoDefinition.ts -- but it's hopefully less ad-hoc than before.Changes in goto-def are less core to the compiler, but might be more complex. It's hard to guess whether this should ship in the RC without making the fix first. If turns out to be simple, I think it would be fine.
andrewbranch commentedon Sep 25, 2020
I actually don’t know if this need be specific to
module.exportsor even to JavaScript. I kind of feel like we should always just jump past shorthand property assignments... maybe? They feel very alias-y, not very declaration-y.andrewbranch commentedon Sep 28, 2020
There’s really not a lot of user feedback on this, and offering too-granular definitions is generally better than making a non-obvious leap past the definition the user was interested in (skipping past an uninteresting declaration is usually as simple as an additional ⌘-click). So, I’ll limit this to skipping past the shorthand property assignments in
module.exports = { one, two, three, ... }as I feel confident from personal experience that those are a nuisance when they show up in go-to-definition.