diff options
| author | Daniel Jasper <djasper@google.com> | 2017-01-31 13:03:07 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2017-01-31 13:03:07 +0000 |
| commit | 24de6fbfdb72a1c06492a922f68b03ed3035c63b (patch) | |
| tree | 4ed1444f850b814d3cba105bd0585f93ed1a0bdc /clang/lib/Format | |
| parent | dbaacc75664e9322643b5a43cde6fc5e5e39e1b1 (diff) | |
| download | bcm5719-llvm-24de6fbfdb72a1c06492a922f68b03ed3035c63b.tar.gz bcm5719-llvm-24de6fbfdb72a1c06492a922f68b03ed3035c63b.zip | |
clang-format: [JS] Properly set scopes inside template strings.
Before:
var f = `aaaaaaaaaaaaa:${aaaaaaa
.aaaaa} aaaaaaaa
aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;
After:
var f = `aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa
aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;
llvm-svn: 293622
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/FormatToken.h | 4 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index b22e4c5d7c4..c838cfbe1da 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -337,11 +337,15 @@ struct FormatToken { /// \brief Returns whether \p Tok is ([{ or a template opening <. bool opensScope() const { + if (is(TT_TemplateString) && TokenText.endswith("${")) + return true; return isOneOf(tok::l_paren, tok::l_brace, tok::l_square, TT_TemplateOpener); } /// \brief Returns whether \p Tok is )]} or a template closing >. bool closesScope() const { + if (is(TT_TemplateString) && TokenText.startswith("}")) + return true; return isOneOf(tok::r_paren, tok::r_brace, tok::r_square, TT_TemplateCloser); } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e58ca6d803e..2785ca45e70 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1454,7 +1454,9 @@ public: // Consume scopes: (), [], <> and {} if (Current->opensScope()) { - while (Current && !Current->closesScope()) { + // In fragment of a JavaScript template string can look like '}..${' and + // thus close a scope and open a new one at the same time. + while (Current && (!Current->closesScope() || Current->opensScope())) { next(); parse(); } |

