@react-native/codegen
Advanced tools
Comparing version 0.72.4 to 0.73.0
@@ -29,5 +29,3 @@ /** | ||
namespace react { | ||
${events} | ||
} // namespace react | ||
@@ -43,7 +41,7 @@ } // namespace facebook | ||
}) => { | ||
const capture = implementation.includes('event') | ||
? 'event=std::move(event)' | ||
const capture = implementation.includes('$event') | ||
? '$event=std::move($event)' | ||
: ''; | ||
return ` | ||
void ${className}EventEmitter::${eventName}(${structName} event) const { | ||
void ${className}EventEmitter::${eventName}(${structName} $event) const { | ||
dispatchEvent("${dispatchEventName}", [${capture}](jsi::Runtime &runtime) { | ||
@@ -53,3 +51,3 @@ ${implementation} | ||
} | ||
`.trim(); | ||
`; | ||
}; | ||
@@ -64,3 +62,3 @@ const BasicComponentTemplate = ({className, eventName, dispatchEventName}) => | ||
const trailingPeriod = propertyParts.length === 0 ? '' : '.'; | ||
const eventChain = `event.${propertyParts.join( | ||
const eventChain = `$event.${propertyParts.join( | ||
'.', | ||
@@ -72,3 +70,3 @@ )}${trailingPeriod}${propertyName});`; | ||
const trailingPeriod = propertyParts.length === 0 ? '' : '.'; | ||
const eventChain = `event.${propertyParts.join( | ||
const eventChain = `$event.${propertyParts.join( | ||
'.', | ||
@@ -78,2 +76,20 @@ )}${trailingPeriod}${propertyName})`; | ||
} | ||
function generateObjectSetter( | ||
variableName, | ||
propertyName, | ||
propertyParts, | ||
typeAnnotation, | ||
) { | ||
return ` | ||
{ | ||
auto ${propertyName} = jsi::Object(runtime); | ||
${generateSetters( | ||
propertyName, | ||
typeAnnotation.properties, | ||
propertyParts.concat([propertyName]), | ||
)} | ||
${variableName}.setProperty(runtime, "${propertyName}", ${propertyName}); | ||
} | ||
`.trim(); | ||
} | ||
function generateSetters(parentPropertyName, properties, propertyParts) { | ||
@@ -85,20 +101,6 @@ const propSetters = properties | ||
case 'BooleanTypeAnnotation': | ||
return generateSetter( | ||
parentPropertyName, | ||
eventProperty.name, | ||
propertyParts, | ||
); | ||
case 'StringTypeAnnotation': | ||
return generateSetter( | ||
parentPropertyName, | ||
eventProperty.name, | ||
propertyParts, | ||
); | ||
case 'Int32TypeAnnotation': | ||
return generateSetter( | ||
parentPropertyName, | ||
eventProperty.name, | ||
propertyParts, | ||
); | ||
case 'DoubleTypeAnnotation': | ||
case 'FloatTypeAnnotation': | ||
return generateSetter( | ||
@@ -109,4 +111,4 @@ parentPropertyName, | ||
); | ||
case 'FloatTypeAnnotation': | ||
return generateSetter( | ||
case 'StringEnumTypeAnnotation': | ||
return generateEnumSetter( | ||
parentPropertyName, | ||
@@ -116,22 +118,9 @@ eventProperty.name, | ||
); | ||
case 'StringEnumTypeAnnotation': | ||
return generateEnumSetter( | ||
case 'ObjectTypeAnnotation': | ||
return generateObjectSetter( | ||
parentPropertyName, | ||
eventProperty.name, | ||
propertyParts, | ||
typeAnnotation, | ||
); | ||
case 'ObjectTypeAnnotation': | ||
const propertyName = eventProperty.name; | ||
return ` | ||
{ | ||
auto ${propertyName} = jsi::Object(runtime); | ||
${generateSetters( | ||
propertyName, | ||
typeAnnotation.properties, | ||
propertyParts.concat([propertyName]), | ||
)} | ||
${parentPropertyName}.setProperty(runtime, "${propertyName}", ${propertyName}); | ||
} | ||
`.trim(); | ||
default: | ||
@@ -157,5 +146,5 @@ typeAnnotation.type; | ||
const implementation = ` | ||
auto payload = jsi::Object(runtime); | ||
${generateSetters('payload', event.typeAnnotation.argument.properties, [])} | ||
return payload; | ||
auto $payload = jsi::Object(runtime); | ||
${generateSetters('$payload', event.typeAnnotation.argument.properties, [])} | ||
return $payload; | ||
`.trim(); | ||
@@ -162,0 +151,0 @@ if (!event.name.startsWith('on')) { |
@@ -36,5 +36,3 @@ /** | ||
namespace react { | ||
${componentEmitters} | ||
} // namespace react | ||
@@ -41,0 +39,0 @@ } // namespace facebook |
@@ -94,4 +94,4 @@ /** | ||
const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation'; | ||
const methodCallArgs = ['rt', ...args].join(', '); | ||
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(${methodCallArgs})`; | ||
const methodCallArgs = [' rt', ...args].join(',\n '); | ||
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\n${methodCallArgs}\n )`; | ||
return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${ | ||
@@ -172,3 +172,3 @@ isVoid | ||
if (optional) { | ||
condition = `count < ${index} || ${condition}`; | ||
condition = `count <= ${index} || ${condition}`; | ||
} | ||
@@ -175,0 +175,0 @@ return `${condition} ? std::nullopt : std::make_optional(${expression})`; |
@@ -108,3 +108,3 @@ /** | ||
public abstract class ${className} extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { | ||
public abstract class ${className} extends ReactContextBaseJavaModule implements TurboModule { | ||
public static final String NAME = "${jsName}"; | ||
@@ -492,3 +492,2 @@ | ||
'com.facebook.react.bridge.ReactMethod', | ||
'com.facebook.react.bridge.ReactModuleWithSpec', | ||
'com.facebook.react.turbomodule.core.interfaces.TurboModule', | ||
@@ -495,0 +494,0 @@ 'com.facebook.proguard.annotations.DoNotStrip', |
@@ -30,4 +30,7 @@ /** | ||
findNativeComponentType = _require7.findNativeComponentType, | ||
propertyNames = _require7.propertyNames, | ||
getCommandOptions = _require7.getCommandOptions, | ||
getOptions = _require7.getOptions; | ||
getOptions = _require7.getOptions, | ||
getCommandTypeNameAndOptionsExpression = | ||
_require7.getCommandTypeNameAndOptionsExpression; | ||
@@ -54,32 +57,3 @@ // $FlowFixMe[signature-verification-failure] there's no flowtype for AST | ||
const commandsTypeNames = namedExports | ||
.map(statement => { | ||
let callExpression; | ||
let calleeName; | ||
try { | ||
callExpression = statement.declaration.declarations[0].init; | ||
calleeName = callExpression.callee.name; | ||
} catch (e) { | ||
return; | ||
} | ||
if (calleeName !== 'codegenNativeCommands') { | ||
return; | ||
} | ||
// const statement.declaration.declarations[0].init | ||
if (callExpression.arguments.length !== 1) { | ||
throw new Error( | ||
'codegenNativeCommands must be passed options including the supported commands', | ||
); | ||
} | ||
const typeArgumentParam = callExpression.typeArguments.params[0]; | ||
if (typeArgumentParam.type !== 'GenericTypeAnnotation') { | ||
throw new Error( | ||
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias", | ||
); | ||
} | ||
return { | ||
commandTypeName: typeArgumentParam.id.name, | ||
commandOptionsExpression: callExpression.arguments[0], | ||
}; | ||
}) | ||
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser)) | ||
.filter(Boolean); | ||
@@ -89,12 +63,10 @@ throwIfMoreThanOneCodegenNativecommands(commandsTypeNames); | ||
} | ||
function getCommandProperties( | ||
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's | ||
* LTI update could not be added via codemod */ | ||
commandTypeName, | ||
types, | ||
commandOptions, | ||
) { | ||
function getCommandProperties(ast, parser) { | ||
const _findComponentConfig = findComponentConfig(ast, parser), | ||
commandTypeName = _findComponentConfig.commandTypeName, | ||
commandOptionsExpression = _findComponentConfig.commandOptionsExpression; | ||
if (commandTypeName == null) { | ||
return []; | ||
} | ||
const types = parser.getTypes(ast); | ||
const typeAlias = types[commandTypeName]; | ||
@@ -106,6 +78,4 @@ if (typeAlias.type !== 'InterfaceDeclaration') { | ||
} | ||
let properties; | ||
try { | ||
properties = typeAlias.body.properties; | ||
} catch (e) { | ||
const properties = parser.bodyProperties(typeAlias); | ||
if (!properties) { | ||
throw new Error( | ||
@@ -115,5 +85,4 @@ `Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`, | ||
} | ||
const flowPropertyNames = properties | ||
.map(property => property && property.key && property.key.name) | ||
.filter(Boolean); | ||
const flowPropertyNames = propertyNames(properties); | ||
const commandOptions = getCommandOptions(commandOptionsExpression); | ||
if (commandOptions == null || commandOptions.supportedCommands == null) { | ||
@@ -141,16 +110,9 @@ throw new Error( | ||
function buildComponentSchema(ast, parser) { | ||
const _findComponentConfig = findComponentConfig(ast, parser), | ||
componentName = _findComponentConfig.componentName, | ||
propsTypeName = _findComponentConfig.propsTypeName, | ||
commandTypeName = _findComponentConfig.commandTypeName, | ||
commandOptionsExpression = _findComponentConfig.commandOptionsExpression, | ||
optionsExpression = _findComponentConfig.optionsExpression; | ||
const _findComponentConfig2 = findComponentConfig(ast, parser), | ||
componentName = _findComponentConfig2.componentName, | ||
propsTypeName = _findComponentConfig2.propsTypeName, | ||
optionsExpression = _findComponentConfig2.optionsExpression; | ||
const types = parser.getTypes(ast); | ||
const propProperties = getProperties(propsTypeName, types); | ||
const commandOptions = getCommandOptions(commandOptionsExpression); | ||
const commandProperties = getCommandProperties( | ||
commandTypeName, | ||
types, | ||
commandOptions, | ||
); | ||
const commandProperties = getCommandProperties(ast, parser); | ||
const extendsProps = getExtendsProps(propProperties, types); | ||
@@ -157,0 +119,0 @@ const options = getOptions(optionsExpression); |
@@ -91,11 +91,6 @@ /** | ||
emitArrayType = _require3.emitArrayType, | ||
emitBoolean = _require3.emitBoolean, | ||
emitFunction = _require3.emitFunction, | ||
emitNumber = _require3.emitNumber, | ||
emitGenericObject = _require3.emitGenericObject, | ||
emitPromise = _require3.emitPromise, | ||
emitRootTag = _require3.emitRootTag, | ||
emitVoid = _require3.emitVoid, | ||
emitString = _require3.emitString, | ||
emitMixed = _require3.emitMixed, | ||
emitUnion = _require3.emitUnion, | ||
@@ -262,14 +257,2 @@ emitCommonTypes = _require3.emitCommonTypes, | ||
} | ||
case 'BooleanTypeAnnotation': { | ||
return emitBoolean(nullable); | ||
} | ||
case 'NumberTypeAnnotation': { | ||
return emitNumber(nullable); | ||
} | ||
case 'VoidTypeAnnotation': { | ||
return emitVoid(nullable); | ||
} | ||
case 'StringTypeAnnotation': { | ||
return emitString(nullable); | ||
} | ||
case 'FunctionTypeAnnotation': { | ||
@@ -299,9 +282,2 @@ return emitFunction( | ||
} | ||
case 'MixedTypeAnnotation': { | ||
if (cxxOnly) { | ||
return emitMixed(nullable); | ||
} else { | ||
return emitGenericObject(nullable); | ||
} | ||
} | ||
case 'EnumStringBody': | ||
@@ -319,7 +295,21 @@ case 'EnumNumberBody': { | ||
default: { | ||
throw new UnsupportedTypeAnnotationParserError( | ||
const commonType = emitCommonTypes( | ||
hasteModuleName, | ||
types, | ||
typeAnnotation, | ||
parser.language(), | ||
aliasMap, | ||
enumMap, | ||
tryParse, | ||
cxxOnly, | ||
nullable, | ||
parser, | ||
); | ||
if (!commonType) { | ||
throw new UnsupportedTypeAnnotationParserError( | ||
hasteModuleName, | ||
typeAnnotation, | ||
parser.language(), | ||
); | ||
} | ||
return commonType; | ||
} | ||
@@ -326,0 +316,0 @@ } |
@@ -88,3 +88,9 @@ /** | ||
nameForGenericTypeAnnotation(typeAnnotation) { | ||
return typeAnnotation.id.name; | ||
var _typeAnnotation$id; | ||
return typeAnnotation === null || typeAnnotation === void 0 | ||
? void 0 | ||
: (_typeAnnotation$id = typeAnnotation.id) === null || | ||
_typeAnnotation$id === void 0 | ||
? void 0 | ||
: _typeAnnotation$id.name; | ||
} | ||
@@ -212,2 +218,5 @@ checkIfInvalidModule(typeArguments) { | ||
} | ||
isGenericTypeAnnotation(type) { | ||
return type === 'GenericTypeAnnotation'; | ||
} | ||
extractAnnotatedElement(typeAnnotation, types) { | ||
@@ -305,2 +314,8 @@ return types[typeAnnotation.typeParameters.params[0].id.name]; | ||
} | ||
bodyProperties(typeAlias) { | ||
return typeAlias.body.properties; | ||
} | ||
convertKeywordToTypeAnnotation(keyword) { | ||
return keyword; | ||
} | ||
} | ||
@@ -307,0 +322,0 @@ module.exports = { |
@@ -161,2 +161,5 @@ /** | ||
} | ||
isGenericTypeAnnotation(type) { | ||
return true; | ||
} | ||
extractAnnotatedElement(typeAnnotation, types) { | ||
@@ -212,2 +215,8 @@ return types[typeAnnotation.typeParameters.params[0].id.name]; | ||
} | ||
bodyProperties(typeAlias) { | ||
return typeAlias.body.properties; | ||
} | ||
convertKeywordToTypeAnnotation(keyword) { | ||
return keyword; | ||
} | ||
} |
@@ -790,2 +790,36 @@ /** | ||
} | ||
function getCommandTypeNameAndOptionsExpression(namedExport, parser) { | ||
let callExpression; | ||
let calleeName; | ||
try { | ||
callExpression = namedExport.declaration.declarations[0].init; | ||
calleeName = callExpression.callee.name; | ||
} catch (e) { | ||
return; | ||
} | ||
if (calleeName !== 'codegenNativeCommands') { | ||
return; | ||
} | ||
if (callExpression.arguments.length !== 1) { | ||
throw new Error( | ||
'codegenNativeCommands must be passed options including the supported commands', | ||
); | ||
} | ||
const typeArgumentParam = | ||
parser.getTypeArgumentParamsFromDeclaration(callExpression)[0]; | ||
if (!parser.isGenericTypeAnnotation(typeArgumentParam.type)) { | ||
throw new Error( | ||
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias", | ||
); | ||
} | ||
return { | ||
commandTypeName: parser.nameForGenericTypeAnnotation(typeArgumentParam), | ||
commandOptionsExpression: callExpression.arguments[0], | ||
}; | ||
} | ||
function propertyNames(properties) { | ||
return properties | ||
.map(property => property && property.key && property.key.name) | ||
.filter(Boolean); | ||
} | ||
module.exports = { | ||
@@ -806,4 +840,6 @@ wrapModuleSchema, | ||
findNativeComponentType, | ||
propertyNames, | ||
getCommandOptions, | ||
getOptions, | ||
getCommandTypeNameAndOptionsExpression, | ||
}; |
@@ -465,2 +465,3 @@ /** | ||
function emitPartial( | ||
nullable, | ||
hasteModuleName, | ||
@@ -473,3 +474,2 @@ typeAnnotation, | ||
cxxOnly, | ||
nullable, | ||
parser, | ||
@@ -507,39 +507,41 @@ ) { | ||
) { | ||
const typeMap = { | ||
Stringish: emitStringish, | ||
Int32: emitInt32, | ||
Double: emitDouble, | ||
Float: emitFloat, | ||
UnsafeObject: emitGenericObject, | ||
Object: emitGenericObject, | ||
$Partial: emitPartial, | ||
Partial: emitPartial, | ||
BooleanTypeAnnotation: emitBoolean, | ||
NumberTypeAnnotation: emitNumber, | ||
VoidTypeAnnotation: emitVoid, | ||
StringTypeAnnotation: emitString, | ||
MixedTypeAnnotation: cxxOnly ? emitMixed : emitGenericObject, | ||
}; | ||
const typeAnnotationName = parser.convertKeywordToTypeAnnotation( | ||
typeAnnotation.type, | ||
); | ||
const simpleEmitter = typeMap[typeAnnotationName]; | ||
if (simpleEmitter) { | ||
return simpleEmitter(nullable); | ||
} | ||
const genericTypeAnnotationName = | ||
parser.nameForGenericTypeAnnotation(typeAnnotation); | ||
switch (genericTypeAnnotationName) { | ||
case 'Stringish': { | ||
return emitStringish(nullable); | ||
} | ||
case 'Int32': { | ||
return emitInt32(nullable); | ||
} | ||
case 'Double': { | ||
return emitDouble(nullable); | ||
} | ||
case 'Float': { | ||
return emitFloat(nullable); | ||
} | ||
case 'UnsafeObject': | ||
case 'Object': { | ||
return emitGenericObject(nullable); | ||
} | ||
case '$Partial': | ||
case 'Partial': { | ||
return emitPartial( | ||
hasteModuleName, | ||
typeAnnotation, | ||
types, | ||
aliasMap, | ||
enumMap, | ||
tryParse, | ||
cxxOnly, | ||
nullable, | ||
parser, | ||
); | ||
} | ||
default: { | ||
return null; | ||
} | ||
const emitter = typeMap[genericTypeAnnotationName]; | ||
if (!emitter) { | ||
return null; | ||
} | ||
return emitter( | ||
nullable, | ||
hasteModuleName, | ||
typeAnnotation, | ||
types, | ||
aliasMap, | ||
enumMap, | ||
tryParse, | ||
cxxOnly, | ||
parser, | ||
); | ||
} | ||
@@ -546,0 +548,0 @@ module.exports = { |
@@ -29,4 +29,7 @@ /** | ||
findNativeComponentType = _require7.findNativeComponentType, | ||
propertyNames = _require7.propertyNames, | ||
getCommandOptions = _require7.getCommandOptions, | ||
getOptions = _require7.getOptions; | ||
getOptions = _require7.getOptions, | ||
getCommandTypeNameAndOptionsExpression = | ||
_require7.getCommandTypeNameAndOptionsExpression; | ||
@@ -53,32 +56,3 @@ // $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser | ||
const commandsTypeNames = namedExports | ||
.map(statement => { | ||
let callExpression; | ||
let calleeName; | ||
try { | ||
callExpression = statement.declaration.declarations[0].init; | ||
calleeName = callExpression.callee.name; | ||
} catch (e) { | ||
return; | ||
} | ||
if (calleeName !== 'codegenNativeCommands') { | ||
return; | ||
} | ||
// const statement.declaration.declarations[0].init | ||
if (callExpression.arguments.length !== 1) { | ||
throw new Error( | ||
'codegenNativeCommands must be passed options including the supported commands', | ||
); | ||
} | ||
const typeArgumentParam = callExpression.typeParameters.params[0]; | ||
if (typeArgumentParam.type !== 'TSTypeReference') { | ||
throw new Error( | ||
"codegenNativeCommands doesn't support inline definitions. Specify a file local type alias", | ||
); | ||
} | ||
return { | ||
commandTypeName: typeArgumentParam.typeName.name, | ||
commandOptionsExpression: callExpression.arguments[0], | ||
}; | ||
}) | ||
.map(statement => getCommandTypeNameAndOptionsExpression(statement, parser)) | ||
.filter(Boolean); | ||
@@ -88,12 +62,10 @@ throwIfMoreThanOneCodegenNativecommands(commandsTypeNames); | ||
} | ||
function getCommandProperties( | ||
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's | ||
* LTI update could not be added via codemod */ | ||
commandTypeName, | ||
types, | ||
commandOptions, | ||
) { | ||
function getCommandProperties(ast, parser) { | ||
const _findComponentConfig = findComponentConfig(ast, parser), | ||
commandTypeName = _findComponentConfig.commandTypeName, | ||
commandOptionsExpression = _findComponentConfig.commandOptionsExpression; | ||
if (commandTypeName == null) { | ||
return []; | ||
} | ||
const types = parser.getTypes(ast); | ||
const typeAlias = types[commandTypeName]; | ||
@@ -105,6 +77,4 @@ if (typeAlias.type !== 'TSInterfaceDeclaration') { | ||
} | ||
let properties; | ||
try { | ||
properties = typeAlias.body.body; | ||
} catch (e) { | ||
const properties = parser.bodyProperties(typeAlias); | ||
if (!properties) { | ||
throw new Error( | ||
@@ -114,5 +84,4 @@ `Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen typescript file`, | ||
} | ||
const typeScriptPropertyNames = properties | ||
.map(property => property && property.key && property.key.name) | ||
.filter(Boolean); | ||
const typeScriptPropertyNames = propertyNames(properties); | ||
const commandOptions = getCommandOptions(commandOptionsExpression); | ||
if (commandOptions == null || commandOptions.supportedCommands == null) { | ||
@@ -143,16 +112,9 @@ throw new Error( | ||
function buildComponentSchema(ast, parser) { | ||
const _findComponentConfig = findComponentConfig(ast, parser), | ||
componentName = _findComponentConfig.componentName, | ||
propsTypeName = _findComponentConfig.propsTypeName, | ||
commandTypeName = _findComponentConfig.commandTypeName, | ||
commandOptionsExpression = _findComponentConfig.commandOptionsExpression, | ||
optionsExpression = _findComponentConfig.optionsExpression; | ||
const _findComponentConfig2 = findComponentConfig(ast, parser), | ||
componentName = _findComponentConfig2.componentName, | ||
propsTypeName = _findComponentConfig2.propsTypeName, | ||
optionsExpression = _findComponentConfig2.optionsExpression; | ||
const types = parser.getTypes(ast); | ||
const propProperties = getProperties(propsTypeName, types); | ||
const commandOptions = getCommandOptions(commandOptionsExpression); | ||
const commandProperties = getCommandProperties( | ||
commandTypeName, | ||
types, | ||
commandOptions, | ||
); | ||
const commandProperties = getCommandProperties(ast, parser); | ||
const options = getOptions(optionsExpression); | ||
@@ -159,0 +121,0 @@ const extendsProps = []; |
@@ -23,11 +23,6 @@ /** | ||
emitArrayType = _require5.emitArrayType, | ||
emitBoolean = _require5.emitBoolean, | ||
emitFunction = _require5.emitFunction, | ||
emitNumber = _require5.emitNumber, | ||
emitGenericObject = _require5.emitGenericObject, | ||
emitPromise = _require5.emitPromise, | ||
emitRootTag = _require5.emitRootTag, | ||
emitVoid = _require5.emitVoid, | ||
emitString = _require5.emitString, | ||
emitMixed = _require5.emitMixed, | ||
emitUnion = _require5.emitUnion, | ||
@@ -345,14 +340,2 @@ emitCommonTypes = _require5.emitCommonTypes, | ||
} | ||
case 'TSBooleanKeyword': { | ||
return emitBoolean(nullable); | ||
} | ||
case 'TSNumberKeyword': { | ||
return emitNumber(nullable); | ||
} | ||
case 'TSVoidKeyword': { | ||
return emitVoid(nullable); | ||
} | ||
case 'TSStringKeyword': { | ||
return emitString(nullable); | ||
} | ||
case 'TSFunctionType': { | ||
@@ -375,15 +358,22 @@ return emitFunction( | ||
} | ||
case 'TSUnknownKeyword': { | ||
if (cxxOnly) { | ||
return emitMixed(nullable); | ||
} | ||
// Fallthrough | ||
} | ||
default: { | ||
throw new UnsupportedTypeAnnotationParserError( | ||
const commonType = emitCommonTypes( | ||
hasteModuleName, | ||
types, | ||
typeAnnotation, | ||
parser.language(), | ||
aliasMap, | ||
enumMap, | ||
tryParse, | ||
cxxOnly, | ||
nullable, | ||
parser, | ||
); | ||
if (!commonType) { | ||
throw new UnsupportedTypeAnnotationParserError( | ||
hasteModuleName, | ||
typeAnnotation, | ||
parser.language(), | ||
); | ||
} | ||
return commonType; | ||
} | ||
@@ -390,0 +380,0 @@ } |
@@ -89,3 +89,9 @@ /** | ||
nameForGenericTypeAnnotation(typeAnnotation) { | ||
return typeAnnotation.typeName.name; | ||
var _typeAnnotation$typeN; | ||
return typeAnnotation === null || typeAnnotation === void 0 | ||
? void 0 | ||
: (_typeAnnotation$typeN = typeAnnotation.typeName) === null || | ||
_typeAnnotation$typeN === void 0 | ||
? void 0 | ||
: _typeAnnotation$typeN.name; | ||
} | ||
@@ -228,2 +234,5 @@ checkIfInvalidModule(typeArguments) { | ||
} | ||
isGenericTypeAnnotation(type) { | ||
return type === 'TSTypeReference'; | ||
} | ||
extractAnnotatedElement(typeAnnotation, types) { | ||
@@ -311,2 +320,20 @@ return types[typeAnnotation.typeParameters.params[0].typeName.name]; | ||
} | ||
bodyProperties(typeAlias) { | ||
return typeAlias.body.body; | ||
} | ||
convertKeywordToTypeAnnotation(keyword) { | ||
switch (keyword) { | ||
case 'TSBooleanKeyword': | ||
return 'BooleanTypeAnnotation'; | ||
case 'TSNumberKeyword': | ||
return 'NumberTypeAnnotation'; | ||
case 'TSVoidKeyword': | ||
return 'VoidTypeAnnotation'; | ||
case 'TSStringKeyword': | ||
return 'StringTypeAnnotation'; | ||
case 'TSUnknownKeyword': | ||
return 'MixedTypeAnnotation'; | ||
} | ||
return keyword; | ||
} | ||
} | ||
@@ -313,0 +340,0 @@ module.exports = { |
{ | ||
"name": "@react-native/codegen", | ||
"version": "0.72.4", | ||
"version": "0.73.0", | ||
"description": "⚛️ Code generation tools for React Native", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/react-native-codegen", |
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1447768
23409