fix noOptimise state being incorrect when recursing into multiple nested functions - fixes #1815
This commit is contained in:
@@ -12,9 +12,10 @@ var memberExpressionOptimisationVisitor = {
|
||||
Function(node, parent, scope, state) {
|
||||
// skip over functions as whatever `arguments` we reference inside will refer
|
||||
// to the wrong function
|
||||
var oldNoOptimise = state.noOptimise;
|
||||
state.noOptimise = true;
|
||||
this.traverse(memberExpressionOptimisationVisitor, state);
|
||||
state.noOptimise = false;
|
||||
state.noOptimise = oldNoOptimise;
|
||||
this.skip();
|
||||
},
|
||||
|
||||
@@ -27,7 +28,9 @@ var memberExpressionOptimisationVisitor = {
|
||||
// is this a referenced identifier and is it referencing the rest parameter?
|
||||
if (node.name !== state.name) return;
|
||||
|
||||
if (!state.noOptimise) {
|
||||
if (state.noOptimise) {
|
||||
state.deopted = true;
|
||||
} else {
|
||||
if (this.parentPath.isMemberExpression({ computed: true, object: node })) {
|
||||
// if we know that this member expression is referencing a number then we can safely
|
||||
// optimise it
|
||||
@@ -46,11 +49,7 @@ var memberExpressionOptimisationVisitor = {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state.noOptimise) {
|
||||
state.deopted = true;
|
||||
} else {
|
||||
state.references.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,3 +41,12 @@ function r(...rest){
|
||||
if (lol) rest;
|
||||
rest;
|
||||
}
|
||||
|
||||
// nested functions
|
||||
function a(...args) {
|
||||
return function() {
|
||||
function b() {}
|
||||
|
||||
console.log("Shouldn't args be from a's scope?", args);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,3 +64,16 @@ function r() {
|
||||
if (lol) rest;
|
||||
rest;
|
||||
}
|
||||
|
||||
// nested functions
|
||||
function a() {
|
||||
for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
||||
args[_key6] = arguments[_key6];
|
||||
}
|
||||
|
||||
return function () {
|
||||
function b() {}
|
||||
|
||||
console.log("Shouldn't args be from a's scope?", args);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user