Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add support for local Flow bindings (TypeAlias, OpaqueTypeAlias and Interface) #7900

Merged
merged 1 commit into from May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/babel-traverse/src/scope/index.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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()) {
Expand Down
72 changes: 68 additions & 4 deletions packages/babel-traverse/test/scope.js
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-types/src/retrievers/getBindingIdentifiers.js
Expand Up @@ -74,6 +74,9 @@ getBindingIdentifiers.keys = {
DeclareFunction: ["id"],
DeclareModule: ["id"],
DeclareVariable: ["id"],
DeclareInterface: ["id"],
DeclareTypeAlias: ["id"],
DeclareOpaqueType: ["id"],
InterfaceDeclaration: ["id"],
TypeAlias: ["id"],
OpaqueType: ["id"],
Expand Down
1 change: 0 additions & 1 deletion packages/babylon/src/plugins/flow.js
Expand Up @@ -34,7 +34,6 @@ function isEsModuleType(bodyElement: N.Node): boolean {
);
}


function hasTypeImportKind(node: N.Node): boolean {
return node.importKind === "type" || node.importKind === "typeof";
}
Expand Down