@@ -541,6 +541,17 @@ describe('compiler compliance', () => {
541
541
const MyComponentDefinition = `
542
542
const $c1$ = ["foo", ""];
543
543
const $c2$ = ["if", ""];
544
+ function MyComponent_li_Template_2(rf, ctx0, ctx) {
545
+ if (rf & 1) {
546
+ $r3$.ɵE(0, "li");
547
+ $r3$.ɵT(1);
548
+ $r3$.ɵe();
549
+ }
550
+ if (rf & 2) {
551
+ const $foo$ = $r3$.ɵr(1, 1);
552
+ $r3$.ɵt(1, $r3$.ɵi2("", ctx.salutation, " ", $foo$, ""));
553
+ }
554
+ }
544
555
…
545
556
MyComponent.ngComponentDef = $r3$.ɵdefineComponent({
546
557
type: MyComponent,
@@ -552,17 +563,6 @@ describe('compiler compliance', () => {
552
563
$r3$.ɵC(2, MyComponent_li_Template_2, null, $c2$);
553
564
$r3$.ɵe();
554
565
}
555
- const $foo$ = $r3$.ɵld(1);
556
- function MyComponent_li_Template_2(rf, ctx0) {
557
- if (rf & 1) {
558
- $r3$.ɵE(0, "li");
559
- $r3$.ɵT(1);
560
- $r3$.ɵe();
561
- }
562
- if (rf & 2) {
563
- $r3$.ɵt(1, $r3$.ɵi2("", ctx.salutation, " ", $foo$, ""));
564
- }
565
- }
566
566
},
567
567
directives:[IfDirective]
568
568
});` ;
@@ -1173,8 +1173,8 @@ describe('compiler compliance', () => {
1173
1173
$r3$.ɵEe(0, "input", null, $c1$);
1174
1174
$r3$.ɵT(2);
1175
1175
}
1176
- const $user$ = $r3$.ɵld(1);
1177
1176
if (rf & 2) {
1177
+ const $user$ = $r3$.ɵld(1);
1178
1178
$r3$.ɵt(2, $r3$.ɵi1("Hello ", $user$.value, "!"));
1179
1179
}
1180
1180
}
@@ -1187,6 +1187,97 @@ describe('compiler compliance', () => {
1187
1187
expectEmit ( source , MyComponentDefinition , 'Incorrect MyComponent.ngComponentDef' ) ;
1188
1188
} ) ;
1189
1189
1190
+ it ( 'local references in nested views' , ( ) => {
1191
+ const files = {
1192
+ app : {
1193
+ 'spec.ts' : `
1194
+ import {Component, Directive, NgModule, TemplateRef} from '@angular/core';
1195
+
1196
+ @Directive({selector: '[if]'})
1197
+ export class IfDirective {
1198
+ constructor(template: TemplateRef<any>) { }
1199
+ }
1200
+
1201
+ @Component({
1202
+ selector: 'my-component',
1203
+ template: \`
1204
+ <div #foo></div>
1205
+ {{foo}}
1206
+ <div *if>
1207
+ {{foo}}-{{bar}}
1208
+ <span *if>{{foo}}-{{bar}}-{{baz}}</span>
1209
+ <span #bar></span>
1210
+ </div>
1211
+ <div #baz></div>
1212
+ \`
1213
+ })
1214
+ export class MyComponent {}
1215
+
1216
+ @NgModule({declarations: [IfDirective, MyComponent]})
1217
+ export class MyModule {}
1218
+ `
1219
+ }
1220
+ } ;
1221
+
1222
+ const MyComponentDefinition = `
1223
+ const $c1$ = ["foo", ""];
1224
+ const $c2$ = ["if", ""];
1225
+ const $c3$ = ["baz", ""];
1226
+ const $c4$ = ["bar", ""];
1227
+ function MyComponent_div_span_Template_2(rf, ctx1, ctx0, ctx) {
1228
+ if (rf & 1) {
1229
+ $r3$.ɵE(0, "span");
1230
+ $r3$.ɵT(1);
1231
+ $r3$.ɵe();
1232
+ }
1233
+ if (rf & 2) {
1234
+ const $foo$ = $r3$.ɵr(2, 1);
1235
+ const $bar$ = $r3$.ɵr(1, 4);
1236
+ const $baz$ = $r3$.ɵr(2, 5);
1237
+ $r3$.ɵt(1, $r3$.ɵi3("", $foo$, "-", $bar$, "-", $baz$, ""));
1238
+ }
1239
+ }
1240
+ function MyComponent_div_Template_3(rf, ctx0, ctx) {
1241
+ if (rf & 1) {
1242
+ $r3$.ɵE(0, "div");
1243
+ $r3$.ɵT(1);
1244
+ $r3$.ɵC(2, MyComponent_div_span_Template_2, null, $c2$);
1245
+ $r3$.ɵEe(3, "span", null, $c4$);
1246
+ $r3$.ɵe();
1247
+ }
1248
+ if (rf & 2) {
1249
+ const $foo$ = $r3$.ɵr(1, 1);
1250
+ const $bar$ = $r3$.ɵld(4);
1251
+ $r3$.ɵt(1, $r3$.ɵi2(" ", $foo$, "-", $bar$, " "));
1252
+ }
1253
+ }
1254
+ …
1255
+ MyComponent.ngComponentDef = $r3$.ɵdefineComponent({
1256
+ type: MyComponent,
1257
+ selectors: [["my-component"]],
1258
+ factory: function MyComponent_Factory() { return new MyComponent(); },
1259
+ template: function MyComponent_Template(rf, ctx) {
1260
+ if (rf & 1) {
1261
+ $r3$.ɵEe(0, "div", null, $c1$);
1262
+ $r3$.ɵT(2);
1263
+ $r3$.ɵC(3, MyComponent_div_Template_3, null, $c2$);
1264
+ $r3$.ɵEe(4, "div", null, $c3$);
1265
+ }
1266
+ if (rf & 2) {
1267
+ const $foo$ = $r3$.ɵld(1);
1268
+ $r3$.ɵt(2, $r3$.ɵi1(" ", $foo$, " "));
1269
+ }
1270
+ },
1271
+ directives:[IfDirective]
1272
+ });` ;
1273
+
1274
+ const result = compile ( files , angularFiles ) ;
1275
+ const source = result . source ;
1276
+
1277
+ expectEmit ( source , MyComponentDefinition , 'Incorrect MyComponent.ngComponentDef' ) ;
1278
+
1279
+ } ) ;
1280
+
1190
1281
describe ( 'lifecycle hooks' , ( ) => {
1191
1282
const files = {
1192
1283
app : {
@@ -1361,6 +1452,14 @@ describe('compiler compliance', () => {
1361
1452
1362
1453
const MyComponentDefinition = `
1363
1454
const $_c0$ = ["for","","forOf",""];
1455
+ function MyComponent__svg_g_Template_1(rf, ctx0, ctx) {
1456
+ if (rf & 1) {
1457
+ $r3$.ɵNS();
1458
+ $r3$.ɵE(0,"g");
1459
+ $r3$.ɵEe(1,"circle");
1460
+ $r3$.ɵe();
1461
+ }
1462
+ }
1364
1463
…
1365
1464
MyComponent.ngComponentDef = $r3$.ɵdefineComponent({
1366
1465
type: MyComponent,
@@ -1374,14 +1473,6 @@ describe('compiler compliance', () => {
1374
1473
$r3$.ɵe();
1375
1474
}
1376
1475
if (rf & 2) { $r3$.ɵp(1,"forOf",$r3$.ɵb(ctx.items)); }
1377
- function MyComponent__svg_g_Template_1(rf, ctx0) {
1378
- if (rf & 1) {
1379
- $r3$.ɵNS();
1380
- $r3$.ɵE(0,"g");
1381
- $r3$.ɵEe(1,"circle");
1382
- $r3$.ɵe();
1383
- }
1384
- }
1385
1476
},
1386
1477
directives: [ForOfDirective]
1387
1478
});
@@ -1434,6 +1525,17 @@ describe('compiler compliance', () => {
1434
1525
1435
1526
const MyComponentDefinition = `
1436
1527
const $_c0$ = ["for","","forOf",""];
1528
+ function MyComponent_li_Template_1(rf, ctx0, ctx) {
1529
+ if (rf & 1) {
1530
+ $r3$.ɵE(0, "li");
1531
+ $r3$.ɵT(1);
1532
+ $r3$.ɵe();
1533
+ }
1534
+ if (rf & 2) {
1535
+ const $item$ = ctx0.$implicit;
1536
+ $r3$.ɵt(1, $r3$.ɵi1("", $item$.name, ""));
1537
+ }
1538
+ }
1437
1539
…
1438
1540
MyComponent.ngComponentDef = $r3$.ɵdefineComponent({
1439
1541
type: MyComponent,
@@ -1448,18 +1550,6 @@ describe('compiler compliance', () => {
1448
1550
if (rf & 2) {
1449
1551
$r3$.ɵp(1, "forOf", $r3$.ɵb(ctx.items));
1450
1552
}
1451
-
1452
- function MyComponent_li_Template_1(rf, ctx0) {
1453
- if (rf & 1) {
1454
- $r3$.ɵE(0, "li");
1455
- $r3$.ɵT(1);
1456
- $r3$.ɵe();
1457
- }
1458
- if (rf & 2) {
1459
- const $item$ = ctx0.$implicit;
1460
- $r3$.ɵt(1, $r3$.ɵi1("", $item$.name, ""));
1461
- }
1462
- }
1463
1553
},
1464
1554
directives: [ForOfDirective]
1465
1555
});
@@ -1512,6 +1602,37 @@ describe('compiler compliance', () => {
1512
1602
1513
1603
const MyComponentDefinition = `
1514
1604
const $c1$ = ["for", "", "forOf", ""];
1605
+ function MyComponent_li_li_Template_4(rf, ctx1, ctx0, ctx) {
1606
+ if (rf & 1) {
1607
+ $r3$.ɵE(0, "li");
1608
+ $r3$.ɵT(1);
1609
+ $r3$.ɵe();
1610
+ }
1611
+ if (rf & 2) {
1612
+ const $item$ = ctx0.$implicit;
1613
+ const $info$ = ctx1.$implicit;
1614
+ $r3$.ɵt(1, $r3$.ɵi2(" ", $item$.name, ": ", $info$.description, " "));
1615
+ }
1616
+ }
1617
+
1618
+ function MyComponent_li_Template_1(rf, ctx0, ctx) {
1619
+ if (rf & 1) {
1620
+ $r3$.ɵE(0, "li");
1621
+ $r3$.ɵE(1, "div");
1622
+ $r3$.ɵT(2);
1623
+ $r3$.ɵe();
1624
+ $r3$.ɵE(3, "ul");
1625
+ $r3$.ɵC(4, MyComponent_li_li_Template_4, null, $c1$);
1626
+ $r3$.ɵe();
1627
+ $r3$.ɵe();
1628
+ }
1629
+ if (rf & 2) {
1630
+ const $item$ = ctx0.$implicit;
1631
+ $r3$.ɵt(2, $r3$.ɵi1("", IDENT.name, ""));
1632
+ $r3$.ɵp(4, "forOf", $r3$.ɵb(IDENT.infos));
1633
+ }
1634
+ }
1635
+
1515
1636
…
1516
1637
MyComponent.ngComponentDef = $r3$.ɵdefineComponent({
1517
1638
type: MyComponent,
@@ -1526,37 +1647,6 @@ describe('compiler compliance', () => {
1526
1647
if (rf & 2) {
1527
1648
$r3$.ɵp(1, "forOf", $r3$.ɵb(ctx.items));
1528
1649
}
1529
-
1530
- function MyComponent_li_Template_1(rf, ctx0) {
1531
- if (rf & 1) {
1532
- $r3$.ɵE(0, "li");
1533
- $r3$.ɵE(1, "div");
1534
- $r3$.ɵT(2);
1535
- $r3$.ɵe();
1536
- $r3$.ɵE(3, "ul");
1537
- $r3$.ɵC(4, MyComponent_li_li_Template_4, null, $c1$);
1538
- $r3$.ɵe();
1539
- $r3$.ɵe();
1540
- }
1541
- if (rf & 2) {
1542
- const $item$ = ctx0.$implicit;
1543
- $r3$.ɵt(2, $r3$.ɵi1("", IDENT.name, ""));
1544
- $r3$.ɵp(4, "forOf", $r3$.ɵb(IDENT.infos));
1545
- }
1546
-
1547
- function MyComponent_li_li_Template_4(rf, ctx1) {
1548
- if (rf & 1) {
1549
- $r3$.ɵE(0, "li");
1550
- $r3$.ɵT(1);
1551
- $r3$.ɵe();
1552
- }
1553
- if (rf & 2) {
1554
- const $item$ = ctx0.$implicit;
1555
- const $info$ = ctx1.$implicit;
1556
- $r3$.ɵt(1, $r3$.ɵi2(" ", $item$.name, ": ", $info$.description, " "));
1557
- }
1558
- }
1559
- }
1560
1650
},
1561
1651
directives: [ForOfDirective]
1562
1652
});` ;
0 commit comments