@react-native/codegen 0.73.0 → 0.74.0-nightly-20231003-5dedf277c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +2 -2
  2. package/lib/CodegenSchema.d.ts +15 -4
  3. package/lib/CodegenSchema.js.flow +33 -21
  4. package/lib/cli/combine/combine-js-to-schema-cli.js +7 -1
  5. package/lib/cli/combine/combine-js-to-schema-cli.js.flow +7 -1
  6. package/lib/generators/components/CppHelpers.js +39 -2
  7. package/lib/generators/components/CppHelpers.js.flow +54 -5
  8. package/lib/generators/components/GenerateEventEmitterCpp.js +222 -28
  9. package/lib/generators/components/GenerateEventEmitterCpp.js.flow +221 -34
  10. package/lib/generators/components/GenerateEventEmitterH.js +77 -26
  11. package/lib/generators/components/GenerateEventEmitterH.js.flow +87 -30
  12. package/lib/generators/components/GeneratePropsH.js +2 -3
  13. package/lib/generators/components/GeneratePropsH.js.flow +2 -3
  14. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +0 -1
  15. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -5
  16. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +4 -0
  17. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +4 -0
  18. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +2 -0
  19. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +2 -0
  20. package/lib/generators/components/__test_fixtures__/fixtures.js +114 -1
  21. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +114 -1
  22. package/lib/generators/modules/GenerateModuleCpp.js +1 -1
  23. package/lib/generators/modules/GenerateModuleCpp.js.flow +1 -1
  24. package/lib/generators/modules/GenerateModuleH.js +44 -39
  25. package/lib/generators/modules/GenerateModuleH.js.flow +51 -39
  26. package/lib/generators/modules/GenerateModuleJavaSpec.js +9 -7
  27. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +10 -6
  28. package/lib/generators/modules/GenerateModuleJniH.js +1 -1
  29. package/lib/generators/modules/GenerateModuleJniH.js.flow +1 -1
  30. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +11 -3
  31. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +13 -3
  32. package/lib/parsers/error-utils.js +44 -0
  33. package/lib/parsers/error-utils.js.flow +59 -0
  34. package/lib/parsers/errors.js +3 -9
  35. package/lib/parsers/errors.js.flow +3 -9
  36. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +51 -0
  37. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +51 -0
  38. package/lib/parsers/flow/components/componentsUtils.js +22 -33
  39. package/lib/parsers/flow/components/componentsUtils.js.flow +24 -45
  40. package/lib/parsers/flow/components/events.js +151 -128
  41. package/lib/parsers/flow/components/events.js.flow +161 -136
  42. package/lib/parsers/flow/components/index.js +13 -94
  43. package/lib/parsers/flow/components/index.js.flow +5 -102
  44. package/lib/parsers/flow/modules/index.js +24 -24
  45. package/lib/parsers/flow/modules/index.js.flow +6 -6
  46. package/lib/parsers/flow/parser.d.ts +9 -2
  47. package/lib/parsers/flow/parser.js +179 -18
  48. package/lib/parsers/flow/parser.js.flow +231 -7
  49. package/lib/parsers/flow/utils.js +0 -63
  50. package/lib/parsers/flow/utils.js.flow +1 -77
  51. package/lib/parsers/parser.js.flow +176 -3
  52. package/lib/parsers/parserMock.js +202 -4
  53. package/lib/parsers/parserMock.js.flow +253 -4
  54. package/lib/parsers/parsers-commons.js +268 -10
  55. package/lib/parsers/parsers-commons.js.flow +365 -12
  56. package/lib/parsers/parsers-primitives.js +95 -1
  57. package/lib/parsers/parsers-primitives.js.flow +136 -1
  58. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +51 -0
  59. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +51 -0
  60. package/lib/parsers/typescript/components/componentsUtils.js +49 -57
  61. package/lib/parsers/typescript/components/componentsUtils.js.flow +48 -66
  62. package/lib/parsers/typescript/components/events.js +136 -115
  63. package/lib/parsers/typescript/components/events.js.flow +148 -119
  64. package/lib/parsers/typescript/components/extends.js +2 -49
  65. package/lib/parsers/typescript/components/extends.js.flow +1 -55
  66. package/lib/parsers/typescript/components/index.js +14 -99
  67. package/lib/parsers/typescript/components/index.js.flow +6 -106
  68. package/lib/parsers/typescript/modules/index.js +28 -26
  69. package/lib/parsers/typescript/modules/index.js.flow +9 -8
  70. package/lib/parsers/typescript/parser.d.ts +9 -2
  71. package/lib/parsers/typescript/parser.js +208 -14
  72. package/lib/parsers/typescript/parser.js.flow +247 -8
  73. package/lib/parsers/utils.js.flow +6 -0
  74. package/package.json +27 -16
  75. package/lib/parsers/flow/components/extends.js +0 -52
  76. package/lib/parsers/flow/components/extends.js.flow +0 -66
  77. package/lib/parsers/flow/components/props.js +0 -47
  78. package/lib/parsers/flow/components/props.js.flow +0 -60
  79. package/lib/parsers/typescript/components/props.js +0 -39
  80. package/lib/parsers/typescript/components/props.js.flow +0 -48
  81. package/lib/parsers/typescript/utils.js +0 -90
  82. package/lib/parsers/typescript/utils.js.flow +0 -104
