MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / leafClass

Function leafClass

src/extraction/syntax-tokens.ts:299–324  ·  view source on GitHub ↗
(node: SyntaxNode, ctx: WalkContext, inString: boolean)

Source from the content-addressed store, hash-verified

297}
298
299function leafClass(node: SyntaxNode, ctx: WalkContext, inString: boolean): SyntaxTokenClass {
300 const type = node.type;
301
302 // An ANONYMOUS node's `type` is its own literal text, so none of the
303 // type-name tests below may be applied to one: `key: string` in TypeScript or
304 // PHP is a token whose type is the word `string`, and reading that as a
305 // string literal greys out half of every signature. Anonymous means keyword
306 // or punctuation, decided on shape alone — which is also what makes `func`,
307 // `fn`, `def`, `Sub` and `END-IF` all land right without naming any of them.
308 if (!node.isNamed) {
309 if (inString) return 'string';
310 if (CONSTANT_TYPES.has(type)) return 'number';
311 return WORD_SHAPE.test(type) ? 'keyword' : 'other';
312 }
313
314 if (inString || isStringType(type)) return 'string';
315 if (isNumberType(type) || CONSTANT_TYPES.has(type)) return 'number';
316
317 const text = ctx.source.slice(node.startIndex, node.endIndex);
318 // Ahead of the type tests: a class name is a `type_identifier` in half these
319 // grammars and a plain `identifier` in the other half, and the design bolds
320 // the thing being DECLARED either way.
321 if (ctx.defStarts.has(node.startIndex) && IDENT_SHAPE.test(text)) return 'def';
322 if (isTypeNameType(type)) return 'type';
323 return IDENT_SHAPE.test(text) ? 'ident' : 'other';
324}
325
326/**
327 * Append a span, skipping empties and merging a run of the same class.

Callers 1

visitFunction · 0.85

Calls 4

isStringTypeFunction · 0.85
isNumberTypeFunction · 0.85
isTypeNameTypeFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected