@@ -541,15 +541,16 @@ 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) {
544
+ function MyComponent_li_Template_2(rf, ctx) {
545
545
if (rf & 1) {
546
546
$r3$.ɵE(0, "li");
547
547
$r3$.ɵT(1);
548
548
$r3$.ɵe();
549
549
}
550
550
if (rf & 2) {
551
- const $foo$ = $r3$.ɵr(1, 1);
552
- $r3$.ɵt(1, $r3$.ɵi2("", ctx.salutation, " ", $foo$, ""));
551
+ const $myComp$ = $r3$.ɵx();
552
+ const $foo$ = $r3$.ɵr(1);
553
+ $r3$.ɵt(1, $r3$.ɵi2("", $myComp$.salutation, " ", $foo$, ""));
553
554
}
554
555
}
555
556
…
@@ -1174,7 +1175,7 @@ describe('compiler compliance', () => {
1174
1175
$r3$.ɵT(2);
1175
1176
}
1176
1177
if (rf & 2) {
1177
- const $user$ = $r3$.ɵld (1);
1178
+ const $user$ = $r3$.ɵr (1);
1178
1179
$r3$.ɵt(2, $r3$.ɵi1("Hello ", $user$.value, "!"));
1179
1180
}
1180
1181
}
@@ -1224,20 +1225,22 @@ describe('compiler compliance', () => {
1224
1225
const $c2$ = ["if", ""];
1225
1226
const $c3$ = ["baz", ""];
1226
1227
const $c4$ = ["bar", ""];
1227
- function MyComponent_div_span_Template_2(rf, ctx1, ctx0, ctx) {
1228
+ function MyComponent_div_span_Template_2(rf, ctx) {
1228
1229
if (rf & 1) {
1229
1230
$r3$.ɵE(0, "span");
1230
1231
$r3$.ɵT(1);
1231
1232
$r3$.ɵe();
1232
1233
}
1233
1234
if (rf & 2) {
1234
- const $foo$ = $r3$.ɵr(2, 1);
1235
- const $bar$ = $r3$.ɵr(1, 4);
1236
- const $baz$ = $r3$.ɵr(2, 5);
1235
+ $r3$.ɵx();
1236
+ const $bar$ = $r3$.ɵr(4);
1237
+ $r3$.ɵx();
1238
+ const $foo$ = $r3$.ɵr(1);
1239
+ const $baz$ = $r3$.ɵr(5);
1237
1240
$r3$.ɵt(1, $r3$.ɵi3("", $foo$, "-", $bar$, "-", $baz$, ""));
1238
1241
}
1239
1242
}
1240
- function MyComponent_div_Template_3(rf, ctx0, ctx) {
1243
+ function MyComponent_div_Template_3(rf, ctx) {
1241
1244
if (rf & 1) {
1242
1245
$r3$.ɵE(0, "div");
1243
1246
$r3$.ɵT(1);
@@ -1246,8 +1249,9 @@ describe('compiler compliance', () => {
1246
1249
$r3$.ɵe();
1247
1250
}
1248
1251
if (rf & 2) {
1249
- const $foo$ = $r3$.ɵr(1, 1);
1250
- const $bar$ = $r3$.ɵld(4);
1252
+ const $bar$ = $r3$.ɵr(4);
1253
+ $r3$.ɵx();
1254
+ const $foo$ = $r3$.ɵr(1);
1251
1255
$r3$.ɵt(1, $r3$.ɵi2(" ", $foo$, "-", $bar$, " "));
1252
1256
}
1253
1257
}
@@ -1264,7 +1268,7 @@ describe('compiler compliance', () => {
1264
1268
$r3$.ɵEe(4, "div", null, $c3$);
1265
1269
}
1266
1270
if (rf & 2) {
1267
- const $foo$ = $r3$.ɵld (1);
1271
+ const $foo$ = $r3$.ɵr (1);
1268
1272
$r3$.ɵt(2, $r3$.ɵi1(" ", $foo$, " "));
1269
1273
}
1270
1274
},
@@ -1278,6 +1282,77 @@ describe('compiler compliance', () => {
1278
1282
1279
1283
} ) ;
1280
1284
1285
+ it ( 'should support local refs mixed with context assignments' , ( ) => {
1286
+ const files = {
1287
+ app : {
1288
+ 'spec.ts' : `
1289
+ import {Component, NgModule} from '@angular/core';
1290
+ import {CommonModule} from '@angular/common';
1291
+
1292
+ @Component({
1293
+ selector: 'my-component',
1294
+ template: \`
1295
+ <div *ngFor="let item of items">
1296
+ <div #foo></div>
1297
+ <span *ngIf="showing">
1298
+ {{ foo }} - {{ item }}
1299
+ </span>
1300
+ </div>\`
1301
+ })
1302
+ export class MyComponent {}
1303
+
1304
+ @NgModule({declarations: [MyComponent], imports: [CommonModule]})
1305
+ export class MyModule {}
1306
+ `
1307
+ }
1308
+ } ;
1309
+
1310
+ const template = `
1311
+ const $c0$ = ["ngFor","","ngForOf",""];
1312
+ const $c1$ = ["foo", ""];
1313
+ const $c2$ = ["ngIf",""];
1314
+
1315
+ function MyComponent_div_span_Template_3(rf, ctx) {
1316
+ if (rf & 1) {
1317
+ $i0$.ɵE(0, "span");
1318
+ $i0$.ɵT(1);
1319
+ $i0$.ɵe();
1320
+ }
1321
+ if (rf & 2) {
1322
+ const $item$ = $i0$.ɵx().$implicit;
1323
+ const $foo$ = $i0$.ɵr(2);
1324
+ $i0$.ɵt(1, $i0$.ɵi2(" ", $foo$, " - ", $item$, " "));
1325
+ }
1326
+ }
1327
+
1328
+ function MyComponent_div_Template_0(rf, ctx) {
1329
+ if (rf & 1) {
1330
+ $i0$.ɵE(0, "div");
1331
+ $i0$.ɵEe(1, "div", null, $c1$);
1332
+ $i0$.ɵC(3, MyComponent_div_span_Template_3, null, $c2$);
1333
+ $i0$.ɵe();
1334
+ }
1335
+ if (rf & 2) {
1336
+ const $app$ = $i0$.ɵx();
1337
+ $i0$.ɵp(3, "ngIf", $i0$.ɵb($app$.showing));
1338
+ }
1339
+ }
1340
+
1341
+ // ...
1342
+ template:function MyComponent_Template(rf, ctx){
1343
+ if (rf & 1) {
1344
+ $i0$.ɵC(0, MyComponent_div_Template_0, null, $c0$);
1345
+ }
1346
+ if (rf & 2) {
1347
+ $i0$.ɵp(0, "ngForOf", $i0$.ɵb(ctx.items));
1348
+ }
1349
+ }` ;
1350
+
1351
+ const result = compile ( files , angularFiles ) ;
1352
+
1353
+ expectEmit ( result . source , template , 'Incorrect template' ) ;
1354
+ } ) ;
1355
+
1281
1356
describe ( 'lifecycle hooks' , ( ) => {
1282
1357
const files = {
1283
1358
app : {
@@ -1452,7 +1527,7 @@ describe('compiler compliance', () => {
1452
1527
1453
1528
const MyComponentDefinition = `
1454
1529
const $_c0$ = ["for","","forOf",""];
1455
- function MyComponent__svg_g_Template_1(rf, ctx0, ctx) {
1530
+ function MyComponent__svg_g_Template_1(rf, ctx) {
1456
1531
if (rf & 1) {
1457
1532
$r3$.ɵNS();
1458
1533
$r3$.ɵE(0,"g");
@@ -1525,14 +1600,14 @@ describe('compiler compliance', () => {
1525
1600
1526
1601
const MyComponentDefinition = `
1527
1602
const $_c0$ = ["for","","forOf",""];
1528
- function MyComponent_li_Template_1(rf, ctx0, ctx) {
1603
+ function MyComponent_li_Template_1(rf, ctx) {
1529
1604
if (rf & 1) {
1530
1605
$r3$.ɵE(0, "li");
1531
1606
$r3$.ɵT(1);
1532
1607
$r3$.ɵe();
1533
1608
}
1534
1609
if (rf & 2) {
1535
- const $item$ = ctx0 .$implicit;
1610
+ const $item$ = ctx .$implicit;
1536
1611
$r3$.ɵt(1, $r3$.ɵi1("", $item$.name, ""));
1537
1612
}
1538
1613
}
@@ -1602,20 +1677,20 @@ describe('compiler compliance', () => {
1602
1677
1603
1678
const MyComponentDefinition = `
1604
1679
const $c1$ = ["for", "", "forOf", ""];
1605
- function MyComponent_li_li_Template_4(rf, ctx1, ctx0, ctx) {
1680
+ function MyComponent_li_li_Template_4(rf, ctx) {
1606
1681
if (rf & 1) {
1607
1682
$r3$.ɵE(0, "li");
1608
1683
$r3$.ɵT(1);
1609
1684
$r3$.ɵe();
1610
1685
}
1611
1686
if (rf & 2) {
1612
- const $item $ = ctx0 .$implicit;
1613
- const $info $ = ctx1 .$implicit;
1687
+ const $info $ = ctx .$implicit;
1688
+ const $item $ = $r3$.ɵx() .$implicit;
1614
1689
$r3$.ɵt(1, $r3$.ɵi2(" ", $item$.name, ": ", $info$.description, " "));
1615
1690
}
1616
1691
}
1617
1692
1618
- function MyComponent_li_Template_1(rf, ctx0, ctx) {
1693
+ function MyComponent_li_Template_1(rf, ctx) {
1619
1694
if (rf & 1) {
1620
1695
$r3$.ɵE(0, "li");
1621
1696
$r3$.ɵE(1, "div");
@@ -1627,7 +1702,7 @@ describe('compiler compliance', () => {
1627
1702
$r3$.ɵe();
1628
1703
}
1629
1704
if (rf & 2) {
1630
- const $item$ = ctx0 .$implicit;
1705
+ const $item$ = ctx .$implicit;
1631
1706
$r3$.ɵt(2, $r3$.ɵi1("", IDENT.name, ""));
1632
1707
$r3$.ɵp(4, "forOf", $r3$.ɵb(IDENT.infos));
1633
1708
}
0 commit comments