File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { ASTWithSource } from '../expression_parser/ast' ;
9+ import { ASTWithSource , EmptyExpr } from '../expression_parser/ast' ;
1010import * as html from '../ml_parser/ast' ;
1111import { ParseError , ParseSourceSpan } from '../parse_util' ;
1212import { BindingParser } from '../template_parser/binding_parser' ;
@@ -256,6 +256,9 @@ function parseForLoopParameters(
256256 new ParseError ( param . sourceSpan , '@for loop can only have one "track" expression' ) ) ;
257257 } else {
258258 const expression = parseBlockParameterToBinding ( param , bindingParser , trackMatch [ 1 ] ) ;
259+ if ( expression . ast instanceof EmptyExpr ) {
260+ errors . push ( new ParseError ( param . sourceSpan , '@for loop must have a "track" expression' ) ) ;
261+ }
259262 const keywordSpan = new ParseSourceSpan (
260263 param . sourceSpan . start , param . sourceSpan . start . moveBy ( 'track' . length ) ) ;
261264 result . trackBy = { expression, keywordSpan} ;
Original file line number Diff line number Diff line change @@ -1520,6 +1520,11 @@ describe('R3 template transform', () => {
15201520 @case {case}
15211521 }
15221522 ` ) ) . toThrowError ( / @ c a s e b l o c k m u s t h a v e e x a c t l y o n e p a r a m e t e r / ) ;
1523+ expect ( ( ) => parse ( `
1524+ @switch (cond) {
1525+ @case ( ) {case}
1526+ }
1527+ ` ) ) . toThrowError ( / @ c a s e b l o c k m u s t h a v e e x a c t l y o n e p a r a m e t e r / ) ;
15231528 } ) ;
15241529
15251530 it ( 'should report if a case has more than one parameter' , ( ) => {
@@ -1711,6 +1716,8 @@ describe('R3 template transform', () => {
17111716 it ( 'should report if for loop does not have a tracking expression' , ( ) => {
17121717 expect ( ( ) => parse ( `@for (a of b) {hello}` ) )
17131718 . toThrowError ( / @ f o r l o o p m u s t h a v e a " t r a c k " e x p r e s s i o n / ) ;
1719+ expect ( ( ) => parse ( `@for (a of b; track ) {hello}` ) )
1720+ . toThrowError ( / @ f o r l o o p m u s t h a v e a " t r a c k " e x p r e s s i o n / ) ;
17141721 } ) ;
17151722
17161723 it ( 'should report mismatching optional parentheses around for loop expression' , ( ) => {
@@ -1932,6 +1939,9 @@ describe('R3 template transform', () => {
19321939 expect ( ( ) => parse ( `
19331940 @if {hello}
19341941 ` ) ) . toThrowError ( / C o n d i t i o n a l b l o c k d o e s n o t h a v e a n e x p r e s s i o n / ) ;
1942+ expect ( ( ) => parse ( `
1943+ @if ( ) {hello}
1944+ ` ) ) . toThrowError ( / C o n d i t i o n a l b l o c k d o e s n o t h a v e a n e x p r e s s i o n / ) ;
19351945 } ) ;
19361946
19371947 it ( 'should report an unknown parameter in an if block' , ( ) => {
You can’t perform that action at this time.
0 commit comments