[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) {
|
||||
state.deopted = true;
|
||||
} else {
|
||||
if (path.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 = path.parentPath.get("property");
|
||||
let {parentPath} = path;
|
||||
|
||||
// ex: args[0]
|
||||
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")) {
|
||||
state.candidates.push(path);
|
||||
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
|
||||
if (path.parentPath.isSpreadElement() && state.offset === 0) {
|
||||
let call = path.parentPath.parentPath;
|
||||
// ex: fn(...args)
|
||||
if (state.offset === 0 && parentPath.isSpreadElement()) {
|
||||
let call = parentPath.parentPath;
|
||||
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
||||
state.candidates.push(path);
|
||||
return;
|
||||
|
||||
@ -28,3 +28,7 @@ var b = function (foo, ...bar) {
|
||||
var join = "join";
|
||||
return bar[join];
|
||||
};
|
||||
|
||||
var b = function (...bar) {
|
||||
return bar.len;
|
||||
};
|
||||
|
||||
@ -53,3 +53,11 @@ var b = function (foo) {
|
||||
|
||||
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 x = items[0];
|
||||
var y = items[1];
|
||||
var x = items[0];
|
||||
var y = items[1];
|
||||
}
|
||||
|
||||
function t(...items) {
|
||||
var x = items[0];
|
||||
var y = items[1];
|
||||
var x = items[0];
|
||||
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 x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
||||
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
||||
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
||||
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
||||
};
|
||||
|
||||
function t() {
|
||||
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
||||
var y = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
|
||||
var x = arguments.length <= 0 || arguments[0] === undefined ? undefined : arguments[0];
|
||||
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