r271401 - clang-format: [JS] no ASI on `import {x as\n y}`.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 08:22:48 PDT 2016
Author: mprobst
Date: Wed Jun 1 10:22:47 2016
New Revision: 271401
URL: http://llvm.org/viewvc/llvm-project?rev=271401&view=rev
Log:
clang-format: [JS] no ASI on `import {x as\n y}`.
Summary: ASI did not handle the ES6 `as` operator correctly.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D20817
Modified:
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/SortJavaScriptImports.cpp?rev=271401&r1=271400&r2=271401&view=diff
==============================================================================
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp (original)
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp Wed Jun 1 10:22:47 2016
@@ -245,7 +245,7 @@ private:
SourceLocation SymbolsEnd = Reference.Symbols.back().Range.getEnd();
Buffer += getSourceText(Reference.Range.getBegin(), SymbolsStart);
// ... then the references in order ...
- for (auto *I = Symbols.begin(), *E = Symbols.end(); I != E; ++I) {
+ for (auto I = Symbols.begin(), E = Symbols.end(); I != E; ++I) {
if (I != Symbols.begin())
Buffer += ",";
Buffer += getSourceText(I->Range);
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=271401&r1=271400&r2=271401&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Jun 1 10:22:47 2016
@@ -668,11 +668,11 @@ static bool mustBeJSIdent(const Addition
// FIXME: This returns true for C/C++ keywords like 'struct'.
return FormatTok->is(tok::identifier) &&
(FormatTok->Tok.getIdentifierInfo() == nullptr ||
- !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of, Keywords.kw_async,
- Keywords.kw_await, Keywords.kw_yield,
- Keywords.kw_finally, Keywords.kw_function,
- Keywords.kw_import, Keywords.kw_is,
- Keywords.kw_let, Keywords.kw_var,
+ !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of, Keywords.kw_as,
+ Keywords.kw_async, Keywords.kw_await,
+ Keywords.kw_yield, Keywords.kw_finally,
+ Keywords.kw_function, Keywords.kw_import,
+ Keywords.kw_is, Keywords.kw_let, Keywords.kw_var,
Keywords.kw_abstract, Keywords.kw_extends,
Keywords.kw_implements, Keywords.kw_instanceof,
Keywords.kw_interface, Keywords.kw_throws));
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=271401&r1=271400&r2=271401&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jun 1 10:22:47 2016
@@ -1010,6 +1010,9 @@ TEST_F(FormatTestJS, Modules) {
"} from 'some/module.js';");
verifyFormat("import {X, Y,} from 'some/module.js';");
verifyFormat("import {X as myLocalX, Y as myLocalY} from 'some/module.js';");
+ // Ensure Automatic Semicolon Insertion does not break on "as\n".
+ verifyFormat("import {X as myX} from 'm';", "import {X as\n"
+ " myX} from 'm';");
verifyFormat("import * as lib from 'some/module.js';");
verifyFormat("var x = {import: 1};\nx.import = 2;");
More information about the cfe-commits
mailing list