[PATCH] clang-format: [js] Support ES6 module exports.

Martin Probst martinprobst at google.com
Thu Feb 19 08:12:03 PST 2015


Addressed comments.


================
Comment at: lib/Format/TokenAnnotator.cpp:1762
@@ -1761,2 +1761,3 @@
     if ((Left.is(tok::l_brace) || Right.is(tok::r_brace)) &&
-        Line.First->is(Keywords.kw_import))
+        (Line.First->is(Keywords.kw_import) ||
+         Line.First->is(tok::kw_export)))
----------------
djasper wrote:
>   Line.First->isOneOf(Keywords.kw_import, tok::kw_export)
That wouldn't work in Java without reified generics. Nice :-)

================
Comment at: lib/Format/UnwrappedLineParser.cpp:737
@@ -736,2 +736,3 @@
     break;
+  case tok::kw_export:
   case tok::identifier:
----------------
djasper wrote:
> I'd add:
> 
>   if (Style.Language == FormatStyle::LK_JavaScript) {
>     parseJavaScriptEs6ImportExport();
>     return;
>   }
>   break;
> 
> here and not fall through or change the block below.
Done.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:744
@@ -742,3 +743,3 @@
     if (Style.Language == FormatStyle::LK_JavaScript &&
-        FormatTok->is(Keywords.kw_import)) {
-      parseJavaScriptEs6Import();
+        (FormatTok->is(Keywords.kw_import) ||
+         FormatTok->is(tok::kw_export))) {
----------------
djasper wrote:
>   Line.First->isOneOf(Keywords.kw_import, tok::kw_export)
No longer needed.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:1609
@@ +1608,3 @@
+void UnwrappedLineParser::parseJavaScriptEs6ImportExport() {
+  nextToken(); // 'import' or 'export'
+  switch (FormatTok->Tok.getKind()) {
----------------
djasper wrote:
> Maybe assert instead of the comment?
Done.

================
Comment at: lib/Format/UnwrappedLineParser.cpp:1622
@@ +1621,3 @@
+  default:
+    if (FormatTok->isOneOf(Keywords.kw_function, Keywords.kw_var))
+      return; // export function ...
----------------
djasper wrote:
> I'd probably use if statements instead of the switch. Seems a bit bad to mix switch and if (which you can't avoid because of Keywords):
> 
>   if (FormatTok->isOneOf(tok::kw_const, tok::kw_class,
>                          Keywords.kw_function, Keywords.kw_var))
>     return; // Fall through to parsing the corresponding structure.
> 
>   if (FormatTok->is(tok::kw_default)) {
>     nextToken();
>     return;
>   }
> 
>   if (FormatTok->is(tok::l_brace)) {
>     FormatTok->BlockKind = BK_Block;
>     parseBracedList();
>   }
Yeah, that's better indeed.

http://reviews.llvm.org/D7754

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list