diff --git a/source/parser/lib.civet b/source/parser/lib.civet index 21e2c49d..806be8ee 100644 --- a/source/parser/lib.civet +++ b/source/parser/lib.civet @@ -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] diff --git a/test/function-block-shorthand.civet b/test/function-block-shorthand.civet index 82ad2a24..c0fc7ac6 100644 --- a/test/function-block-shorthand.civet +++ b/test/function-block-shorthand.civet @@ -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 ---