Skip to content

Commit

Permalink
feat: add react attr generation for collectionBindingProperties (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch authored Sep 10, 2021
1 parent 4f492cd commit 33390ed
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,17 @@ export function buildOpeningElementAttributes(
prop.defaultValue === undefined
? buildCollectionBindingAttr(prop, propName)
: buildCollectionBindingAttrWithDefault(prop, propName, prop.defaultValue);
return attr;
}
return factory.createJsxAttribute(factory.createIdentifier(propName), undefined);
}

export function buildCollectionBindingAttr(prop: CollectionStudioComponentProperty, propName: string): JsxAttribute {
const expr =
prop.collectionBindingProperties.field === undefined
? factory.createIdentifier(prop.collectionBindingProperties.property)
? factory.createIdentifier('item')
: factory.createPropertyAccessExpression(
factory.createIdentifier(prop.collectionBindingProperties.property),
factory.createIdentifier('item'),
prop.collectionBindingProperties.field,
);

Expand All @@ -176,9 +177,9 @@ export function buildCollectionBindingAttrWithDefault(
const rightExpr = factory.createStringLiteral(defaultValue);
const leftExpr =
prop.collectionBindingProperties.field === undefined
? factory.createIdentifier(prop.collectionBindingProperties.property)
? factory.createIdentifier('item')
: factory.createPropertyAccessExpression(
factory.createIdentifier(prop.collectionBindingProperties.property),
factory.createIdentifier('item'),
prop.collectionBindingProperties.field,
);

Expand Down

0 comments on commit 33390ed

Please sign in to comment.