feat(parser): throw when expected an identifier

This commit is contained in:
vsavkin
2014-11-04 09:21:28 -08:00
parent c41f59c794
commit 8a829d346b
2 changed files with 22 additions and 1 deletions

View File

@ -10,6 +10,12 @@ class TestData {
}
}
class ContextWithErrors {
get boo() {
throw new Error("boo to you");
}
}
export function main() {
function td(a = 0, b = 0) {
return new TestData(a, b);
@ -145,6 +151,18 @@ export function main() {
it('should throw on incorrect ternary operator syntax', () => {
expectEvalError("true?1").toThrowError(new RegExp('Parser Error: Conditional expression true\\?1 requires all 3 expressions'));
});
it('should pass exceptions', () => {
expect(() => {
createParser().parse('boo').eval(new ContextWithErrors(), null);
}).toThrowError('boo to you');
});
it('should only allow identifier or keyword as member names', () => {
expectEvalError('x.(').toThrowError(new RegExp('identifier or keyword'));
expectEvalError('x. 1234').toThrowError(new RegExp('identifier or keyword'));
expectEvalError('x."foo"').toThrowError(new RegExp('identifier or keyword'));
});
});
});
}