@putout/printer
Advanced tools
Comparing version 12.26.0 to 12.27.0
@@ -23,2 +23,3 @@ 'use strict'; | ||
isClassMethod, | ||
isDecorator, | ||
} = types; | ||
@@ -46,9 +47,10 @@ | ||
const hasDecorators = (path) => { | ||
const {parentPath} = path; | ||
const hasDecoratorsWithComments = (path) => { | ||
if (isDecorator(path)) | ||
return false; | ||
if (path.node.decorators?.length) | ||
if (path.node.decorators) | ||
return true; | ||
return parentPath.node.decorators?.length; | ||
return path?.parentPath.node?.decorators; | ||
}; | ||
@@ -102,3 +104,3 @@ | ||
if (hasDecorators(path)) | ||
if (hasDecoratorsWithComments(path)) | ||
return; | ||
@@ -145,3 +147,3 @@ | ||
indent(); | ||
} else if (isBinaryExpression(path)) { | ||
} else if (isBinaryExpression(path) || isDecorator(path)) { | ||
indent.inc(); | ||
@@ -148,0 +150,0 @@ indent(); |
'use strict'; | ||
const {parseComments} = require('../../comment/comment'); | ||
const noop = () => {}; | ||
@@ -5,0 +6,0 @@ const parseParams = (path) => path.get('params'); |
'use strict'; | ||
const {printParams} = require('./params'); | ||
const {hasLeadingComment} = require('../../is'); | ||
const isDecoratorHasLeadingComment = (path) => { | ||
const [firstParam] = path.get('params'); | ||
const decorators = firstParam.get('decorators'); | ||
if (!decorators.length) | ||
return false; | ||
const [firstDecorator] = decorators; | ||
return hasLeadingComment(firstDecorator); | ||
}; | ||
const hasDecorators = ({decorators}) => decorators?.length; | ||
@@ -13,3 +26,3 @@ | ||
const printBeforeFirst = createPrint({ | ||
const printBeforeFirst = createPrint(path, { | ||
type: 'inc', | ||
@@ -20,3 +33,3 @@ printer, | ||
const printAfterLast = createPrint({ | ||
const printAfterLast = createPrint(path, { | ||
type: 'dec', | ||
@@ -34,3 +47,3 @@ printer, | ||
const createPrint = ({isNewline, printer, type}) => () => { | ||
const createPrint = (path, {isNewline, printer, type}) => () => { | ||
if (!isNewline) | ||
@@ -40,4 +53,7 @@ return; | ||
const {indent, print} = printer; | ||
indent[type](); | ||
if (!isDecoratorHasLeadingComment(path)) | ||
indent[type](); | ||
print.breakline(); | ||
}; |
{ | ||
"name": "@putout/printer", | ||
"version": "12.26.0", | ||
"version": "12.27.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
257294
5584