From 7c710a0378d40e6c579fb0424406bf9a907472d6 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 4 Apr 2015 14:09:34 +1100 Subject: [PATCH] move var scope collector to before block - fixes #1153 --- src/babel/traversal/scope.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index 99052d2c8c..3a6b550fa6 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -240,7 +240,6 @@ export default class Scope { if (kind === "param") return; if (kind === "hoisted" && local.kind === "let") return; - var duplicate = false; duplicate ||= local.kind === "let" || local.kind === "const" || local.kind === "module"; duplicate ||= local.kind === "param" && (kind === "let" || kind === "const"); @@ -477,6 +476,15 @@ export default class Scope { this.traverse(path.get("body").node, blockVariableVisitor, this); } + // Program, Function - var variables + + if (path.isProgram() || path.isFunction()) { + this.traverse(path.node, functionVariableVisitor, { + blockId: path.get("id").node, + scope: this + }); + } + // Program, BlockStatement, Function - let variables if (path.isBlockStatement() || path.isProgram()) { @@ -495,15 +503,6 @@ export default class Scope { this.registerBinding("let", path); } - // Program, Function - var variables - - if (path.isProgram() || path.isFunction()) { - this.traverse(path.node, functionVariableVisitor, { - blockId: path.get("id").node, - scope: this - }); - } - // Program if (path.isProgram()) {