throw takes an expression
This commit is contained in:
parent
1682a7ccb7
commit
2c2b277b29
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user