Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -627,6 +627,9 @@ /// \brief The JavaScriptQuoteStyle to use for JavaScript strings. JavaScriptQuoteStyle JavaScriptQuotes; + /// \brief Whether to wrap JavaScript import/export statements. + bool WrapJavaScriptImports; + bool operator==(const FormatStyle &R) const { return AccessModifierOffset == R.AccessModifierOffset && AlignAfterOpenBracket == R.AlignAfterOpenBracket && Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -354,6 +354,7 @@ IO.mapOptional("TabWidth", Style.TabWidth); IO.mapOptional("UseTab", Style.UseTab); IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes); + IO.mapOptional("WrapJavaScriptImports", Style.WrapJavaScriptImports); } }; @@ -613,6 +614,7 @@ GoogleStyle.MaxEmptyLinesToKeep = 3; GoogleStyle.SpacesInContainerLiterals = false; GoogleStyle.JavaScriptQuotes = FormatStyle::JSQS_Single; + GoogleStyle.WrapJavaScriptImports = false; } else if (Language == FormatStyle::LK_Proto) { GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; GoogleStyle.SpacesInContainerLiterals = false; Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -786,7 +786,7 @@ // import {...} from '...'; if (Style.Language == FormatStyle::LK_JavaScript && - CurrentToken->is(Keywords.kw_import)) + CurrentToken->is(Keywords.kw_import) && !Style.WrapJavaScriptImports) return LT_ImportStatement; bool KeywordVirtualFound = false; @@ -804,7 +804,7 @@ if (Line.First->is(tok::kw_export) && CurrentToken->is(Keywords.kw_from) && CurrentToken->Next && CurrentToken->Next->isStringLiteral()) - ImportStatement = true; + ImportStatement = !Style.WrapJavaScriptImports; if (isClosureImportStatement(*CurrentToken)) ImportStatement = true; } Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1078,6 +1078,27 @@ "}"); } +TEST_F(FormatTestJS, ImportWrapping) { + FormatStyle Style = getGoogleJSStyleWithColumns(80); + Style.WrapJavaScriptImports = true; + verifyFormat("import {\n" + " VeryLongImportsAreAnnoying,\n" + " VeryLongImportsAreAnnoying,\n" + " VeryLongImportsAreAnnoying,\n" + "} from 'some/module.js';", + Style); + verifyFormat("import {\n" + " A,\n" + " A,\n" + "} from 'some/module.js';", + Style); + verifyFormat("export {\n" + " A,\n" + " A,\n" + "} from 'some/module.js';", + Style); +} + TEST_F(FormatTestJS, TemplateStrings) { // Keeps any whitespace/indentation within the template string. verifyFormat("var x = `hello\n"