@putout/printer
Advanced tools
Comparing version 1.16.2 to 1.17.0
@@ -6,3 +6,10 @@ 'use strict'; | ||
const isLogical = (path) => path.isLogicalExpression(); | ||
const isLogical = (main, path) => { | ||
const is = path.isLogicalExpression(); | ||
if (!is) | ||
return false; | ||
return main.node.operator !== path.node.operator; | ||
}; | ||
@@ -12,4 +19,4 @@ function BinaryExpression(path, {write, traverse, maybe}) { | ||
const right = path.get('right'); | ||
const isLeft = isLogical(left); | ||
const isRight = isLogical(right); | ||
const isLeft = isLogical(path, left); | ||
const isRight = isLogical(path, right); | ||
@@ -16,0 +23,0 @@ maybe.write(isLeft, '('); |
@@ -35,3 +35,3 @@ 'use strict'; | ||
function unaryExpression(path, {print, maybe}) { | ||
function unaryExpression(path, {maybe, traverse}) { | ||
const { | ||
@@ -42,13 +42,13 @@ prefix, | ||
if (prefix) | ||
print(operator); | ||
const argPath = path.get('argument'); | ||
const round = argPath.isBinaryExpression(); | ||
maybe.print(isWord( | ||
operator, | ||
), ' '); | ||
maybe.print(prefix, operator); | ||
print('__argument'); | ||
maybe.print(isWord(operator), ' '); | ||
if (!prefix) | ||
print(operator); | ||
maybe.print(round, '('); | ||
traverse(argPath); | ||
maybe.print(round, ')'); | ||
maybe.print(!prefix, operator); | ||
} |
@@ -18,3 +18,3 @@ 'use strict'; | ||
module.exports.isFirst = (path) => path.node === path.parentPath.node.body[0]; | ||
module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0]; | ||
module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement(); | ||
@@ -21,0 +21,0 @@ module.exports.isNext = isNext; |
@@ -62,3 +62,6 @@ 'use strict'; | ||
function shouldAddNewlineBefore(path) { | ||
if (path.parentPath.isIfStatement()) | ||
return false; | ||
return !isFirst(path) && !hasPrevNewline(path); | ||
} |
{ | ||
"name": "@putout/printer", | ||
"version": "1.16.2", | ||
"version": "1.17.0", | ||
"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
62180
1745