Skip to content

Commit

Permalink
Remove inner parenthesis wrapping from unary expression rendering (#422)
Browse files Browse the repository at this point in the history
At some point, `#{}` and `-{}` became valid in luau, making it
unnecessary to wrap tables in parenthesis.
  • Loading branch information
rimuy authored Feb 7, 2024
1 parent d5f0f34 commit 10c5c64
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/LuauRenderer/nodes/expressions/renderUnaryExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import luau from "LuauAST";
import { render, RenderState } from "LuauRenderer";
import { needsParentheses } from "LuauRenderer/util/needsParentheses";

function needsInnerParentheses(node: luau.UnaryExpression) {
// #{} and -{} are invalid
if ((node.operator === "#" || node.operator === "-") && luau.isTable(node.expression)) {
return true;
}

return false;
}

function needsSpace(node: luau.UnaryExpression) {
// not always needs a space
if (node.operator === "not") {
Expand All @@ -27,19 +18,12 @@ function needsSpace(node: luau.UnaryExpression) {
}

export function renderUnaryExpression(state: RenderState, node: luau.UnaryExpression) {
let expStr = render(state, node.expression);
let opStr = node.operator;

if (needsSpace(node)) {
opStr += " ";
}

if (needsInnerParentheses(node)) {
expStr = `(${expStr})`;
}

let result = `${opStr}${expStr}`;

let result = `${opStr}${render(state, node.expression)}`;
if (needsParentheses(node)) {
result = `(${result})`;
}
Expand Down

0 comments on commit 10c5c64

Please sign in to comment.