Minor refactoring

This commit is contained in:
Victor Felder 2015-12-21 10:43:59 +01:00
parent 28adaa49b2
commit 27f2918abb

View File

@ -6,9 +6,10 @@ export let visitor = {
// 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;
let hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0;
let outputParamsLength = params.length - hoistTweak;
for (let i = 0; i < params.length - hoistTweak; i++) {
for (let i = 0; i < outputParamsLength; i++) {
let param = params[i];
if (param.isArrayPattern() || param.isObjectPattern()) {
let uid = path.scope.generateUidIdentifier("ref");
@ -16,7 +17,7 @@ export let visitor = {
let declar = t.variableDeclaration("let", [
t.variableDeclarator(param.node, uid)
]);
declar._blockHoist = params.length - i - hoistTweak;
declar._blockHoist = outputParamsLength - i;
path.ensureBlock();
path.get("body").unshiftContainer("body", declar);