diff options
author | Martin Probst <martin@probst.io> | 2016-08-25 10:13:21 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2016-08-25 10:13:21 +0000 |
commit | 6181da4796ef8c095e3e5250413ff7e82878cba4 (patch) | |
tree | d15bbe889e7006f431ffc90df9825ee54d81319a /clang/unittests/Format/FormatTestJS.cpp | |
parent | 86ce267a4ace2ec170653611099786324808d68e (diff) | |
download | bcm5719-llvm-6181da4796ef8c095e3e5250413ff7e82878cba4.tar.gz bcm5719-llvm-6181da4796ef8c095e3e5250413ff7e82878cba4.zip |
clang-format: [JS] nested and tagged template strings.
JavaScript template strings can be nested arbitrarily:
foo = `text ${es.map(e => { return `<${e}>`; })} text`;
This change lexes nested template strings using a stack of lexer states to
correctly switch back to template string lexing on closing braces.
Also, reuse the same stack for the token-stashed logic.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D22431
llvm-svn: 279727
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index f6e8ff2f385..60063934cd9 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1122,7 +1122,7 @@ TEST_F(FormatTestJS, ImportWrapping) { TEST_F(FormatTestJS, TemplateStrings) { // Keeps any whitespace/indentation within the template string. verifyFormat("var x = `hello\n" - " ${ name }\n" + " ${name}\n" " !`;", "var x = `hello\n" " ${ name }\n" @@ -1206,6 +1206,18 @@ TEST_F(FormatTestJS, TemplateStrings) { "var y;", "var x = ` \\` a`;\n" "var y;"); + // Escaped dollar. + verifyFormat("var x = ` \\${foo}`;\n"); +} + +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`;"); +} + +TEST_F(FormatTestJS, TaggedTemplateStrings) { + verifyFormat("var x = html`<ul>`;"); } TEST_F(FormatTestJS, CastSyntax) { |