Commit Graph

330 Commits

Author SHA1 Message Date
Ramanpreet Nara 00cfb0f919 Remove pipes from Object literal Flow types
Summary:
## Changes
{| ... |} -> { ... }

**Motivation:** In Flow, object literals are exact by default. So, there's no need for the pipes. Also: Now, the syntax for object literals is consistent across react-native-codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24774771

fbshipit-source-id: 24ceb6f5876122aa8ad9e08c7e903215864ad6f5
2020-11-06 16:24:44 -08:00
Ramanpreet Nara 1ee406b9cc Pull out ReservedPropTypeAnnotation into type alias
Summary:
This type annotation was declared inline twice. Just pulling it out into a type alias in this diff.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24723191

fbshipit-source-id: 9f2061087172979ea838dfdf2533e17b9b559c71
2020-11-05 18:30:09 -08:00
Ramanpreet Nara 0de4b514be Simplify Int32EnumTypeAnnotation and StringEnumTypeAnnotation
Summary:
Int32EnumTypeAnnotation represents a union of numbers. In the corresponding type annotation, we represent options as `$ReadOnlyArray<{value: number}>`. Since each option is a number, we could instead represent options as `$ReadOnlyArray<number>` - there's no need to use an object with a singular property (i.e: 'value'). The same is could be said of StringEnumTypeAnnotation.

In this diff, we change `Int32EnumTypeAnnotation.options` to `$ReadOnlyArray<number>`, and `StringEnumTypeAnnotation.options` to `$ReadOnlyArray<string>`.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24723107

fbshipit-source-id: 4734cf72a4a29b6b321d8161bea70cf524ce0963
2020-11-05 18:30:09 -08:00
Ramanpreet Nara a31d7aa2d3 Standardize on one FunctionTypeAnnotation shape
Summary:
Commands are `FunctionTypeAnnotation`, but they don't have a return type. I this diff, I introduced a `FunctionTypeAnnotation<+P, +R>` utility type, and made the `CommandTypeAnnotation` be an instantiation of it, with the return type fixed to `VoidTypeAnnotation`.

Now, the shape of a FunctionTypeAnnotation is unified across the NativeModule and Component schemas.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719965

fbshipit-source-id: 0089c3b23f05b0c534ba28dbe336c7f2db5866b3
2020-11-05 18:30:09 -08:00
Ramanpreet Nara 0d748cf8bb Rename NativeModulePropertySchema -> NativeModulePropertyShape
Summary:
Everywhere else in the CodegenSchema, type annotation partials are suffixed with "Shape". In the NativeModule schema, we were using the suffix "Schema". In this diff, we standardize on the "Shape" suffix.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719395

fbshipit-source-id: 307935f5fe0681c31cd52e9cf4ae579f61c1ae68
2020-11-05 18:30:08 -08:00
Ramanpreet Nara c6b8c75b6b Remove miscellaneous exports of NativeModule Flow types in Codegen Schema
Summary:
CodegenSchema exports `NativeModuleMethodParamSchema` and `NativeModuleObjectTypeAnnotationPropertySchema`, which are partials of NativeModule type annotations. This creates unnecessary coupling between the type annotations of CodegenSchema and the files that depend on it.

**Actual Problem:** Suppose that we want to rename one of these partials. Then, all imports in all files would have to be updated, even when the actual shape of the composed type annotation wasn't changed.

This diff removes these partials, which reduces the surface area of the exports of CodegenSchema.js

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719396

fbshipit-source-id: c822aaa252f156c524f4ef4917ebb61b1a39ff9e
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 04f235e7fb Rename Commands* -> Command*
Summary:
The names of events and props flow type annotations are singular. The names of the commands flow types are however plural. This diff renames all "Commands*" flow types to be singular.

**Motivation:** Consistency

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24708276

fbshipit-source-id: 5d5d2123426ca1139953169d0ea764b82b2f3809
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 688caa0bdc Introduce ObjectTypeAnnotation utility type
Summary:
All throughout the Codegen schema, we re-declare the following shape:
```
{
  type: 'ObjectTypeAnnotation',
  properties: $ReadOnlyArray<{
    name: string,
    optional: boolean,
    typeAnnotation: ...
  }>
}
```

