Properly resolve scope from switch statement - fixes T6761

This commit is contained in:
Logan Smyth 2015-12-04 09:00:21 -08:00
parent e526643f79
commit 8efd1d71ad
4 changed files with 29 additions and 4 deletions

View File

@ -0,0 +1,10 @@
function fn(){}
var args = [1, 2, 3];
var obj = {obj: {fn}};
switch (true){
case true:
obj.obj.fn(...args);
break;
}

View File

@ -0,0 +1,12 @@
var _obj$obj;
function fn() {}
var args = [1, 2, 3];
var obj = { obj: { fn } };
switch (true) {
case true:
(_obj$obj = obj.obj).fn.apply(_obj$obj, args);
break;
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["external-helpers-2", "transform-es2015-spread", "transform-es2015-parameters"]
}

View File

@ -741,14 +741,14 @@ export default class Scope {
}) {
let path = this.path;
if (path.isSwitchStatement()) {
path = this.getFunctionParent().path;
}
if (!path.isBlockStatement() && !path.isProgram()) {
path = this.getBlockParent().path;
}
if (path.isSwitchStatement()) {
path = this.getFunctionParent().path;
}
if (path.isLoop() || path.isCatchClause() || path.isFunction()) {
t.ensureBlock(path.node);
path = path.get("body");