use a map to avoid false positives

pull/434/head
Rich-Harris 8 years ago
parent 6c754c2a3d
commit 6e0d0b1a12

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

Loading…
Cancel
Save