mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Fix location, Transpiler
This commit is contained in:
parent
38d40143d7
commit
591192c3e5
4 changed files with 37 additions and 3 deletions
|
@ -511,6 +511,28 @@ struct Printer
|
|||
writer.keyword("else");
|
||||
visualize(*a->falseExpr);
|
||||
}
|
||||
else if (const auto& a = expr.as<AstExprInterpString>())
|
||||
{
|
||||
writer.symbol("`");
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
for (const auto& string : a->strings)
|
||||
{
|
||||
writer.write(escape(std::string_view(string.data, string.size)));
|
||||
|
||||
if (index < a->expressions.size)
|
||||
{
|
||||
writer.symbol("{");
|
||||
visualize(*a->expressions.data[index]);
|
||||
writer.symbol("}");
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
writer.symbol("`");
|
||||
}
|
||||
else if (const auto& a = expr.as<AstExprError>())
|
||||
{
|
||||
writer.symbol("(error-expr");
|
||||
|
|
|
@ -2638,6 +2638,8 @@ AstExpr* Parser::parseInterpString()
|
|||
std::vector<AstArray<char>> strings;
|
||||
std::vector<AstExpr*> expressions;
|
||||
|
||||
Location startLocation = lexer.current().location;
|
||||
|
||||
do {
|
||||
auto currentLexeme = lexer.current();
|
||||
LUAU_ASSERT(currentLexeme.type == Lexeme::InterpStringBegin || currentLexeme.type == Lexeme::InterpStringMid || currentLexeme.type == Lexeme::InterpStringEnd);
|
||||
|
@ -2651,7 +2653,7 @@ AstExpr* Parser::parseInterpString()
|
|||
if (!Lexer::fixupQuotedString(scratchData))
|
||||
{
|
||||
nextLexeme();
|
||||
return reportExprError(location, {}, "Interpolated string literal contains malformed escape sequence");
|
||||
return reportExprError(startLocation, {}, "Interpolated string literal contains malformed escape sequence");
|
||||
}
|
||||
|
||||
AstArray<char> chars = copy(scratchData);
|
||||
|
@ -2670,7 +2672,7 @@ AstExpr* Parser::parseInterpString()
|
|||
AstArray<AstArray<char>> stringsArray = copy(strings.data(), strings.size());
|
||||
AstArray<AstExpr*> expressionsArray = copy(expressions.data(), expressions.size());
|
||||
|
||||
return allocator.alloc<AstExprInterpString>(location, stringsArray, expressionsArray);
|
||||
return allocator.alloc<AstExprInterpString>(startLocation, stringsArray, expressionsArray);
|
||||
}
|
||||
|
||||
AstExpr* expression = parseExpr();
|
||||
|
|
|
@ -183,7 +183,7 @@ 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"}]}]})";
|
||||
R"({"type":"AstStatLocal","location":"0,0 - 0,17","vars":[{"luauType":null,"name":"a","type":"AstLocal","location":"0,6 - 0,7"}],"values":[{"type":"AstExprInterpString","location":"0,10 - 0,17","strings":["var = ",""],"expressions":[{"type":"AstExprGlobal","location":"0,18 - 0,19","global":"x"}]}]})";
|
||||
|
||||
CHECK(toJson(statement) == expected);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "Luau/Transpiler.h"
|
||||
|
||||
#include "Fixture.h"
|
||||
#include "ScopedFlags.h"
|
||||
|
||||
#include "doctest.h"
|
||||
|
||||
|
@ -678,4 +679,13 @@ TEST_CASE_FIXTURE(Fixture, "transpile_for_in_multiple_types")
|
|||
CHECK_EQ(code, transpile(code, {}, true).code);
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "transpile_string_interp")
|
||||
{
|
||||
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||
|
||||
std::string code = R"( local _ = `hello {name}` )";
|
||||
|
||||
CHECK_EQ(code, transpile(code, {}, true).code);
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
|
Loading…
Add table
Reference in a new issue