make constants and module imports synonymous - closes #954

This commit is contained in:
Sebastian McKenzie 2015-03-29 17:36:23 +11:00
parent e26f994075
commit 286ae68da2
2 changed files with 14 additions and 11 deletions

View File

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

View File

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