@putout/printer
Advanced tools
Comparing version 6.11.5 to 6.11.6
@@ -12,2 +12,3 @@ 'use strict'; | ||
}; | ||
const isLotsOfElementsFirstNotObject = (path) => { | ||
@@ -295,2 +296,1 @@ const {elements} = path.node; | ||
}; | ||
@@ -8,2 +8,4 @@ 'use strict'; | ||
exists, | ||
satisfy, | ||
} = require('../../is'); | ||
@@ -16,2 +18,4 @@ | ||
isExportDeclaration, | ||
isDoWhileStatement, | ||
isBlockStatement, | ||
} = require('@putout/babel').types; | ||
@@ -82,31 +86,58 @@ | ||
function shouldAddNewlineAfter(path) { | ||
const {parentPath} = path; | ||
if (parentPath.isDoWhileStatement()) | ||
const isTopLevelWithNoNext = (path) => { | ||
if (isNext(path)) | ||
return false; | ||
if (parentPath.isBlockStatement()) | ||
return true; | ||
return !isNext(path.parentPath) && isParentProgram(path.parentPath); | ||
}; | ||
const isInsideIfWithoutElseInsideFn = (path) => { | ||
return parentIfWithoutElse(path) && path.find(isMethodOrArrow); | ||
}; | ||
const isEmptyBodyNoNext = (path) => { | ||
const {parentPath} = path; | ||
return parentPath.isStatement() && !path.node.body.length && !isNext(parentPath); | ||
}; | ||
const isLooksLikeInsideFn = ({parentPath}) => { | ||
return /FunctionExpression/.test(parentPath.type); | ||
}; | ||
const NEWLINE = true; | ||
const NO_NEWLINE = false; | ||
const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath); | ||
const isInsideBlock = ({parentPath}) => isBlockStatement(parentPath); | ||
const isNoNewline = satisfy([ | ||
isInsideDoWhile, | ||
isTopLevelWithNoNext, | ||
insideIfWithNoBody, | ||
]); | ||
function shouldAddNewlineAfter(path) { | ||
if (isInsideBlock(path)) | ||
return NEWLINE; | ||
if (!isNext(path) && !isNext(path.parentPath) && isParentProgram(path.parentPath)) | ||
return false; | ||
if (isNoNewline(path)) | ||
return NO_NEWLINE; | ||
if (insideIfWithNoBody(path)) | ||
return false; | ||
if (isInsideIfWithoutElseInsideFn(path)) | ||
return NEWLINE; | ||
if (parentIfWithoutElse(path) && path.find(isMethodOrArrow)) | ||
return true; | ||
if (isEmptyBodyNoNext(path)) | ||
return NO_NEWLINE; | ||
if (parentPath.isStatement() && !path.node.body.length && !isNext(parentPath)) | ||
return false; | ||
if (isTry(path)) | ||
return NO_NEWLINE; | ||
if (isTry(path) || /FunctionExpression/.test(path.parentPath.type)) | ||
return false; | ||
if (isLooksLikeInsideFn(path)) | ||
return NO_NEWLINE; | ||
if (isLast(path)) | ||
return false; | ||
return NO_NEWLINE; | ||
if (isExportFunction(path)) | ||
return false; | ||
return NO_NEWLINE; | ||
@@ -113,0 +144,0 @@ return !isNextIfAlternate(path); |
{ | ||
"name": "@putout/printer", | ||
"version": "6.11.5", | ||
"version": "6.11.6", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201389
4568