Skip to content

Commit

Permalink
Add support for flow object types
Browse files Browse the repository at this point in the history
Summary:
Used P1185952533 and https://babeljs.io/docs/babel-types as reference for input shapes

We probably don't need to use this for parsing RelayResolver weak types. But it is necessary for parsing production files

Reviewed By: evanyeung

Differential Revision: D55348839

fbshipit-source-id: 0f90539a6ba588345316dc2d8b2004832176bd80
  • Loading branch information
tyao1 authored and facebook-github-bot committed Apr 1, 2024
1 parent acb4596 commit 9e94f5a
Show file tree
Hide file tree
Showing 4 changed files with 558 additions and 53 deletions.
132 changes: 131 additions & 1 deletion unsupported/hermes/crates/hermes_estree_codegen/src/ecmascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,122 @@
"type": "Identifier"
}
}
},
"ObjectTypeAnnotation": {
"fields": {
"properties": {
"type": "Vec<ObjectTypePropertyType>"
},
"indexers": {
"type": "Vec<ObjectTypeIndexer>"
},
"call_properties": {
"type": "Vec<ObjectTypeCallProperty>",
"rename": "callProperties"
},
"internal_slots": {
"type": "Vec<ObjectTypeInternalSlot>",
"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<Variance>",
"optional": true,
"hermes_default": true
},
"kind": {
"type": "PropertyKind"
}
}
},
"ObjectTypeIndexer": {
"fields": {
"id": {
"type": "Option<Identifier>",
"optional": true
},
"key": {
"type": "FlowTypeAnnotation"
},
"value": {
"type": "FlowTypeAnnotation"
},
"is_static": {
"type": "bool",
"rename": "static"
},
"variance": {
"type": "Option<Variance>",
"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": {
Expand Down Expand Up @@ -1484,7 +1600,17 @@
"QualifiedTypeIdentifier",
"TypeofTypeAnnotation",
"KeyofTypeAnnotation",
"QualifiedTypeofIdentifier"
"QualifiedTypeofIdentifier",
"ObjectTypeAnnotation",
"ObjectTypeProperty"
],
"ObjectTypePropertyType": [
"ObjectTypeProperty",
"ObjectTypeSpreadProperty"
],
"ObjectTypePropertyKey": [
"Identifier",
"_Literal"
],
"TypeIdentifier": [
"Identifier",
Expand Down Expand Up @@ -1572,6 +1698,10 @@
"Method": "method",
"Get": "get",
"Set": "set"
},
"Variance": {
"Minus": "minus",
"Plus": "plus"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit 9e94f5a

Please sign in to comment.