Skip to content

Commit

Permalink
Fix immediately called (op) in pipeline context
Browse files Browse the repository at this point in the history
Fixes #1672
  • Loading branch information
edemaine committed Jan 5, 2025
1 parent 3514f86 commit 66d8440
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 11 additions & 5 deletions source/parser/lib.civet
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,18 @@ function processCallMemberExpression(node: CallExpression | MemberExpression): A
(isComma(arg) as ASTLeaf).token = `)${op.token}(`
commaCount++
// Don't mess with (+)()
if args.length
children.splice 0, 2,
commaCount ?
if args#
if commaCount
children.splice 0, 2,
type: "ParenthesizedExpression"
children: ["(", ...call.children, ")"]
: { ...call, type: "ParenthesizedExpression" }
children: ["(", call.children, ")"]
expression: call.children
else // already parenthesized by argument parens
middle := call.children[<..<]
children.splice 0, 2,
type: "ParenthesizedExpression"
expression: middle
children: [ call.children.0, middle, call.children.-1 ]
// If nothing left to this CallExpression, remove the wrapper
if children# is 1
return children[0]
Expand Down
8 changes: 8 additions & 0 deletions test/function-block-shorthand.civet
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,14 @@ describe "(op) shorthand", ->
(1)
"""

testCase """
apply binary op with one argument in pipeline
---
foo |> (+) x
---
(x)(foo)
"""

testCase """
apply binary op with no arguments
---
Expand Down

0 comments on commit 66d8440

Please sign in to comment.