Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly transpile when cross-param refs with obj rest (#11326)
* Transform initializers with ids in rest elements Fix issue 11281. Transform parameters with default initializers that have ids that are also in a parameter with a rest element. Before, these parameters were not transformed. * Add plugin-transform-parameters as dependency * Remove outdated comment * Use set instead of array for paramsWithRestElement * Skip when encounter "Scope" Previously, f({...R}, f = R => R) would be incorrectly transformed. * Pass in loose mode option instead of false * Address review and re-organize tests Checking the RHS of an assignment pattern/checking the parent of an identifier node fails on cases like "({...R}, a = f(R))" or "({...R}, {[R.key]: a = 42})". Also refactor tests by removing unecessary tests and separating "should transform" from "should not transform" tests.
- Loading branch information
Showing
7 changed files
with
171 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...el-plugin-proposal-object-rest-spread/test/fixtures/object-rest/parameters-extra/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
({...R}, a = R) => {} | ||
({X: Y,...R}, {a = {Y}}) => {} | ||
(a = R, {...R}) => {} | ||
({...R}, e, c = 2, a = R, f = q) => { let q; } | ||
({...R}, a = f(R)) => {} | ||
({...R}, { [R.key]: a = 42 }) => {} | ||
|
||
({...R}, {a = {R: b}}) => {} | ||
({...R}, {a = R => R} = {b: R => R}) => {} |
61 changes: 61 additions & 0 deletions
61
...l-plugin-proposal-object-rest-spread/test/fixtures/object-rest/parameters-extra/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(_ref) => { | ||
let R = babelHelpers.extends({}, _ref); | ||
let a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : R; | ||
}; | ||
|
||
(_ref2, _ref3) => { | ||
let { | ||
X: Y | ||
} = _ref2, | ||
R = babelHelpers.objectWithoutProperties(_ref2, ["X"]); | ||
let { | ||
a = { | ||
Y | ||
} | ||
} = _ref3; | ||
}; | ||
|
||
() => { | ||
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : R; | ||
|
||
let _ref4 = arguments.length > 1 ? arguments[1] : undefined; | ||
|
||
let R = babelHelpers.extends({}, _ref4); | ||
}; | ||
|
||
(_ref5, e, c = 2) => { | ||
let R = babelHelpers.extends({}, _ref5); | ||
let a = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : R; | ||
let f = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : q; | ||
return function () { | ||
let q; | ||
}(); | ||
}; | ||
|
||
(_ref6) => { | ||
let R = babelHelpers.extends({}, _ref6); | ||
let a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : f(R); | ||
}; | ||
|
||
(_ref7, _ref8) => { | ||
let R = babelHelpers.extends({}, _ref7); | ||
let { | ||
[R.key]: a = 42 | ||
} = _ref8; | ||
}; | ||
|
||
(_ref9, { | ||
a = { | ||
R: b | ||
} | ||
}) => { | ||
let R = babelHelpers.extends({}, _ref9); | ||
}; | ||
|
||
(_ref10, { | ||
a = R => R | ||
} = { | ||
b: R => R | ||
}) => { | ||
let R = babelHelpers.extends({}, _ref10); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters