diff --git a/compiler/parse/read/directives.js b/compiler/parse/read/directives.js index e1bd3f6c30..32bcf39e68 100644 --- a/compiler/parse/read/directives.js +++ b/compiler/parse/read/directives.js @@ -43,17 +43,21 @@ export function readEventHandlerDirective ( parser, start, name ) { } export function readBindingDirective ( parser, start, name ) { - const quoteMark = ( - parser.eat( `'` ) ? `'` : - parser.eat( `"` ) ? `"` : - null - ); + let value = name; // shorthand – bind:foo equivalent to bind:foo='foo' - const value = parser.read( /([a-zA-Z_$][a-zA-Z0-9_$]*)(\.[a-zA-Z_$][a-zA-Z0-9_$]*)*/ ); - if ( !value ) parser.error( `Expected valid property name` ); + if ( parser.eat( '=' ) ) { + const quoteMark = ( + parser.eat( `'` ) ? `'` : + parser.eat( `"` ) ? `"` : + null + ); - if ( quoteMark ) { - parser.eat( quoteMark, true ); + value = parser.read( /([a-zA-Z_$][a-zA-Z0-9_$]*)(\.[a-zA-Z_$][a-zA-Z0-9_$]*)*/ ); + if ( !value ) parser.error( `Expected valid property name` ); + + if ( quoteMark ) { + parser.eat( quoteMark, true ); + } } return { diff --git a/compiler/parse/state/tag.js b/compiler/parse/state/tag.js index 15e65d8cea..e8c627c93a 100644 --- a/compiler/parse/state/tag.js +++ b/compiler/parse/state/tag.js @@ -147,7 +147,6 @@ function readAttribute ( parser ) { } if ( /^bind:/.test( name ) ) { - parser.eat( '=', true ); return readBindingDirective( parser, start, name.slice( 5 ) ); } diff --git a/test/parser/binding-shorthand/input.html b/test/parser/binding-shorthand/input.html new file mode 100644 index 0000000000..31f9c872b0 --- /dev/null +++ b/test/parser/binding-shorthand/input.html @@ -0,0 +1 @@ + diff --git a/test/parser/binding-shorthand/output.json b/test/parser/binding-shorthand/output.json new file mode 100644 index 0000000000..61c24975a2 --- /dev/null +++ b/test/parser/binding-shorthand/output.json @@ -0,0 +1,27 @@ +{ + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Element", + "name": "Widget", + "attributes": [ + { + "start": 8, + "end": 16, + "type": "Binding", + "name": "foo", + "value": "foo" + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +}