Author: mprobst Date: Wed Jan 4 07:36:43 2017 New Revision: 290959 URL: http://llvm.org/viewvc/llvm-project?rev=290959&view=rev Log: clang-format: [JS] avoid indent after ambient function declarations.
Summary: Before: declare function foo(); let x = 1; After: declare function foo(); let x = 1; The problem was that clang-format would unconditionally try to parse a child block, even though ambient function declarations do not have a body (similar to forward declarations). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28246 Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTestJS.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=290959&r1=290958&r2=290959&view=diff ============================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Jan 4 07:36:43 2017 @@ -1255,10 +1255,13 @@ void UnwrappedLineParser::tryToParseJSFu if (FormatTok->is(tok::l_brace)) tryToParseBracedList(); else - while (FormatTok->isNot(tok::l_brace) && !eof()) + while (!FormatTok->isOneOf(tok::l_brace, tok::semi) && !eof()) nextToken(); } + if (FormatTok->is(tok::semi)) + return; + parseChildBlock(); } Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=290959&r1=290958&r2=290959&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jan 4 07:36:43 2017 @@ -377,6 +377,16 @@ TEST_F(FormatTestJS, AmbientDeclarations "declare function\n" "x();", // TODO(martinprobst): should ideally be indented. NineCols); + verifyFormat("declare function foo();\n" + "let x = 1;\n"); + verifyFormat("declare function foo(): string;\n" + "let x = 1;\n"); + verifyFormat("declare function foo(): {x: number};\n" + "let x = 1;\n"); + verifyFormat("declare class X {}\n" + "let x = 1;\n"); + verifyFormat("declare interface Y {}\n" + "let x = 1;\n"); verifyFormat( "declare enum X {\n" "}", _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits