[PATCH] D20817: clang-format: [JS] no ASI on `import {x as\n y}`.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Tue May 31 08:18:48 PDT 2016


mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

ASI did not handle the ES6 `as` operator correctly.

http://reviews.llvm.org/D20817

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1010,6 +1010,9 @@
                "} from 'some/module.js';");
   verifyFormat("import {X, Y,} from 'some/module.js';");
   verifyFormat("import {X as myLocalX, Y as myLocalY} from 'some/module.js';");
+  // Ensure Automatic Semicolon Insertion does not break on "as\n".
+  verifyFormat("import {X as myX} from 'm';", "import {X as\n"
+                                              " myX} from 'm';");
   verifyFormat("import * as lib from 'some/module.js';");
   verifyFormat("var x = {import: 1};\nx.import = 2;");
 
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -668,11 +668,11 @@
   // FIXME: This returns true for C/C++ keywords like 'struct'.
   return FormatTok->is(tok::identifier) &&
          (FormatTok->Tok.getIdentifierInfo() == nullptr ||
-          !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of, Keywords.kw_async,
-                              Keywords.kw_await, Keywords.kw_yield,
-                              Keywords.kw_finally, Keywords.kw_function,
-                              Keywords.kw_import, Keywords.kw_is,
-                              Keywords.kw_let, Keywords.kw_var,
+          !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of, Keywords.kw_as,
+                              Keywords.kw_async, Keywords.kw_await,
+                              Keywords.kw_yield, Keywords.kw_finally,
+                              Keywords.kw_function, Keywords.kw_import,
+                              Keywords.kw_is, Keywords.kw_let, Keywords.kw_var,
                               Keywords.kw_abstract, Keywords.kw_extends,
                               Keywords.kw_implements, Keywords.kw_instanceof,
                               Keywords.kw_interface, Keywords.kw_throws));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20817.59074.patch
Type: text/x-patch
Size: 2046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160531/b78ab89d/attachment.bin>


More information about the cfe-commits mailing list