@@ -20,23 +20,46 @@ import type {
20
20
  NativeModuleEnumMemberType,
21
21
  NativeModuleAliasMap,
22
22
  NativeModuleEnumMap,
23
+ PropTypeAnnotation,
24
+ ExtendsPropsShape,
23
25
  } from '../../CodegenSchema';
24
26
  import type {ParserType} from '../errors';
25
- import type {Parser} from '../parser';
26
- import type {ParserErrorCapturer, TypeDeclarationMap} from '../utils';
27
+ import type {
28
+ GetSchemaInfoFN,
29
+ GetTypeAnnotationFN,
30
+ Parser,
31
+ ResolveTypeAnnotationFN,
32
+ } from '../parser';
33
+ import type {
34
+ ParserErrorCapturer,
35
+ TypeDeclarationMap,
36
+ PropAST,
37
+ TypeResolutionStatus,
38
+ } from '../utils';
39
+ const invariant = require('invariant');
27
40
 
28
41
  const {typeScriptTranslateTypeAnnotation} = require('./modules');
29
42
 
30
43
  // $FlowFixMe[untyped-import] Use flow-types for @babel/parser
31
44
  const babelParser = require('@babel/parser');
32
45
 
33
- const {buildSchema} = require('../parsers-commons');
34
46
  const {Visitor} = require('../parsers-primitives');
35
47
  const {buildComponentSchema} = require('./components');
36
48
  const {wrapComponentSchema} = require('../schema.js');
37
- const {buildModuleSchema} = require('../parsers-commons.js');
38
- const {resolveTypeAnnotation} = require('./utils');
39
-
49
+ const {
50
+ buildSchema,
51
+ buildModuleSchema,
52
+ extendsForProp,
53
+ buildPropSchema,
54
+ handleGenericTypeAnnotation,
55
+ } = require('../parsers-commons.js');
56
+
57
+ const {parseTopLevelType} = require('./parseTopLevelType');
58
+ const {
59
+ getSchemaInfo,
60
+ getTypeAnnotation,
61
+ flattenProperties,
62
+ } = require('./components/componentsUtils');
40
63
  const fs = require('fs');
41
64
 
