From eb5389699fe4ea6cecee0ec0b1285516e55466ec Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 13 Sep 2025 14:03:39 +0200 Subject: [PATCH 1/4] Add test case --- tests/inputs-luau/ambiguous-syntax-1.lua | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/inputs-luau/ambiguous-syntax-1.lua diff --git a/tests/inputs-luau/ambiguous-syntax-1.lua b/tests/inputs-luau/ambiguous-syntax-1.lua new file mode 100644 index 00000000..719f98b4 --- /dev/null +++ b/tests/inputs-luau/ambiguous-syntax-1.lua @@ -0,0 +1,3 @@ +-- https://github.com/JohnnyMorganz/StyLua/issues/1010 +(child :: BasePart).Size = if true then x else y; +(child :: BasePart).CFrame = value From bcaca9e6ba5d3bab0a88680c1d8c7f3fac856ddb Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 13 Sep 2025 14:03:53 +0200 Subject: [PATCH 2/4] Handle if expression when checking if expression ends with identifier --- src/formatters/block.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/formatters/block.rs b/src/formatters/block.rs index 8f6a7f71..110cdb60 100644 --- a/src/formatters/block.rs +++ b/src/formatters/block.rs @@ -484,6 +484,10 @@ fn expression_ends_with_identifier_or_parentheses(expression: &Expression) -> bo Expression::UnaryOperator { expression, .. } => { expression_ends_with_identifier_or_parentheses(expression) } + #[cfg(feature = "luau")] + Expression::IfExpression(if_expression) => { + expression_ends_with_identifier_or_parentheses(if_expression.else_expression()) + } _ => false, } } From f8cd5e3aa10084daf4369e8fc7686bc2957b8d0e Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 13 Sep 2025 14:03:57 +0200 Subject: [PATCH 3/4] Update snapshot --- tests/snapshots/tests__luau@ambiguous-syntax-1.lua.snap | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/snapshots/tests__luau@ambiguous-syntax-1.lua.snap diff --git a/tests/snapshots/tests__luau@ambiguous-syntax-1.lua.snap b/tests/snapshots/tests__luau@ambiguous-syntax-1.lua.snap new file mode 100644 index 00000000..26d8c0b1 --- /dev/null +++ b/tests/snapshots/tests__luau@ambiguous-syntax-1.lua.snap @@ -0,0 +1,8 @@ +--- +source: tests/tests.rs +expression: "format(&contents, LuaVersion::Luau)" +input_file: tests/inputs-luau/ambiguous-syntax-1.lua +--- +-- https://github.com/JohnnyMorganz/StyLua/issues/1010 +(child :: BasePart).Size = if true then x else y; +(child :: BasePart).CFrame = value From bda12e12c8a1504b69a1742c2ba4abe96156c1a0 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 13 Sep 2025 14:04:01 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b544cce..7cb06046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added option `block_newline_gaps` to determine whether newline gaps at the start / end of blocks should be preserved. Defaults to `Never`, which is the original behaviour. ([#857](https://github.com/JohnnyMorganz/StyLua/pull/857)) ### Fixed + - Fixed formatting of index containing brackets string in parentheses ([#992](https://github.com/JohnnyMorganz/StyLua/pull/992)) - Fixed goto not being recognised for LuaJIT ([#986](https://github.com/JohnnyMorganz/StyLua/issues/986)) +- Fixed semicolon removed after a statement ending with an if-expression leading to ambiguous syntax when the next line begins with parentheses ([#1010](https://github.com/JohnnyMorganz/StyLua/issues/1010)) ## [2.1.0] - 2025-04-21