Skip to content

Commit

Permalink
Remove support for space in the middle of partial application syntax
Browse files Browse the repository at this point in the history
Summary: This was carried over from mustache but is just a source of inconsistency

Reviewed By: dtolnay

Differential Revision: D66780396

fbshipit-source-id: 1b375dd246f025be68338a990d963fb100177a1c
  • Loading branch information
iahs authored and facebook-github-bot committed Dec 5, 2024
1 parent c8128c8 commit 765c85d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ file.
}}{{/value:const_struct_type}}{{!
}}({{#value:const_struct}}{{!
}}{{constant:name}}={{#constant:type}}{{#constant:value}}{{!
}}{{ >types/constant_value }}{{!
}}{{> types/constant_value }}{{!
}}{{/constant:value}}{{/constant:type}}{{^last?}}, {{/last?}}{{!
}}{{/value:const_struct}}){{!
}}{{/value:const_struct?}}{{!
Expand Down
4 changes: 0 additions & 4 deletions third-party/thrift/src/thrift/compiler/whisker/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,6 @@ lexer::state_text::result lexer::state_text::next(lexer& lex) {
if (scan_within.peek() == '!') {
return ptr(std::make_unique<lexer::state_comment>());
}
// While Mustache does not technically support spaces between "{{" and
// ">" for partial applications, mstch does so we skip whitespace *only*
// in this case for backward compatibility.
skip_whitespace(&scan_within);
return scan_within.peek() == '>'
? ptr(std::make_unique<lexer::state_partial_application>())
: ptr(std::make_unique<lexer::state_template>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ TEST_F(LexerTest, partial_apply) {
}

TEST_F(LexerTest, partial_apply_single_component) {
auto lexer = make_lexer("{{ > foo }}");
auto lexer = make_lexer("{{> foo }}");
const std::vector<token_description> expected = {
{tok::open, {}},
{tok::gt, {}},
Expand All @@ -299,7 +299,7 @@ TEST_F(LexerTest, partial_apply_no_path) {
}

TEST_F(LexerTest, partial_apply_keyword_and_dots) {
auto lexer = make_lexer("{{ > foo-bar / true /source.cpp }}");
auto lexer = make_lexer("{{> foo-bar / true /source.cpp }}");
const std::vector<token_description> expected = {
{tok::open, {}},
{tok::gt, {}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,36 +482,36 @@ TEST_F(ParserTest, basic_partial_apply) {
}

TEST_F(ParserTest, partial_apply_single_id) {
auto ast = parse_ast("{{ > foo }}");
auto ast = parse_ast("{{> foo }}");
EXPECT_EQ(
to_string(*ast),
"root [path/to/test-1.whisker]\n"
"|- partial-apply <line:1:1, col:12> 'foo'\n"
"|- partial-apply <line:1:1, col:11> 'foo'\n"
"| `- standalone-offset ''\n");
}

TEST_F(ParserTest, partial_apply_in_section) {
auto ast = parse_ast(
"{{#news.has-update?}}\n"
" {{ > print/news}}\n"
" {{> print/news}}\n"
"{{/news.has-update?}}");
EXPECT_EQ(
to_string(*ast),
"root [path/to/test-1.whisker]\n"
"|- section-block <line:1:1, line:3:22>\n"
"| `- variable-lookup <line:1:4, col:20> 'news.has-update?'\n"
"| |- text <line:2:1, col:3> ' '\n"
"| |- partial-apply <line:2:3, col:20> 'print/news'\n"
"| |- partial-apply <line:2:3, col:19> 'print/news'\n"
"| | `- standalone-offset ' '\n");
}

TEST_F(ParserTest, partial_apply_preserves_whitespace_offset) {
auto ast = parse_ast(" \t {{ > print/news}}\n");
auto ast = parse_ast(" \t {{> print/news}}\n");
EXPECT_EQ(
to_string(*ast),
"root [path/to/test-1.whisker]\n"
"|- text <line:1:1, col:4> ' \\t '\n"
"|- partial-apply <line:1:4, col:21> 'print/news'\n"
"|- partial-apply <line:1:4, col:20> 'print/news'\n"
"| `- standalone-offset ' \\t '\n");
}

Expand All @@ -528,7 +528,7 @@ TEST_F(ParserTest, partial_apply_no_id) {
}

TEST_F(ParserTest, partial_apply_extra_stuff) {
auto ast = parse_ast("{{ > foo ! }}");
auto ast = parse_ast("{{> foo ! }}");
EXPECT_FALSE(ast.has_value());
EXPECT_THAT(
diagnostics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ TEST_F(
auto result = render(
"| This Is\n"
" {{#boolean\n"
" .condition}} {{ > ineligible}} \n"
" .condition}} {{> ineligible}} \n"
"|\n"
" {{/boolean.condition}}\n"
"| A Line\n",
Expand Down

0 comments on commit 765c85d

Please sign in to comment.