mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
JsonEncoder
This commit is contained in:
parent
7893ca20bb
commit
8496af7907
2 changed files with 25 additions and 2 deletions
|
@ -445,6 +445,14 @@ struct AstJsonEncoder : public AstVisitor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write(class AstExprInterpString* node)
|
||||||
|
{
|
||||||
|
writeNode(node, "AstExprInterpString", [&]() {
|
||||||
|
PROP(strings);
|
||||||
|
PROP(expressions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void write(class AstExprTable* node)
|
void write(class AstExprTable* node)
|
||||||
{
|
{
|
||||||
writeNode(node, "AstExprTable", [&]() {
|
writeNode(node, "AstExprTable", [&]() {
|
||||||
|
@ -773,7 +781,7 @@ struct AstJsonEncoder : public AstVisitor
|
||||||
PROP(indexer);
|
PROP(indexer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(struct AstTableIndexer* indexer)
|
void write(struct AstTableIndexer* indexer)
|
||||||
{
|
{
|
||||||
if (indexer)
|
if (indexer)
|
||||||
|
@ -888,6 +896,12 @@ struct AstJsonEncoder : public AstVisitor
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool visit(class AstExprInterpString* node) override
|
||||||
|
{
|
||||||
|
write(node);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool visit(class AstExprLocal* node) override
|
bool visit(class AstExprLocal* node) override
|
||||||
{
|
{
|
||||||
write(node);
|
write(node);
|
||||||
|
@ -1178,7 +1192,7 @@ struct AstJsonEncoder : public AstVisitor
|
||||||
write("location", comment.location);
|
write("location", comment.location);
|
||||||
popComma(c);
|
popComma(c);
|
||||||
writeRaw("}");
|
writeRaw("}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -175,6 +175,15 @@ TEST_CASE_FIXTURE(JsonEncoderFixture, "encode_AstExprIfThen")
|
||||||
CHECK(toJson(statement) == expected);
|
CHECK(toJson(statement) == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(JsonEncoderFixture, "encode_AstExprInterpString")
|
||||||
|
{
|
||||||
|
AstStat* statement = expectParseStatement("local a = `var = {x}`");
|
||||||
|
|
||||||
|
std::string_view expected =
|
||||||
|
R"({"type":"AstStatLocal","location":"0,0 - 0,21","vars":[{"luauType":null,"name":"a","type":"AstLocal","location":"0,6 - 0,7"}],"values":[{"type":"AstExprInterpString","location":"0,20 - 0,21","strings":["var = ",""],"expressions":[{"type":"AstExprGlobal","location":"0,18 - 0,19","global":"x"}]}]})";
|
||||||
|
|
||||||
|
CHECK(toJson(statement) == expected);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("encode_AstExprLocal")
|
TEST_CASE("encode_AstExprLocal")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue