Skip to content

Commit

Permalink
Merge pull request #439 from sveltejs/gh-437
Browse files Browse the repository at this point in the history
better error for bind:value="{{foo}}"
  • Loading branch information
Rich-Harris committed Apr 2, 2017
2 parents a3ecb67 + 75e8d62 commit 949dcc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/parse/read/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ export function readBindingDirective ( parser, start, name ) {

const a = parser.index;

if ( parser.eat( '{{' ) ) {
let message = 'bound values should not be wrapped';
const b = parser.template.indexOf( '}}', a );
if ( b !== -1 ) {
const value = parser.template.slice( parser.index, b );
message += ` — use '${value}', not '{{${value}}}'`;
}

parser.error( message, a );
}

// this is a bit of a hack so that we can give Acorn something parseable
let b;
if ( quoteMark ) {
Expand Down
8 changes: 8 additions & 0 deletions test/parser/samples/error-binding-mustaches/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"message": "bound values should not be wrapped — use 'foo', not '{{foo}}'",
"loc": {
"line": 1,
"column": 19
},
"pos": 19
}
1 change: 1 addition & 0 deletions test/parser/samples/error-binding-mustaches/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input bind:value='{{foo}}'>

0 comments on commit 949dcc5

Please sign in to comment.