throw takes an expression

This commit is contained in:
Chris Wanstrath 2025-11-25 16:08:14 -08:00
parent 1d2c85b19c
commit c6e5c44755
2 changed files with 13 additions and 1 deletions

View File

@ -729,7 +729,7 @@ export class Parser {
// throw blah // throw blah
throw(): SyntaxNode { throw(): SyntaxNode {
const keyword = this.keyword('throw') const keyword = this.keyword('throw')
const val = this.value() const val = this.expression()
const node = new SyntaxNode('Throw', keyword.from, val.to) const node = new SyntaxNode('Throw', keyword.from, val.to)
return node.push(keyword, val) 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', () => { test('parses throw statement with identifier', () => {
expect('throw error-object').toMatchTree(` expect('throw error-object').toMatchTree(`
Throw Throw