diff --git a/unsupported/hermes/crates/hermes_estree_codegen/src/ecmascript.json b/unsupported/hermes/crates/hermes_estree_codegen/src/ecmascript.json index cd9a21805b4..753575cce6e 100644 --- a/unsupported/hermes/crates/hermes_estree_codegen/src/ecmascript.json +++ b/unsupported/hermes/crates/hermes_estree_codegen/src/ecmascript.json @@ -1270,6 +1270,122 @@ "type": "Identifier" } } + }, + "ObjectTypeAnnotation": { + "fields": { + "properties": { + "type": "Vec" + }, + "indexers": { + "type": "Vec" + }, + "call_properties": { + "type": "Vec", + "rename": "callProperties" + }, + "internal_slots": { + "type": "Vec", + "rename": "internalSlots" + }, + "inexact": { + "type": "bool" + }, + "exact": { + "type": "bool" + } + } + }, + "ObjectTypeProperty": { + "fields": { + "key": { + "type": "ObjectTypePropertyKey" + }, + "value": { + "type": "FlowTypeAnnotation" + }, + "method": { + "type": "bool" + }, + "optional": { + "type": "bool" + }, + "is_static": { + "type": "bool", + "rename": "static" + }, + "proto": { + "type": "bool" + }, + "variance": { + "type": "Option", + "optional": true, + "hermes_default": true + }, + "kind": { + "type": "PropertyKind" + } + } + }, + "ObjectTypeIndexer": { + "fields": { + "id": { + "type": "Option", + "optional": true + }, + "key": { + "type": "FlowTypeAnnotation" + }, + "value": { + "type": "FlowTypeAnnotation" + }, + "is_static": { + "type": "bool", + "rename": "static" + }, + "variance": { + "type": "Option", + "optional": true, + "hermes_default": true + } + } + }, + "ObjectTypeInternalSlot": { + "fields": { + "id": { + "type": "Identifier" + }, + "value": { + "type": "FlowTypeAnnotation" + }, + "optional": { + "type": "bool" + }, + "is_static": { + "type": "bool", + "rename": "static" + }, + "method": { + "type": "bool" + } + } + }, + "ObjectTypeCallProperty": { + "fields": { + "value": { + "type": "FlowTypeAnnotation" + }, + "is_static": { + "type": "bool", + "rename": "static" + } + } + }, + "ObjectTypeSpreadProperty": { + "fields": { + "argument": { + "type": "FlowTypeAnnotation" + } + } } }, "enums": { @@ -1484,7 +1600,17 @@ "QualifiedTypeIdentifier", "TypeofTypeAnnotation", "KeyofTypeAnnotation", - "QualifiedTypeofIdentifier" + "QualifiedTypeofIdentifier", + "ObjectTypeAnnotation", + "ObjectTypeProperty" + ], + "ObjectTypePropertyType": [ + "ObjectTypeProperty", + "ObjectTypeSpreadProperty" + ], + "ObjectTypePropertyKey": [ + "Identifier", + "_Literal" ], "TypeIdentifier": [ "Identifier", @@ -1572,6 +1698,10 @@ "Method": "method", "Get": "get", "Set": "set" + }, + "Variance": { + "Minus": "minus", + "Plus": "plus" } } } diff --git a/unsupported/hermes/crates/hermes_parser/tests/fixtures/type-definitions.flow.js b/unsupported/hermes/crates/hermes_parser/tests/fixtures/object-type-definitions.flow.js similarity index 56% rename from unsupported/hermes/crates/hermes_parser/tests/fixtures/type-definitions.flow.js rename to unsupported/hermes/crates/hermes_parser/tests/fixtures/object-type-definitions.flow.js index 44ef80f2884..39034c322a5 100644 --- a/unsupported/hermes/crates/hermes_parser/tests/fixtures/type-definitions.flow.js +++ b/unsupported/hermes/crates/hermes_parser/tests/fixtures/object-type-definitions.flow.js @@ -5,10 +5,28 @@ * LICENSE file in the root directory of this source tree. */ -/* TODO // User type User = { // name name: string, }; -*/ + +type Map = { + [string]: Value, +}; + +type Actor = { + lastName: string, + ...User, +} + + +type Data = { + "hello": string, + 123: ?string, +} + + +type IPerson = { + name(): string +} diff --git a/unsupported/hermes/crates/hermes_parser/tests/snapshots/parser_test__fixtures@object-type-definitions.flow.js.snap b/unsupported/hermes/crates/hermes_parser/tests/snapshots/parser_test__fixtures@object-type-definitions.flow.js.snap new file mode 100644 index 00000000000..f1802e30f63 --- /dev/null +++ b/unsupported/hermes/crates/hermes_parser/tests/snapshots/parser_test__fixtures@object-type-definitions.flow.js.snap @@ -0,0 +1,407 @@ +--- +source: crates/hermes_parser/tests/parser_test.rs +expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\\n\\nComments:{comments_json}\")" +input_file: crates/hermes_parser/tests/fixtures/object-type-definitions.flow.js +--- +Input: +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// User +type User = { + // name + name: string, +}; + +type Map = { + [string]: Value, +}; + +type Actor = { + lastName: string, + ...User, +} + + +type Data = { + "hello": string, + 123: ?string, +} + + + +Output: +{ + "type": "Program", + "body": [ + { + "type": "TypeAlias", + "id": { + "type": "Identifier", + "name": "User", + "typeAnnotation": null, + "loc": null, + "range": [ + 205, + 209 + ] + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "properties": [ + { + "type": "ObjectTypeProperty", + "key": { + "type": "Identifier", + "name": "name", + "typeAnnotation": null, + "loc": null, + "range": [ + 230, + 234 + ] + }, + "value": { + "type": "StringTypeAnnotation", + "loc": null, + "range": [ + 236, + 242 + ] + }, + "method": false, + "optional": false, + "static": false, + "proto": false, + "variance": null, + "kind": "init", + "loc": null, + "range": [ + 230, + 242 + ] + } + ], + "indexers": [], + "callProperties": [], + "internalSlots": [], + "inexact": false, + "exact": false, + "loc": null, + "range": [ + 212, + 245 + ] + }, + "loc": null, + "range": [ + 200, + 246 + ] + }, + { + "type": "TypeAlias", + "id": { + "type": "Identifier", + "name": "Map", + "typeAnnotation": null, + "loc": null, + "range": [ + 253, + 256 + ] + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "properties": [], + "indexers": [ + { + "type": "ObjectTypeIndexer", + "id": null, + "key": { + "type": "StringTypeAnnotation", + "loc": null, + "range": [ + 266, + 272 + ] + }, + "value": { + "type": "GenericTypeAnnotation", + "id": { + "type": "Identifier", + "name": "Value", + "typeAnnotation": null, + "loc": null, + "range": [ + 275, + 280 + ] + }, + "typeParameters": null, + "loc": null, + "range": [ + 275, + 280 + ] + }, + "static": false, + "variance": null, + "loc": null, + "range": [ + 265, + 280 + ] + } + ], + "callProperties": [], + "internalSlots": [], + "inexact": false, + "exact": false, + "loc": null, + "range": [ + 259, + 283 + ] + }, + "loc": null, + "range": [ + 248, + 284 + ] + }, + { + "type": "TypeAlias", + "id": { + "type": "Identifier", + "name": "Actor", + "typeAnnotation": null, + "loc": null, + "range": [ + 291, + 296 + ] + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "properties": [ + { + "type": "ObjectTypeProperty", + "key": { + "type": "Identifier", + "name": "lastName", + "typeAnnotation": null, + "loc": null, + "range": [ + 305, + 313 + ] + }, + "value": { + "type": "StringTypeAnnotation", + "loc": null, + "range": [ + 315, + 321 + ] + }, + "method": false, + "optional": false, + "static": false, + "proto": false, + "variance": null, + "kind": "init", + "loc": null, + "range": [ + 305, + 321 + ] + }, + { + "type": "ObjectTypeSpreadProperty", + "argument": { + "type": "GenericTypeAnnotation", + "id": { + "type": "Identifier", + "name": "User", + "typeAnnotation": null, + "loc": null, + "range": [ + 330, + 334 + ] + }, + "typeParameters": null, + "loc": null, + "range": [ + 330, + 334 + ] + }, + "loc": null, + "range": [ + 327, + 334 + ] + } + ], + "indexers": [], + "callProperties": [], + "internalSlots": [], + "inexact": false, + "exact": false, + "loc": null, + "range": [ + 299, + 337 + ] + }, + "loc": null, + "range": [ + 286, + 337 + ] + }, + { + "type": "TypeAlias", + "id": { + "type": "Identifier", + "name": "Data", + "typeAnnotation": null, + "loc": null, + "range": [ + 345, + 349 + ] + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "properties": [ + { + "type": "ObjectTypeProperty", + "key": { + "type": "StringLiteral", + "value": "hello", + "loc": null, + "range": [ + 358, + 365 + ] + }, + "value": { + "type": "StringTypeAnnotation", + "loc": null, + "range": [ + 367, + 373 + ] + }, + "method": false, + "optional": false, + "static": false, + "proto": false, + "variance": null, + "kind": "init", + "loc": null, + "range": [ + 358, + 373 + ] + }, + { + "type": "ObjectTypeProperty", + "key": { + "type": "NumericLiteral", + "value": 123.0, + "loc": null, + "range": [ + 379, + 382 + ] + }, + "value": { + "type": "NullableTypeAnnotation", + "typeAnnotation": { + "type": "StringTypeAnnotation", + "loc": null, + "range": [ + 385, + 391 + ] + }, + "loc": null, + "range": [ + 384, + 391 + ] + }, + "method": false, + "optional": false, + "static": false, + "proto": false, + "variance": null, + "kind": "init", + "loc": null, + "range": [ + 379, + 391 + ] + } + ], + "indexers": [], + "callProperties": [], + "internalSlots": [], + "inexact": false, + "exact": false, + "loc": null, + "range": [ + 352, + 394 + ] + }, + "loc": null, + "range": [ + 340, + 394 + ] + } + ], + "sourceType": "script", + "loc": null, + "range": [ + 200, + 394 + ] +} + +Comments:[ + { + "value": "*\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n ", + "range": [ + 0, + 190 + ] + }, + { + "value": " User", + "range": [ + 192, + 199 + ] + }, + { + "value": " name", + "range": [ + 218, + 225 + ] + } +] diff --git a/unsupported/hermes/crates/hermes_parser/tests/snapshots/parser_test__fixtures@type-definitions.flow.js.snap b/unsupported/hermes/crates/hermes_parser/tests/snapshots/parser_test__fixtures@type-definitions.flow.js.snap deleted file mode 100644 index dd1b8015307..00000000000 --- a/unsupported/hermes/crates/hermes_parser/tests/snapshots/parser_test__fixtures@type-definitions.flow.js.snap +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/hermes_parser/tests/parser_test.rs -expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\\n\\nComments:{comments_json}\")" -input_file: crates/hermes_parser/tests/fixtures/type-definitions.flow.js ---- -Input: -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/* TODO -// User -type User = { - // name - name: string, -}; -*/ - - -Output: -{ - "type": "Program", - "body": [], - "sourceType": "script", - "loc": null, - "range": [ - 258, - 258 - ] -} - -Comments:[ - { - "value": "*\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n ", - "range": [ - 0, - 190 - ] - }, - { - "value": " TODO\n// User\ntype User = {\n // name\n name: string,\n};\n", - "range": [ - 192, - 257 - ] - } -]