throw takes an expression

This commit is contained in:
Chris Wanstrath 2025-11-25 16:08:14 -08:00 committed by Chris Wanstrath
parent 1682a7ccb7
commit 2c2b277b29
2 changed files with 13 additions and 1 deletions

View File

@ -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)
}

View File

@ -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