diff --git a/src/parser/parser2.ts b/src/parser/parser2.ts index c978109..50a453d 100644 --- a/src/parser/parser2.ts +++ b/src/parser/parser2.ts @@ -729,7 +729,7 @@ export class Parser { // throw blah throw(): SyntaxNode { const keyword = this.keyword('throw') - const val = this.value() + const val = this.expression() const node = new SyntaxNode('Throw', keyword.from, val.to) return node.push(keyword, val) } diff --git a/src/parser/tests/exceptions.test.ts b/src/parser/tests/exceptions.test.ts index e89c80e..a0708f9 100644 --- a/src/parser/tests/exceptions.test.ts +++ b/src/parser/tests/exceptions.test.ts @@ -139,6 +139,18 @@ describe('try/catch/finally/throw', () => { `) }) + test('parses throw statement with BinOp', () => { + expect("throw 'error message:' + msg").toMatchTree(` + Throw + keyword throw + BinOp + String + StringFragment error message: + Plus + + Identifier msg + `) + }) + test('parses throw statement with identifier', () => { expect('throw error-object').toMatchTree(` Throw