@putout/printer
Advanced tools
Comparing version 1.57.0 to 1.58.0
@@ -13,8 +13,15 @@ 'use strict'; | ||
const isClass = !path.isClassMethod(); | ||
const insideFn = path.parentPath.isFunction(); | ||
const isIndent = !path.isClassMethod() && !insideFn; | ||
for (const {type, value} of leadingComments) { | ||
maybe.indent(isClass); | ||
maybe.indent(isIndent); | ||
if (type === 'CommentLine') { | ||
maybe.indent.inc(insideFn); | ||
maybe.indent.inc(insideFn); | ||
maybe.print.breakline(insideFn); | ||
maybe.indent.dec(insideFn); | ||
maybe.indent.dec(insideFn); | ||
print(`//${value}`); | ||
@@ -21,0 +28,0 @@ print.newline(); |
'use strict'; | ||
const {isNext} = require('../is'); | ||
module.exports.ClassExpression = classVisitor; | ||
module.exports.ClassDeclaration = classVisitor; | ||
module.exports.ClassDeclaration = (path, {print, indent, maybe}) => { | ||
module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => { | ||
indent(); | ||
@@ -14,2 +16,6 @@ | ||
}); | ||
if (!path.parentPath.isExportDeclaration() && isNext(path)) { | ||
write.newline(); | ||
} | ||
}; | ||
@@ -16,0 +22,0 @@ |
@@ -40,3 +40,10 @@ 'use strict'; | ||
print('=>'); | ||
print.space(); | ||
const body = path.get('body'); | ||
const insideCall = path.parentPath.isCallExpression(); | ||
const isJSX = body.isJSXElement(); | ||
maybe.print.space(!insideCall && isJSX); | ||
maybe.print.space(!isJSX); | ||
print('__body'); | ||
@@ -43,0 +50,0 @@ }, |
@@ -5,4 +5,16 @@ 'use strict'; | ||
const {isNext} = require('../../is'); | ||
const isFirst = (path) => !path.getPrevSibling().node; | ||
module.exports.FunctionDeclaration = { | ||
beforeIf(path) { | ||
if (isFirst(path)) | ||
return false; | ||
const prev = path.getPrevSibling(); | ||
return prev.isClassDeclaration(); | ||
}, | ||
before(path, {write}) { | ||
write.newline(); | ||
}, | ||
print(path, {print, maybe}) { | ||
@@ -9,0 +21,0 @@ const {async} = path.node; |
@@ -10,6 +10,21 @@ 'use strict'; | ||
}, | ||
print(path, {print, traverse}) { | ||
print(path, {print, traverse, indent, maybe}) { | ||
const insideFn = path.parentPath.isArrowFunctionExpression(); | ||
const insideCall = path.parentPath.parentPath.isCallExpression(); | ||
if (insideFn && insideCall) { | ||
indent.inc(); | ||
indent.inc(); | ||
indent(); | ||
} | ||
print('__openingElement'); | ||
path.get('children').map(traverse); | ||
print('__closingElement'); | ||
if (insideFn && insideCall) { | ||
indent.dec(); | ||
maybe.print.breakline(insideCall); | ||
indent.dec(); | ||
} | ||
}, | ||
@@ -16,0 +31,0 @@ after(path, {write, indent}) { |
@@ -5,25 +5,27 @@ 'use strict'; | ||
module.exports.JSXOpeningElement = (path, {print, maybe}) => { | ||
print('<'); | ||
print('__name'); | ||
const coupleLines = isCoupleLines(path); | ||
const noCoupleLines = !coupleLines; | ||
const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement(); | ||
maybe.indent.inc(shouldIndent); | ||
for (const attr of path.get('attributes')) { | ||
maybe.print.space(noCoupleLines); | ||
print(attr); | ||
} | ||
if (isCoupleLines(path)) | ||
print.breakline(); | ||
if (path.node.selfClosing) | ||
print('/'); | ||
print('>'); | ||
maybe.indent.dec(shouldIndent); | ||
module.exports.JSXOpeningElement = { | ||
print(path, {print, maybe}) { | ||
print('<'); | ||
print('__name'); | ||
const coupleLines = isCoupleLines(path); | ||
const noCoupleLines = !coupleLines; | ||
const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement(); | ||
maybe.indent.inc(shouldIndent); | ||
for (const attr of path.get('attributes')) { | ||
maybe.print.space(noCoupleLines); | ||
print(attr); | ||
} | ||
if (isCoupleLines(path)) | ||
print.breakline(); | ||
if (path.node.selfClosing) | ||
print('/'); | ||
print('>'); | ||
maybe.indent.dec(shouldIndent); | ||
}, | ||
}; |
{ | ||
"name": "@putout/printer", | ||
"version": "1.57.0", | ||
"version": "1.58.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
92525
2477