Merge pull request #434 from sveltejs/gh-424-alt

Treat literals as special cases when parsing
pull/435/head
Rich Harris 8 years ago committed by GitHub
commit 67d6eb89f2

@ -1,10 +1,28 @@
import { parseExpressionAt } from 'acorn';
const literals = new Map([
[ 'true', true ],
[ 'false', false ],
[ 'null', null ]
]);
export default function readExpression ( parser ) {
const start = parser.index;
const name = parser.readUntil( /\s*}}/ );
if ( name && /^[a-z]+$/.test( name ) ) {
const end = start + name.length;
if ( literals.has( name ) ) {
return {
type: 'Literal',
start,
end,
value: literals.get( name ),
raw: name
};
}
return {
type: 'Identifier',
start,

@ -0,0 +1,19 @@
export default {
'skip-ssr': true,
data: {
foo: false
},
test ( assert, component, target ) {
const inputs = target.querySelectorAll( 'input' );
assert.ok( inputs[0].checked );
assert.ok( !inputs[1].checked );
component.set( { foo: true } );
assert.ok( !inputs[0].checked );
assert.ok( inputs[1].checked );
}
};

@ -0,0 +1,2 @@
<input type='radio' bind:group='foo' value='{{false}}'>
<input type='radio' bind:group='foo' value='{{true}}'>
Loading…
Cancel
Save