refactor(ivy): misc cleanup (#23441)

PR Close #23441
This commit is contained in:
Victor Berchet 2018-04-16 11:49:11 -07:00
parent c6b206ee4b
commit 84f024309a
2 changed files with 20 additions and 19 deletions

View File

@ -575,15 +575,20 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver {
// TemplateAstVisitor
visitNgContent(ngContent: NgContentAst) {
const info = this._contentProjections.get(ngContent) !;
info ||
error(`Expected ${ngContent.sourceSpan} to be included in content projection collection`);
const slot = this.allocateDataSlot();
const parameters = [o.literal(slot), o.literal(this._projectionDefinitionIndex)];
if (info.index !== 0) {
parameters.push(o.literal(info.index));
const info = this._contentProjections.get(ngContent);
if (!info) {
error(`Expected ${ngContent.sourceSpan} to be included in content projection collection`);
} else {
const slot = this.allocateDataSlot();
const parameters = [
o.literal(slot),
o.literal(this._projectionDefinitionIndex),
];
if (info.index !== 0) {
parameters.push(o.literal(info.index));
}
this.instruction(this._creationMode, ngContent.sourceSpan, R3.projection, ...parameters);
}
this.instruction(this._creationMode, ngContent.sourceSpan, R3.projection, ...parameters);
}
// TemplateAstVisitor

View File

@ -1722,32 +1722,28 @@ function appendToProjectionNode(
* @param nodeIndex
* @param localIndex - index under which distribution of projected nodes was memorized
* @param selectorIndex - 0 means <ng-content> without any selector
* @param attrs - attributes attached to the ng-content node, if present
*/
export function projection(
nodeIndex: number, localIndex: number, selectorIndex: number = 0, attrs?: string[]): void {
export function projection(nodeIndex: number, localIndex: number, selectorIndex: number = 0): void {
const node = createLNode(nodeIndex, LNodeType.Projection, null, {head: null, tail: null});
if (node.tNode == null) {
node.tNode = createTNode(null, attrs || null, null);
}
isParent = false; // self closing
// `<ng-content>` has no content
isParent = false;
const currentParent = node.parent;
// re-distribution of projectable nodes is memorized on a component's view level
const componentNode = findComponentHost(currentView);
// make sure that nodes to project were memorized
const nodesForSelector = componentNode.data !.data ![localIndex][selectorIndex];
const componentLView = componentNode.data !;
const nodesForSelector = componentLView.data ![localIndex][selectorIndex];
// build the linked list of projected nodes:
for (let i = 0; i < nodesForSelector.length; i++) {
const nodeToProject = nodesForSelector[i];
if (nodeToProject.type === LNodeType.Projection) {
// Reprojecting a projection -> append the list of previously projected nodes
const previouslyProjected = (nodeToProject as LProjectionNode).data;
appendToProjectionNode(node, previouslyProjected.head, previouslyProjected.tail);
} else {
// Projecting a single node
appendToProjectionNode(
node, nodeToProject as LTextNode | LElementNode | LContainerNode,
nodeToProject as LTextNode | LElementNode | LContainerNode);