Order of arguments initialization - fixes T6809
When using a default param + some destructuring param + a rest param, the initialization order of the destructured arguments was incorrect due to the presence of the rest parameter.
This commit is contained in:
@@ -3,8 +3,12 @@ import * as t from "babel-types";
|
||||
export let visitor = {
|
||||
Function(path) {
|
||||
let params: Array = path.get("params");
|
||||
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
|
||||
// If there's a rest param, no need to loop through it. Also, we need to
|
||||
// hoist one more level to get `declar` at the right spot.
|
||||
const hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0;
|
||||
|
||||
for (let i = 0; i < params.length - hoistTweak; i++) {
|
||||
let param = params[i];
|
||||
if (param.isArrayPattern() || param.isObjectPattern()) {
|
||||
let uid = path.scope.generateUidIdentifier("ref");
|
||||
@@ -12,7 +16,7 @@ export let visitor = {
|
||||
let declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(param.node, uid)
|
||||
]);
|
||||
declar._blockHoist = params.length - i;
|
||||
declar._blockHoist = params.length - i - hoistTweak;
|
||||
|
||||
path.ensureBlock();
|
||||
path.get("body").unshiftContainer("body", declar);
|
||||
|
||||
Reference in New Issue
Block a user