Correctly transpile when default parameter initializer references binding in rest pattern #11317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes the bug where
({ a, ...R }, b = R, c = a) => {}
was not transpiled correctly iftransform-function-parameters
was not enabled.I used solution 2 as described by @JLHwung in the issue post. This solution loops over each param with a default initializer
a = b
/nested default initializer (like{a = b}
and roughly only transforms it if it is referencing a id created in an object rest pattern or if the previous parameter has been processed.For example, only the last 2 parameters in this function will be transformed.
({...b}, e, c = 2, a = b, f) => {}
Looking at the "parameters-extra" tests will clarify. There are some edge cases.
Problem: Because I extracted
convertParam
fromextractFunctionParams
in thebabel-plugin-transform-parameters
package, I had to import that package into this plugin, and update thepackage.json
for this plugin. However, I couldn't do that because that would break thepackage-lock.json
. This is causing the CI to fail, even though the tests pass locally on my computer.