@putout/printer
Advanced tools
Comparing version 8.32.0 to 8.33.0
'use strict'; | ||
const {isIdentifier} = require('@putout/babel').types; | ||
const { | ||
isAssignmentPattern, | ||
isIdentifier, | ||
} = require('@putout/babel').types; | ||
@@ -8,3 +11,15 @@ module.exports.moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => { | ||
for (const {key} of properties) { | ||
for (const {key, value} of properties) { | ||
if (isAssignmentPattern(value)) { | ||
const {left, right} = value; | ||
if (!isIdentifier(left) || !isIdentifier(right)) | ||
continue; | ||
const length = left.name.length + right.name.length; | ||
if (length >= maxPropertiesLengthInOneLine) | ||
return true; | ||
} | ||
if (!isIdentifier(key)) | ||
@@ -21,1 +36,2 @@ continue; | ||
}; | ||
@@ -29,4 +29,14 @@ 'use strict'; | ||
const isCoupleProperties = ({path, valuePath, property}) => { | ||
if (!isCoupleLines(valuePath)) | ||
return false; | ||
if (exists(property.getPrevSibling())) | ||
return false; | ||
return !path.parentPath.isObjectProperty(); | ||
}; | ||
module.exports.ObjectPattern = { | ||
print: maybeTypeAnnotation((path, {print, maybe}, semantics) => { | ||
print: maybeTypeAnnotation((path, {print, maybe, indent}, semantics) => { | ||
const shouldIndent = isIndent(path); | ||
@@ -68,3 +78,7 @@ const { | ||
const {shorthand, computed} = property.node; | ||
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling()) && !path.parentPath.isObjectProperty(); | ||
const couple = isCoupleProperties({ | ||
path, | ||
property, | ||
valuePath, | ||
}); | ||
@@ -89,3 +103,3 @@ maybe.indent(is); | ||
if (is || hasObject) { | ||
if (is || hasObject && !isAssign) { | ||
print(','); | ||
@@ -103,5 +117,3 @@ print.newline(); | ||
maybe.indent.dec(shouldIndent); | ||
maybe.indent.dec(!shouldIndent); | ||
indent.dec(); | ||
maybe.indent(is); | ||
@@ -194,5 +206,3 @@ maybe.indent.inc(!shouldIndent); | ||
function isFunctionParam(path) { | ||
const {parentPath} = path; | ||
function isFunctionParam({parentPath}) { | ||
if (parentPath.isFunction()) | ||
@@ -206,1 +216,2 @@ return true; | ||
} | ||
{ | ||
"name": "@putout/printer", | ||
"version": "8.32.0", | ||
"version": "8.33.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
219904
4881