diff options
| -rw-r--r-- | clang/lib/Format/FormatTokenLexer.cpp | 2 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index 8c795fb4d6d..c9670aeff66 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -235,6 +235,8 @@ void FormatTokenLexer::handleTemplateStrings() { return; } if (BacktickToken->is(tok::r_brace)) { + if (StateStack.size() == 1) + return; StateStack.pop(); if (StateStack.top() != LexerState::TEMPLATE_STRING) return; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 528986a0c94..9ccb75b6296 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1253,6 +1253,9 @@ TEST_F(FormatTestJS, NestedTemplateStrings) { verifyFormat( "var x = `<ul>${xs.map(x => `<li>${x}</li>`).join('\\n')}</ul>`;"); verifyFormat("var x = `he${({text: 'll'}.text)}o`;"); + + // Crashed at some point. + verifyFormat("}"); } TEST_F(FormatTestJS, TaggedTemplateStrings) { |

