diff options
| author | Martin Probst <martin@probst.io> | 2016-04-19 14:55:37 +0000 |
|---|---|---|
| committer | Martin Probst <martin@probst.io> | 2016-04-19 14:55:37 +0000 |
| commit | 053f1aa6d09df250ef27b992974b06bbad637557 (patch) | |
| tree | 0d382a67f01cb33a395af6d7a9f3bf6bb67862c3 /clang/lib | |
| parent | 0b0271ef976cec3ee6a1ab2d654e42cf111a68bd (diff) | |
| download | bcm5719-llvm-053f1aa6d09df250ef27b992974b06bbad637557.tar.gz bcm5719-llvm-053f1aa6d09df250ef27b992974b06bbad637557.zip | |
clang-format: [JS] simplify import/export.
Summary:
Change `import` and `export` parsing to special case the renaming
syntax (`import x, {y as bar} ...`, `export {x}`) and otherwise just
parse a regular structural element.
This simplifies the code a bit and should be more correct - it's easier
to recognise the specific import syntax than to recognise arbitrary
expressions and declarations.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D19242
llvm-svn: 266743
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 6cd74f91a8a..91856a74c35 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1880,7 +1880,8 @@ void UnwrappedLineParser::parseObjCProtocol() { } 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 @@ void UnwrappedLineParser::parseJavaScriptEs6ImportExport() { 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)) { |

