MCPcopy
hub / github.com/prettier/prettier / printDecorators

Function printDecorators

src/language-js/print/decorators.js:37–67  ·  view source on GitHub ↗
(path, options, print)

Source from the content-addressed store, hash-verified

35}
36
37function printDecorators(path, options, print) {
38 const { node, parent } = path;
39 const { decorators } = node;
40
41 if (
42 !isNonEmptyArray(decorators) ||
43 // If the parent node is an export declaration and the decorator
44 // was written before the export, the export will be responsible
45 // for printing the decorators.
46 hasDecoratorsBeforeExport(parent) ||
47 // Decorators already printed in ignored node
48 isIgnored(path)
49 ) {
50 return "";
51 }
52
53 const shouldBreak =
54 node.type === "ClassExpression" ||
55 node.type === "ClassDeclaration" ||
56 hasNewlineBetweenOrAfterDecorators(node, options);
57
58 return [
59 path.key === "declaration" && isExportDeclaration(parent)
60 ? hardline
61 : shouldBreak
62 ? breakParent
63 : "",
64 join(line, path.map(print, "decorators")),
65 line,
66 ];
67}
68
69function hasNewlineBetweenOrAfterDecorators(node, options) {
70 return node.decorators.some((decorator) =>

Callers 2

printClassFunction · 0.90
printFunction · 0.90

Calls 6

joinFunction · 0.90
isNonEmptyArrayFunction · 0.85
isIgnoredFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…