@@ -15,16 +15,20 @@ function createNode(
1515 layoutSizingHorizontal,
1616 styledTextSegments = [ ] ,
1717 variantProperties,
18+ componentProperties,
19+ getMainComponentAsync,
1820 ...props
1921 } : {
2022 [ _ : string ] : any
2123 characters ?: string
2224 name ?: string
25+ componentProperties ?: ComponentProperties
2326 textStyleId ?: string
2427 children ?: SceneNode [ ]
2528 layoutPositioning ?: string
2629 styledTextSegments ?: any [ ]
2730 variantProperties ?: Record < string , string >
31+ getMainComponentAsync ?: ( ) => Promise < ComponentNode | null >
2832 } = { } ,
2933) : SceneNode {
3034 const ret = {
@@ -44,6 +48,8 @@ function createNode(
4448 fills,
4549 variantProperties,
4650 children : children ?? [ ] ,
51+ componentProperties,
52+ getMainComponentAsync : getMainComponentAsync ?? ( async ( ) => null ) ,
4753 } as unknown as SceneNode
4854 ; ( ret as any ) . children . forEach ( ( child : any ) => {
4955 ; ( child as any ) . parent = ret
@@ -1213,10 +1219,69 @@ describe('Element', () => {
12131219
12141220 describe ( 'Instance' , ( ) => {
12151221 it ( 'should render Instance' , async ( ) => {
1216- const element = createElement ( 'INSTANCE' , {
1217- name : 'Instance' ,
1218- } )
1219- expect ( await element . render ( ) ) . toEqual ( '<Instance />' )
1222+ {
1223+ const element = createElement ( 'INSTANCE' , {
1224+ name : 'Instance' ,
1225+ componentProperties : { } ,
1226+ } )
1227+ expect ( await element . render ( ) ) . toEqual ( '<Instance />' )
1228+ }
1229+ {
1230+ const element = createElement ( 'INSTANCE' , {
1231+ name : 'Instance' ,
1232+ componentProperties : {
1233+ children : { type : 'TEXT' , value : 'Hello' } ,
1234+ } ,
1235+ } )
1236+ expect ( await element . render ( ) ) . toEqual (
1237+ '<Instance>\n Hello\n</Instance>' ,
1238+ )
1239+ }
1240+ {
1241+ const element = createElement ( 'INSTANCE' , {
1242+ name : 'Instance' ,
1243+ componentProperties : {
1244+ children : { type : 'TEXT' , value : 'Hello' } ,
1245+ color : { type : 'TEXT' , value : 'red' } ,
1246+ width : { type : 'TEXT' , value : '100px' } ,
1247+ height : { type : 'TEXT' , value : '100px' } ,
1248+ danger : { type : 'BOOLEAN' , value : true } ,
1249+ } ,
1250+ } )
1251+ expect ( await element . render ( ) ) . toEqual (
1252+ '<Instance color="red" width="100px" height="100px" danger>\n Hello\n</Instance>' ,
1253+ )
1254+ }
1255+ {
1256+ const element = createElement ( 'INSTANCE' , {
1257+ name : 'Instance' ,
1258+ componentProperties : {
1259+ children : { type : 'TEXT' , value : 'Hello' } ,
1260+ color : { type : 'TEXT' , value : 'red' } ,
1261+ width : { type : 'TEXT' , value : '100px' } ,
1262+ height : { type : 'TEXT' , value : '100px' } ,
1263+ danger : { type : 'BOOLEAN' , value : true } ,
1264+ } ,
1265+ getMainComponentAsync : async ( ) =>
1266+ createNode ( 'COMPONENT' , {
1267+ name : 'MainComponent' ,
1268+ children : [ ] ,
1269+ } ) ,
1270+ } )
1271+ expect ( await element . render ( ) ) . toEqual (
1272+ `<Instance color="red" width="100px" height="100px" danger>
1273+ Hello
1274+ </Instance>
1275+
1276+ /*
1277+ export function MainComponent() {
1278+ return (
1279+ <Box />
1280+ )
1281+ }
1282+ */` ,
1283+ )
1284+ }
12201285 } )
12211286 } )
12221287
0 commit comments