From 2c2b277b29f8cddf4c028313e314806651b52fc1 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Tue, 25 Nov 2025 16:08:14 -0800 Subject: [PATCH] `throw` takes an expression --- src/parser/parser2.ts | 2 +- src/parser/tests/exceptions.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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