Fix some reserved type handling and declare class with multiple extends (#6725)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -392,8 +392,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();
|
||||
@@ -407,7 +407,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")) {
|
||||
@@ -471,7 +471,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();
|
||||
@@ -1780,7 +1780,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 {
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
1
packages/babylon/test/fixtures/flow/interfaces-module-and-script/id-reserved-value/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/interfaces-module-and-script/id-reserved-value/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
interface switch {}
|
||||
88
packages/babylon/test/fixtures/flow/interfaces-module-and-script/id-reserved-value/expected.json
vendored
Normal file
88
packages/babylon/test/fixtures/flow/interfaces-module-and-script/id-reserved-value/expected.json
vendored
Normal file
@@ -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": []
|
||||
}
|
||||
}
|
||||
1
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
opaque type string = number;
|
||||
3
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/options.json
vendored
Normal file
3
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Cannot overwrite primitive type string (1:12)"
|
||||
}
|
||||
1
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-value/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-value/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
opaque type switch = number;
|
||||
83
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-value/expected.json
vendored
Normal file
83
packages/babylon/test/fixtures/flow/opaque-type-alias/reserved-value/expected.json
vendored
Normal file
@@ -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": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user