@putout/printer
Advanced tools
Comparing version 1.28.0 to 1.29.0
'use strict'; | ||
const {stringify} = JSON; | ||
const {TYPES} = require('../types'); | ||
const toSnakeCase = require('just-snake-case'); | ||
const { | ||
@@ -13,2 +13,3 @@ LOG, | ||
} = process.env; | ||
const {codeFrameColumns} = require('@babel/code-frame'); | ||
@@ -28,5 +29,9 @@ | ||
if (LOG_TOKENS) { | ||
console.log(codeFrameColumns(stringify({type, value}), {}, { | ||
console.log(codeFrameColumns(stringify({ | ||
type, | ||
value, | ||
}), {}, { | ||
highlightCode: true, | ||
})); | ||
return; | ||
@@ -39,2 +44,3 @@ } | ||
})); | ||
return; | ||
@@ -48,2 +54,3 @@ } | ||
})); | ||
return; | ||
@@ -68,2 +75,3 @@ } | ||
const result = chunks.join(''); | ||
chunks = []; | ||
@@ -74,2 +82,1 @@ | ||
} | ||
@@ -203,8 +203,5 @@ 'use strict'; | ||
const aLength = a | ||
.node.value.length; | ||
const aLength = a.node.value.length; | ||
const bLength = b.node.value.length; | ||
const bLength = b | ||
.node.value.length; | ||
return round(bLength / aLength) > 2; | ||
@@ -211,0 +208,0 @@ } |
@@ -38,4 +38,3 @@ 'use strict'; | ||
indent.dec(); | ||
print.newline(); | ||
print.indent(); | ||
print.breakline(); | ||
} | ||
@@ -42,0 +41,0 @@ |
'use strict'; | ||
const {hasPrevNewline} = require('../mark'); | ||
const isFirst = (path) => !path.getPrevSibling().node; | ||
const isFirst = (path) => !path | ||
.getPrevSibling().node; | ||
@@ -9,6 +10,3 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => { | ||
const { | ||
generator, | ||
async, | ||
} = node; | ||
const {generator, async} = node; | ||
@@ -15,0 +13,0 @@ maybe.print(async, 'async '); |
@@ -7,2 +7,3 @@ 'use strict'; | ||
isThisExpression, | ||
isUnaryExpression, | ||
} = require('@babel/types'); | ||
@@ -27,3 +28,3 @@ | ||
const isChain = looksLikeChain(path); | ||
const isChain = isLooksLikeChain(path); | ||
maybe.indent.inc(isChain); | ||
@@ -57,3 +58,3 @@ | ||
function looksLikeChain(path) { | ||
function isLooksLikeChain(path) { | ||
const {parentPath} = path; | ||
@@ -67,2 +68,5 @@ | ||
if (path.find(isUnaryExpression)) | ||
return false; | ||
const isMember = ({parentPath}) => parentPath.parentPath.isMemberExpression(); | ||
@@ -76,5 +80,2 @@ const isExpression = ({parentPath}) => parentPath.parentPath.isExpressionStatement(); | ||
if (parentPath.isUnaryExpression()) | ||
return false; | ||
if (!itMember && !path.parentPath.isExpressionStatement() && !parentPath.isCallExpression()) | ||
@@ -89,5 +90,8 @@ return false; | ||
if (compare(parentPath, '__a.__b(__args);') && !itMember && !itExpression) | ||
if (compare(path.parentPath.parentPath, '(__args) => __b.__c(__args).__d()')) | ||
return false; | ||
if (compare(parentPath, '__a.__b(__args);') && !itExpression && !itMember) | ||
return false; | ||
if (compare(parentPath, '__a.__b.__c(__args)') && !itMember) | ||
@@ -99,2 +103,5 @@ return false; | ||
if (compare(parentPath, '(__args) => __a.__b(__args).__c')) | ||
return false; | ||
const {__a, __b} = getTemplateValues(parentPath, '__a.__b(__args)'); | ||
@@ -101,0 +108,0 @@ const aType = __a?.type; |
@@ -5,11 +5,11 @@ 'use strict'; | ||
const {isFunction} = require('@babel/types'); | ||
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node; | ||
const isBodyOfArrow = (path) => path | ||
.parentPath.node.body === path.node; | ||
const isLogical = (path) => path | ||
.get('argument').isLogicalExpression(); | ||
const isValue = (path) => path | ||
.get('properties.0.value').node; | ||
const isIf = (path) => path | ||
.parentPath.parentPath.isIfStatement(); | ||
const isIf = (path) => path.parentPath.parentPath.isIfStatement(); | ||
const isParentExpression = (path) => path.parentPath.isExpressionStatement(); | ||
@@ -71,4 +71,3 @@ | ||
return path | ||
.parentPath.parentPath.isSpreadElement(); | ||
return path.parentPath.parentPath.isSpreadElement(); | ||
} | ||
@@ -128,2 +127,1 @@ module.exports.ObjectProperty = (path, {print, maybe}) => { | ||
} | ||
'use strict'; | ||
const {isIdentifier} = require('@babel/types'); | ||
const isForOf = (path) => path.parentPath?.parentPath?.parentPath?.isForOfStatement(); | ||
@@ -54,3 +55,8 @@ | ||
for (const prop of properties) { | ||
if (prop.node.value.name.length > 4) | ||
const {value} = prop.node; | ||
if (!isIdentifier(value)) | ||
continue; | ||
if (value.name.length > 4) | ||
return true; | ||
@@ -57,0 +63,0 @@ } |
'use strict'; | ||
const {isMarkedAfter} = require('./mark'); | ||
const { | ||
@@ -8,2 +9,3 @@ isStringLiteral, | ||
} = require('@babel/types'); | ||
const isParentProgram = (path) => path.parentPath?.isProgram(); | ||
@@ -48,3 +50,2 @@ const isParentBlock = (path) => path.parentPath.isBlockStatement(); | ||
} | ||
module.exports.isStringAndIdentifier = ([a, b]) => isStringLiteral(a) && isIdentifier(b); |
@@ -38,5 +38,3 @@ 'use strict'; | ||
traverse(bodyPath); | ||
maybe.markAfter(isMarkedAfter(bodyPath), path); | ||
indent.dec(); | ||
@@ -43,0 +41,0 @@ maybe.print.newline(isNext(path)); |
@@ -9,4 +9,6 @@ 'use strict'; | ||
const {isFirst} = require('../is'); | ||
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement(); | ||
const isEmptyConsequent = (path) => path | ||
.get('consequent').isEmptyStatement(); | ||
module.exports.IfStatement = { | ||
@@ -13,0 +15,0 @@ before: (path, {print}) => { |
@@ -35,3 +35,7 @@ 'use strict'; | ||
print('__interpreter'); | ||
path.get('body').forEach(print); | ||
path | ||
.get('body') | ||
.forEach(print); | ||
print.newline(); | ||
@@ -38,0 +42,0 @@ }, |
@@ -102,3 +102,4 @@ 'use strict'; | ||
return nextPath.get('expression').isAssignmentExpression(); | ||
return nextPath | ||
.get('expression').isAssignmentExpression(); | ||
}; |
@@ -6,3 +6,7 @@ 'use strict'; | ||
print('<'); | ||
path.get('params').forEach(print); | ||
path | ||
.get('params') | ||
.forEach(print); | ||
print('>'); | ||
@@ -12,3 +16,7 @@ }, | ||
print('<'); | ||
path.get('params').forEach(print); | ||
path | ||
.get('params') | ||
.forEach(print); | ||
print('>'); | ||
@@ -15,0 +23,0 @@ }, |
{ | ||
"name": "@putout/printer", | ||
"version": "1.28.0", | ||
"version": "1.29.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
70424
1932