[PATCH] D19242: clang-format: [JS] simplify import/export.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 19 08:01:24 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266743: clang-format: [JS] simplify import/export. (authored by mprobst).
Changed prior to commit:
http://reviews.llvm.org/D19242?vs=54124&id=54190#toc
Repository:
rL LLVM
http://reviews.llvm.org/D19242
Files:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1880,7 +1880,8 @@
}
void UnwrappedLineParser::parseJavaScriptEs6ImportExport() {
- assert(FormatTok->isOneOf(Keywords.kw_import, tok::kw_export));
+ bool IsImport = FormatTok->is(Keywords.kw_import);
+ assert(IsImport || FormatTok->is(tok::kw_export));
nextToken();
// Consume the "default" in "export default class/function".
@@ -1894,14 +1895,13 @@
return;
}
- // Consume the "abstract" in "export abstract class".
- if (FormatTok->is(Keywords.kw_abstract))
- nextToken();
-
- if (FormatTok->isOneOf(tok::kw_const, tok::kw_class, tok::kw_enum,
- Keywords.kw_interface, Keywords.kw_let,
- Keywords.kw_var))
- return; // Fall through to parsing the corresponding structure.
+ // For imports, `export *`, `export {...}`, consume the rest of the line up
+ // to the terminating `;`. For everything else, just return and continue
+ // parsing the structural element, i.e. the declaration or expression for
+ // `export default`.
+ if (!IsImport && !FormatTok->isOneOf(tok::l_brace, tok::star) &&
+ !FormatTok->isStringLiteral())
+ return;
while (!eof() && FormatTok->isNot(tok::semi)) {
if (FormatTok->is(tok::l_brace)) {
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -961,6 +961,10 @@
verifyFormat("export function A() {}\n"
"export default function B() {}\n"
"export function C() {}");
+ verifyFormat("export default () => {\n"
+ " let x = 1;\n"
+ " return x;\n"
+ "}");
verifyFormat("export const x = 12;");
verifyFormat("export default class X {}");
verifyFormat("export {X, Y} from 'some/module.js';");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19242.54190.patch
Type: text/x-patch
Size: 2093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160419/69d66504/attachment.bin>
More information about the cfe-commits
mailing list