( node: Node, options: AngularToMitosisOptions, )
| 51 | const isBoundText = (node: Node): node is BoundText => typeof (node as any).value === 'object'; |
| 52 | |
| 53 | const angularTemplateNodeToMitosisNode = ( |
| 54 | node: Node, |
| 55 | options: AngularToMitosisOptions, |
| 56 | ): MitosisNode => { |
| 57 | if (isTemplate(node)) { |
| 58 | const ngIf = node.templateAttrs.find((item) => item.name === 'ngIf'); |
| 59 | if (ngIf) { |
| 60 | return createMitosisNode({ |
| 61 | name: 'Show', |
| 62 | bindings: { |
| 63 | when: createSingleBinding({ |
| 64 | code: transformBinding((ngIf.value as ASTWithSource).source!, options), |
| 65 | }), |
| 66 | }, |
| 67 | children: [angularTemplateNodeToMitosisNode(omit(node, 'templateAttrs'), options)], |
| 68 | }); |
| 69 | } |
| 70 | const ngFor = node.templateAttrs.find((item) => item.name === 'ngFor'); |
| 71 | if (ngFor) { |
| 72 | const value = (ngFor.value as ASTWithSource).source!; |
| 73 | const split = value.split(/let\s|\sof\s/); |
| 74 | const [_let, itemName, _of, expression] = split; |
| 75 | return createMitosisNode({ |
| 76 | name: 'For', |
| 77 | bindings: { |
| 78 | each: createSingleBinding({ code: transformBinding(expression, options) }), |
| 79 | }, |
| 80 | scope: { |
| 81 | forName: itemName, |
| 82 | }, |
| 83 | children: [angularTemplateNodeToMitosisNode(omit(node, 'templateAttrs'), options)], |
| 84 | }); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (isElement(node)) { |
| 89 | const properties: Record<string, string> = {}; |
| 90 | const bindings: Dictionary<Binding> = {}; |
| 91 | |
| 92 | for (const input of node.inputs) { |
| 93 | bindings[input.name] = createSingleBinding({ |
| 94 | code: transformBinding((input.value as ASTWithSource).source!, options), |
| 95 | }); |
| 96 | } |
| 97 | for (const output of node.outputs) { |
| 98 | bindings['on' + capitalize(output.name)] = createSingleBinding({ |
| 99 | code: transformBinding( |
| 100 | (output.handler as ASTWithSource) |
| 101 | .source! // TODO: proper reference replace |
| 102 | .replace(/\$event/g, 'event'), |
| 103 | options, |
| 104 | ), |
| 105 | }); |
| 106 | } |
| 107 | for (const attribute of node.attributes) { |
| 108 | properties[attribute.name] = attribute.value; |
| 109 | } |
| 110 |
no test coverage detected