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

JSDoc type reference understands require with entity name #34804

Merged

Conversation

sandersn
Copy link
Member

For example, require("x").c. This is the value equivalent of import("x").a.b.c, but the syntax tree is not as nicely designed for this purpose.

Fixes #34802

For example, `require("x").c`. This is the value equivalent of
`import("x").a.b.c`, but the syntax tree is not as nicely designed for
this purpose.

Fixes #34802
@sandersn
Copy link
Member Author

note: this needs to be in 3.7 too

if (isVariableDeclaration(decl) && decl.initializer) {
let expr = decl.initializer;
// skip past entity names, eg `require("x").a.b.c`
while (isPropertyAccessExpression(expr)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about optional chains?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those work -- I added a test. I guess they use the same AST as normal property access expressions?

@sandersn sandersn merged commit 7635884 into master Oct 29, 2019
@sandersn sandersn deleted the jsdoc-type-reference-understands-require-w/entity-name branch October 29, 2019 21:56
@sandersn
Copy link
Member Author

@typescript-bot cherry-pick this to release-3.7

(Not sure this is going to work, this has been a hot spot of bug fixes.)

@typescript-bot
Copy link
Collaborator

Hey @sandersn, I couldn't open a PR with the cherry-pick. (You can check the log here). You may need to squash and pick this PR into release-3.7 manually.

sandersn added a commit that referenced this pull request Oct 29, 2019
* resolve require with entity name postfix

For example, `require("x").c`. This is the value equivalent of
`import("x").a.b.c`, but the syntax tree is not as nicely designed for
this purpose.

Fixes #34802

* Add bug number to test

* Add optional chain test
@sandersn
Copy link
Member Author

Thanks for trying, typescript-bot. I cherry-picked the squashed commit manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type reference to require import resolves to static side
3 participants