@putout/printer
Advanced tools
Comparing version 8.3.0 to 8.4.0
'use strict'; | ||
const {types} = require('@putout/babel'); | ||
const { | ||
@@ -22,8 +23,9 @@ isCoupleLines, | ||
const {types} = require('@putout/babel'); | ||
const { | ||
isObjectExpression, | ||
isSpreadElement, | ||
isStringLiteral, | ||
} = types; | ||
const isNextString = (path) => isStringLiteral(path.getNextSibling()); | ||
const isNextObject = (a) => a.getNextSibling().isObjectExpression(); | ||
@@ -102,5 +104,5 @@ const isPrevObject = (a) => a.getPrevSibling().isObjectExpression(); | ||
if (isInsideArray(path) && isStringAndArray(parentElements)) { | ||
indent.dec(); | ||
maybe.indent.dec(!isNextString(path)); | ||
maybe.indent(elements.length && isNewLine); | ||
indent.inc(); | ||
maybe.indent.inc(!isNextString(path)); | ||
} else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) { | ||
@@ -133,1 +135,2 @@ maybe.indent(elements.length && isNewLine); | ||
}; | ||
'use strict'; | ||
const {types} = require('@putout/babel'); | ||
const {isStringLiteral} = types; | ||
const {isIndented} = require('../../is'); | ||
const { | ||
isStringLiteral, | ||
isArrayExpression, | ||
} = types; | ||
const isInsideArray = (path) => path.parentPath.isArrayExpression(); | ||
@@ -29,3 +32,10 @@ | ||
return path.parentPath.node.elements.length <= 3; | ||
const parentElements = path.parentPath.node.elements; | ||
const parentHasArrays = parentElements.filter(isArrayExpression).length; | ||
const lastIsArray = !isArrayExpression(parentElements.at(-1)); | ||
if (parentHasArrays && lastIsArray) | ||
return false; | ||
return parentElements.length <= 3; | ||
} | ||
@@ -32,0 +42,0 @@ |
@@ -99,3 +99,3 @@ 'use strict'; | ||
if (isStringAndArray(elements)) | ||
if (isStringAndArray(elements) && elements.length < 3) | ||
return ONE_LINE; | ||
@@ -102,0 +102,0 @@ |
@@ -68,8 +68,3 @@ 'use strict'; | ||
module.exports.isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b); | ||
module.exports.isStringAndArray = (array) => { | ||
if (array.length > 2) | ||
return false; | ||
const [a, b] = array; | ||
module.exports.isStringAndArray = ([a, b]) => { | ||
if (!isStringLiteral(a)) | ||
@@ -76,0 +71,0 @@ return false; |
{ | ||
"name": "@putout/printer", | ||
"version": "8.3.0", | ||
"version": "8.4.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
206043
4609