[llvm][mustache] Align standalone partial indentation with spec#159185
Merged
Conversation
This was referenced Sep 16, 2025
Contributor
Author
This was referenced Sep 16, 2025
Member
|
@llvm/pr-subscribers-llvm-support Author: Paul Kirth (ilovepi) ChangesThe current implementaion did not correctly handle indentation for Full diff: https://github.com/llvm/llvm-project/pull/159185.diff 2 Files Affected:
diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index be9cbfd46982f..9c71d6a510056 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -292,8 +292,7 @@ void stripTokenBefore(SmallVectorImpl<Token> &Tokens, size_t Idx,
StringRef PrevTokenBody = PrevToken.TokenBody;
StringRef Unindented = PrevTokenBody.rtrim(" \r\t\v");
size_t Indentation = PrevTokenBody.size() - Unindented.size();
- if (CurrentType != Token::Type::Partial)
- PrevToken.TokenBody = Unindented.str();
+ PrevToken.TokenBody = Unindented.str();
CurrentToken.setIndentation(Indentation);
}
@@ -425,7 +424,8 @@ class AddIndentationStringStream : public raw_ostream {
public:
explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
size_t Indentation)
- : Indentation(Indentation), WrappedStream(WrappedStream) {
+ : Indentation(Indentation), WrappedStream(WrappedStream),
+ NeedsIndent(true) {
SetUnbuffered();
}
@@ -434,10 +434,15 @@ class AddIndentationStringStream : public raw_ostream {
llvm::StringRef Data(Ptr, Size);
SmallString<0> Indent;
Indent.resize(Indentation, ' ');
+
for (char C : Data) {
+ if (NeedsIndent && C != '\n') {
+ WrappedStream << Indent;
+ NeedsIndent = false;
+ }
WrappedStream << C;
if (C == '\n')
- WrappedStream << Indent;
+ NeedsIndent = true;
}
}
@@ -446,6 +451,7 @@ class AddIndentationStringStream : public raw_ostream {
private:
size_t Indentation;
llvm::raw_ostream &WrappedStream;
+ bool NeedsIndent;
};
class Parser {
diff --git a/llvm/unittests/Support/MustacheTest.cpp b/llvm/unittests/Support/MustacheTest.cpp
index dadee6bcf7b60..b80c39fb7c5bc 100644
--- a/llvm/unittests/Support/MustacheTest.cpp
+++ b/llvm/unittests/Support/MustacheTest.cpp
@@ -998,7 +998,7 @@ TEST(MustachePartials, StandaloneIndentation) {
std::string Out;
raw_string_ostream OS(Out);
T.render(D, OS);
- EXPECT_NE("\\\n |\n <\n ->\n |\n/\n", Out);
+ EXPECT_EQ("\\\n |\n <\n ->\n |\n/\n", Out);
}
TEST(MustacheLambdas, BasicInterpolation) {
|
This was referenced Sep 16, 2025
8b5ffb2 to
f2623ab
Compare
b6d2c4b to
db6bc75
Compare
f2623ab to
31dc0ed
Compare
6fa7a86 to
5fa6844
Compare
31dc0ed to
d34b03a
Compare
6f2cc7e to
77ea7e9
Compare
abd5ab1 to
9a8d968
Compare
Base automatically changed from
users/ilovepi/mustache-indent-tests
to
main
September 24, 2025 22:12
9c99ef9 to
c4b1cba
Compare
evelez7
approved these changes
Sep 29, 2025
The current implementation did not correctly handle indentation for standalone partial tags. It was only applied to lines following a newline, instead of the first line of a partial's content. This was fixed by updating the AddIndentation implementation to prepend the indentation to the first line of the partial.
c4b1cba to
c58ac89
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/19026 Here is the relevant piece of the build log for the reference |
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Oct 3, 2025
…#159185) The current implementaion did not correctly handle indentation for standalone partial tags. It was only applied to lines following a newline, instead of the first line of a partial's content. This was fixed by updating the AddIndentation implementaion to prepend the indentation to the first line of the partial.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The current implementaion did not correctly handle indentation for
standalone partial tags. It was only applied to lines following a
newline, instead of the first line of a partial's content. This was
fixed by updating the AddIndentation implementaion to prepend the
indentation to the first line of the partial.