Re-add support for local Flow bindings (TypeAlias, OpaqueTypeAlias and Interface) (#7900)
This commit is contained in:
parent
af7ab71486
commit
bc6f0f989d
@ -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()) {
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -74,6 +74,9 @@ getBindingIdentifiers.keys = {
|
||||
DeclareFunction: ["id"],
|
||||
DeclareModule: ["id"],
|
||||
DeclareVariable: ["id"],
|
||||
DeclareInterface: ["id"],
|
||||
DeclareTypeAlias: ["id"],
|
||||
DeclareOpaqueType: ["id"],
|
||||
InterfaceDeclaration: ["id"],
|
||||
TypeAlias: ["id"],
|
||||
OpaqueType: ["id"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user