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

flow: Let interface … extends take Foo.Bar, not just Foo #754

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion def/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export default function (fork: Fork) {
def("InterfaceExtends")
.bases("Node")
.build("id")
.field("id", def("Identifier"))
.field("id", or(def("Identifier"), def("QualifiedTypeIdentifier")))
.field("typeParameters",
or(def("TypeParameterInstantiation"), null),
defaults["null"]);
Expand Down
4 changes: 2 additions & 2 deletions gen/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2122,11 +2122,11 @@ export interface InterfaceTypeAnnotationBuilder {
}

export interface InterfaceExtendsBuilder {
(id: K.IdentifierKind): namedTypes.InterfaceExtends;
(id: K.IdentifierKind | K.QualifiedTypeIdentifierKind): namedTypes.InterfaceExtends;
from(
params: {
comments?: K.CommentKind[] | null,
id: K.IdentifierKind,
id: K.IdentifierKind | K.QualifiedTypeIdentifierKind,
loc?: K.SourceLocationKind | null,
typeParameters?: K.TypeParameterInstantiationKind | null
}
Expand Down
2 changes: 1 addition & 1 deletion gen/namedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ export namespace namedTypes {

export interface InterfaceExtends extends Omit<Node, "type"> {
type: "InterfaceExtends";
id: K.IdentifierKind;
id: K.IdentifierKind | K.QualifiedTypeIdentifierKind;
typeParameters?: K.TypeParameterInstantiationKind | null;
}

Expand Down
98 changes: 26 additions & 72 deletions test/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ var types = forkFn([
flowDef,
]);

const parser = {
parse(code: string) {
return flowParser.parse(code, {
types: true,
});
},
};

describe("flow types", function () {
it("issue #242", function () {
const parser = {
parse(code: string) {
return flowParser.parse(code, {
types: true
});
}
};

const program = parser.parse([
"class A<B> extends C<D> {}",
"function f<E>() {}",
Expand All @@ -46,14 +46,6 @@ describe("flow types", function () {
});

it("issue #261", function () {
const parser = {
parse(code: string) {
return flowParser.parse(code, {
types: true
});
}
};

const program = parser.parse('declare module.exports: {};');

assert.strictEqual(program.body[0].type, 'DeclareModuleExports');
Expand All @@ -62,14 +54,6 @@ describe("flow types", function () {
});

it("Explicit type arguments", function () {
const parser = {
parse(code: string) {
return flowParser.parse(code, {
types: true
});
}
};

const program = parser.parse([
'test<A>();',
'test<B, C>();',
Expand Down Expand Up @@ -128,14 +112,6 @@ describe("flow types", function () {
}

it("issue #294 - function declarations", function () {
const parser = {
parse(code: string) {
return require('flow-parser').parse(code, {
types: true
});
}
};

const program = parser.parse([
"function foo<T>(): T { }",
"let bar: T",
Expand All @@ -154,14 +130,6 @@ describe("flow types", function () {
});

it("issue #294 - function expressions", function () {
const parser = {
parse(code: string) {
return require('flow-parser').parse(code, {
types: true
});
}
};

const program = parser.parse([
"const foo = function <T>(): T { }",
"let bar: T",
Expand All @@ -182,14 +150,6 @@ describe("flow types", function () {
});

it("issue #294 - arrow function expressions", function () {
const parser = {
parse(code: string) {
return require('flow-parser').parse(code, {
types: true
});
}
};

const program = parser.parse([
"const foo = <T>(): T => { }",
"let bar: T"
Expand All @@ -208,14 +168,6 @@ describe("flow types", function () {
});

it("issue #294 - class declarations", function () {
const parser = {
parse(code: string) {
return require('flow-parser').parse(code, {
types: true
});
}
};

const program = parser.parse([
"class Foo<T> extends Bar<Array<T>> { }",
"let bar: T"
Expand All @@ -234,14 +186,6 @@ describe("flow types", function () {
});

it("issue #294 - class expressions", function () {
const parser = {
parse(code: string) {
return require('flow-parser').parse(code, {
types: true
});
}
};

const program = parser.parse([
"const foo = class Foo<T> extends Bar<Array<T>> { }",
"let bar: T"
Expand All @@ -263,14 +207,6 @@ describe("flow types", function () {
});

it("issue #296 - interface declarations", function () {
const parser = {
parse(code: string) {
return require('flow-parser').parse(code, {
types: true
});
}
};

const program = parser.parse([
"interface Foo<T> extends Bar<Array<T>> { }",
"let bar: T"
Expand All @@ -288,4 +224,22 @@ describe("flow types", function () {
}
});
});

it("interface extends qualified name", function () {
const program = parser.parse([
"interface I<T> extends Module.J<T[]> { }",
"declare interface I<T> extends Module.J<T[]> { }",
// Plain `class C extends A.B` gets a ClassDeclaration with superClass
// a MemberExpression. But with `declare`, it's a DeclareClass with
// `extends` containing an InterfaceExtends, much like on `interface`.
"declare class C extends React.Component<{||}> { }"
].join("\n"));

assertVisited(program, {
visitInterfaceExtends(path) {
types.builders.interfaceExtends.from(path.node);
this.traverse(path);
},
});
});
});