From e7e7593ca5be845ff7c541a2df7a1c3438f54db1 Mon Sep 17 00:00:00 2001 From: jbrown215 Date: Fri, 21 Jul 2017 10:48:28 -0400 Subject: [PATCH] Flow opaque type aliases parsing (#643) * Add support for Flow opaque type aliases * Add tests for Flow opaque type aliases --- src/plugins/flow.js | 58 +++- src/types.js | 2 + .../declare_opaque/actual.js | 1 + .../declare_opaque/options.json | 3 + .../opaque_collision/actual.js | 2 + .../opaque_collision/expected.json | 150 +++++++++++ .../opaque_declare_export_neither/actual.js | 1 + .../expected.json | 85 ++++++ .../opaque_declare_export_st_no_t/actual.js | 1 + .../expected.json | 117 ++++++++ .../opaque_declare_export_t_and_st/actual.js | 1 + .../options.json | 3 + .../opaque_declare_export_t_no_st/actual.js | 1 + .../options.json | 3 + .../opaque_declare_neither/actual.js | 1 + .../opaque_declare_neither/expected.json | 69 +++++ .../opaque_declare_st_no_t/actual.js | 1 + .../opaque_declare_st_no_t/expected.json | 101 +++++++ .../opaque_declare_t_and_st/actual.js | 1 + .../opaque_declare_t_and_st/options.json | 3 + .../opaque_declare_t_no_st/actual.js | 1 + .../opaque_declare_t_no_st/options.json | 3 + .../opaque-type-alias/opaque_in_exp/actual.js | 2 + .../opaque_in_exp/expected.json | 172 ++++++++++++ .../opaque_in_func/actual.js | 1 + .../opaque_in_func/expected.json | 103 ++++++++ .../opaque_invalid1/actual.js | 1 + .../opaque_invalid1/options.json | 3 + .../opaque_invalid2/actual.js | 1 + .../opaque_invalid2/options.json | 3 + .../opaque_invalid_decl1/actual.js | 1 + .../opaque_invalid_decl1/options.json | 3 + .../opaque_invalid_decl2/actual.js | 1 + .../opaque_invalid_decl2/options.json | 3 + .../opaque_invalid_decl3/actual.js | 1 + .../opaque_invalid_decl3/options.json | 3 + .../opaque_subtype/actual.js | 1 + .../opaque_subtype/expected.json | 231 ++++++++++++++++ .../opaque_subtype_allow_export/actual.js | 3 + .../opaque_subtype_allow_export/options.json | 3 + .../opaque_subtype_export/actual.js | 1 + .../opaque_subtype_export/expected.json | 249 ++++++++++++++++++ .../opaque_subtype_invalid1/actual.js | 1 + .../opaque_subtype_invalid1/options.json | 3 + .../opaque_subtype_invalid2/actual.js | 1 + .../opaque_subtype_invalid2/options.json | 3 + .../opaque_subtype_invalid3/actual.js | 1 + .../opaque_subtype_invalid3/options.json | 3 + .../opaque-type-alias/opaque_type/actual.js | 1 + .../opaque_type/expected.json | 83 ++++++ .../opaque_type_allow_export/actual.js | 3 + .../opaque_type_allow_export/options.json | 3 + .../opaque_type_export/actual.js | 1 + .../opaque_type_export/expected.json | 101 +++++++ 54 files changed, 1595 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/flow/opaque-type-alias/declare_opaque/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/declare_opaque/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_collision/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_collision/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_neither/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_neither/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_in_exp/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_in_exp/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_in_func/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_in_func/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid1/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid1/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid2/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid2/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_export/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_export/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_type/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_type/expected.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/options.json create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_type_export/actual.js create mode 100644 test/fixtures/flow/opaque-type-alias/opaque_type_export/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 4aef3fc723..0ae0587eef 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -165,6 +165,8 @@ export default (superClass: Class): Class => } } else if (this.isContextual("type")) { return this.flowParseDeclareTypeAlias(node); + } else if (this.isContextual("opaque")) { + return this.flowParseDeclareOpaqueType(node); } else if (this.isContextual("interface")) { return this.flowParseDeclareInterface(node); } else if (this.match(tt._export)) { @@ -285,7 +287,8 @@ export default (superClass: Class): Class => if ( this.match(tt._var) || // declare export var ... this.match(tt._function) || // declare export function ... - this.match(tt._class) // declare export class ... + this.match(tt._class) || // declare export class ... + this.isContextual("opaque") // declare export opaque .. ) { node.declaration = this.flowParseDeclare(this.startNode()); node.default = false; @@ -295,7 +298,8 @@ export default (superClass: Class): Class => this.match(tt.star) || // declare export * from '' this.match(tt.braceL) || // declare export {} ... this.isContextual("interface") || // declare export interface ... - this.isContextual("type") // declare export type ... + this.isContextual("type") || // declare export type ... + this.isContextual("opaque") // declare export opaque type ... ) { node = this.parseExport(node); if (node.type === "ExportNamedDeclaration") { @@ -337,6 +341,14 @@ export default (superClass: Class): Class => return this.finishNode(node, "DeclareTypeAlias"); } + flowParseDeclareOpaqueType( + node: N.FlowDeclareOpaqueType, + ): N.FlowDeclareOpaqueType { + this.next(); + this.flowParseOpaqueType(node, true); + return this.finishNode(node, "DeclareOpaqueType"); + } + flowParseDeclareInterface( node: N.FlowDeclareInterface, ): N.FlowDeclareInterface { @@ -421,6 +433,34 @@ export default (superClass: Class): Class => return this.finishNode(node, "TypeAlias"); } + flowParseOpaqueType( + node: N.FlowOpaqueType, + declare: boolean, + ): N.FlowOpaqueType { + this.expectContextual("type"); + node.id = this.flowParseRestrictedIdentifier(); + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + node.typeParameters = null; + } + + // Parse the supertype + node.supertype = null; + if (this.match(tt.colon)) { + node.supertype = this.flowParseTypeInitialiser(tt.colon); + } + + node.impltype = null; + if (!declare) { + node.impltype = this.flowParseTypeInitialiser(tt.eq); + } + this.semicolon(); + + return this.finishNode(node, "OpaqueType"); + } + // Type annotations flowParseTypeParameter(): N.TypeParameter { @@ -1205,6 +1245,8 @@ export default (superClass: Class): Class => return this.flowParseInterface(node); } else if (expr.name === "type") { return this.flowParseTypeAlias(node); + } else if (expr.name === "opaque") { + return this.flowParseOpaqueType(node, false); } } } @@ -1217,6 +1259,7 @@ export default (superClass: Class): Class => return ( this.isContextual("type") || this.isContextual("interface") || + this.isContextual("opaque") || super.shouldParseExportDeclaration() ); } @@ -1224,7 +1267,9 @@ export default (superClass: Class): Class => isExportDefaultSpecifier(): boolean { if ( this.match(tt.name) && - (this.state.value === "type" || this.state.value === "interface") + (this.state.value === "type" || + this.state.value === "interface" || + this.state.value == "opaque") ) { return false; } @@ -1308,6 +1353,13 @@ export default (superClass: Class): Class => // export type Foo = Bar; return this.flowParseTypeAlias(declarationNode); } + } else if (this.isContextual("opaque")) { + node.exportKind = "type"; + + const declarationNode = this.startNode(); + this.next(); + // export opaque type Foo = Bar; + return this.flowParseOpaqueType(declarationNode, false); } else if (this.isContextual("interface")) { node.exportKind = "type"; const declarationNode = this.startNode(); diff --git a/src/types.js b/src/types.js index 8a30a73f22..51ff177ea5 100644 --- a/src/types.js +++ b/src/types.js @@ -831,10 +831,12 @@ export type FlowDeclareVariable = Node; export type FlowDeclareModule = Node; export type FlowDeclareModuleExports = Node; export type FlowDeclareTypeAlias = Node; +export type FlowDeclareOpaqueType = Node; export type FlowDeclareInterface = Node; export type FlowInterface = Node; export type FlowInterfaceExtends = Node; export type FlowTypeAlias = Node; +export type FlowOpaqueType = Node; export type FlowObjectTypeIndexer = Node; export type FlowFunctionTypeAnnotation = Node; export type FlowObjectTypeProperty = Node; diff --git a/test/fixtures/flow/opaque-type-alias/declare_opaque/actual.js b/test/fixtures/flow/opaque-type-alias/declare_opaque/actual.js new file mode 100644 index 0000000000..6ab3cb673c --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/declare_opaque/actual.js @@ -0,0 +1 @@ +declare opaque type ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/declare_opaque/options.json b/test/fixtures/flow/opaque-type-alias/declare_opaque/options.json new file mode 100644 index 0000000000..bdd84a6c76 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/declare_opaque/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:23)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_collision/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_collision/actual.js new file mode 100644 index 0000000000..ed40fbab10 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_collision/actual.js @@ -0,0 +1,2 @@ +opaque type opaque = number; +opaque type not_transparent = opaque; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_collision/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_collision/expected.json new file mode 100644 index 0000000000..20ae32763c --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_collision/expected.json @@ -0,0 +1,150 @@ +{ + "type": "File", + "start": 0, + "end": 66, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 66, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "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": "opaque" + }, + "name": "opaque" + }, + "typeParameters": null, + "supertype": null, + "impltype": { + "type": "NumberTypeAnnotation", + "start": 21, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + }, + { + "type": "OpaqueType", + "start": 29, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 27 + }, + "identifierName": "not_transparent" + }, + "name": "not_transparent" + }, + "typeParameters": null, + "supertype": null, + "impltype": { + "type": "GenericTypeAnnotation", + "start": 59, + "end": 65, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 59, + "end": 65, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 36 + }, + "identifierName": "opaque" + }, + "name": "opaque" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/actual.js new file mode 100644 index 0000000000..fedf0e58b0 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/actual.js @@ -0,0 +1 @@ +declare export opaque type Foo diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/expected.json new file mode 100644 index 0000000000..831a2db783 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_neither/expected.json @@ -0,0 +1,85 @@ +{ + "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": "DeclareExportDeclaration", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "declaration": { + "type": "DeclareOpaqueType", + "start": 15, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeParameters": null, + "supertype": null, + "impltype": null + }, + "default": false + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/actual.js new file mode 100644 index 0000000000..3d20f9ea18 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/actual.js @@ -0,0 +1 @@ +declare export opaque type Foo: Bar diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/expected.json new file mode 100644 index 0000000000..edaa801532 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_st_no_t/expected.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "declaration": { + "type": "DeclareOpaqueType", + "start": 15, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeParameters": null, + "supertype": { + "type": "GenericTypeAnnotation", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 35 + }, + "identifierName": "Bar" + }, + "name": "Bar" + } + }, + "impltype": null + }, + "default": false + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/actual.js new file mode 100644 index 0000000000..ec2fa4be77 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/actual.js @@ -0,0 +1 @@ +declare export opaque type Foo: Bar = Baz diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/options.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/options.json new file mode 100644 index 0000000000..52a8725a65 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_and_st/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:36)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/actual.js new file mode 100644 index 0000000000..3bd35eb0f8 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/actual.js @@ -0,0 +1 @@ +declare export opaque type Foo = Bar diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/options.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/options.json new file mode 100644 index 0000000000..b883a989ae --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_export_t_no_st/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:31)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_neither/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_neither/actual.js new file mode 100644 index 0000000000..6fd5fb284a --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_neither/actual.js @@ -0,0 +1 @@ +declare opaque type Foo diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_neither/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_neither/expected.json new file mode 100644 index 0000000000..3e3cc5a2de --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_neither/expected.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareOpaqueType", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeParameters": null, + "supertype": null, + "impltype": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/actual.js new file mode 100644 index 0000000000..8e71e6c842 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/actual.js @@ -0,0 +1 @@ +declare opaque type Test: Foo diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/expected.json new file mode 100644 index 0000000000..1281d4dae1 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_st_no_t/expected.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareOpaqueType", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "Test" + }, + "name": "Test" + }, + "typeParameters": null, + "supertype": { + "type": "GenericTypeAnnotation", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + }, + "impltype": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/actual.js new file mode 100644 index 0000000000..de48c5412c --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/actual.js @@ -0,0 +1 @@ +declare opaque type Foo: Bar = Baz diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/options.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/options.json new file mode 100644 index 0000000000..7dcae78ae3 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_and_st/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:29)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/actual.js new file mode 100644 index 0000000000..084079d6bc --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/actual.js @@ -0,0 +1 @@ +declare opaque type Foo = Bar diff --git a/test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/options.json b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/options.json new file mode 100644 index 0000000000..bfe4fdd7c7 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_declare_t_no_st/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:24)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_in_exp/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_in_exp/actual.js new file mode 100644 index 0000000000..8bd643ca26 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_in_exp/actual.js @@ -0,0 +1,2 @@ +var opaque = 0; +opaque += 4; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_in_exp/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_in_exp/expected.json new file mode 100644 index 0000000000..ad128a80b2 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_in_exp/expected.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "opaque" + }, + "name": "opaque" + }, + "init": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "kind": "var" + }, + { + "type": "ExpressionStatement", + "start": 16, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 16, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "operator": "+=", + "left": { + "type": "Identifier", + "start": 16, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "opaque" + }, + "name": "opaque" + }, + "right": { + "type": "NumericLiteral", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_in_func/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_in_func/actual.js new file mode 100644 index 0000000000..621f571453 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_in_func/actual.js @@ -0,0 +1 @@ +opaque(0); diff --git a/test/fixtures/flow/opaque-type-alias/opaque_in_func/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_in_func/expected.json new file mode 100644 index 0000000000..39ea67093c --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_in_func/expected.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "opaque" + }, + "name": "opaque" + }, + "arguments": [ + { + "type": "NumericLiteral", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid1/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_invalid1/actual.js new file mode 100644 index 0000000000..0b09a8313b --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid1/actual.js @@ -0,0 +1 @@ +export opaque potato ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid1/options.json b/test/fixtures/flow/opaque-type-alias/opaque_invalid1/options.json new file mode 100644 index 0000000000..d50e8469b8 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:14)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid2/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_invalid2/actual.js new file mode 100644 index 0000000000..f8654a12a7 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid2/actual.js @@ -0,0 +1 @@ +opaque potato ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid2/options.json b/test/fixtures/flow/opaque-type-alias/opaque_invalid2/options.json new file mode 100644 index 0000000000..c958665c03 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:7)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/actual.js new file mode 100644 index 0000000000..243a903b53 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/actual.js @@ -0,0 +1 @@ +declare export opaque = potato; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/options.json b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/options.json new file mode 100644 index 0000000000..a015cd4108 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:22)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/actual.js new file mode 100644 index 0000000000..ca19159f39 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/actual.js @@ -0,0 +1 @@ +declare export opaque type ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/options.json b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/options.json new file mode 100644 index 0000000000..62e1e03ac5 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:30)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/actual.js new file mode 100644 index 0000000000..96689b6c19 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/actual.js @@ -0,0 +1 @@ +declare export opaque potato ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/options.json b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/options.json new file mode 100644 index 0000000000..a015cd4108 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_invalid_decl3/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:22)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_subtype/actual.js new file mode 100644 index 0000000000..1d3425d37d --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype/actual.js @@ -0,0 +1 @@ +opaque type Counter: Box = Container; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_subtype/expected.json new file mode 100644 index 0000000000..2231c556b2 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype/expected.json @@ -0,0 +1,231 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "module", + "body": [ + { + "type": "OpaqueType", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "id": { + "type": "Identifier", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "Counter" + }, + "name": "Counter" + }, + "typeParameters": null, + "supertype": { + "type": "GenericTypeAnnotation", + "start": 21, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "Box" + }, + "name": "Box" + } + }, + "impltype": { + "type": "GenericTypeAnnotation", + "start": 30, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 41 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 39 + }, + "identifierName": "Container" + }, + "name": "Container" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/actual.js new file mode 100644 index 0000000000..270b9f19fe --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/actual.js @@ -0,0 +1,3 @@ +declare module 'foo' { + declare export opaque type MyType: number = string; +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/options.json b/test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/options.json new file mode 100644 index 0000000000..a36cfb32c5 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_allow_export/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (2:44)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_export/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_subtype_export/actual.js new file mode 100644 index 0000000000..517a12522d --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_export/actual.js @@ -0,0 +1 @@ +export opaque type Counter: Box = Container; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_export/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_subtype_export/expected.json new file mode 100644 index 0000000000..98bf344fe9 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_export/expected.json @@ -0,0 +1,249 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "specifiers": [], + "source": null, + "exportKind": "type", + "declaration": { + "type": "OpaqueType", + "start": 7, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "id": { + "type": "Identifier", + "start": 19, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "Counter" + }, + "name": "Counter" + }, + "typeParameters": null, + "supertype": { + "type": "GenericTypeAnnotation", + "start": 28, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "Box" + }, + "name": "Box" + } + }, + "impltype": { + "type": "GenericTypeAnnotation", + "start": 37, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 49 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 46, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 49 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 48 + }, + "identifierName": "S" + }, + "name": "S" + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 37, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 46 + }, + "identifierName": "Container" + }, + "name": "Container" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/actual.js new file mode 100644 index 0000000000..16c8fa3c60 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/actual.js @@ -0,0 +1 @@ +opaque Ident: Type = SuperType; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/options.json b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/options.json new file mode 100644 index 0000000000..c958665c03 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:7)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/actual.js new file mode 100644 index 0000000000..ef767b18c8 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/actual.js @@ -0,0 +1 @@ +export opaque potato: ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/options.json b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/options.json new file mode 100644 index 0000000000..d50e8469b8 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:14)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/actual.js new file mode 100644 index 0000000000..04beb59377 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/actual.js @@ -0,0 +1 @@ +opaque stuff: Box = Container diff --git a/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/options.json b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/options.json new file mode 100644 index 0000000000..c958665c03 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_subtype_invalid3/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:7)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_type/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_type/actual.js new file mode 100644 index 0000000000..bbc9133f0c --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_type/actual.js @@ -0,0 +1 @@ +opaque type ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_type/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_type/expected.json new file mode 100644 index 0000000000..deab9e4291 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_type/expected.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "module", + "body": [ + { + "type": "OpaqueType", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "typeParameters": null, + "supertype": null, + "impltype": { + "type": "NumberTypeAnnotation", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/actual.js new file mode 100644 index 0000000000..2fb871dbf1 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/actual.js @@ -0,0 +1,3 @@ +declare module 'foo' { + declare export opaque type MyType = string; +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/options.json b/test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/options.json new file mode 100644 index 0000000000..6612fb253c --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_type_allow_export/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (2:36)" +} diff --git a/test/fixtures/flow/opaque-type-alias/opaque_type_export/actual.js b/test/fixtures/flow/opaque-type-alias/opaque_type_export/actual.js new file mode 100644 index 0000000000..d431d5cfd2 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_type_export/actual.js @@ -0,0 +1 @@ +export opaque type ID = number; diff --git a/test/fixtures/flow/opaque-type-alias/opaque_type_export/expected.json b/test/fixtures/flow/opaque-type-alias/opaque_type_export/expected.json new file mode 100644 index 0000000000..e2c4f90fe1 --- /dev/null +++ b/test/fixtures/flow/opaque-type-alias/opaque_type_export/expected.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "specifiers": [], + "source": null, + "exportKind": "type", + "declaration": { + "type": "OpaqueType", + "start": 7, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "id": { + "type": "Identifier", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "typeParameters": null, + "supertype": null, + "impltype": { + "type": "NumberTypeAnnotation", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 30 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file