From 286ae68da295bd9deb99ce713cdd2c8b62e751ac Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 29 Mar 2015 17:36:23 +1100 Subject: [PATCH] make constants and module imports synonymous - closes #954 --- .../transformers/es6/constants.js | 4 ++-- src/babel/traversal/scope.js | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/babel/transformation/transformers/es6/constants.js b/src/babel/transformation/transformers/es6/constants.js index 4a4e5c95d2..8cc5a786f1 100644 --- a/src/babel/transformation/transformers/es6/constants.js +++ b/src/babel/transformation/transformers/es6/constants.js @@ -2,7 +2,7 @@ import * as messages from "../../../messages"; import * as t from "../../../types"; export function check(node) { - return t.isVariableDeclaration(node, { kind: "const" }); + return t.isVariableDeclaration(node, { kind: "const" }) || t.isImportDeclaration(node); } var visitor = { @@ -38,7 +38,7 @@ var visitor = { export function Scopable(node, parent, scope, file) { this.traverse(visitor, { - constants: scope.getAllBindingsOfKind("const"), + constants: scope.getAllBindingsOfKind("const", "module"), file: file }); } diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index 9cc73182e2..24a3d8cb40 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -551,17 +551,20 @@ export default class Scope { * Walks the scope tree and gathers all declarations of `kind`. */ - getAllBindingsOfKind(kind: string): Object { + getAllBindingsOfKind(): Object { var ids = object(); - var scope = this; - do { - for (var name in scope.bindings) { - var binding = scope.bindings[name]; - if (binding.kind === kind) ids[name] = binding; - } - scope = scope.parent; - } while (scope); + for (let i = 0; i < arguments.length; i++) { + var kind = arguments[i]; + var scope = this; + do { + for (var name in scope.bindings) { + var binding = scope.bindings[name]; + if (binding.kind === kind) ids[name] = binding; + } + scope = scope.parent; + } while (scope); + } return ids; }