diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index be46a3b4a0..7c41d5738b 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -68,9 +68,6 @@ const collectorVisitor = { return; } - // TODO(amasad): remove support for flow as bindings (See warning below). - //if (path.isFlow()) return; - // we've ran into a declaration! const parent = path.scope.getFunctionParent() || path.scope.getProgramParent(); @@ -468,8 +465,6 @@ export default class Scope { } registerDeclaration(path: NodePath) { - if (path.isFlow()) return; - if (path.isLabeledStatement()) { this.registerLabel(path); } else if (path.isFunctionDeclaration()) { diff --git a/packages/babel-traverse/test/scope.js b/packages/babel-traverse/test/scope.js index 4e9ae8cae3..8747d66790 100644 --- a/packages/babel-traverse/test/scope.js +++ b/packages/babel-traverse/test/scope.js @@ -72,16 +72,80 @@ describe("scope", function() { expect( getPath("declare var foo;", { plugins: ["flow"] }).scope.getBinding( "foo", - ), - ).toBeUndefined(); + ).path.type, + ).toBe("DeclareVariable"); }); it("declare function", function() { expect( getPath("declare function foo(): void;", { plugins: ["flow"], - }).scope.getBinding("foo"), - ).toBeUndefined(); + }).scope.getBinding("foo").path.type, + ).toBe("DeclareFunction"); + }); + + it("declare module", function() { + expect( + getPath("declare module foo {};", { + plugins: ["flow"], + }).scope.getBinding("foo").path.type, + ).toBe("DeclareModule"); + }); + + it("declare type alias", function() { + expect( + getPath("declare type foo = string;", { + plugins: ["flow"], + }).scope.getBinding("foo").path.type, + ).toBe("DeclareTypeAlias"); + }); + + it("declare opaque type", function() { + expect( + getPath("declare opaque type foo;", { + plugins: ["flow"], + }).scope.getBinding("foo").path.type, + ).toBe("DeclareOpaqueType"); + }); + + it("declare interface", function() { + expect( + getPath("declare interface Foo {};", { + plugins: ["flow"], + }).scope.getBinding("Foo").path.type, + ).toBe("DeclareInterface"); + }); + + it("type alias", function() { + expect( + getPath("type foo = string;", { + plugins: ["flow"], + }).scope.getBinding("foo").path.type, + ).toBe("TypeAlias"); + }); + + it("opaque type alias", function() { + expect( + getPath("opaque type foo = string;", { + plugins: ["flow"], + }).scope.getBinding("foo").path.type, + ).toBe("OpaqueType"); + }); + + it("interface", function() { + expect( + getPath("interface Foo {};", { + plugins: ["flow"], + }).scope.getBinding("Foo").path.type, + ).toBe("InterfaceDeclaration"); + }); + + it("import type", function() { + expect( + getPath("import type {Foo} from 'foo';", { + plugins: ["flow"], + }).scope.getBinding("Foo").path.type, + ).toBe("ImportSpecifier"); }); it("variable constantness", function() { diff --git a/packages/babel-types/src/retrievers/getBindingIdentifiers.js b/packages/babel-types/src/retrievers/getBindingIdentifiers.js index bd289a8168..d437409f40 100644 --- a/packages/babel-types/src/retrievers/getBindingIdentifiers.js +++ b/packages/babel-types/src/retrievers/getBindingIdentifiers.js @@ -74,6 +74,9 @@ getBindingIdentifiers.keys = { DeclareFunction: ["id"], DeclareModule: ["id"], DeclareVariable: ["id"], + DeclareInterface: ["id"], + DeclareTypeAlias: ["id"], + DeclareOpaqueType: ["id"], InterfaceDeclaration: ["id"], TypeAlias: ["id"], OpaqueType: ["id"],