This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGf6740fe483e9: [clang-format] Indent import statements in JavaScript. (authored by sstwcw).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121906/new/ https://reviews.llvm.org/D121906 Files: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTestJS.cpp Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -1875,6 +1875,11 @@ " myX} from 'm';"); verifyFormat("import * as lib from 'some/module.js';"); verifyFormat("var x = {import: 1};\nx.import = 2;"); + // Ensure an import statement inside a block is at the correct level. + verifyFormat("function() {\n" + " var x;\n" + " import 'some/module.js';\n" + "}"); verifyFormat("export function fn() {\n" " return 'fn';\n" Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1431,8 +1431,10 @@ if (Newlines) Indent = NewlineIndent; - // Preprocessor directives get indented before the hash only if specified - if (Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash && + // Preprocessor directives get indented before the hash only if specified. In + // Javascript import statements are indented like normal statements. + if (!Style.isJavaScript() && + Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash && (Line.Type == LT_PreprocessorDirective || Line.Type == LT_ImportStatement)) Indent = 0;
Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -1875,6 +1875,11 @@ " myX} from 'm';"); verifyFormat("import * as lib from 'some/module.js';"); verifyFormat("var x = {import: 1};\nx.import = 2;"); + // Ensure an import statement inside a block is at the correct level. + verifyFormat("function() {\n" + " var x;\n" + " import 'some/module.js';\n" + "}"); verifyFormat("export function fn() {\n" " return 'fn';\n" Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1431,8 +1431,10 @@ if (Newlines) Indent = NewlineIndent; - // Preprocessor directives get indented before the hash only if specified - if (Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash && + // Preprocessor directives get indented before the hash only if specified. In + // Javascript import statements are indented like normal statements. + if (!Style.isJavaScript() && + Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash && (Line.Type == LT_PreprocessorDirective || Line.Type == LT_ImportStatement)) Indent = 0;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits