bind:foo shorthand – closes #20

pull/31/head
Rich-Harris 8 years ago
parent cf1a80a28f
commit 2741eee8bf

@ -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 {

@ -147,7 +147,6 @@ function readAttribute ( parser ) {
}
if ( /^bind:/.test( name ) ) {
parser.eat( '=', true );
return readBindingDirective( parser, start, name.slice( 5 ) );
}

@ -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
}
Loading…
Cancel
Save