diff options
author | Daniel Jasper <djasper@google.com> | 2015-10-18 07:02:28 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-10-18 07:02:28 +0000 |
commit | 265309e38a99a74d872a818b1c49085165e4e1ac (patch) | |
tree | 35745ed2cc0973e7d2e6251c6405c7fefe9e3287 /clang/unittests/Format | |
parent | 273dbc602f783d5f99b969d51d57a67cc7c8d6c0 (diff) | |
download | bcm5719-llvm-265309e38a99a74d872a818b1c49085165e4e1ac.tar.gz bcm5719-llvm-265309e38a99a74d872a818b1c49085165e4e1ac.zip |
clang-format: [JS] Handle string literals spanning character classes.
If a RegExp contains a character group with a quote (/["]/), the
trailing end of it is first tokenized as a string literal, which leads
to the merging code seeing an unbalanced bracket.
This change parses regex literals from the left hand side. That
simplifies the parsing code and also allows correctly handling escapes
and character classes, hopefully correctly parsing all regex literals.
Patch by Martin Probst, thank you.
Review: http://reviews.llvm.org/D13765
llvm-svn: 250648
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index d63a24d8056..8538a7d94a8 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -600,6 +600,13 @@ TEST_F(FormatTestJS, RegexLiteralClassification) { // Not regex literals. verifyFormat("var a = a / 2 + b / 3;"); + verifyFormat("var a = a++ / 2;"); + // Prefix unary can operate on regex literals, not that it makes sense. + verifyFormat("var a = ++/a/;"); + + // This is a known issue, regular expressions are incorrectly detected if + // directly following a closing parenthesis. + verifyFormat("if (foo) / bar /.exec(baz);"); } TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) { @@ -625,6 +632,9 @@ TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) { verifyFormat("var regex = /[\\/]/;"); verifyFormat("var regex = /\\[/;"); verifyFormat("var regex = /\\\\[/]/;"); + verifyFormat("var regex = /}[\"]/;"); + verifyFormat("var regex = /}[/\"]/;"); + verifyFormat("var regex = /}[\"/]/;"); verifyFormat("var regex = /\\b/;"); verifyFormat("var regex = /\\B/;"); |