fix(ivy): adding projectDef instructions to all templates where <ng-content> is present (FW-745) (#27384)

Prior to this change `projectDef` instructions were placed to root templates only, thus the necessary information (selectors) in nested templates was missing. This update adds the logic to insert `projectDef` instructions to all templates where <ng-content> is present.

PR Close #27384
This commit is contained in:
Andrew Kushnir
2018-11-30 15:01:37 -08:00
committed by Igor Minar
parent 8e644d99fc
commit f0b0d64453
7 changed files with 132 additions and 105 deletions

View File

@ -39,7 +39,7 @@ class R3AstHumanizer implements t.Visitor<void> {
}
visitContent(content: t.Content) {
this.result.push(['Content', content.selectorIndex]);
this.result.push(['Content', content.selector]);
t.visitAll(this, content.attributes);
}
@ -110,17 +110,15 @@ describe('R3 template transform', () => {
it('should parse ngContent', () => {
const res = parse('<ng-content select="a"></ng-content>');
expect(res.hasNgContent).toEqual(true);
expect(res.ngContentSelectors).toEqual(['a']);
expectFromR3Nodes(res.nodes).toEqual([
['Content', 1],
['Content', 'a'],
['TextAttribute', 'select', 'a'],
]);
});
it('should parse ngContent when it contains WS only', () => {
expectFromHtml('<ng-content select="a"> \n </ng-content>').toEqual([
['Content', 1],
['Content', 'a'],
['TextAttribute', 'select', 'a'],
]);
});
@ -128,7 +126,7 @@ describe('R3 template transform', () => {
it('should parse ngContent regardless the namespace', () => {
expectFromHtml('<svg><ng-content select="a"></ng-content></svg>').toEqual([
['Element', ':svg:svg'],
['Content', 1],
['Content', 'a'],
['TextAttribute', 'select', 'a'],
]);
});
@ -377,30 +375,16 @@ describe('R3 template transform', () => {
describe('ng-content', () => {
it('should parse ngContent without selector', () => {
const res = parse('<ng-content></ng-content>');
expect(res.hasNgContent).toEqual(true);
expect(res.ngContentSelectors).toEqual([]);
expectFromR3Nodes(res.nodes).toEqual([
['Content', 0],
]);
});
it('should parse ngContent with a * selector', () => {
const res = parse('<ng-content></ng-content>');
const selectors = [''];
expect(res.hasNgContent).toEqual(true);
expect(res.ngContentSelectors).toEqual([]);
expectFromR3Nodes(res.nodes).toEqual([
['Content', 0],
['Content', '*'],
]);
});
it('should parse ngContent with a specific selector', () => {
const res = parse('<ng-content select="tag[attribute]"></ng-content>');
const selectors = ['', 'tag[attribute]'];
expect(res.hasNgContent).toEqual(true);
expect(res.ngContentSelectors).toEqual(['tag[attribute]']);
expectFromR3Nodes(res.nodes).toEqual([
['Content', 1],
['Content', selectors[1]],
['TextAttribute', 'select', selectors[1]],
]);
});
@ -408,24 +392,20 @@ describe('R3 template transform', () => {
it('should parse ngContent with a selector', () => {
const res = parse(
'<ng-content select="a"></ng-content><ng-content></ng-content><ng-content select="b"></ng-content>');
const selectors = ['', 'a', 'b'];
expect(res.hasNgContent).toEqual(true);
expect(res.ngContentSelectors).toEqual(['a', 'b']);
const selectors = ['*', 'a', 'b'];
expectFromR3Nodes(res.nodes).toEqual([
['Content', 1],
['Content', selectors[1]],
['TextAttribute', 'select', selectors[1]],
['Content', 0],
['Content', 2],
['Content', selectors[0]],
['Content', selectors[2]],
['TextAttribute', 'select', selectors[2]],
]);
});
it('should parse ngProjectAs as an attribute', () => {
const res = parse('<ng-content ngProjectAs="a"></ng-content>');
expect(res.hasNgContent).toEqual(true);
expect(res.ngContentSelectors).toEqual([]);
expectFromR3Nodes(res.nodes).toEqual([
['Content', 0],
['Content', '*'],
['TextAttribute', 'ngProjectAs', 'a'],
]);
});