42
65
  const {
@@ -45,6 +68,11 @@ const {
45
68
 
46
69
  class TypeScriptParser implements Parser {
47
70
  typeParameterInstantiation: string = 'TSTypeParameterInstantiation';
71
+ typeAlias: string = 'TSTypeAliasDeclaration';
72
+ enumDeclaration: string = 'TSEnumDeclaration';
73
+ interfaceDeclaration: string = 'TSInterfaceDeclaration';
74
+ nullLiteralTypeAnnotation: string = 'TSNullKeyword';
75
+ undefinedLiteralTypeAnnotation: string = 'TSUndefinedKeyword';
48
76
 
49
77
  isProperty(property: $FlowFixMe): boolean {
50
78
  return property.type === 'TSPropertySignature';
@@ -66,7 +94,7 @@ class TypeScriptParser implements Parser {
66
94
  return 'TypeScript';
67
95
  }
68
96
 
69
- nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string {
97
+ getTypeAnnotationName(typeAnnotation: $FlowFixMe): string {
70
98
  return typeAnnotation?.typeName?.name;
71
99
  }
72
100
 
@@ -108,7 +136,6 @@ class TypeScriptParser implements Parser {
108
136
  buildModuleSchema,
109
137
  Visitor,
110
138
  this,
111
- resolveTypeAnnotation,
112
139
  typeScriptTranslateTypeAnnotation,
113
140
  );
114
141
  }
@@ -328,6 +355,218 @@ class TypeScriptParser implements Parser {
328
355
 
329
356
  return keyword;
330
357
  }
358
+
359
+ argumentForProp(prop: PropAST): $FlowFixMe {
360
+ return prop.expression;
361
+ }
362
+
363
+ nameForArgument(prop: PropAST): $FlowFixMe {
364
+ return prop.expression.name;
365
+ }
366
+
367
+ isOptionalProperty(property: $FlowFixMe): boolean {
368
+ return property.optional || false;
369
+ }
370
+
371
+ getGetSchemaInfoFN(): GetSchemaInfoFN {
372
+ return getSchemaInfo;
373
+ }
374
+
375
+ getTypeAnnotationFromProperty(property: PropAST): $FlowFixMe {
376
+ return property.typeAnnotation.typeAnnotation;
377
+ }
378
+
379
+ getGetTypeAnnotationFN(): GetTypeAnnotationFN {
380
+ return getTypeAnnotation;
381
+ }
382
+
383
+ getResolvedTypeAnnotation(
384
+ // TODO(T108222691): Use flow-types for @babel/parser
385
+ typeAnnotation: $FlowFixMe,
386
+ types: TypeDeclarationMap,
387
+ parser: Parser,
388
+ ): {
389
+ nullable: boolean,
390
+ typeAnnotation: $FlowFixMe,
391
+ typeResolutionStatus: TypeResolutionStatus,
392
+ } {
393
+ invariant(
394
+ typeAnnotation != null,
395
+ 'resolveTypeAnnotation(): typeAnnotation cannot be null',
396
+ );
397
+
398
+ let node =
399
+ typeAnnotation.type === 'TSTypeAnnotation'
400
+ ? typeAnnotation.typeAnnotation
401
+ : typeAnnotation;
402
+ let nullable = false;
403
+ let typeResolutionStatus: TypeResolutionStatus = {
404
+ successful: false,
405
+ };
406
+
407
+ for (;;) {
408
+ const topLevelType = parseTopLevelType(node);
409
+ nullable = nullable || topLevelType.optional;
410
+ node = topLevelType.type;
411
+
412
+ if (node.type !== 'TSTypeReference') {
413
+ break;
414
+ }
415
+
416
+ const typeAnnotationName = this.getTypeAnnotationName(node);
417
+ const resolvedTypeAnnotation = types[typeAnnotationName];
418
+ if (resolvedTypeAnnotation == null) {
419
+ break;
420
+ }
421
+
422
+ const {typeAnnotation: typeAnnotationNode, typeResolutionStatus: status} =
423
+ handleGenericTypeAnnotation(node, resolvedTypeAnnotation, this);
424
+ typeResolutionStatus = status;
425
+ node = typeAnnotationNode;
426
+ }
427
+
428
+ return {
429
+ nullable: nullable,
430
+ typeAnnotation: node,
431
+ typeResolutionStatus,
432
+ };
433
+ }
434
+
435
+ getResolveTypeAnnotationFN(): ResolveTypeAnnotationFN {
436
+ return (
437
+ typeAnnotation: $FlowFixMe,
438
+ types: TypeDeclarationMap,
439
+ parser: Parser,
440
+ ) => {
441
+ return this.getResolvedTypeAnnotation(typeAnnotation, types, parser);
442
+ };
443
+ }
444
+
445
+ isEvent(typeAnnotation: $FlowFixMe): boolean {
446
+ if (typeAnnotation.type !== 'TSTypeReference') {
447
+ return false;
448
+ }
449
+ const eventNames = new Set(['BubblingEventHandler', 'DirectEventHandler']);
450
+ return eventNames.has(this.getTypeAnnotationName(typeAnnotation));
451
+ }
452
+
453
+ isProp(name: string, typeAnnotation: $FlowFixMe): boolean {
454
+ if (typeAnnotation.type !== 'TSTypeReference') {
455
+ return true;
456
+ }
457
+ const isStyle =
458
+ name === 'style' &&
459
+ typeAnnotation.type === 'GenericTypeAnnotation' &&
460
+ this.getTypeAnnotationName(typeAnnotation) === 'ViewStyleProp';
461
+ return !isStyle;
462
+ }
463
+
464
+ getProps(
465
+ typeDefinition: $ReadOnlyArray<PropAST>,
466
+ types: TypeDeclarationMap,
467
+ ): {
468
+ props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
469
+ extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
470
+ } {
471
+ const extendsProps: Array<ExtendsPropsShape> = [];
472
+ const componentPropAsts: Array<PropAST> = [];
473
+ const remaining: Array<PropAST> = [];
474
+
475
+ for (const prop of typeDefinition) {
476
+ // find extends
477
+ if (prop.type === 'TSExpressionWithTypeArguments') {
478
+ const extend = extendsForProp(prop, types, this);
479
+ if (extend) {
480
+ extendsProps.push(extend);
481
+ continue;
482
+ }
483
+ }
484
+
485
+ remaining.push(prop);
486
+ }
487
+
488
+ // find events and props
489
+ for (const prop of flattenProperties(remaining, types, this)) {
490
+ const topLevelType = parseTopLevelType(
491
+ prop.typeAnnotation.typeAnnotation,
492
+ types,
493
+ );
494
+
495
+ if (
496
+ prop.type === 'TSPropertySignature' &&
497
+ !this.isEvent(topLevelType.type) &&
498
+ this.isProp(prop.key.name, prop)
499
+ ) {
500
+ componentPropAsts.push(prop);
501
+ }
502
+ }
503
+
504
+ return {
505
+ props: componentPropAsts
506
+ .map(property => buildPropSchema(property, types, this))
507
+ .filter(Boolean),
508
+ extendsProps,
509
+ };
510
+ }
511
+
512
+ getProperties(typeName: string, types: TypeDeclarationMap): $FlowFixMe {
513
+ const alias = types[typeName];
514
+ if (!alias) {
515
+ throw new Error(
516
+ `Failed to find definition for "${typeName}", please check that you have a valid codegen typescript file`,
517
+ );
518
+ }
519
+ const aliasKind =
520
+ alias.type === 'TSInterfaceDeclaration' ? 'interface' : 'type';
521
+
522
+ try {
523
+ if (aliasKind === 'interface') {
524
+ return [...(alias.extends ?? []), ...alias.body.body];
525
+ }
526
+
527
+ return (
528
+ alias.typeAnnotation.members ||
529
+ alias.typeAnnotation.typeParameters.params[0].members ||
530
+ alias.typeAnnotation.typeParameters.params
531
+ );
532
+ } catch (e) {
533
+ throw new Error(
534
+ `Failed to find ${aliasKind} definition for "${typeName}", please check that you have a valid codegen typescript file`,
535
+ );
536
+ }
537
+ }
538
+
539
+ nextNodeForTypeAlias(typeAnnotation: $FlowFixMe): $FlowFixMe {
540
+ return typeAnnotation.typeAnnotation;
541
+ }
542
+
543
+ nextNodeForEnum(typeAnnotation: $FlowFixMe): $FlowFixMe {
544
+ return typeAnnotation;
545
+ }
546
+
547
+ genericTypeAnnotationErrorMessage(typeAnnotation: $FlowFixMe): string {
548
+ return `A non GenericTypeAnnotation must be a type declaration ('${this.typeAlias}'), an interface ('${this.interfaceDeclaration}'), or enum ('${this.enumDeclaration}'). Instead, got the unsupported ${typeAnnotation.type}.`;
549
+ }
550
+
551
+ extractTypeFromTypeAnnotation(typeAnnotation: $FlowFixMe): string {
552
+ return typeAnnotation.type === 'TSTypeReference'
553
+ ? typeAnnotation.typeName.name
554
+ : typeAnnotation.type;
555
+ }
556
+
557
+ getObjectProperties(typeAnnotation: $FlowFixMe): $FlowFixMe {
558
+ return typeAnnotation.members;
559
+ }
560
+
561
+ getLiteralValue(option: $FlowFixMe): $FlowFixMe {
562
+ return option.literal.value;
563
+ }
564
+
565
+ getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
566
+ return typeAnnotation.typeParameters.params.length > 1
567
+ ? typeAnnotation.typeParameters.params[1].literal.value
568
+ : null;
569
+ }
331
570
  }
332
571
 
333
572
  module.exports = {
@@ -34,6 +34,12 @@ function extractNativeModuleName(filename: string): string {
34
34
 
35
35
  export type ParserErrorCapturer = <T>(fn: () => T) => ?T;
36
36
 
37
+ // $FlowFixMe[unclear-type] there's no flowtype for ASTs
38
+ export type PropAST = Object;
39
+
40
+ // $FlowFixMe[unclear-type] there's no flowtype for ASTs
41
+ export type ASTNode = Object;
42
+
37
43
  function createParserErrorCapturer(): [
38
44
  Array<ParserError>,
39
45
  ParserErrorCapturer,
package/package.json CHANGED
@@ -1,45 +1,56 @@
1
1
  {
2
2
  "name": "@react-native/codegen",
3
- "version": "0.73.0",
4
- "description": "⚛️ Code generation tools for React Native",
5
- "homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/react-native-codegen",
3
+ "version": "0.74.0-nightly-20231003-5dedf277c",
4
+ "description": "Code generation tools for React Native",
5
+ "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git@github.com:facebook/react-native.git",
8
+ "url": "https://github.com/facebook/react-native.git",
9
9
  "directory": "packages/react-native-codegen"
10
10
  },
11
+ "homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/react-native-codegen#readme",
12
+ "keywords": [
13
+ "code",
14
+ "generation",
15
+ "codegen",
16
+ "tools",
17
+ "react-native"
18
+ ],
19
+ "bugs": "https://github.com/facebook/react-native/issues",
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
11
23
  "scripts": {
12
24
  "build": "yarn clean && node scripts/build.js --verbose",
13
25
  "clean": "rimraf lib",
14
26
  "prepare": "yarn run build"
15
27
  },
16
- "license": "MIT",
17
28
  "files": [
18
29
  "lib"
19
30
  ],
20
31
  "dependencies": {
21
32
  "@babel/parser": "^7.20.0",
22
- "flow-parser": "^0.185.0",
33
+ "flow-parser": "^0.206.0",
23
34
  "jscodeshift": "^0.14.0",
24
35
  "nullthrows": "^1.1.1"
25
36
  },
26
37
  "devDependencies": {
27
38
  "@babel/core": "^7.20.0",
28
- "@babel/plugin-proposal-class-properties": "^7.0.0",
29
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
30
- "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
31
- "@babel/plugin-proposal-optional-chaining": "^7.0.0",
32
- "@babel/plugin-syntax-dynamic-import": "^7.0.0",
33
- "@babel/plugin-transform-async-to-generator": "^7.0.0",
34
- "@babel/plugin-transform-destructuring": "^7.0.0",
35
- "@babel/plugin-transform-flow-strip-types": "^7.0.0",
36
- "@babel/preset-env": "^7.14.0",
39
+ "@babel/plugin-proposal-class-properties": "^7.18.0",
40
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.0",
41
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.0",
42
+ "@babel/plugin-proposal-optional-chaining": "^7.20.0",
43
+ "@babel/plugin-syntax-dynamic-import": "^7.8.0",
44
+ "@babel/plugin-transform-async-to-generator": "^7.20.0",
45
+ "@babel/plugin-transform-destructuring": "^7.20.0",
46
+ "@babel/plugin-transform-flow-strip-types": "^7.20.0",
47
+ "@babel/preset-env": "^7.20.0",
37
48
  "chalk": "^4.0.0",
38
49
  "glob": "^7.1.1",
39
50
  "invariant": "^2.2.4",
40
51
  "micromatch": "^4.0.4",
41
52
  "mkdirp": "^0.5.1",
42
- "prettier": "^2.4.1",
53
+ "prettier": "2.8.8",
43
54
  "rimraf": "^3.0.2"
44
55
  },
45
56
  "peerDependencies": {
@@ -1,52 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- function extendsForProp(prop, types) {
14
- if (!prop.argument) {
15
- console.log('null', prop);
16
- }
17
- const name = prop.argument.id.name;
18
- if (types[name] != null) {
19
- // This type is locally defined in the file
20
- return null;
21
- }
22
- switch (name) {
23
- case 'ViewProps':
24
- return {
25
- type: 'ReactNativeBuiltInType',
26
- knownTypeName: 'ReactNativeCoreViewProps',
27
- };
28
- default: {
29
- throw new Error(`Unable to handle prop spread: ${name}`);
30
- }
31
- }
32
- }
33
- function removeKnownExtends(typeDefinition, types) {
34
- return typeDefinition.filter(
35
- prop =>
36
- prop.type !== 'ObjectTypeSpreadProperty' ||
37
- extendsForProp(prop, types) === null,
38
- );
39
- }
40
-
41
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
42
-
43
- function getExtendsProps(typeDefinition, types) {
44
- return typeDefinition
45
- .filter(prop => prop.type === 'ObjectTypeSpreadProperty')
46
- .map(prop => extendsForProp(prop, types))
47
- .filter(Boolean);
48
- }
49
- module.exports = {
50
- getExtendsProps,
51
- removeKnownExtends,
52
- };
@@ -1,66 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
14
- import type {TypeDeclarationMap} from '../../utils';
15
-
16
- function extendsForProp(prop: PropsAST, types: TypeDeclarationMap) {
17
- if (!prop.argument) {
18
- console.log('null', prop);
19
- }
20
- const name = prop.argument.id.name;
21
-
22
- if (types[name] != null) {
23
- // This type is locally defined in the file
24
- return null;
25
- }
26
-
27
- switch (name) {
28
- case 'ViewProps':
29
- return {
30
- type: 'ReactNativeBuiltInType',
31
- knownTypeName: 'ReactNativeCoreViewProps',
32
- };
33
- default: {
34
- throw new Error(`Unable to handle prop spread: ${name}`);
35
- }
36
- }
37
- }
38
-
39
- function removeKnownExtends(
40
- typeDefinition: $ReadOnlyArray<PropsAST>,
41
- types: TypeDeclarationMap,
42
- ): $ReadOnlyArray<PropsAST> {
43
- return typeDefinition.filter(
44
- prop =>
45
- prop.type !== 'ObjectTypeSpreadProperty' ||
46
- extendsForProp(prop, types) === null,
47
- );
48
- }
49
-
50
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
51
- type PropsAST = Object;
52
-
53
- function getExtendsProps(
54
- typeDefinition: $ReadOnlyArray<PropsAST>,
55
- types: TypeDeclarationMap,
56
- ): $ReadOnlyArray<ExtendsPropsShape> {
57
- return typeDefinition
58
- .filter(prop => prop.type === 'ObjectTypeSpreadProperty')
59
- .map(prop => extendsForProp(prop, types))
60
- .filter(Boolean);
61
- }
62
-
63
- module.exports = {
64
- getExtendsProps,
65
- removeKnownExtends,
66
- };
@@ -1,47 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- const _require = require('./componentsUtils.js'),
14
- flattenProperties = _require.flattenProperties,
15
- getSchemaInfo = _require.getSchemaInfo,
16
- getTypeAnnotation = _require.getTypeAnnotation;
17
- function buildPropSchema(property, types) {
18
- const info = getSchemaInfo(property, types);
19
- if (info == null) {
20
- return null;
21
- }
22
- const name = info.name,
23
- optional = info.optional,
24
- typeAnnotation = info.typeAnnotation,
25
- defaultValue = info.defaultValue,
26
- withNullDefault = info.withNullDefault;
27
- return {
28
- name,
29
- optional,
30
- typeAnnotation: getTypeAnnotation(
31
- name,
32
- typeAnnotation,
33
- defaultValue,
34
- withNullDefault,
35
- types,
36
- buildPropSchema,
37
- ),
38
- };
39
- }
40
- function getProps(typeDefinition, types) {
41
- return flattenProperties(typeDefinition, types)
42
- .map(property => buildPropSchema(property, types))
43
- .filter(Boolean);
44
- }
45
- module.exports = {
46
- getProps,
47
- };
@@ -1,60 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- const {
14
- flattenProperties,
15
- getSchemaInfo,
16
- getTypeAnnotation,
17
- } = require('./componentsUtils.js');
18
-
19
- import type {NamedShape, PropTypeAnnotation} from '../../../CodegenSchema.js';
20
- import type {TypeDeclarationMap} from '../../utils';
21
-
22
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
23
- type PropAST = Object;
24
-
25
- function buildPropSchema(
26
- property: PropAST,
27
- types: TypeDeclarationMap,
28
- ): ?NamedShape<PropTypeAnnotation> {
29
- const info = getSchemaInfo(property, types);
30
- if (info == null) {
31
- return null;
32
- }
33
- const {name, optional, typeAnnotation, defaultValue, withNullDefault} = info;
34
-
35
- return {
36
- name,
37
- optional,
38
- typeAnnotation: getTypeAnnotation(
39
- name,
40
- typeAnnotation,
41
- defaultValue,
42
- withNullDefault,
43
- types,
44
- buildPropSchema,
45
- ),
46
- };
47
- }
48
-
49
- function getProps(
50
- typeDefinition: $ReadOnlyArray<PropAST>,
51
- types: TypeDeclarationMap,
52
- ): $ReadOnlyArray<NamedShape<PropTypeAnnotation>> {
53
- return flattenProperties(typeDefinition, types)
54
- .map(property => buildPropSchema(property, types))
55
- .filter(Boolean);
56
- }
57
-
58
- module.exports = {
59
- getProps,
60
- };
@@ -1,39 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- const _require = require('./componentsUtils.js'),
14
- getSchemaInfo = _require.getSchemaInfo,
15
- getTypeAnnotation = _require.getTypeAnnotation;
16
- function buildPropSchema(property, types) {
17
- const info = getSchemaInfo(property, types);
18
- const name = info.name,
19
- optional = info.optional,
20
- typeAnnotation = info.typeAnnotation,
21
- defaultValue = info.defaultValue;
22
- return {
23
- name,
24
- optional,
25
- typeAnnotation: getTypeAnnotation(
26
- name,
27
- typeAnnotation,
28
- defaultValue,
29
- types,
30
- buildPropSchema,
31
- ),
32
- };
33
- }
34
- function getProps(typeDefinition, types) {
35
- return typeDefinition.map(property => buildPropSchema(property, types));
36
- }
37
- module.exports = {
38
- getProps,
39
- };
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- 'use strict';
12
- const {getSchemaInfo, getTypeAnnotation} = require('./componentsUtils.js');
13
-
14
- import type {NamedShape, PropTypeAnnotation} from '../../../CodegenSchema.js';
15
- import type {TypeDeclarationMap} from '../../utils';
16
-
17
- // $FlowFixMe[unclear-type] there's no flowtype for ASTs
18
- type PropAST = Object;
19
-
20
- function buildPropSchema(
21
- property: PropAST,
22
- types: TypeDeclarationMap,
23
- ): NamedShape<PropTypeAnnotation> {
24
- const info = getSchemaInfo(property, types);
25
- const {name, optional, typeAnnotation, defaultValue} = info;
26
- return {
27
- name,
28
- optional,
29
- typeAnnotation: getTypeAnnotation(
30
- name,
31
- typeAnnotation,
32
- defaultValue,
33
- types,
34
- buildPropSchema,
35
- ),
36
- };
37
- }
38
-
39
- function getProps(
40
- typeDefinition: $ReadOnlyArray<PropAST>,
41
- types: TypeDeclarationMap,
42
- ): $ReadOnlyArray<NamedShape<PropTypeAnnotation>> {
43
- return typeDefinition.map(property => buildPropSchema(property, types));
44
- }
45
-
46
- module.exports = {
47
- getProps,
48
- };