Merge pull request #3141 from babel/mul-def

Fix bug with evaluating an expression in it's own binding
This commit is contained in:
Henry Zhu 2015-12-06 11:22:49 -05:00
commit f52b8f9e99
2 changed files with 22 additions and 1 deletions

View 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();
}
}
}
}
});

View File

@ -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);