mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Until https://github.com/babel/babel/pull/3249 is fixed properly, it's better simply to disable the rest parameter optimizations.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
|
|
|
|
exports.__esModule = true;
|
|
|
|
var _babelTypes = require("babel-types");
|
|
|
|
var t = _interopRequireWildcard(_babelTypes);
|
|
|
|
var visitor = {
|
|
Function: function Function(path) {
|
|
var params /*: Array*/ = path.get("params");
|
|
|
|
// 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.
|
|
var hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0;
|
|
var outputParamsLength = params.length - hoistTweak;
|
|
|
|
for (var i = 0; i < outputParamsLength; i++) {
|
|
var param = params[i];
|
|
if (param.isArrayPattern() || param.isObjectPattern()) {
|
|
var uid = path.scope.generateUidIdentifier("ref");
|
|
|
|
var declar = t.variableDeclaration("let", [t.variableDeclarator(param.node, uid)]);
|
|
declar._blockHoist = outputParamsLength - i;
|
|
|
|
path.ensureBlock();
|
|
path.get("body").unshiftContainer("body", declar);
|
|
|
|
param.replaceWith(uid);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
exports.visitor = visitor; |