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 - allow type parameter defaults in function declarations #10084

Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
MAKEFLAGS = -j1
FLOW_COMMIT = 2ac56861e3ceff9ca406ae586fbafb3480c6c0b7
FLOW_COMMIT = 09669846b7a7ca5a6c23c12d56bb3bebdafd67e9
TEST262_COMMIT = de567d3aa5de4eaa11e00131d26b9fe77997dfb0

# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
Expand Down
20 changes: 5 additions & 15 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -798,9 +798,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node.typeParameters = null;

if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration(
/* allowDefault */ false,
);
node.typeParameters = this.flowParseTypeParameterDeclaration();
}

this.expect(tt.parenL);
Expand Down Expand Up @@ -1287,9 +1285,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

case tt.relational:
if (this.state.value === "<") {
node.typeParameters = this.flowParseTypeParameterDeclaration(
/* allowDefault */ false,
);
node.typeParameters = this.flowParseTypeParameterDeclaration();
this.expect(tt.parenL);
tmp = this.flowParseFunctionTypeParams();
node.params = tmp.params;
Expand Down Expand Up @@ -2092,9 +2088,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
delete (method: $FlowFixMe).variance;
if (this.isRelational("<")) {
method.typeParameters = this.flowParseTypeParameterDeclaration(
/* allowDefault */ false,
);
method.typeParameters = this.flowParseTypeParameterDeclaration();
}

super.pushClassMethod(
Expand Down Expand Up @@ -2176,9 +2170,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

// method shorthand
if (this.isRelational("<")) {
typeParameters = this.flowParseTypeParameterDeclaration(
/* allowDefault */ false,
);
typeParameters = this.flowParseTypeParameterDeclaration();
if (!this.match(tt.parenL)) this.unexpected();
}

Expand Down Expand Up @@ -2386,9 +2378,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// $FlowFixMe
const kind = node.kind;
if (kind !== "get" && kind !== "set" && this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration(
/* allowDefault */ false,
);
node.typeParameters = this.flowParseTypeParameterDeclaration();
}
super.parseFunctionParams(node, allowModifiers);
}
Expand Down
@@ -1,3 +1 @@
(class A {
foo<T = string>() {}
});
declare function foo<T = string>() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're in here shuffling things, can we give these tests better names so we don't have to go through this renumbering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder how i should name it, i copied the test case from flow fixtures, should i renamed it based on their test id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

default-invalid-declare-func
default-invalid-var-type
default-invalid-class-extends

🤷‍♂

@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:8)"
}
"throws": "Unexpected token, expected \":\" (1:35)"
}
@@ -1 +1 @@
({ foo<T = string>() {} });
var x: Array<T = number>
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:9)"
}
"throws": "Unexpected token, expected \",\" (1:15)"
}
@@ -1 +1 @@
declare class A { foo<T = string>(): void }
class A extends B<T = number> {}
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:24)"
}
"throws": "Unexpected token, expected \",\" (1:20)"
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -20,3 +20,13 @@ interface A19<T: ?string = string> {}
interface A20<S, T: ?string = string> {}
interface A21<S = number, T: ?string = string> {}
type A22<T = void> = T
function A26<T = string>() {}
;({ A28<T = string>() {} });
class A29 {
foo<T = string>() {}
}
;(class A30 {
foo<T = string>() {}
});
declare class A31 { foo<T = string>(): void }
<T = string>() => 123;