-
-
Notifications
You must be signed in to change notification settings - Fork 601
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
fix(inject): detect references inside object destructuring #1241
Conversation
What platform are you developing on? We get quite a few Windows users submitting PRs and a good chunk of the maintainers use MacOS and Linux. |
Windows 10 / Node 17.4.0. |
Maybe it's your Node version? Even Node doesn't recommend running odd number versions for anything remotely production. |
I upgraded Node.js to 18.7.0.
|
There's something awry on your system I'm afraid. Just cloned a fresh copy, applied your changes, and had no issues with committing. WSL might be an option for you, but generally when we see odd errors like that, it points back to bad system config. |
Out of curiosity, which version of pnpm are you using? |
pnpm 7.9.0. Someone in the thread (pnpm/pnpm#4790) did suggest that downgrading pnpm solves the issue. Should I try that? |
Yes please try the last v6.x version. fwiw our lockfile here is still v6 format. |
Yes downgrading pnpm to 6.x works.
|
sweet. something still squirrelly with v7 |
I'm going to be bumping the pnpm lockfile version in master on Monday (I think). we can resolve the CI issues with this PR then. |
The error is that when testing on Windows, one test snapshot is missing. I think we need someone who dont use Windows to rebuild snapshots in this pr. |
Or fix the test so it can generate snapshots correctly on Windows. |
@@ -167,7 +167,7 @@ export default function inject(options) { | |||
|
|||
// special case – shorthand properties. because node.key === node.value, | |||
// we can't differentiate once we've descended into the node | |||
if (node.type === 'Property' && node.shorthand) { | |||
if (node.type === 'Property' && node.shorthand && node.value.type === 'Identifier') { |
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.
My worry is that with this change, if the shorthand property is an assignment pattern but the left side should be replaced, it would cause the same issue we are guarding against.
i.e. what would happen here
export const test = ({process = {}}) => {
console.log(process);
};
(Admittedly I did not run the code...)
Maybe we should rather add special handling for assignment patterns in shorthands than restrict the current special handling to the identifier case?
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.
I think it should be guarded by if (scope.contains(...))
since process
is a local variable in this case.
I guess we can add more test cases e.g.
{
const {$} = foo;
}
{
const foo = {$};
}
{
const foo = ({$}) => {};
}
{
const foo = ({bar = $}) => {};
}
I tried to build this on master but then got a new error:
Seems like a cross platform issue related to path separator. |
Fair enough
Also const {$ = fallback} = foo; which is the example I should have written. |
Done |
b11bbcb
to
c32a7e4
Compare
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.
Somehow when you recreated the snapshots, one test case was removed, I fixed this from my side by recreating them again, I wonder what caused it. (I usually do pnpm t -- -u
to recreate, if you do the same, then it might be some environment thing). Looks good to be merged.
Rollup Plugin Name:
inject
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
#1235
Description
Currently the plugin doesn't detect references inside object destructuring:
This PR fixes it.
Another issue: I ran
git commit
and hit this bug: pnpm/pnpm#4790I ended up running
git commit --no-verify
so something might be wrong.Also it seems that test snapshots are built differently on different platforms. You may want to rebuild it on Unix.