diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index dfc89d57c..f93379daa 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -1024,6 +1024,9 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti ExportAllDeclaration (node) { const tokens = tokenStore.getTokens(node) const firstToken = tokens.shift() + if (isSemicolon(last(tokens))) { + tokens.pop() + } setOffset(tokens, 1, firstToken) }, @@ -1445,25 +1448,20 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti // Process semicolons. ':statement' (node) { - const info = offsets.get(tokenStore.getFirstToken(node)) + const firstToken = tokenStore.getFirstToken(node) const lastToken = tokenStore.getLastToken(node) - if (info == null) { - return - } - if (isSemicolon(lastToken)) { - offsets.set(lastToken, info) + if (isSemicolon(lastToken) && firstToken !== lastToken) { + setOffset(lastToken, 0, firstToken) } // Set to the semicolon of the previous token for semicolon-free style. // E.g., // foo // ;[1,2,3].forEach(f) - const prevToken = tokenStore.getTokenBefore(node) - if (isSemicolon(prevToken)) { - const prevPrevToken = tokenStore.getTokenBefore(prevToken) - if (prevPrevToken == null || prevToken.loc.end.line !== prevPrevToken.loc.start.line) { - offsets.set(prevToken, info) - } + const info = offsets.get(firstToken) + const prevToken = tokenStore.getTokenBefore(firstToken) + if (info != null && isSemicolon(prevToken) && prevToken.loc.end.line === firstToken.loc.start.line) { + offsets.set(prevToken, info) } }, diff --git a/tests/fixtures/script-indent/export-named-declaration-04.vue b/tests/fixtures/script-indent/export-named-declaration-04.vue index 410623c43..5cd53b33e 100644 --- a/tests/fixtures/script-indent/export-named-declaration-04.vue +++ b/tests/fixtures/script-indent/export-named-declaration-04.vue @@ -2,7 +2,7 @@