Skip to content

Commit

Permalink
Clean up whitespace logic in standalone lines scanner
Browse files Browse the repository at this point in the history
Summary:
When we strip a standalone partial, per the mustache spec we have to retain the indentation on the left side:

```
// the two spaces in front must be in the output
// spaces to the right are removed
  {{#partial foo}}
```

There can only ever be 0 or 1 `tok::whitespace` on the left. The current code performs an iteration which implies there's more going on.

Reviewed By: rmakheja

Differential Revision: D68994634

fbshipit-source-id: 1d7c0640a130dcea6da4561bc2c7d938293f669e
  • Loading branch information
praihan authored and facebook-github-bot committed Feb 4, 2025
1 parent 7394188 commit fb12a6a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions third-party/thrift/src/thrift/compiler/whisker/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,15 @@ class standalone_lines_scanner {
drain_current_line();
continue;
}
std::string preceding_whitespace;
for (cursor c = current_line.start; c != scan_start; ++c) {
assert(c->kind == tok::whitespace);
preceding_whitespace += c->string_value();
}
auto preceding_whitespace = std::invoke([&]() -> std::string {
if (current_line.start == scan_start) {
return {};
}
// There should be exactly one whitespace token on the line
assert(current_line.start->kind == tok::whitespace);
assert(std::next(current_line.start) == scan_start);
return std::string(current_line.start->string_value());
});
current_line.markings.emplace_back(
scan_start, partial_apply{std::move(preceding_whitespace)});
// Do not strip the left side
Expand Down

0 comments on commit fb12a6a

Please sign in to comment.