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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(amasad): remove support for flow as bindings (See warning below).
|
|
||||||
//if (path.isFlow()) return;
|
|
||||||
|
|
||||||
// we've ran into a declaration!
|
// we've ran into a declaration!
|
||||||
const parent =
|
const parent =
|
||||||
path.scope.getFunctionParent() || path.scope.getProgramParent();
|
path.scope.getFunctionParent() || path.scope.getProgramParent();
|
||||||
@ -468,8 +465,6 @@ export default class Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerDeclaration(path: NodePath) {
|
registerDeclaration(path: NodePath) {
|
||||||
if (path.isFlow()) return;
|
|
||||||
|
|
||||||
if (path.isLabeledStatement()) {
|
if (path.isLabeledStatement()) {
|
||||||
this.registerLabel(path);
|
this.registerLabel(path);
|
||||||
} else if (path.isFunctionDeclaration()) {
|
} else if (path.isFunctionDeclaration()) {
|
||||||
|
|||||||
@ -72,16 +72,80 @@ describe("scope", function() {
|
|||||||
expect(
|
expect(
|
||||||
getPath("declare var foo;", { plugins: ["flow"] }).scope.getBinding(
|
getPath("declare var foo;", { plugins: ["flow"] }).scope.getBinding(
|
||||||
"foo",
|
"foo",
|
||||||
),
|
).path.type,
|
||||||
).toBeUndefined();
|
).toBe("DeclareVariable");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("declare function", function() {
|
it("declare function", function() {
|
||||||
expect(
|
expect(
|
||||||
getPath("declare function foo(): void;", {
|
getPath("declare function foo(): void;", {
|
||||||
plugins: ["flow"],
|
plugins: ["flow"],
|
||||||
}).scope.getBinding("foo"),
|
}).scope.getBinding("foo").path.type,
|
||||||
).toBeUndefined();
|
).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() {
|
it("variable constantness", function() {
|
||||||
|
|||||||
@ -74,6 +74,9 @@ getBindingIdentifiers.keys = {
|
|||||||
DeclareFunction: ["id"],
|
DeclareFunction: ["id"],
|
||||||
DeclareModule: ["id"],
|
DeclareModule: ["id"],
|
||||||
DeclareVariable: ["id"],
|
DeclareVariable: ["id"],
|
||||||
|
DeclareInterface: ["id"],
|
||||||
|
DeclareTypeAlias: ["id"],
|
||||||
|
DeclareOpaqueType: ["id"],
|
||||||
InterfaceDeclaration: ["id"],
|
InterfaceDeclaration: ["id"],
|
||||||
TypeAlias: ["id"],
|
TypeAlias: ["id"],
|
||||||
OpaqueType: ["id"],
|
OpaqueType: ["id"],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user