EndBacktick->OriginalColumn + EndBacktick->ColumnWidth;
for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; I++) {
++TokenCount;
- if (I[0]->NewlinesBefore > 0 || I[0]->IsMultiline)
+ if (I[0]->IsMultiline)
IsMultiline = true;
// If there was a preceding template string, this must be the start of a
EndColumnInFirstLine = I[0]->OriginalColumn + I[0]->ColumnWidth;
// If the token has newlines, the token before it (if it exists) is the
// rhs end of the previous line.
- if (I[0]->NewlinesBefore > 0 && (I + 1 != E))
+ if (I[0]->NewlinesBefore > 0 && (I + 1 != E)) {
EndColumnInFirstLine = I[1]->OriginalColumn + I[1]->ColumnWidth;
-
+ IsMultiline = true;
+ }
continue;
}
// until here`;
Tokens.back()->ColumnWidth =
EndColumnInFirstLine - Tokens.back()->OriginalColumn;
- Tokens.back()->LastLineColumnWidth = EndOriginalColumn;
+ // +1 for the ` itself.
+ Tokens.back()->LastLineColumnWidth = EndOriginalColumn + 1;
Tokens.back()->IsMultiline = true;
} else {
// Token simply spans from start to end, +1 for the ` itself.
break;
default:
FormatTok->Type = TT_ImplicitStringLiteral;
- ++Column;
break;
}
}
" ${ name }\n"
" !`;"));
- // FIXME: +1 / -1 offsets are to work around clang-format miscalculating
- // widths for unknown tokens that are not whitespace (e.g. '`'). Remove when
- // the code is corrected.
-
verifyFormat("var x =\n"
" `hello ${world}` >= some();",
getGoogleJSStyleWithColumns(34)); // Barely doesn't fit.
verifyFormat("var x = `hello ${world}` >= some();",
- getGoogleJSStyleWithColumns(35 + 1)); // Barely fits.
+ getGoogleJSStyleWithColumns(35)); // Barely fits.
EXPECT_EQ("var x = `hello\n"
" ${world}` >=\n"
" some();",
" ${world}` >= some();",
getGoogleJSStyleWithColumns(22))); // Barely fits.
- verifyFormat("var x =\n `h`;", getGoogleJSStyleWithColumns(13 - 1));
+ verifyFormat("var x =\n"
+ " `h`;",
+ getGoogleJSStyleWithColumns(11));
EXPECT_EQ(
"var x =\n `multi\n line`;",
- format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(14 - 1)));
+ format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(13)));
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`);");
// Make sure template strings get a proper ColumnWidth assigned, even if they
// are first token in line.