mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add recursive types for Object types
Summary: We weren't adding the local imports recursively as well. This is a similar change as was made when creating the CppHelpers.getImports in D16759170. Reviewed By: rickhanlonii, JoshuaGross Differential Revision: D16840667 fbshipit-source-id: 1090a774c9e96798d5900bc0b4bf1be29b3ba090
This commit is contained in:
committed by
Facebook Github Bot
parent
84f148ba44
commit
2d937c63e4
@@ -17,7 +17,11 @@ const {
|
||||
getImports,
|
||||
} = require('./CppHelpers.js');
|
||||
|
||||
import type {PropTypeShape, SchemaType} from '../../CodegenSchema';
|
||||
import type {
|
||||
ExtendsPropsShape,
|
||||
PropTypeShape,
|
||||
SchemaType,
|
||||
} from '../../CodegenSchema';
|
||||
|
||||
// File path -> contents
|
||||
type FilesOutput = Map<string, string>;
|
||||
@@ -420,10 +424,12 @@ function generatePropsString(
|
||||
.join('\n' + ' ');
|
||||
}
|
||||
|
||||
function getLocalImports(component): Set<string> {
|
||||
function getExtendsImports(
|
||||
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
||||
): Set<string> {
|
||||
const imports: Set<string> = new Set();
|
||||
|
||||
component.extendsProps.forEach(extendProps => {
|
||||
extendsProps.forEach(extendProps => {
|
||||
switch (extendProps.type) {
|
||||
case 'ReactNativeBuiltInType':
|
||||
switch (extendProps.knownTypeName) {
|
||||
@@ -440,6 +446,14 @@ function getLocalImports(component): Set<string> {
|
||||
}
|
||||
});
|
||||
|
||||
return imports;
|
||||
}
|
||||
|
||||
function getLocalImports(
|
||||
properties: $ReadOnlyArray<PropTypeShape>,
|
||||
): Set<string> {
|
||||
const imports: Set<string> = new Set();
|
||||
|
||||
function addImportsForNativeName(name) {
|
||||
switch (name) {
|
||||
case 'ColorPrimitive':
|
||||
@@ -459,7 +473,7 @@ function getLocalImports(component): Set<string> {
|
||||
}
|
||||
}
|
||||
|
||||
component.props.forEach(prop => {
|
||||
properties.forEach(prop => {
|
||||
const typeAnnotation = prop.typeAnnotation;
|
||||
|
||||
if (typeAnnotation.type === 'NativePrimitiveTypeAnnotation') {
|
||||
@@ -483,7 +497,9 @@ function getLocalImports(component): Set<string> {
|
||||
if (typeAnnotation.type === 'ObjectTypeAnnotation') {
|
||||
imports.add('#include <react/core/propsConversions.h>');
|
||||
const objectImports = getImports(typeAnnotation.properties);
|
||||
const localImports = getLocalImports(typeAnnotation.properties);
|
||||
objectImports.forEach(imports.add, imports);
|
||||
localImports.forEach(imports.add, imports);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -631,8 +647,10 @@ module.exports = {
|
||||
component.props,
|
||||
);
|
||||
const extendString = getClassExtendString(component);
|
||||
const imports = getLocalImports(component);
|
||||
const extendsImports = getExtendsImports(component.extendsProps);
|
||||
const imports = getLocalImports(component.props);
|
||||
|
||||
extendsImports.forEach(allImports.add, allImports);
|
||||
imports.forEach(allImports.add, allImports);
|
||||
|
||||
const replacedTemplate = classTemplate
|
||||
|
||||
+4
@@ -658,6 +658,10 @@ Map {
|
||||
#include <react/components/image/conversions.h>
|
||||
#include <react/components/view/ViewProps.h>
|
||||
#include <react/core/propsConversions.h>
|
||||
#include <react/graphics/Color.h>
|
||||
#include <react/graphics/Geometry.h>
|
||||
#include <react/imagemanager/primitives.h>
|
||||
#include <vector>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
Reference in New Issue
Block a user