@putout/printer
Advanced tools
Comparing version 12.11.0 to 12.12.0
@@ -20,2 +20,3 @@ 'use strict'; | ||
isSpreadElement, | ||
isClassBody, | ||
} = types; | ||
@@ -74,6 +75,16 @@ | ||
return line === loc.start.line - 1; | ||
return line <= loc.start.line - 1; | ||
} | ||
const isFirst = (path) => path === path.parentPath?.get('properties')[0]; | ||
const isFirst = (path) => { | ||
const {parentPath} = path; | ||
if (path === parentPath.get('properties')[0]) | ||
return true; | ||
if (isClassBody(parentPath) && isClassProperty(path)) | ||
return path === parentPath.get('body')[0]; | ||
return false; | ||
}; | ||
@@ -106,6 +117,9 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics) => { | ||
for (const {type, value} of leadingComments) { | ||
maybe.indent(isIndent); | ||
const count = leadingComments.length - 1; | ||
for (const [index, {type, value}] of leadingComments.entries()) { | ||
if (type === 'CommentLine') { | ||
if (!path.isClassProperty() || index) | ||
maybe.indent(isIndent); | ||
maybeInsideFn(insideFn, { | ||
@@ -123,4 +137,8 @@ print, | ||
maybe.print.breakline(propIs); | ||
maybe.print.newline(!propIs); | ||
if (index === count) { | ||
maybe.print.breakline(propIs); | ||
maybe.print.newline(!propIs); | ||
} else { | ||
print.newline(); | ||
} | ||
@@ -137,2 +155,4 @@ if (isInsideVar(path)) { | ||
if (type === 'CommentBlock') { | ||
maybe.indent(isIndent); | ||
const looksLikeMethod = path.isClassMethod(); | ||
@@ -139,0 +159,0 @@ const looksLikeDirective = path.isDirective(); |
{ | ||
"name": "@putout/printer", | ||
"version": "12.11.0", | ||
"version": "12.12.0", | ||
"type": "commonjs", | ||
@@ -55,3 +55,3 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
"#test/printer": { | ||
"default": "./test/printer.js" | ||
"default": "./test/print-extension/print-extension.js" | ||
}, | ||
@@ -63,2 +63,5 @@ "#test/fixture": { | ||
"default": "./lib/printer.js" | ||
}, | ||
"#test": { | ||
"default": "./test/create-test.js" | ||
} | ||
@@ -65,0 +68,0 @@ }, |
Sorry, the diff of this file is not supported yet
250527
5452