This diff introduces an `ObjectTypeAnnotation<T>` utility type and replaces those re-declarations with instantiations of this type.

**Motivation:** To reduce noise in the CodegenSchema. This should be a pure refactor, and shouldn't actually change any behaviour.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24707963

fbshipit-source-id: 6b4eb711ddd041f3a041109ade5ad5644fb16924
2020-11-05 18:30:08 -08:00
Ramanpreet Nara b9f6937288 Reorganize CodegenSchema types into "use before declaration" order
Summary:
This diff re-organizes CodegenSchema to declare the larger types first, which use smaller undeclared types. The smaller types are declared further down the file, and they themselves use even smaller undeclared types.

**Motivation:** Increase the readability of CodegenSchema.js. Now, if people want to understand the shape of the Codegen Schema, they can just read the file from top to bottom.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24701424

fbshipit-source-id: 181e87bff5e32d998463221891f459b0df26ef52
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 1231db0d7f Rename ReservedFunctionValueTypeAnnotation to ReservedTypeAnnotation
Summary:
Reserved type annotations can appear in three different contexts: commands, props, and NativeModules. For now, commands and NativeModules share the same reserved type annotations. In the future, we may want to merge these reserved type annotations with the props reserved type annotations.

**Motivation:** The meaning of FunctionValue in FunctionValueTypeAnnotation isn't clear - in fact, it's downright confusing. Therefore, this diff renames this Flow type to ReservedTypeAnnotation, which I believe sufficiently captures the intent of the type annotation.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24701322

fbshipit-source-id: bde0273b4a89c9e7175c60ed3468ed870b320044
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 856bc2978c Introduce NamedShape utility type
Summary:
Our CodegenSchema is littered with types that have the following shape
```
{
  name: string,
  optional: boolean,
  typeAnnotation: ...
}
```

In all these types, the only difference is the typeAnnotation. This diff introduces a new utility type called `NamedShape`, that just creates this shape, given a type annotation. This should help reduce the amount of noise in the CodegenSchema, and make it a bit easier to read.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24701331

fbshipit-source-id: a30d3e22933116e3dabf7929615905febacecba3
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 0e46080847 Clean up EventObjectPropertyType
Summary:
All ObjectTypeAnnotation *properties* in the codegen have the following shape:
```
{
  name: string,
  optional: boolean,
  typeAnnotation: ...
}
```

EventObjectTypeProperty is a property of some ObjectTypeAnnotation, yet it doesn't follow this pattern. This diff cleans up EventObjectPropertyType. This is a part of a larger effort to clean up the Component Schema and unify the notion of a "type annotation" across the Component and Module schemas.

Reviewed By: yungsters

Differential Revision: D24701027

fbshipit-source-id: edc7dc632a217fb5a82ffd8a62aef990baf398c2
2020-11-05 18:30:07 -08:00
Kevin Gozali a1d374e504 Codegen Android: optional NativeModule method should not be marked abstract
Summary:
This fixed a bug in the JS Java spec generator. Optional methods were still marked `abstract` before this fix. Instead it should be a normal method with potentially falsy return value.

The JavaPoet version does this correctly already, but there was a minor typo with void return type vs optional.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24524432

fbshipit-source-id: 57a248580a78bc255f34d0492ebe3a4691e66667
2020-10-26 22:02:05 -07:00
Ramanpreet Nara f1f9cef9d3 Disallow object spreads in ObjectTypeAnnotations
Summary:
We don't currently support object spreads in `ObjectTypeAnnotation`s. This diff adds an explicit error for the case in the parser, so that when people use object spreads in ObjectTypeAnnotations, they get feedback from the linter rule and parser.

Previously, the Linter would crash, and the parser would fail, but the error wouldn't be immediately obvious.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24543650

