@react-native/codegen
Advanced tools
| 'use strict'; | ||
| const { | ||
| unwrapNullable | ||
| } = require('../../../../parsers/parsers-commons'); | ||
| const { | ||
| wrapOptional: wrapCxxOptional | ||
| } = require('../../../TypeUtils/Cxx'); | ||
| const { | ||
| wrapOptional: wrapObjCOptional | ||
| } = require('../../../TypeUtils/Objective-C'); | ||
| const { | ||
| capitalize | ||
| } = require('../../../Utils'); | ||
| const { | ||
| getNamespacedStructName | ||
| } = require('../Utils'); | ||
| function toObjCType(hasteModuleName, nullableTypeAnnotation, structContext, isOptional = false) { | ||
| const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); | ||
| const isRequired = !nullable && !isOptional; | ||
| switch (typeAnnotation.type) { | ||
| case 'ReservedTypeAnnotation': | ||
| switch (typeAnnotation.name) { | ||
| case 'RootTag': | ||
| return wrapCxxOptional('double', isRequired); | ||
| default: | ||
| typeAnnotation.name; | ||
| throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`); | ||
| } | ||
| case 'StringTypeAnnotation': | ||
| return 'NSString *'; | ||
| case 'StringLiteralTypeAnnotation': | ||
| return 'NSString *'; | ||
| case 'UnionTypeAnnotation': | ||
| return 'NSObject *'; | ||
| case 'NumberTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'NumberLiteralTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'FloatTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'Int32TypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'DoubleTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'BooleanTypeAnnotation': | ||
| return wrapCxxOptional('bool', isRequired); | ||
| case 'BooleanLiteralTypeAnnotation': | ||
| return wrapCxxOptional('bool', isRequired); | ||
| case 'EnumDeclaration': | ||
| switch (typeAnnotation.memberType) { | ||
| case 'NumberTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'StringTypeAnnotation': | ||
| return 'NSString *'; | ||
| default: | ||
| throw new Error(`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`); | ||
| } | ||
| case 'GenericObjectTypeAnnotation': | ||
| return wrapObjCOptional('id<NSObject>', isRequired); | ||
| case 'ArrayTypeAnnotation': | ||
| if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') { | ||
| return wrapObjCOptional('id<NSObject>', isRequired); | ||
| } | ||
| return wrapCxxOptional(structContext === 'CONSTANTS' ? `std::vector<${toObjCType(hasteModuleName, typeAnnotation.elementType, structContext)}>` : `facebook::react::LazyVector<${toObjCType(hasteModuleName, typeAnnotation.elementType, structContext)}>`, isRequired); | ||
| case 'TypeAliasTypeAnnotation': | ||
| const structName = capitalize(typeAnnotation.name); | ||
| const namespacedStructName = getNamespacedStructName(hasteModuleName, structName); | ||
| return wrapCxxOptional(structContext === 'CONSTANTS' ? `${namespacedStructName}::Builder` : namespacedStructName, isRequired); | ||
| default: | ||
| typeAnnotation.type; | ||
| throw new Error(`Couldn't convert into ObjC type: ${typeAnnotation.type}"`); | ||
| } | ||
| } | ||
| module.exports = { | ||
| toObjCType | ||
| }; |
Sorry, the diff of this file is not supported yet
@@ -7,14 +7,7 @@ 'use strict'; | ||
| const { | ||
| wrapOptional: wrapCxxOptional | ||
| } = require('../../../TypeUtils/Cxx'); | ||
| const { | ||
| wrapOptional: wrapObjCOptional | ||
| } = require('../../../TypeUtils/Objective-C'); | ||
| const { | ||
| capitalize | ||
| } = require('../../../Utils'); | ||
| const { | ||
| getNamespacedStructName, | ||
| getSafePropertyName | ||
| } = require('../Utils'); | ||
| const { | ||
| toObjCType | ||
| } = require('./serializeStructUtils'); | ||
| const StructTemplate = ({ | ||
@@ -66,59 +59,2 @@ hasteModuleName, | ||
| }) {}`; | ||
| function toObjCType(hasteModuleName, nullableTypeAnnotation, isOptional = false) { | ||
| const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); | ||
| const isRequired = !nullable && !isOptional; | ||
| switch (typeAnnotation.type) { | ||
| case 'ReservedTypeAnnotation': | ||
| switch (typeAnnotation.name) { | ||
| case 'RootTag': | ||
| return wrapCxxOptional('double', isRequired); | ||
| default: | ||
| typeAnnotation.name; | ||
| throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`); | ||
| } | ||
| case 'StringTypeAnnotation': | ||
| return 'NSString *'; | ||
| case 'StringLiteralTypeAnnotation': | ||
| return 'NSString *'; | ||
| case 'UnionTypeAnnotation': | ||
| return 'NSObject *'; | ||
| case 'NumberTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'NumberLiteralTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'FloatTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'Int32TypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'DoubleTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'BooleanTypeAnnotation': | ||
| return wrapCxxOptional('bool', isRequired); | ||
| case 'BooleanLiteralTypeAnnotation': | ||
| return wrapCxxOptional('bool', isRequired); | ||
| case 'EnumDeclaration': | ||
| switch (typeAnnotation.memberType) { | ||
| case 'NumberTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'StringTypeAnnotation': | ||
| return 'NSString *'; | ||
| default: | ||
| throw new Error(`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`); | ||
| } | ||
| case 'GenericObjectTypeAnnotation': | ||
| return wrapObjCOptional('id<NSObject>', isRequired); | ||
| case 'ArrayTypeAnnotation': | ||
| if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') { | ||
| return wrapObjCOptional('id<NSObject>', isRequired); | ||
| } | ||
| return wrapCxxOptional(`std::vector<${toObjCType(hasteModuleName, typeAnnotation.elementType)}>`, isRequired); | ||
| case 'TypeAliasTypeAnnotation': | ||
| const structName = capitalize(typeAnnotation.name); | ||
| const namespacedStructName = getNamespacedStructName(hasteModuleName, structName); | ||
| return wrapCxxOptional(`${namespacedStructName}::Builder`, isRequired); | ||
| default: | ||
| typeAnnotation.type; | ||
| throw new Error(`Couldn't convert into ObjC type: ${typeAnnotation.type}"`); | ||
| } | ||
| } | ||
| function toObjCValue(hasteModuleName, nullableTypeAnnotation, value, depth, isOptional = false) { | ||
@@ -178,3 +114,3 @@ const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); | ||
| const localVarName = `el${'_'.repeat(depth + 1)}`; | ||
| const elementObjCType = toObjCType(hasteModuleName, elementType); | ||
| const elementObjCType = toObjCType(hasteModuleName, elementType, 'CONSTANTS'); | ||
| const elementObjCValue = toObjCValue(hasteModuleName, elementType, localVarName, depth + 1); | ||
@@ -202,3 +138,3 @@ const RCTConvertVecToArray = transformer => { | ||
| const safePropName = getSafePropertyName(property); | ||
| const objCType = toObjCType(hasteModuleName, typeAnnotation, optional); | ||
| const objCType = toObjCType(hasteModuleName, typeAnnotation, 'CONSTANTS', optional); | ||
| if (!optional) { | ||
@@ -205,0 +141,0 @@ return `RCTRequired<${objCType}> ${safePropName};`; |
@@ -7,8 +7,2 @@ 'use strict'; | ||
| const { | ||
| wrapOptional: wrapCxxOptional | ||
| } = require('../../../TypeUtils/Cxx'); | ||
| const { | ||
| wrapOptional: wrapObjCOptional | ||
| } = require('../../../TypeUtils/Objective-C'); | ||
| const { | ||
| capitalize | ||
@@ -20,2 +14,5 @@ } = require('../../../Utils'); | ||
| } = require('../Utils'); | ||
| const { | ||
| toObjCType | ||
| } = require('./serializeStructUtils'); | ||
| const StructTemplate = ({ | ||
@@ -52,59 +49,2 @@ hasteModuleName, | ||
| }`; | ||
| function toObjCType(hasteModuleName, nullableTypeAnnotation, isOptional = false) { | ||
| const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); | ||
| const isRequired = !nullable && !isOptional; | ||
| switch (typeAnnotation.type) { | ||
| case 'ReservedTypeAnnotation': | ||
| switch (typeAnnotation.name) { | ||
| case 'RootTag': | ||
| return wrapCxxOptional('double', isRequired); | ||
| default: | ||
| typeAnnotation.name; | ||
| throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`); | ||
| } | ||
| case 'StringTypeAnnotation': | ||
| return 'NSString *'; | ||
| case 'StringLiteralTypeAnnotation': | ||
| return 'NSString *'; | ||
| case 'UnionTypeAnnotation': | ||
| return 'NSObject *'; | ||
| case 'NumberTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'NumberLiteralTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'FloatTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'Int32TypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'DoubleTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'BooleanTypeAnnotation': | ||
| return wrapCxxOptional('bool', isRequired); | ||
| case 'BooleanLiteralTypeAnnotation': | ||
| return wrapCxxOptional('bool', isRequired); | ||
| case 'EnumDeclaration': | ||
| switch (typeAnnotation.memberType) { | ||
| case 'NumberTypeAnnotation': | ||
| return wrapCxxOptional('double', isRequired); | ||
| case 'StringTypeAnnotation': | ||
| return 'NSString *'; | ||
| default: | ||
| throw new Error(`Couldn't convert enum into ObjC type: ${typeAnnotation.type}"`); | ||
| } | ||
| case 'GenericObjectTypeAnnotation': | ||
| return wrapObjCOptional('id<NSObject>', isRequired); | ||
| case 'ArrayTypeAnnotation': | ||
| if (typeAnnotation.elementType.type === 'AnyTypeAnnotation') { | ||
| return wrapObjCOptional('id<NSObject>', isRequired); | ||
| } | ||
| return wrapCxxOptional(`facebook::react::LazyVector<${toObjCType(hasteModuleName, typeAnnotation.elementType)}>`, isRequired); | ||
| case 'TypeAliasTypeAnnotation': | ||
| const structName = capitalize(typeAnnotation.name); | ||
| const namespacedStructName = getNamespacedStructName(hasteModuleName, structName); | ||
| return wrapCxxOptional(namespacedStructName, isRequired); | ||
| default: | ||
| typeAnnotation.type; | ||
| throw new Error(`Couldn't convert into ObjC type: ${typeAnnotation.type}"`); | ||
| } | ||
| } | ||
| function toObjCValue(hasteModuleName, nullableTypeAnnotation, value, depth, isOptional = false) { | ||
@@ -165,3 +105,3 @@ const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); | ||
| const localVarName = `itemValue_${depth}`; | ||
| const elementObjCType = toObjCType(hasteModuleName, elementType); | ||
| const elementObjCType = toObjCType(hasteModuleName, elementType, 'REGULAR'); | ||
| const elementObjCValue = toObjCValue(hasteModuleName, elementType, localVarName, depth + 1); | ||
@@ -188,3 +128,3 @@ return RCTBridgingTo('Vec', `^${elementObjCType}(id ${localVarName}) { return ${elementObjCValue}; }`); | ||
| const safePropName = getSafePropertyName(property); | ||
| const returnType = toObjCType(hasteModuleName, typeAnnotation, optional); | ||
| const returnType = toObjCType(hasteModuleName, typeAnnotation, 'REGULAR', optional); | ||
| const padding = ' '.repeat(returnType.endsWith('*') ? 0 : 1); | ||
@@ -201,3 +141,3 @@ return `${returnType}${padding}${safePropName}() const;`; | ||
| const safePropertyName = getSafePropertyName(property); | ||
| const returnType = toObjCType(hasteModuleName, typeAnnotation, optional); | ||
| const returnType = toObjCType(hasteModuleName, typeAnnotation, 'REGULAR', optional); | ||
| const returnValue = toObjCValue(hasteModuleName, typeAnnotation, 'p', 0, optional); | ||
@@ -204,0 +144,0 @@ const padding = ' '.repeat(returnType.endsWith('*') ? 0 : 1); |
+4
-4
| { | ||
| "name": "@react-native/codegen", | ||
| "version": "0.86.0-nightly-20260316-2a63938c1", | ||
| "version": "0.86.0-nightly-20260319-941ace990", | ||
| "description": "Code generation tools for React Native", | ||
@@ -34,3 +34,3 @@ "license": "MIT", | ||
| "@babel/parser": "^7.29.0", | ||
| "hermes-parser": "0.33.3", | ||
| "hermes-parser": "0.34.0", | ||
| "invariant": "^2.2.4", | ||
@@ -49,4 +49,4 @@ "nullthrows": "^1.1.1", | ||
| "@babel/preset-env": "^7.25.3", | ||
| "babel-plugin-syntax-hermes-parser": "0.33.3", | ||
| "hermes-estree": "0.33.3", | ||
| "babel-plugin-syntax-hermes-parser": "0.34.0", | ||
| "hermes-estree": "0.34.0", | ||
| "micromatch": "^4.0.4", | ||
@@ -53,0 +53,0 @@ "prettier": "3.6.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
171
1.18%1041349
-0.36%12056
-0.4%+ Added
+ Added
- Removed
- Removed
Updated