Skip to content

Commonjs import with destructuring ignores trailing property access #40578

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
sandersn opened this issue Sep 15, 2020 · 5 comments · Fixed by #40702
Closed

Commonjs import with destructuring ignores trailing property access #40578

sandersn opened this issue Sep 15, 2020 · 5 comments · Fixed by #40702
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

sandersn commented Sep 15, 2020

Discovered in prettier/prettier#9207, where @brodybits is investigating whether #40143 works.

// @filename: mod1.js
var o = {
    concat() { }
}
exports.builders = o
// @filename: test.js
const { concat } = require('./mod1').builders;

Expected behavior:

concat: () => void

Actual behavior:

Error: module "mod1" has no exported member 'concat'.

Looks like we miss the trailing property access and don't fall back to the faked import type.

@brody4hire
Copy link

Small question: does the milestone mean that we would have to wait for 4.1.1 rather than 4.1.0?

In any case, thanks again for your efforts to support Prettier.

@j-oliveras
Copy link
Contributor

@brodybits Version 4.1.0 is the beta, 4.1.1 is the release candidate and 4.1.2 is the final release. They use it like this because the nuget or Visual Studio release (I don't remember witch one) don't support tags/branches.

Probably they wait for the release candidate because the beta will be launched this week (see #40124).

sandersn added a commit that referenced this issue Sep 22, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 22, 2020
sandersn added a commit that referenced this issue Sep 24, 2020
* CommonJS imports support destructuring+property access

Fixes #40578 for prettier

* will I ever remember semicolons? haha no

* move code around

* move function declaration closer to use

* Add missing space after `if`

Thanks to @weswigham for noticing this. Somehow it passed the linter.
@brody4hire
Copy link

I tried making my own, local build of TypeScript from master, and it DOES seem to work properly with Prettier.

When I tried recent version 4.1.0-dev.20200924 from npm, that one does not seem to be fixed. I tried it here: prettier/prettier#9207

I would be happy to try a newer beta version from npm once it is ready.

@sandersn
Copy link
Member Author

Hmm. I think 0924 is built on early on the morning of 9/24, and this was merged in the afternoon. Perhaps 0925 will work?

@brody4hire
Copy link

0925 will work?

Seems to work for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants