[PATCH] D17440: clang-format: [JS] do not wrap ES6 imports/exports.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 22 04:22:53 PDT 2016


mprobst marked an inline comment as done.

================
Comment at: lib/Format/TokenAnnotator.cpp:760
@@ +759,3 @@
+      if (CurrentToken->is(tok::kw_export)) {
+        // Find the 'from' part of export {...} from '...';
+        // The difference here is that "export {...};" should not be treated as
----------------
djasper wrote:
> Can you actually have:
> 
>   export {a as from};
> 
> ?
Good observation. Fixed by specifically looking for `from 'some tring';`.

================
Comment at: lib/Format/TokenAnnotator.cpp:763
@@ +762,3 @@
+        // an export.
+        while (CurrentToken) {
+          if (CurrentToken->is(tok::semi))
----------------
djasper wrote:
> Not a big fan of the code duplication in this loop. How about doing:
> 
>   if (Style.Language == FormatStyle::LK_JavaScript &&
>       ((Line.First->is(tok::kw_export) && CurrentToken->is(Keywords.kw_from)) ||
>        isClosureImportStatement(*CurrentToken)))
>     return LT_ImportStatement;
> 
> in the lower loop? The ImportStatement variable can likely go away then.
Merged with the code below. My intent was to not do this check for JavaScript code that doesn't start with `import` or `export`, but merging seems fair, too.


http://reviews.llvm.org/D17440





More information about the cfe-commits mailing list