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 ) { export function readBindingDirective ( parser, start, name ) {
const quoteMark = ( let value = name; // shorthand bind:foo equivalent to bind:foo='foo'
parser.eat( `'` ) ? `'` :
parser.eat( `"` ) ? `"` :
null
);
const value = parser.read( /([a-zA-Z_$][a-zA-Z0-9_$]*)(\.[a-zA-Z_$][a-zA-Z0-9_$]*)*/ ); if ( parser.eat( '=' ) ) {
if ( !value ) parser.error( `Expected valid property name` ); const quoteMark = (
parser.eat( `'` ) ? `'` :
parser.eat( `"` ) ? `"` :
null
);
if ( quoteMark ) { value = parser.read( /([a-zA-Z_$][a-zA-Z0-9_$]*)(\.[a-zA-Z_$][a-zA-Z0-9_$]*)*/ );
parser.eat( quoteMark, true ); if ( !value ) parser.error( `Expected valid property name` );
if ( quoteMark ) {
parser.eat( quoteMark, true );
}
} }
return { return {

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