diff --git a/Ast/include/Luau/PrettyPrinter.h b/Ast/include/Luau/PrettyPrinter.h index 6d69bb59f..a2e430d01 100644 --- a/Ast/include/Luau/PrettyPrinter.h +++ b/Ast/include/Luau/PrettyPrinter.h @@ -24,6 +24,7 @@ void dump(AstNode* node); // Never fails on a well-formed AST std::string prettyPrint(AstStatBlock& ast); +std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap); std::string prettyPrintWithTypes(AstStatBlock& block); std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap); diff --git a/Ast/src/PrettyPrinter.cpp b/Ast/src/PrettyPrinter.cpp index f95fe1ab8..78ecb39db 100644 --- a/Ast/src/PrettyPrinter.cpp +++ b/Ast/src/PrettyPrinter.cpp @@ -1966,6 +1966,11 @@ std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap) return writer.str(); } +std::string prettyPrint(AstStatBlock& block) +{ + return prettyPrint(block, CstNodeMap{nullptr}); +} + std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap) { StringWriter writer; diff --git a/tests/PrettyPrinter.test.cpp b/tests/PrettyPrinter.test.cpp index d0d8f726d..6d4a40e7e 100644 --- a/tests/PrettyPrinter.test.cpp +++ b/tests/PrettyPrinter.test.cpp @@ -31,6 +31,19 @@ end CHECK_EQ(example, prettyPrint(example).code); } +TEST_CASE("prettyPrint_AstStatBlock_overload") +{ + const std::string code = "local a = 1"; + ParseOptions options; + Allocator allocator; + AstNameTable names(allocator); + ParseResult result = Parser::parse(code.c_str(), code.size(), names, allocator, options); + REQUIRE(result.root != nullptr); + + std::string printed = prettyPrint(*result.root); + CHECK_EQ("local a = 1", printed); +} + TEST_CASE("string_literals") { const std::string code = R"( local S='abcdef\n\f\a\020' )";