[babel-plugin-transform-es2015-parameters] more oportunities for optimisations
This commit is contained in:
parent
16ae7c2d9a
commit
3868d36e31
@ -52,19 +52,34 @@ let memberExpressionOptimisationVisitor = {
|
|||||||
if (state.noOptimise) {
|
if (state.noOptimise) {
|
||||||
state.deopted = true;
|
state.deopted = true;
|
||||||
} else {
|
} else {
|
||||||
if (path.parentPath.isMemberExpression({ computed: true, object: node })) {
|
let {parentPath} = path;
|
||||||
// if we know that this member expression is referencing a number then we can safely
|
|
||||||
// optimise it
|
// ex: args[0]
|
||||||
let prop = path.parentPath.get("property");
|
if (parentPath.isMemberExpression({ computed: true, object: node })) {
|
||||||
|
// if we know that this member expression is referencing a number then
|
||||||
|
// we can safely optimise it
|
||||||
|
let prop = parentPath.get("property");
|
||||||
if (prop.isBaseType("number")) {
|
if (prop.isBaseType("number")) {
|
||||||
state.candidates.push(path);
|
state.candidates.push(path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ex: args.length
|
||||||
|
if (parentPath.isMemberExpression({ computed: false, object: node })) {
|
||||||
|
let prop = parentPath.get("property");
|
||||||
|
if (prop.node.name === "length") {
|
||||||
|
state.candidates.push(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we can only do these optimizations if the rest variable would match
|
||||||
|
// the arguments exactly
|
||||||
// optimise single spread args in calls
|
// optimise single spread args in calls
|
||||||
if (path.parentPath.isSpreadElement() && state.offset === 0) {
|
// ex: fn(...args)
|
||||||
let call = path.parentPath.parentPath;
|
if (state.offset === 0 && parentPath.isSpreadElement()) {
|
||||||
|
let call = parentPath.parentPath;
|
||||||
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
||||||
state.candidates.push(path);
|
state.candidates.push(path);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -28,3 +28,7 @@ var b = function (foo, ...bar) {
|
|||||||
var join = "join";
|
var join = "join";
|
||||||
return bar[join];
|
return bar[join];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var b = function (...bar) {
|
||||||
|
return bar.len;
|
||||||
|
};
|
||||||
|
|||||||
@ -53,3 +53,11 @@ var b = function (foo) {
|
|||||||
|
|
||||||
return bar[join];
|
return bar[join];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var b = function () {
|
||||||
|
for (var _len7 = arguments.length, bar = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
||||||
|
bar[_key7] = arguments[_key7];
|
||||||
|
}
|
||||||
|
|
||||||
|
return bar.len;
|
||||||
|
};
|
||||||
|
|||||||
@ -1,9 +1,17 @@
|
|||||||
var t = function (...items) {
|
var t = function (...items) {
|
||||||
var x = items[0];
|
var x = items[0];
|
||||||
var y = items[1];
|
var y = items[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function t(...items) {
|
function t(...items) {
|
||||||
var x = items[0];
|
var x = items[0];
|
||||||
var y = items[1];
|
var y = items[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function t(...items) {
|
||||||
|
var a = [];
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
a.push(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
@ -1,9 +1,17 @@
|
|||||||
var t = function () {
|
var t = function () {
|
||||||
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
||||||
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
function t() {
|
function t() {
|
||||||
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
||||||
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function t() {
|
||||||
|
var a = [];
|
||||||
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
|
a.push(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user