Skip to content

Commit f634490

Browse files
committed
fixup! refactor(compiler): support passing content to specific foreign component props
1 parent 146e109 commit f634490

1 file changed

Lines changed: 40 additions & 24 deletions

File tree

  • packages/compiler/src/template/pipeline/src

packages/compiler/src/template/pipeline/src/ingest.ts

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -313,34 +313,24 @@ function ingestElement(unit: ViewCompilationUnit, element: t.Element): void {
313313
}
314314

315315
for (const block of contentBlocks) {
316-
const blockView = unit.job.allocateView(unit.xref);
317-
ingestNodes(blockView, block.children);
318-
319-
unit.create.push(
320-
ir.createContentOp(
321-
id,
322-
block.name,
323-
blockView.xref,
324-
block.name.charAt(0).toUpperCase() + block.name.slice(1),
325-
block.startSourceSpan,
326-
block.sourceSpan,
327-
),
316+
ingestForeignContentBlock(
317+
unit,
318+
id,
319+
block.name,
320+
block.children,
321+
block.startSourceSpan,
322+
block.sourceSpan,
328323
);
329324
}
330325

331326
if (childNodes.length > 0) {
332-
const childView = unit.job.allocateView(unit.xref);
333-
ingestNodes(childView, childNodes);
334-
335-
unit.create.push(
336-
ir.createContentOp(
337-
id,
338-
'children',
339-
childView.xref,
340-
'Children',
341-
element.startSourceSpan,
342-
element.sourceSpan,
343-
),
327+
ingestForeignContentBlock(
328+
unit,
329+
id,
330+
'children',
331+
childNodes,
332+
element.startSourceSpan,
333+
element.sourceSpan,
344334
);
345335
}
346336

@@ -395,6 +385,32 @@ function ingestElement(unit: ViewCompilationUnit, element: t.Element): void {
395385
}
396386
}
397387

388+
/**
389+
* Ingest a content block for a foreign component.
390+
*/
391+
function ingestForeignContentBlock(
392+
unit: ViewCompilationUnit,
393+
targetId: ir.XrefId,
394+
propertyName: string,
395+
childNodes: t.Node[],
396+
startSourceSpan: ParseSourceSpan,
397+
sourceSpan: ParseSourceSpan,
398+
): void {
399+
const childView = unit.job.allocateView(unit.xref);
400+
ingestNodes(childView, childNodes);
401+
402+
unit.create.push(
403+
ir.createContentOp(
404+
targetId,
405+
propertyName,
406+
childView.xref,
407+
propertyName.charAt(0).toUpperCase + propertyName.slice(1),
408+
startSourceSpan,
409+
sourceSpan,
410+
),
411+
);
412+
}
413+
398414
/**
399415
* Ingest an `ng-template` node from the AST into the given `ViewCompilation`.
400416
*/

0 commit comments

Comments
 (0)