fbshipit-source-id: 76f389c72f858ee6281c5aff5ce797f3be685096
2020-10-26 16:23:03 -07:00
Kevin Gozali 2a634f452c Codegen BUCK: moved generate-test.sh to be general-purpose generate-all CLI
Summary:
This moves the test script that generates **all outputs using all generators** to a dedicated "generate-all" CLI. This allows us to use it via Buck, at FB and OSS.
Also renamed the target to be more specific: "rn_codegen" => "generate_all_from_schema"

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24513995

fbshipit-source-id: 8435d3d065718eb1309c1c61fe28fb592787311a
2020-10-24 14:02:47 -07:00
Kevin Gozali 82c95fadc1 Codegen (FB): define internal BUCK targets for Android + JNI
Summary:
`rn_codegen_modules()` now defines 2 additional Android targets:
* the rn_android_library()
* the C++ library for JNI files

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24411783

fbshipit-source-id: 5ee4550dc313041f87e133397f266279b3eec6ee
2020-10-20 14:11:45 -07:00
Kevin Gozali 13d9927a48 Codegen: separate Android/Cxx/iOS modules codegen outputs
Summary:
For now, separate the definition of `modules` generator per platform to avoid file output collision. Additionally:
* For Android, produce files under java/ (plus nested subdirs based on packageName) and jni/ (for C++ files) - JavaPoet version already does it
* Allow configuring packageName for Android - JavaPoet version has this
* Avoid tmp directory dance in the CLI script, given the proper modules separation

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24410864

fbshipit-source-id: 9bd6bc1d65bec037bfca32ec478f3af50d72e927
2020-10-20 14:11:45 -07:00
Ramanpreet Nara 9c1f0c697d Make NativeModule spec parser collect all parsing errors
Summary:
## Rationale
Previously, the NativeModule spec parser would throw an error the first time it encountered an invalid Flow type. While this is ideal from a parsing standpoint, from a linting standpoint, however, we may want to display all errors that make the NativeModule spec invalid.

## Changes
This diff extends the NativeModule spec parser to collect all parsing errors in an array. In the codegen, if after building the schema, any parsing errors were detected, we throw the first one. In the ESLint rule, if after building the schema, any parsing errors were detected, the plan is to display them all.

## Notes
- All ParserErrors keep a track of the invalid AST Node
- When a Parsing error occurs, the Parser tries its best to continue parsing the rest of the source. For function parameters, it'll move on to the next param. For object proroperties, it'll move to the next property. It'll form a half-baked schema in the process, when a parsing error occurs. However, higher up in the stack, we have a check that discards the half-baked schema, if any ParsingErrors were collected.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24379511

fbshipit-source-id: 1989433da9b356b9ad5d9dcf901b429f585803c2
2020-10-19 21:59:29 -07:00
Ramanpreet Nara 2f438b03d7 Make buildModuleSchema and buildComponentSchema operate on Program AST nodes
Summary:
## Why
We want to reuse these functions inside the ESLint rule. Therefore, it's better to make them accept the AST node object, as opposed to a custom type defined in codegen.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24379512

fbshipit-source-id: 9f7378fc6c5f48cce34da109f5a7c017332b302a
2020-10-19 21:59:29 -07:00
Ramanpreet Nara 33789ba0ea GenerateModuleCpp: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Differential Revision: D24386276

fbshipit-source-id: d5913122221960c06c5256af10ace1d2f7a60b49
2020-10-19 21:59:29 -07:00
Ramanpreet Nara de32fd2539 GenerateModuleH: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Differential Revision: D24386278

fbshipit-source-id: b6cfa9fe17e1f7c54f4d541fd19281bf9a6c6796
2020-10-19 21:59:29 -07:00
Ramanpreet Nara ac46837d35 GenerateModuleJavaSpec: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Differential Revision: D24386277

fbshipit-source-id: 28fbc0eab2c4455d391a1644b5c42c0cb39f69ad
2020-10-19 21:59:29 -07:00
Ramanpreet Nara 5a73af684d GenerateModuleJniCpp: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24386280

fbshipit-source-id: 9af78d8aabd86a6afb53660ff97d550973e5d11b
2020-10-19 21:59:28 -07:00
Ramanpreet Nara 35ee7c8246 GenerateModuleJniH: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24386281

