@putout/printer
Advanced tools
| 'use strict'; | ||
| const createPrintCommentLine = (fn) => (value) => fn(`//${value}`); | ||
| const createPrintCommentBlock = (fn) => (value) => fn(`/*${value}*/`); | ||
| module.exports.printLeadingComments = (path, {print}) => { | ||
| const printCommentLine = createPrintCommentLine(print); | ||
| const printCommentBlock = createPrintCommentBlock(print); | ||
| const {leadingComments} = path.node; | ||
| if (!leadingComments) | ||
| return; | ||
| for (const {type, value} of leadingComments) { | ||
| if (type === 'CommentLine') | ||
| printCommentLine(value); | ||
| else | ||
| printCommentBlock(value); | ||
| print.breakline(); | ||
| } | ||
| }; |
| 'use strict'; | ||
| const {types} = require('@putout/babel'); | ||
| const {wrongShorthand} = require('./wrong-shorthand'); | ||
@@ -23,2 +24,4 @@ | ||
| const {printLeadingComments} = require('./comments'); | ||
| const { | ||
@@ -156,2 +159,5 @@ isObjectExpression, | ||
| printLeadingComments(property, { | ||
| print, | ||
| }); | ||
| printKey(property, printer); | ||
@@ -278,2 +284,11 @@ | ||
| function hasPropertyLeadingComment(properties) { | ||
| for (const property of properties) { | ||
| if (property.node.leadingComments) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function shouldAddNewline(path, semantics) { | ||
@@ -284,2 +299,5 @@ const {parentPath} = path; | ||
| if (hasPropertyLeadingComment(properties)) | ||
| return true; | ||
| const { | ||
@@ -286,0 +304,0 @@ maxPropertiesInOneLine, |
@@ -91,5 +91,5 @@ 'use strict'; | ||
| const last = index === n; | ||
| const penulty = index === n - 1; | ||
| const penalty = index === n - 1; | ||
| maybe.write.newline(penulty && defaults.length); | ||
| maybe.write.newline(penalty && defaults.length); | ||
| maybe.write.newline(last); | ||
@@ -96,0 +96,0 @@ } |
+1
-1
| { | ||
| "name": "@putout/printer", | ||
| "version": "15.27.0", | ||
| "version": "15.28.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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
294827
0.39%168
0.6%6346
0.47%