MCPcopy
hub / github.com/BuilderIO/mitosis / angularTemplateNodeToMitosisNode

Function angularTemplateNodeToMitosisNode

packages/core/src/parsers/angular.ts:53–137  ·  view source on GitHub ↗
(
  node: Node,
  options: AngularToMitosisOptions,
)

Source from the content-addressed store, hash-verified

51const isBoundText = (node: Node): node is BoundText => typeof (node as any).value === 'object';
52
53const 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

Callers 1

Calls 8

createMitosisNodeFunction · 0.90
createSingleBindingFunction · 0.90
capitalizeFunction · 0.90
isTemplateFunction · 0.85
transformBindingFunction · 0.85
isElementFunction · 0.85
isTextFunction · 0.85
isBoundTextFunction · 0.85

Tested by

no test coverage detected