Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Fixed
- Fix formatting of index containing brackets string in parentheses ([#992](https://github.com/JohnnyMorganz/StyLua/pull/992))
- 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))

## [2.1.0] - 2025-04-21

Expand Down
4 changes: 2 additions & 2 deletions src/formatters/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ fn stmt_remove_leading_newlines(stmt: Stmt) -> Stmt {
type_function.type_token(),
with_type_token
),
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Goto(goto) => update_first_token!(Goto, goto, goto.goto_token(), with_goto_token),
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Label(label) => {
update_first_token!(Label, label, label.left_colons(), with_left_colons)
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub mod expression;
#[cfg(any(feature = "luau", feature = "cfxlua"))]
pub mod compound_assignment;
pub mod functions;
#[cfg(feature = "lua52")]
pub mod lua52;
#[cfg(any(feature = "lua52", feature = "luajit"))]
pub mod goto;
#[cfg(feature = "lua54")]
pub mod lua54;
#[cfg(feature = "luau")]
Expand Down
14 changes: 7 additions & 7 deletions src/formatters/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(any(feature = "luau", feature = "cfxlua"))]
use crate::formatters::compound_assignment::format_compound_assignment;
#[cfg(feature = "lua52")]
use crate::formatters::lua52::{format_goto, format_goto_no_trivia, format_label};
#[cfg(any(feature = "lua52", feature = "luajit"))]
use crate::formatters::goto::{format_goto, format_goto_no_trivia, format_label};
#[cfg(feature = "luau")]
use crate::formatters::luau::{
format_exported_type_declaration, format_exported_type_function, format_type_declaration_stmt,
Expand Down Expand Up @@ -1089,9 +1089,9 @@ pub(crate) mod stmt_block {
Stmt::TypeFunction(type_function) => {
Stmt::TypeFunction(format_type_function_block(ctx, type_function, block_shape))
}
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Goto(node) => Stmt::Goto(node.to_owned()),
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Label(node) => Stmt::Label(node.to_owned()),
other => panic!("unknown node {:?}", other),
}
Expand Down Expand Up @@ -1124,8 +1124,8 @@ pub fn format_stmt(ctx: &Context, stmt: &Stmt, shape: Shape) -> Stmt {
#[cfg(feature = "luau")] TypeDeclaration = format_type_declaration_stmt,
#[cfg(feature = "luau")] ExportedTypeFunction = format_exported_type_function,
#[cfg(feature = "luau")] TypeFunction = format_type_function_stmt,
#[cfg(feature = "lua52")] Goto = format_goto,
#[cfg(feature = "lua52")] Label = format_label,
#[cfg(any(feature = "lua52", feature = "luajit"))] Goto = format_goto,
#[cfg(any(feature = "lua52", feature = "luajit"))] Label = format_label,
})
}

Expand All @@ -1141,7 +1141,7 @@ pub fn format_stmt_no_trivia(ctx: &Context, stmt: &Stmt, shape: Shape) -> Stmt {
}
Stmt::Assignment(stmt) => Stmt::Assignment(format_assignment_no_trivia(ctx, stmt, shape)),
Stmt::FunctionCall(stmt) => Stmt::FunctionCall(format_function_call(ctx, stmt, shape)),
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Goto(goto) => Stmt::Goto(format_goto_no_trivia(ctx, goto, shape)),
_ => unreachable!("format_stmt_no_trivia: node != assignment/function call/goto"),
}
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/trivia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,13 @@ define_update_trivia!(Stmt, |this, leading, trailing| {
}
#[cfg(feature = "luau")]
Stmt::TypeFunction(stmt) => Stmt::TypeFunction(stmt.update_trivia(leading, trailing)),
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Goto(stmt) => Stmt::Goto(
stmt.to_owned()
.with_goto_token(stmt.goto_token().update_leading_trivia(leading))
.with_label_name(stmt.label_name().update_trailing_trivia(trailing)),
),
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Label(stmt) => Stmt::Label(
stmt.to_owned()
.with_left_colons(stmt.left_colons().update_leading_trivia(leading))
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/trivia_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn is_block_simple(block: &Block) -> bool {
true
}
Stmt::FunctionCall(_) => true,
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Goto(_) => true,
_ => false,
})
Expand Down Expand Up @@ -948,7 +948,7 @@ pub fn get_stmt_trailing_trivia(stmt: Stmt) -> (Stmt, Vec<Token>) {
let (type_declaration, trailing_trivia) = take_trailing_trivia(&stmt);
(Stmt::TypeFunction(type_declaration), trailing_trivia)
}
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Goto(stmt) => {
let trailing_trivia = stmt
.label_name()
Expand All @@ -963,7 +963,7 @@ pub fn get_stmt_trailing_trivia(stmt: Stmt) -> (Stmt, Vec<Token>) {
trailing_trivia,
)
}
#[cfg(feature = "lua52")]
#[cfg(any(feature = "lua52", feature = "luajit"))]
Stmt::Label(stmt) => {
let trailing_trivia = stmt
.right_colons()
Expand Down
4 changes: 4 additions & 0 deletions tests/inputs-luajit/goto.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if opaque then
goto label
end
::label::
9 changes: 9 additions & 0 deletions tests/snapshots/tests__luajit.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: tests/tests.rs
expression: "format(&contents, LuaVersion::LuaJIT)"
input_file: tests/inputs-luajit/goto.lua
---
if opaque then
goto label
end
::label::
9 changes: 9 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ fn test_lua54() {
})
}

#[test]
#[cfg(feature = "luajit")]
fn test_luajit() {
insta::glob!("inputs-luajit/*.lua", |path| {
let contents = std::fs::read_to_string(path).unwrap();
insta::assert_snapshot!(format(&contents, LuaVersion::LuaJIT));
})
}

#[test]
#[cfg(feature = "cfxlua")]
fn test_cfxlua() {
Expand Down
Loading