MCPcopy
hub / github.com/prettier/prettier / shouldPrintClassInGroupModeWithoutCache

Function shouldPrintClassInGroupModeWithoutCache

src/language-js/print/class.js:181–221  ·  view source on GitHub ↗

@returns {boolean}

(path)

Source from the content-addressed store, hash-verified

179@returns {boolean}
180*/
181function shouldPrintClassInGroupModeWithoutCache(path) {
182 const { node } = path;
183 if (
184 hasComment(node.id, CommentCheckFlags.Trailing) ||
185 hasComment(node.typeParameters, CommentCheckFlags.Trailing) ||
186 hasComment(node.superClass) ||
187 hasMultipleHeritage(node)
188 ) {
189 return true;
190 }
191
192 if (node.superClass) {
193 if (path.parent.type === "AssignmentExpression") {
194 return false;
195 }
196
197 return (
198 !node.superTypeArguments &&
199 isMemberExpression(stripChainElementWrappers(node.superClass))
200 );
201 }
202
203 const heritage =
204 node.extends?.[0] ?? node.mixins?.[0] ?? node.implements?.[0];
205
206 if (!heritage) {
207 return false;
208 }
209
210 const groupMode =
211 // `ClassImplements` seem not allow `QualifiedTypeIdentifier`
212 (heritage.type === "InterfaceExtends" &&
213 heritage.id.type === "QualifiedTypeIdentifier" &&
214 !heritage.typeParameters) ||
215 ((heritage.type === "TSClassImplements" ||
216 heritage.type === "TSInterfaceHeritage") &&
217 isMemberExpression(heritage.expression) &&
218 !heritage.typeArguments);
219
220 return groupMode;
221}
222
223const shouldPrintClassInGroupModeCache = new WeakMap();
224function shouldPrintClassInGroupMode(path) {

Callers 1

Calls 3

hasCommentFunction · 0.90
hasMultipleHeritageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…