Skip to content

Commit

Permalink
Properly resolve scope from switch statement - fixes T6762
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Dec 4, 2015
1 parent e526643 commit c6fd459
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function fn(){}

var args = [1, 2, 3];
var obj = {obj: {fn}};

switch (true){
case true:
obj.obj.fn(...args);
break;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers-2", "transform-es2015-spread", "transform-es2015-parameters"]
}
8 changes: 4 additions & 4 deletions packages/babel-traverse/src/scope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit c6fd459

Please sign in to comment.