File tree Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const InvalidSyntaxBoxOpen = '([';
99const InvalidSyntaxBoxClose = '])' ;
1010const ValidSyntaxOpen = '[(' ;
1111const ValidSyntaxClose = ')]' ;
12- const InvalidSyntaxBoxRe = new RegExp ( '\\(\\ [(.*?)\\]\\)(.*?) ' ) ;
12+ const InvalidSyntaxBoxRe = new RegExp ( '\\[(.*?)\\]' ) ;
1313
1414const getReplacements = ( text : ast . BoundEventAst , absolutePosition : number ) => {
1515 const expr : string = ( text . sourceSpan as any ) . toString ( ) ;
@@ -29,15 +29,14 @@ class BananaInBoxTemplateVisitor extends BasicTemplateAstVisitor {
2929
3030 visitEvent ( prop : ast . BoundEventAst , context : any ) : any {
3131
32- if ( prop . sourceSpan ) {
33- // Note that will not be reliable for different interpolation symbols
32+ if ( prop . name ) {
3433 let error = null ;
35- const expr : any = ( < any > prop . sourceSpan ) . toString ( ) ;
36- if ( InvalidSyntaxBoxRe . test ( expr ) ) {
34+ if ( InvalidSyntaxBoxRe . test ( prop . name ) ) {
3735 error = 'Invalid binding syntax. Use [(expr)] instead' ;
3836 }
3937
4038 if ( error ) {
39+ const expr : any = ( < any > prop . sourceSpan ) . toString ( ) ;
4140 const internalStart = expr . indexOf ( InvalidSyntaxBoxOpen ) + 1 ;
4241 const start = prop . sourceSpan . start . offset + internalStart ;
4342 const absolutePosition = this . getSourcePosition ( start - 1 ) ;
Original file line number Diff line number Diff line change @@ -14,8 +14,19 @@ describe('banana-in-box', () => {
1414 assertSuccess ( 'banana-in-box' , source ) ;
1515 } ) ;
1616
17+ it ( 'should work with proper style' , ( ) => {
18+ let source = `
19+ @Component({
20+ template: \` <a (click)="navigate(['/resources'])"> \`
21+ })
22+ class Bar {}
23+ ` ;
24+ assertSuccess ( 'banana-in-box' , source ) ;
25+ } ) ;
26+
1727 } ) ;
1828
29+
1930 describe ( 'failure' , ( ) => {
2031 it ( 'should fail when the box is in the banana' , ( ) => {
2132 let source = `
@@ -32,6 +43,22 @@ describe('banana-in-box', () => {
3243 source
3344 } ) ;
3445 } ) ;
46+
47+ it ( 'should fail when the box is in the banana' , ( ) => {
48+ let source = `
49+ @Component({
50+ template: \` <comp ([bar])="foo" name="foo"></comp>
51+ ~~~~~~~~~~~~~
52+ \`
53+ })
54+ class Bar {}
55+ ` ;
56+ assertAnnotated ( {
57+ ruleName : 'banana-in-box' ,
58+ message : 'Invalid binding syntax. Use [(expr)] instead' ,
59+ source
60+ } ) ;
61+ } ) ;
3562 } ) ;
3663
3764 describe ( 'replacements' , ( ) => {
You can’t perform that action at this time.
0 commit comments