fbshipit-source-id: 558bc13edff51e801b605669613cd63309522236
2020-10-19 21:59:28 -07:00
Ramanpreet Nara fc94054915 Refactor: Rename codegenModuleName to hasteModuleName
Summary:
In our Codegen generators, we were using `codegenModuleName` to refer to the name of the spec file. Calling this `hasteModuleName` makes it more clear what this name refers to (i.e: the name of the spec file). This diff performs that rename.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24386282

fbshipit-source-id: fe2beda9a0abf63a5cf88fa0664f83416c9f1aa2
2020-10-19 21:59:28 -07:00
Kevin Gozali b05294dd99 Codegen fbsource: filter JS files for all cases, then enable codegen_module=True for react-native-github
Summary:
The specific file filtering in the CLI only covers the case where the input is a directory. We should filter when files are provided as well.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24399225

fbshipit-source-id: 186e39c157faf90bdd825ec5c5860017d49e9404
2020-10-19 15:30:05 -07:00
Kevin Gozali 4dfa3be871 Codegen Android: handle nullable getConstants() properties generation.
Summary:
The GenerateModuleJavaSpec.js mistakenly treated nullable getConstants() properties as required, such that the Java spec will throw an exception when the properties are missing. This fixed it.

Note that the JavaPoet-based generator got this correct already.

Changelog: [Internal]

Differential Revision: D24381941

fbshipit-source-id: c95d2181c66443e2191318f09b6454a5296009e4
2020-10-19 09:33:53 -07:00
Ramanpreet Nara 6c88afc044 Refactor: Rename moduleName to hasteModuleName
Summary:
The NativeModules spec parser uses `moduleName` to refer to the name of the NativeModule spec. This is confusing, because the NativeModules spec also has a `moduleNames` array, which refers to names of the NativeModules that get required in the spec.

This diff renames `moduleName` to `hasteModuleName` within the NativeModule spec parser.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24386279

fbshipit-source-id: 8e4eb8dfc647241bf2bdae54dc8d9ab0122f49f9
2020-10-18 19:04:58 -07:00
Kevin Gozali 76098831fd Codegen: exclude NativeModules that are not for the specific platform
Summary:
If a native module schema has `excludedPlatforms` defined, honor it and skip the module that doesn't belong to the platform.

E.g. NativeImagePickerIOS shouldn't generate anything for Android codegen output.
Similarly, IntentAndroid shouldn't generate anything for iOS codegen output.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24373092

fbshipit-source-id: cfeb455a18c92f60191d988af2e9ce7ea5021304
2020-10-17 02:45:48 -07:00
Kevin Gozali ec094e75bd Codegen: denote Android/iOS exclusive platform modules in the schema
Summary:
Some existing NativeModules have either Android or IOS suffix to denote the exclusive intent for that platform. For now, note this in the codegen schema output, so that the generator can skip irrelevant modules. Long term, each Flow type for module Spec should denote the intended/excluded platforms directly.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24370568

fbshipit-source-id: 8f725bdb39107d73c1aba0689db7f47ed7c374b0
2020-10-17 02:45:48 -07:00
Ramanpreet Nara c4f23354fd Update Module Generators to follow new NativeModuleSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

## Changes
1. NativeModule generators now use the new RN Codegen NativeModule schema.
2. Tangential: We're no longer removing the `Native` prefix from the NativeModule filename, assuming that that's the module name (problem: wrong), and prefixing again with Native (problem: redundant), when we're generating code. Instead, like the internal codegen, we simply pass the filename to the Codegen output. Our linters enforce that all NativeModule specs are contained with files that start off with `Native`.
3. `GenerateModuleCpp` was fixed to use the actual module name as opposed to the spec name. I added a comment inline.

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236405

fbshipit-source-id: ccd6b5674d252c350be0ec8a86e7ca5f2f614778
2020-10-15 22:53:56 -07:00
Ramanpreet Nara ee177f6cba Update ViewConfig generator test to follow new ComponentSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236504

fbshipit-source-id: 0ca70101a855fb713fa15ed63849b138eb73dc6c
2020-10-15 22:53:56 -07:00
Ramanpreet Nara 100c0528f3 Update component generators to follow new ComponentSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

