@putout/printer
Advanced tools
Comparing version 1.6.13 to 1.7.0
'use strict'; | ||
module.exports.AssignmentPattern = (path, {print}) => { | ||
const isArg = (path) => path.parentPath.isFunction(); | ||
module.exports.AssignmentPattern = (path, {print, maybe}) => { | ||
maybe.print(isArg(path), '__left'); | ||
print(' = '); | ||
@@ -5,0 +8,0 @@ print('__right'); |
@@ -29,17 +29,19 @@ 'use strict'; | ||
const shouldAddNewLine = !isNewLineAdded(path); | ||
const shouldAddNewLine = isAddNewLineAfter(path); | ||
maybe.print.newline(shouldAddNewLine); | ||
if (shouldAddNewLine) { | ||
print.newline(); | ||
} | ||
}; | ||
function isNewLineAdded(path) { | ||
function isAddNewLineAfter(path) { | ||
const {parentPath} = path; | ||
if (isTry(path) || /FunctionExpression/.test(path.parentPath.type)) | ||
return true; | ||
return false; | ||
if (parentPath.isIfStatement() && parentPath.get('consequent').node === path.node && parentPath.node.alternate) | ||
return true; | ||
return false; | ||
return false; | ||
return true; | ||
} | ||
@@ -46,0 +48,0 @@ |
'use strict'; | ||
const {hasPrevNewline} = require('../mark'); | ||
const {hasPrevNewline, markAfter} = require('../mark'); | ||
@@ -28,2 +28,4 @@ const {isFirst} = require('../is'); | ||
print.newline(); | ||
return; | ||
} | ||
@@ -35,2 +37,8 @@ | ||
} | ||
if (path.getNextSibling().node) { | ||
print.indent(); | ||
print.newline(); | ||
markAfter(path); | ||
} | ||
}; |
'use strict'; | ||
const {isPrevBody} = require('../is'); | ||
const {hasPrevNewline} = require('../mark'); | ||
const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2; | ||
module.exports.ReturnStatement = (path, {indent, write, traverse}) => { | ||
if (isBodyLength(path) || isPrevBody(path)) { | ||
write.indent(); | ||
write.newline(); | ||
module.exports.ReturnStatement = (path, {indent, traverse, print}) => { | ||
if (!hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path)) { | ||
print.indent(); | ||
print.newline(); | ||
} | ||
indent(); | ||
write('return'); | ||
print('return'); | ||
@@ -18,9 +19,8 @@ const argPath = path.get('argument'); | ||
if (argPath.node) { | ||
write(' '); | ||
print(' '); | ||
traverse(argPath); | ||
} | ||
write(';'); | ||
write.newline(); | ||
print(';'); | ||
print.newline(); | ||
}; | ||
@@ -22,4 +22,5 @@ 'use strict'; | ||
module.exports.VariableDeclaration = (path, {maybe, print}) => { | ||
if (!isFirst(path) && shouldAddNewLineBefore(path) && !hasPrevNewline(path)) | ||
if (!isFirst(path) && isNewLineBefore(path) && !hasPrevNewline(path)) { | ||
print.breakline(); | ||
} | ||
@@ -68,3 +69,3 @@ const isParentBlock = /Program|BlockStatement/.test(path.parentPath.type); | ||
function shouldAddNewLineBefore(path) { | ||
function isNewLineBefore(path) { | ||
const prevPath = path.getPrevSibling(); | ||
@@ -71,0 +72,0 @@ |
@@ -10,2 +10,3 @@ 'use strict'; | ||
const {createDebug} = require('./debug'); | ||
const { | ||
@@ -19,2 +20,3 @@ maybeMarkAfter, | ||
const {assign} = Object; | ||
const traversers = { | ||
@@ -40,2 +42,3 @@ ...expressions, | ||
const debug = createDebug(tokens); | ||
const write = (value) => { | ||
@@ -53,6 +56,6 @@ tokens.push({ | ||
const maybeBreakline = (a) => a && breakline(); | ||
let i = 0; | ||
const incIndent = () => ++i; | ||
const decIndent = () => --i; | ||
const indent = () => { | ||
@@ -139,4 +142,9 @@ tokens.push({ | ||
const print = createPrint(path, {write, traverse}); | ||
const print = createPrint(path, { | ||
write, | ||
traverse, | ||
}); | ||
assign(print, write); | ||
assign(printer, { | ||
@@ -143,0 +151,0 @@ print, |
{ | ||
"name": "@putout/printer", | ||
"version": "1.6.13", | ||
"version": "1.7.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
42693
1217