Skip to content

Commit 80e3a45

Browse files
committed
fix(parser): changes parser to throw an error when it encounters an unexpected token
Change the handling of unexpected tokens. Make the parser throw the "is an unexpected token" exception, so ExpressionVisitor won't throw confusing "Can not watch expression containing ';'". Closes dart-archive#830
1 parent 155582d commit 80e3a45

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/core/parser/dynamic_parser_impl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class DynamicParserImpl {
4040
if (isChain && expr is Filter) {
4141
error('Cannot have a filter in a chain');
4242
}
43+
if(!isChain && index < tokens.length){
44+
error("'${next}' is an unexpected token", index);
45+
}
4346
}
4447
return (expressions.length == 1)
4548
? expressions.first

test/core/parser/parser_spec.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ main() {
194194
expectEval("4()").toThrow('4 is not a function');
195195
});
196196

197+
it("should throw on an unexpected token", (){
198+
expectEval("[1,2] trac").toThrow('Parser Error: \'trac\' is an unexpected token at column 7 in [[1,2] trac]');
199+
});
197200

198201
it('should fail gracefully when invoking non-function', () {
199202
expect(() {

0 commit comments

Comments
 (0)