Socket
Book a DemoInstallSign in
Socket

@react-native/codegen

Package Overview
Dependencies
Maintainers
10
Versions
779
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-native/codegen - npm Package Compare versions

Comparing version

to
0.73.0-nightly-20230605-5062553c6

19

lib/parsers/flow/components/componentsUtils.js

@@ -15,12 +15,2 @@ /**

getValueFromTypes = _require.getValueFromTypes;
function getProperties(typeName, types) {
const typeAlias = types[typeName];
try {
return typeAlias.right.typeParameters.params[0].properties;
} catch (e) {
throw new Error(
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
);
}
}
function getTypeAnnotationForArray(

@@ -57,2 +47,3 @@ name,

types,
parser,
)

@@ -77,2 +68,3 @@ .map(prop => buildSchema(prop, types, parser))

types,
parser,
)

@@ -176,3 +168,3 @@ .map(prop => buildSchema(prop, types, parser))

}
function flattenProperties(typeDefinition, types) {
function flattenProperties(typeDefinition, types, parser) {
return typeDefinition

@@ -184,4 +176,5 @@ .map(property => {

return flattenProperties(
getProperties(property.argument.id.name, types),
parser.getProperties(property.argument.id.name, types),
types,
parser,
);

@@ -246,2 +239,3 @@ }

types,
parser,
)

@@ -462,3 +456,2 @@ .map(prop => buildSchema(prop, types, parser))

module.exports = {
getProperties,
getSchemaInfo,

@@ -465,0 +458,0 @@ getTypeAnnotation,

@@ -23,3 +23,4 @@ /**

emitFloatProp = _require3.emitFloatProp,
emitStringProp = _require3.emitStringProp;
emitStringProp = _require3.emitStringProp,
emitInt32Prop = _require3.emitInt32Prop;
function getPropertyType(

@@ -40,9 +41,3 @@ /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's

case 'Int32':
return {
name,
optional,
typeAnnotation: {
type: 'Int32TypeAnnotation',
},
};
return emitInt32Prop(name, optional);
case 'Double':

@@ -49,0 +44,0 @@ return emitDoubleProp(name, optional);

@@ -17,57 +17,15 @@ /**

getEvents = _require2.getEvents;
const _require3 = require('./componentsUtils.js'),
getProperties = _require3.getProperties;
const _require4 = require('../../error-utils'),
throwIfTypeAliasIsNotInterface = _require4.throwIfTypeAliasIsNotInterface;
const _require5 = require('../../parsers-commons'),
propertyNames = _require5.propertyNames,
getCommandOptions = _require5.getCommandOptions,
getOptions = _require5.getOptions,
findComponentConfig = _require5.findComponentConfig;
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];
throwIfTypeAliasIsNotInterface(typeAlias, parser);
const properties = parser.bodyProperties(typeAlias);
if (!properties) {
throw new Error(
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
);
}
const flowPropertyNames = propertyNames(properties);
const commandOptions = getCommandOptions(commandOptionsExpression);
if (commandOptions == null || commandOptions.supportedCommands == null) {
throw new Error(
'codegenNativeCommands must be given an options object with supportedCommands array',
);
}
if (
commandOptions.supportedCommands.length !== flowPropertyNames.length ||
!commandOptions.supportedCommands.every(supportedCommand =>
flowPropertyNames.includes(supportedCommand),
)
) {
throw new Error(
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${flowPropertyNames.join(
', ',
)}`,
);
}
return properties;
}
const _require3 = require('../../parsers-commons'),
getOptions = _require3.getOptions,
findComponentConfig = _require3.findComponentConfig,
getCommandProperties = _require3.getCommandProperties;
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
function buildComponentSchema(ast, parser) {
const _findComponentConfig2 = findComponentConfig(ast, parser),
componentName = _findComponentConfig2.componentName,
propsTypeName = _findComponentConfig2.propsTypeName,
optionsExpression = _findComponentConfig2.optionsExpression;
const _findComponentConfig = findComponentConfig(ast, parser),
componentName = _findComponentConfig.componentName,
propsTypeName = _findComponentConfig.propsTypeName,
optionsExpression = _findComponentConfig.optionsExpression;
const types = parser.getTypes(ast);
const propProperties = getProperties(propsTypeName, types);
const propProperties = parser.getProperties(propsTypeName, types);
const commandProperties = getCommandProperties(ast, parser);

@@ -74,0 +32,0 @@ const _parser$getProps = parser.getProps(propProperties, types),

@@ -446,3 +446,3 @@ /**

const nonExtendsProps = this.removeKnownExtends(typeDefinition, types);
const props = flattenProperties(nonExtendsProps, types)
const props = flattenProperties(nonExtendsProps, types, this)
.map(property => buildPropSchema(property, types, this))

@@ -455,2 +455,12 @@ .filter(Boolean);

}
getProperties(typeName, types) {
const typeAlias = types[typeName];
try {
return typeAlias.right.typeParameters.params[0].properties;
} catch (e) {
throw new Error(
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
);
}
}
}

@@ -457,0 +467,0 @@ module.exports = {

@@ -366,3 +366,3 @@ /**

const nonExtendsProps = this.removeKnownExtends(typeDefinition, types);
const props = flattenProperties(nonExtendsProps, types)
const props = flattenProperties(nonExtendsProps, types, this)
.map(property => buildPropSchema(property, types, this))

@@ -375,2 +375,12 @@ .filter(Boolean);

}
getProperties(typeName, types) {
const typeAlias = types[typeName];
try {
return typeAlias.right.typeParameters.params[0].properties;
} catch (e) {
throw new Error(
`Failed to find type definition for "${typeName}", please check that you have a valid codegen flow file`,
);
}
}
}

@@ -176,3 +176,4 @@ /**

throwIfConfigNotfound = _require2.throwIfConfigNotfound,
throwIfMoreThanOneConfig = _require2.throwIfMoreThanOneConfig;
throwIfMoreThanOneConfig = _require2.throwIfMoreThanOneConfig,
throwIfTypeAliasIsNotInterface = _require2.throwIfTypeAliasIsNotInterface;
const _require3 = require('./errors'),

@@ -904,2 +905,41 @@ MissingTypeParameterGenericParserError =

}
// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
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];
throwIfTypeAliasIsNotInterface(typeAlias, parser);
const properties = parser.bodyProperties(typeAlias);
if (!properties) {
throw new Error(
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen file`,
);
}
const commandPropertyNames = propertyNames(properties);
const commandOptions = getCommandOptions(commandOptionsExpression);
if (commandOptions == null || commandOptions.supportedCommands == null) {
throw new Error(
'codegenNativeCommands must be given an options object with supportedCommands array',
);
}
if (
commandOptions.supportedCommands.length !== commandPropertyNames.length ||
!commandOptions.supportedCommands.every(supportedCommand =>
commandPropertyNames.includes(supportedCommand),
)
) {
throw new Error(
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${commandPropertyNames.join(
', ',
)}`,
);
}
return properties;
}
module.exports = {

@@ -928,2 +968,3 @@ wrapModuleSchema,

findComponentConfig,
getCommandProperties,
};

@@ -113,2 +113,11 @@ /**

}
function emitInt32Prop(name, optional) {
return {
name,
optional,
typeAnnotation: {
type: 'Int32TypeAnnotation',
},
};
}
function emitNumber(nullable) {

@@ -598,2 +607,3 @@ return wrapNullable(nullable, {

emitInt32,
emitInt32Prop,
emitNumber,

@@ -600,0 +610,0 @@ emitGenericObject,

@@ -16,33 +16,2 @@ /**

flattenIntersectionType = _require.flattenIntersectionType;
function getProperties(typeName, types) {
const alias = types[typeName];
if (!alias) {
throw new Error(
`Failed to find definition for "${typeName}", please check that you have a valid codegen typescript file`,
);
}
const aliasKind =
alias.type === 'TSInterfaceDeclaration' ? 'interface' : 'type';
try {
if (aliasKind === 'interface') {
var _alias$extends;
return [
...((_alias$extends = alias.extends) !== null &&
_alias$extends !== void 0
? _alias$extends
: []),
...alias.body.body,
];
}
return (
alias.typeAnnotation.members ||
alias.typeAnnotation.typeParameters.params[0].members ||
alias.typeAnnotation.typeParameters.params
);
} catch (e) {
throw new Error(
`Failed to find ${aliasKind} definition for "${typeName}", please check that you have a valid codegen typescript file`,
);
}
}
function getUnionOfLiterals(name, forArray, elementTypes, defaultValue, types) {

@@ -171,3 +140,3 @@ var _elementTypes$0$liter, _elementTypes$0$liter2;

function buildObjectType(rawProperties, types, parser, buildSchema) {
const flattenedProperties = flattenProperties(rawProperties, types);
const flattenedProperties = flattenProperties(rawProperties, types, parser);
const properties = flattenedProperties

@@ -460,3 +429,3 @@ .map(prop => buildSchema(prop, types, parser))

}
function flattenProperties(typeDefinition, types) {
function flattenProperties(typeDefinition, types, parser) {
return typeDefinition

@@ -468,4 +437,5 @@ .map(property => {

return flattenProperties(
getProperties(property.typeName.name, types),
parser.getProperties(property.typeName.name, types),
types,
parser,
);

@@ -477,11 +447,16 @@ } else if (

return flattenProperties(
getProperties(property.expression.name, types),
parser.getProperties(property.expression.name, types),
types,
parser,
);
} else if (property.type === 'TSTypeLiteral') {
return flattenProperties(property.members, types);
return flattenProperties(property.members, types, parser);
} else if (property.type === 'TSInterfaceDeclaration') {
return flattenProperties(getProperties(property.id.name, types), types);
return flattenProperties(
parser.getProperties(property.id.name, types),
types,
parser,
);
} else if (property.type === 'TSIntersectionType') {
return flattenProperties(property.types, types);
return flattenProperties(property.types, types, parser);
} else {

@@ -509,3 +484,2 @@ throw new Error(

module.exports = {
getProperties,
getSchemaInfo,

@@ -512,0 +486,0 @@ getTypeAnnotation,

@@ -27,3 +27,4 @@ /**

emitFloatProp = _require5.emitFloatProp,
emitStringProp = _require5.emitStringProp;
emitStringProp = _require5.emitStringProp,
emitInt32Prop = _require5.emitInt32Prop;
function getPropertyType(

@@ -52,9 +53,3 @@ /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's

case 'Int32':
return {
name,
optional,
typeAnnotation: {
type: 'Int32TypeAnnotation',
},
};
return emitInt32Prop(name, optional);
case 'Double':

@@ -178,3 +173,3 @@ return emitDoubleProp(name, optional);

return {
argumentProps: flattenProperties([typeAnnotation], types),
argumentProps: flattenProperties([typeAnnotation], types, parser),
paperTopLevelNameDeprecated: paperName,

@@ -181,0 +176,0 @@ bubblingType,

@@ -19,49 +19,6 @@ /**

categorizeProps = _require3.categorizeProps;
const _require4 = require('./componentsUtils.js'),
getProperties = _require4.getProperties;
const _require5 = require('../../error-utils'),
throwIfTypeAliasIsNotInterface = _require5.throwIfTypeAliasIsNotInterface;
const _require6 = require('../../parsers-commons'),
propertyNames = _require6.propertyNames,
getCommandOptions = _require6.getCommandOptions,
getOptions = _require6.getOptions,
findComponentConfig = _require6.findComponentConfig;
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];
throwIfTypeAliasIsNotInterface(typeAlias, parser);
const properties = parser.bodyProperties(typeAlias);
if (!properties) {
throw new Error(
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen typescript file`,
);
}
const typeScriptPropertyNames = propertyNames(properties);
const commandOptions = getCommandOptions(commandOptionsExpression);
if (commandOptions == null || commandOptions.supportedCommands == null) {
throw new Error(
'codegenNativeCommands must be given an options object with supportedCommands array',
);
}
if (
commandOptions.supportedCommands.length !==
typeScriptPropertyNames.length ||
!commandOptions.supportedCommands.every(supportedCommand =>
typeScriptPropertyNames.includes(supportedCommand),
)
) {
throw new Error(
`codegenNativeCommands expected the same supportedCommands specified in the ${commandTypeName} interface: ${typeScriptPropertyNames.join(
', ',
)}`,
);
}
return properties;
}
const _require4 = require('../../parsers-commons'),
getOptions = _require4.getOptions,
findComponentConfig = _require4.findComponentConfig,
getCommandProperties = _require4.getCommandProperties;

@@ -72,8 +29,8 @@ // $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser

function buildComponentSchema(ast, parser) {
const _findComponentConfig2 = findComponentConfig(ast, parser),
componentName = _findComponentConfig2.componentName,
propsTypeName = _findComponentConfig2.propsTypeName,
optionsExpression = _findComponentConfig2.optionsExpression;
const _findComponentConfig = findComponentConfig(ast, parser),
componentName = _findComponentConfig.componentName,
propsTypeName = _findComponentConfig.propsTypeName,
optionsExpression = _findComponentConfig.optionsExpression;
const types = parser.getTypes(ast);
const propProperties = getProperties(propsTypeName, types);
const propProperties = parser.getProperties(propsTypeName, types);
const commandProperties = getCommandProperties(ast, parser);

@@ -80,0 +37,0 @@ const options = getOptions(optionsExpression);

@@ -263,3 +263,3 @@ /**

nullable,
flattenProperties([typeAnnotation], types),
flattenProperties([typeAnnotation], types, parser),
typeResolutionStatus,

@@ -282,2 +282,3 @@ baseTypes,

types,
parser,
),

@@ -284,0 +285,0 @@ typeResolutionStatus,

@@ -475,3 +475,3 @@ /**

// find events and props
for (const prop of flattenProperties(remaining, types)) {
for (const prop of flattenProperties(remaining, types, this)) {
const topLevelType = parseTopLevelType(

@@ -496,2 +496,33 @@ prop.typeAnnotation.typeAnnotation,

}
getProperties(typeName, types) {
const alias = types[typeName];
if (!alias) {
throw new Error(
`Failed to find definition for "${typeName}", please check that you have a valid codegen typescript file`,
);
}
const aliasKind =
alias.type === 'TSInterfaceDeclaration' ? 'interface' : 'type';
try {
if (aliasKind === 'interface') {
var _alias$extends;
return [
...((_alias$extends = alias.extends) !== null &&
_alias$extends !== void 0
? _alias$extends
: []),
...alias.body.body,
];
}
return (
alias.typeAnnotation.members ||
alias.typeAnnotation.typeParameters.params[0].members ||
alias.typeAnnotation.typeParameters.params
);
} catch (e) {
throw new Error(
`Failed to find ${aliasKind} definition for "${typeName}", please check that you have a valid codegen typescript file`,
);
}
}
}

@@ -498,0 +529,0 @@ module.exports = {

{
"name": "@react-native/codegen",
"version": "0.73.0-nightly-20230603-fd9e295be",
"version": "0.73.0-nightly-20230605-5062553c6",
"description": "Code generation tools for React Native",

@@ -5,0 +5,0 @@ "license": "MIT",

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.