Properly resolve scope from switch statement - fixes T6761
This commit is contained in:
parent
e526643f79
commit
8efd1d71ad
10
packages/babel-plugin-transform-es2015-spread/test/fixtures/regression/T6761/actual.js
vendored
Normal file
10
packages/babel-plugin-transform-es2015-spread/test/fixtures/regression/T6761/actual.js
vendored
Normal 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;
|
||||||
|
}
|
||||||
12
packages/babel-plugin-transform-es2015-spread/test/fixtures/regression/T6761/expected.js
vendored
Normal file
12
packages/babel-plugin-transform-es2015-spread/test/fixtures/regression/T6761/expected.js
vendored
Normal 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;
|
||||||
|
}
|
||||||
3
packages/babel-plugin-transform-es2015-spread/test/fixtures/regression/options.json
vendored
Normal file
3
packages/babel-plugin-transform-es2015-spread/test/fixtures/regression/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["external-helpers-2", "transform-es2015-spread", "transform-es2015-parameters"]
|
||||||
|
}
|
||||||
@ -741,14 +741,14 @@ export default class Scope {
|
|||||||
}) {
|
}) {
|
||||||
let path = this.path;
|
let path = this.path;
|
||||||
|
|
||||||
if (path.isSwitchStatement()) {
|
|
||||||
path = this.getFunctionParent().path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!path.isBlockStatement() && !path.isProgram()) {
|
if (!path.isBlockStatement() && !path.isProgram()) {
|
||||||
path = this.getBlockParent().path;
|
path = this.getBlockParent().path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path.isSwitchStatement()) {
|
||||||
|
path = this.getFunctionParent().path;
|
||||||
|
}
|
||||||
|
|
||||||
if (path.isLoop() || path.isCatchClause() || path.isFunction()) {
|
if (path.isLoop() || path.isCatchClause() || path.isFunction()) {
|
||||||
t.ensureBlock(path.node);
|
t.ensureBlock(path.node);
|
||||||
path = path.get("body");
|
path = path.get("body");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user