try to parse expressions as javascript before interpreting them as an identifier (#424)

pull/426/head
Conduitry 8 years ago
parent 38ee4f15cf
commit eab3f62f25

@ -3,6 +3,14 @@ import { parseExpressionAt } from 'acorn';
export default function readExpression ( parser ) { export default function readExpression ( parser ) {
const start = parser.index; const start = parser.index;
parser.index = start;
try {
const node = parseExpressionAt( parser.template, parser.index );
parser.index = node.end;
return node;
} catch ( err ) {
const name = parser.readUntil( /\s*}}/ ); const name = parser.readUntil( /\s*}}/ );
if ( name && /^[a-z]+$/.test( name ) ) { if ( name && /^[a-z]+$/.test( name ) ) {
return { return {
@ -12,15 +20,6 @@ export default function readExpression ( parser ) {
name name
}; };
} }
parser.index = start;
try {
const node = parseExpressionAt( parser.template, parser.index );
parser.index = node.end;
return node;
} catch ( err ) {
parser.acornError( err ); parser.acornError( err );
} }
} }

Loading…
Cancel
Save