Navigation Menu

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

Fix some reserved type handling and declare class with multiple extends #6725

Merged
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
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
MAKEFLAGS = -j1
FLOW_COMMIT = 4cc2b9f7fadf2e9e445ee9b7b980c65d69d3fbc0
FLOW_COMMIT = 0dfdb8bf984205f03e95b71680e39bae6b8f7066
TEST262_COMMIT = 1282e842febf418ca27df13fa4b32f7e5021b470

export NODE_ENV = test
Expand Down
12 changes: 6 additions & 6 deletions packages/babylon/src/plugins/flow.js
Expand Up @@ -123,7 +123,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

flowParseDeclareClass(node: N.FlowDeclareClass): N.FlowDeclareClass {
this.next();
this.flowParseInterfaceish(node);
this.flowParseInterfaceish(node, /*isClass*/ true);
return this.finishNode(node, "DeclareClass");
}

Expand Down Expand Up @@ -389,8 +389,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>

// Interfaces

flowParseInterfaceish(node: N.FlowDeclare): void {
node.id = this.parseIdentifier();
flowParseInterfaceish(node: N.FlowDeclare, isClass?: boolean): void {
node.id = this.flowParseRestrictedIdentifier(/*liberal*/ !isClass);

if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
Expand All @@ -404,7 +404,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (this.eat(tt._extends)) {
do {
node.extends.push(this.flowParseInterfaceExtends());
} while (this.eat(tt.comma));
} while (!isClass && this.eat(tt.comma));
}

if (this.isContextual("mixins")) {
Expand Down Expand Up @@ -468,7 +468,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
declare: boolean,
): N.FlowOpaqueType {
this.expectContextual("type");
node.id = this.flowParseRestrictedIdentifier();
node.id = this.flowParseRestrictedIdentifier(/*liberal*/ true);

if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
Expand Down Expand Up @@ -1775,7 +1775,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const implemented: N.FlowClassImplements[] = (node.implements = []);
do {
const node = this.startNode();
node.id = this.parseIdentifier();
node.id = this.flowParseRestrictedIdentifier(/*liberal*/ true);
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterInstantiation();
} else {
Expand Down
@@ -0,0 +1 @@
declare class A extends B, C {}
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected { (1:25)"
}
@@ -0,0 +1 @@
interface string {}
@@ -0,0 +1,3 @@
{
"throws": "Cannot overwrite primitive type string (1:10)"
}
@@ -0,0 +1 @@
interface switch {}
@@ -0,0 +1,88 @@
{
"type": "File",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"program": {
"type": "Program",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"sourceType": "module",
"body": [
{
"type": "InterfaceDeclaration",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "switch"
},
"name": "switch"
},
"typeParameters": null,
"extends": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start": 17,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 19
}
},
"callProperties": [],
"properties": [],
"indexers": [],
"exact": false
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
class Foo implements string {}
@@ -0,0 +1,3 @@
{
"throws": "Cannot overwrite primitive type string (1:21)"
}
@@ -0,0 +1 @@
class Foo implements switch {}
@@ -0,0 +1,118 @@
{
"type": "File",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 30
}
},
"program": {
"type": "Program",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 30
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 30
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "Foo"
},
"name": "Foo"
},
"superClass": null,
"implements": [
{
"type": "ClassImplements",
"start": 21,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 27
}
},
"id": {
"type": "Identifier",
"start": 21,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 27
},
"identifierName": "switch"
},
"name": "switch"
},
"typeParameters": null
}
],
"body": {
"type": "ClassBody",
"start": 28,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 30
}
},
"body": []
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
opaque type string = number;
@@ -0,0 +1,3 @@
{
"throws": "Cannot overwrite primitive type string (1:12)"
}
@@ -0,0 +1 @@
opaque type switch = number;
@@ -0,0 +1,83 @@
{
"type": "File",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"program": {
"type": "Program",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"sourceType": "module",
"body": [
{
"type": "OpaqueType",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"id": {
"type": "Identifier",
"start": 12,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 18
},
"identifierName": "switch"
},
"name": "switch"
},
"typeParameters": null,
"supertype": null,
"impltype": {
"type": "NumberTypeAnnotation",
"start": 21,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 27
}
}
}
}
],
"directives": []
}
}
1 change: 0 additions & 1 deletion scripts/tests/flow/flow_tests_whitelist.txt
Expand Up @@ -57,4 +57,3 @@ types/parameter_defaults/migrated_0031.js
types/parameter_defaults/migrated_0032.js
types/string_literal_invalid/migrated_0000.js
types/typecasts_invalid/migrated_0001.js
types/import_types/typeof_named_reserved_type.js