File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,9 @@ class _ParseAST {
241241
242242 parseIdentifier ( ) :string {
243243 var n = this . next ;
244+ if ( ! n . isIdentifier ( ) && ! n . isKeyword ( ) ) {
245+ this . error ( `Unexpected token ${ n } , expected identifier or keyword` )
246+ }
244247 this . advance ( ) ;
245248 return n . toString ( ) ;
246249 }
@@ -249,7 +252,7 @@ class _ParseAST {
249252 if ( isBlank ( index ) ) index = this . index ;
250253
251254 var location = ( index < this . tokens . length )
252- ? `at column ${ tokens [ index ] . index + 1 } in`
255+ ? `at column ${ this . tokens [ index ] . index + 1 } in`
253256 : `at the end of the expression` ;
254257
255258 throw new ParserError ( `Parser Error: ${ message } ${ location } [${ this . input } ]` ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ class TestData {
1010 }
1111}
1212
13+ class ContextWithErrors {
14+ get boo ( ) {
15+ throw new Error ( "boo to you" ) ;
16+ }
17+ }
18+
1319export function main ( ) {
1420 function td ( a = 0 , b = 0 ) {
1521 return new TestData ( a , b ) ;
@@ -145,6 +151,18 @@ export function main() {
145151 it ( 'should throw on incorrect ternary operator syntax' , ( ) => {
146152 expectEvalError ( "true?1" ) . toThrowError ( new RegExp ( 'Parser Error: Conditional expression true\\?1 requires all 3 expressions' ) ) ;
147153 } ) ;
154+
155+ it ( 'should pass exceptions' , ( ) => {
156+ expect ( ( ) => {
157+ createParser ( ) . parse ( 'boo' ) . eval ( new ContextWithErrors ( ) , null ) ;
158+ } ) . toThrowError ( 'boo to you' ) ;
159+ } ) ;
160+
161+ it ( 'should only allow identifier or keyword as member names' , ( ) => {
162+ expectEvalError ( 'x.(' ) . toThrowError ( new RegExp ( 'identifier or keyword' ) ) ;
163+ expectEvalError ( 'x. 1234' ) . toThrowError ( new RegExp ( 'identifier or keyword' ) ) ;
164+ expectEvalError ( 'x."foo"' ) . toThrowError ( new RegExp ( 'identifier or keyword' ) ) ;
165+ } ) ;
148166 } ) ;
149167 } ) ;
150168}
You can’t perform that action at this time.
0 commit comments