## Changes
Previously, the "Module" schema could either contain a `components` property, or a `nativeModules` property. The existence of the `components` property was used to determine (1) if the generators would run and (2) filter schemas on which the generators would run. Now, we simply check whether the type of the "Module" schema is `Component`.

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236508

fbshipit-source-id: 68cb3f25178b6757c9a4aee767bb6173db4932a6
2020-10-15 22:53:55 -07:00
Ramanpreet Nara a5a12cffeb Update SchemaValidator test to follow new CodegenSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236507

fbshipit-source-id: 2ffa0414db731a6ee844a2d1a5b07dc32bc763cb
2020-10-15 22:53:55 -07:00
Ramanpreet Nara abeae870d4 Update Component generator fixtures to follow new ComponentSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236502

fbshipit-source-id: 288c6d9588bde177732fe8165d3374eeacad999d
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 4ee65f66cf Update Module generator fixtures to follow new NativeModuleSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236509

fbshipit-source-id: 1b603e8728d7be1e8bdede5878f57d6556b5c52f
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 3d0a626c87 Update NativeModule parser to generate new schema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

## Changes
1. Update the RN Codegen Module Parser
2. Update all RN Codegen Module Parser Jest tests & snapshots.

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236505

fbshipit-source-id: e24a39b4837c75a90fb4c957c56dfcf789511cc9
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 8b1ae7a4ae Annotate Component parser's output with 'Component' type
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

## Changes
1. Update the RN Codegen Component Parser
2. Update all RN Codegen Component Parser snapshots.

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236503

fbshipit-source-id: 975d97dd29bb5ca08e5de96e7814290c3dc4357b
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 3a75b376cc Create NativeModuleSchema and ComponentSchema
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).

## Description
The Codegen deals with "Modules". Hence:
```
type SchemaType = {
  modules: {
    [moduleName]: ...
  }
};
```

Each "Module" has a name, and represents a file. The `moduleName` is the base name of the file. This file can contain a component specification or a NativeModule specification. Hence:

```
type SchemaType = {
  modules: {
    [moduleName]: ComponentSchema | NativeModuleSchema
  }
};
```

The `ComponentSchema` can contain specifications for many different components. Hence:

```
type ComponentSchema = {
  type: 'Component'
  components: {
    [componentName]: ComponentShape
  }
}
```

The `NativeModuleSchema` contains
1. Type aliases (no surprises/nothing new).
2. One Flow interface that extends `TurboModule`.
3. Potentially many different NativeModule requires (for now) via `TurboModuleRegistry.get(Enforcing)?<specName>('moduleName')`.

Hence, the shape looks like:
```
type NativeModuleSchema = {
  type: 'NativeModule',
  aliases: NativeModuleAliasMap, // nothing new
  spec: NativeModuleSpec,
  moduleNames: $ReadOnlyArray<string>
}

type NativeModuleSpec = {
  properties: $ReadOnlyArray<...>,
}
```

## Major Notes
1. We now parse the NativeModule requires (TurboModuleRegistry.get(Enforcing)?<Spec> calls) and record them in the schema.
2. A Codegen "Module" can contain either a Component schema, or a NativeModule schema, but **not** both.

## Snapshot Updates
The changes to the schema are visible in the snapshots updated in D24236505.

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: fkgozali

Differential Revision: D24236510

fbshipit-source-id: bd344d67136418725d840e7332fd2f6957326bb4
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 8e943d8f5a Remove reliance on util.inspect in snapshot tests
Summary:
According to Node's documentation: https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors

> The util.inspect() method returns a string representation of object that is intended for debugging. **The output of util.inspect may change at any time and should not be depended upon programmatically.**

Therefore, this diff switches over our RN Codegen snapshot tests to use a `JSON.stringify` call, followed by a replace of `"` with `'`. This gets the job done without compromising readability.

**Question:** Why do we not use `"`? A: Jest escapes all `"` in the snapshots, which makes reading the snapshots/using them in the console harder.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24157056

