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 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, } } 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 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