forked from OSchip/llvm-project
clang-format: [JS] Parse exported functions as free-standing.
Before: export function foo() {} export function bar() {} After: export function foo() { } export function bar() { } llvm-svn: 236978
This commit is contained in:
parent
0a8416fdef
commit
668c7bb34f
|
@ -1666,8 +1666,16 @@ void UnwrappedLineParser::parseJavaScriptEs6ImportExport() {
|
||||||
assert(FormatTok->isOneOf(Keywords.kw_import, tok::kw_export));
|
assert(FormatTok->isOneOf(Keywords.kw_import, tok::kw_export));
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
if (FormatTok->isOneOf(tok::kw_const, tok::kw_class, Keywords.kw_function,
|
// Consume "function" and "default function", so that these get parsed as
|
||||||
Keywords.kw_var))
|
// free-standing JS functions, i.e. do not require a trailing semicolon.
|
||||||
|
if (FormatTok->is(tok::kw_default))
|
||||||
|
nextToken();
|
||||||
|
if (FormatTok->is(Keywords.kw_function)) {
|
||||||
|
nextToken();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FormatTok->isOneOf(tok::kw_const, tok::kw_class, Keywords.kw_var))
|
||||||
return; // Fall through to parsing the corresponding structure.
|
return; // Fall through to parsing the corresponding structure.
|
||||||
|
|
||||||
if (FormatTok->is(tok::kw_default)) {
|
if (FormatTok->is(tok::kw_default)) {
|
||||||
|
|
|
@ -600,6 +600,12 @@ TEST_F(FormatTestJS, Modules) {
|
||||||
verifyFormat("export function fn() {\n"
|
verifyFormat("export function fn() {\n"
|
||||||
" return 'fn';\n"
|
" return 'fn';\n"
|
||||||
"}");
|
"}");
|
||||||
|
verifyFormat("export function A() {\n"
|
||||||
|
"}\n"
|
||||||
|
"export default function B() {\n"
|
||||||
|
"}\n"
|
||||||
|
"export function C() {\n"
|
||||||
|
"}");
|
||||||
verifyFormat("export const x = 12;");
|
verifyFormat("export const x = 12;");
|
||||||
verifyFormat("export default class X {}");
|
verifyFormat("export default class X {}");
|
||||||
verifyFormat("export {X, Y} from 'some/module.js';");
|
verifyFormat("export {X, Y} from 'some/module.js';");
|
||||||
|
|
Loading…
Reference in New Issue