From f671da7d31950b233810d51b237aa86d4d053704 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Tue, 14 Jan 2025 14:33:35 +0530 Subject: [PATCH] (fix) grammar: allow constructors as call arguments --- src/bali/grammar/parser.nim | 8 ++++++++ tests/data/constructor-as-arg-001.js | 1 + 2 files changed, 9 insertions(+) create mode 100644 tests/data/constructor-as-arg-001.js diff --git a/src/bali/grammar/parser.nim b/src/bali/grammar/parser.nim index 3ceb122..3db77d5 100644 --- a/src/bali/grammar/parser.nim +++ b/src/bali/grammar/parser.nim @@ -783,6 +783,14 @@ proc parseArguments*(parser: Parser): Option[PositionedArguments] = of TokenKind.RParen: metEnd = true break + of TokenKind.New: + # constructor! + let + call = parser.parseConstructor() + resIdent = "@0_" & $idx + + parser.ast.appendToCurrentScope(callAndStoreMut(resIdent, &call)) + args.pushIdent(resIdent) else: parser.error UnexpectedToken, $token.kind diff --git a/tests/data/constructor-as-arg-001.js b/tests/data/constructor-as-arg-001.js new file mode 100644 index 0000000..a30df7e --- /dev/null +++ b/tests/data/constructor-as-arg-001.js @@ -0,0 +1 @@ +console.log(new Date())