mirror of
https://github.com/luau-lang/luau.git
synced 2025-08-26 11:27:08 +01:00
Add "AstStatDeclareGlobal" to the Transpiler, so you can use it with Luau::toString (#1889)
This commit is contained in:
parent
0ce993fe6c
commit
b668ffb8c8
2 changed files with 25 additions and 0 deletions
|
@ -1252,6 +1252,15 @@ struct Printer
|
|||
|
||||
writer.symbol(")");
|
||||
}
|
||||
else if (const auto& a = program.as<AstStatDeclareGlobal>())
|
||||
{
|
||||
writer.keyword("declare");
|
||||
writer.advance(a->nameLocation.begin);
|
||||
writer.identifier(a->name.value);
|
||||
|
||||
writer.symbol(":");
|
||||
visualizeTypeAnnotation(*a->type);
|
||||
}
|
||||
else
|
||||
{
|
||||
LUAU_ASSERT(!"Unknown AstStat");
|
||||
|
|
|
@ -1568,6 +1568,22 @@ TEST_CASE_FIXTURE(Fixture, "transpile_parse_error")
|
|||
CHECK_EQ("Expected identifier when parsing expression, got <eof>", result.parseError);
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "transpile_declare_global_stat")
|
||||
{
|
||||
std::string code = "declare _G: any";
|
||||
|
||||
ParseOptions options;
|
||||
options.allowDeclarationSyntax = true;
|
||||
|
||||
auto allocator = Allocator{};
|
||||
auto names = AstNameTable{allocator};
|
||||
ParseResult parseResult = Parser::parse(code.data(), code.size(), names, allocator, options);
|
||||
|
||||
auto result = transpileWithTypes(*parseResult.root);
|
||||
|
||||
CHECK_EQ(result, code);
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "transpile_to_string")
|
||||
{
|
||||
std::string code = "local a: string = 'hello'";
|
||||
|
|
Loading…
Add table
Reference in a new issue