Merge pull request #3141 from babel/mul-def
Fix bug with evaluating an expression in it's own binding
This commit is contained in:
commit
f52b8f9e99
18
packages/babel-core/test/fixtures/plugins/multiple-definition-evaluation/exec.js
vendored
Normal file
18
packages/babel-core/test/fixtures/plugins/multiple-definition-evaluation/exec.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
var code = multiline([
|
||||
"function foo() {",
|
||||
" var a = a ? a : a;",
|
||||
"}",
|
||||
]);
|
||||
|
||||
transform(code, {
|
||||
plugins: function (b) {
|
||||
var t = b.types;
|
||||
return {
|
||||
visitor: {
|
||||
ConditionalExpression: function(path) {
|
||||
path.get("test").evaluateTruthy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -360,7 +360,10 @@ export function _resolve(dangerous?, resolved?): ?NodePath {
|
||||
if (binding.kind === "module") return;
|
||||
|
||||
if (binding.path !== this) {
|
||||
return binding.path.resolve(dangerous, resolved);
|
||||
let ret = binding.path.resolve(dangerous, resolved);
|
||||
// If the identifier resolves to parent node then we can't really resolve it.
|
||||
if (this.find(parent => parent.node === ret.node)) return;
|
||||
return ret;
|
||||
}
|
||||
} else if (this.isTypeCastExpression()) {
|
||||
return this.get("expression").resolve(dangerous, resolved);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user