fbshipit-source-id: 2f1aa2df28ac3ed4aa17bcdbcd23846ddbf804cf
2020-10-07 14:28:20 -07:00
Héctor Ramos 4eb8bd5084 trivial: Remove whitespace in generated output
Summary:
Remove extraneous newlines before and after structs, before copyright headers, and other locations.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24117137

fbshipit-source-id: 194996019b4cadef9239a78334f31c0bc89e3901
2020-10-06 01:44:20 -07:00
Héctor Ramos d4937b925b Use correct var name for element when handling arrays of type aliases
Summary:
Fixes an issue where, if a spec uses an array of elements where the element is a type alias, the generated code would use the wrong variable name.

An example of such a spec can be found in `NativeExceptionsManager.js`:
```
  +reportSoftException: (
    message: string,
    stack: Array<StackFrame>,
    exceptionId: number,
  ) => void;
```

The fix ensures the local variable name is passed through, ensuring that either p or itemValue_N is used when appropriate.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24116429

fbshipit-source-id: f39b75adb604c751d70a284a11a7fa6649b1344d
2020-10-05 12:57:34 -07:00
Christoph Nakazawa 43624dd193 Update Babel to 7.11.6
Summary: Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D24039996

fbshipit-source-id: 26ec2a988faadf24ea76d9124052d9397682787b
2020-10-05 05:46:31 -07:00
Ramanpreet Nara 5122e33f4e Make ObjCPP Generator handle NullableTypeAnnotation
Summary:
See title.
Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027243

fbshipit-source-id: 4e03a14fd23c1f5f3d282fc14a760d7549cdd6b9
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 6d7e763e85 Make JniCpp Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027245

fbshipit-source-id: 73f9e7ec7ccb7627d2df63798a4269c860388dde
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 0a2228ae3f Make JavaSpec Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027248

fbshipit-source-id: 7ca0e04e8e2f19cffc9aea3d6db51f86703c06f7
2020-10-01 19:30:08 -07:00
Ramanpreet Nara d9dc9d5d0a Make H Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027247

fbshipit-source-id: cc326f5db919de1f6c6b56603f420c87272da918
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 1a90e1b471 Make Cpp Generator handle NullableTypeAnnotation
Summary:
See title.
Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027244

fbshipit-source-id: 4f967a7a72afd6aa7a886c16eeb683c52da2dc9c
2020-10-01 19:30:07 -07:00
Ramanpreet Nara 6fe06ca160 Update generator fixtures to use NullableTypeAnnotation
Summary:
This will make sure that the snapshot tests for the generators work with NullableTypeAnnotation.
Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027246

fbshipit-source-id: cee93e40be7585ec527087d114f8326c2ecb9ddd
2020-10-01 19:30:07 -07:00
Ramanpreet Nara 8d807dfbc3 Introduce NullableTypeAnnotation for Flow Module Parser
Summary:
Previously, all our type annotations contained a `nullable` property. This diff removes that property from all our NativeModule type annotations, and instead introduces a `NullableTypeAnnotation`.

**Some Benefits:**
- In all our serialization functions, we use Flow exhaustive checking to ensure that all type-annotations can be serialized. Since nullability is now recorded as a type annotation, Flow will ensure we always explicitly handle nullability. Previously, with nullability as a property, we could ignore it without any feedback from flow.
- This aligns the NativeModule schema with the ESTree spec.
- After this diff, we're one step closer to sharing type annotations with Codegen's schema. Many NativeModule type annotations now have the same shape as their Codegen counterparts. They will be merged in a subsequent diff.

**Downsides:**
- If you want to check whether a type annotation is of type `T`, you have to remember to unwrap the type annotation *yourself*. Flow won't warn you if you forget to unwrap the type, which can lead to incomplete handling to nullable types in our generators.
- When you're creating type annotations in code, previously, you *had* to specify nullability, since it was a property on all type annotation objects. Now, it's very possible for you to forget to wrap the type annotation, which will just lead to nullability bugs.

**Notes:**
- In the scheam, exported type annotations are *always* required. They can be made nullable using the new `Nullable` genric type.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24026887

fbshipit-source-id: 9e71e2c6102dc506824403dbb712488ca8507d08
2020-10-01 19:30:07 -07:00