MCPcopy
hub / github.com/analogjs/analog / stringValue

Function stringValue

packages/vite-plugin-angular/src/lib/compiler/metadata.ts:39–66  ·  view source on GitHub ↗

* Extract the string value from an OXC string literal or template literal node. * * If `consts` is provided, interpolated template literals (e.g. * `\`hello ${NAME}\``) are resolved when every `${...}` expression is a bare * `Identifier` whose name is present in the map. This lets metadata field

(node: any, consts?: Map<string, string>)

Source from the content-addressed store, hash-verified

37 * Returns `null` if the node is not statically resolvable.
38 */
39function stringValue(node: any, consts?: Map<string, string>): string | null {
40 if (node?.type === 'StringLiteral') return node.value;
41 if (node?.type === 'Literal' && typeof node.value === 'string')
42 return node.value;
43 if (node?.type === 'TemplateLiteral') {
44 const quasis = node.quasis ?? [];
45 const expressions = node.expressions ?? [];
46 if (expressions.length === 0) {
47 return quasis[0]?.value?.cooked ?? null;
48 }
49 if (!consts) return null;
50 let result = '';
51 for (let i = 0; i < quasis.length; i++) {
52 const cooked = quasis[i]?.value?.cooked;
53 if (cooked == null) return null;
54 result += cooked;
55 if (i < expressions.length) {
56 const expr = expressions[i];
57 if (expr?.type !== 'Identifier') return null;
58 const resolved = consts.get(expr.name);
59 if (resolved == null) return null;
60 result += resolved;
61 }
62 }
63 return result;
64 }
65 return null;
66}
67
68/** Check if an OXC node is a string-like literal. */
69function isStringLike(node: any, consts?: Map<string, string>): boolean {

Callers 6

isStringLikeFunction · 0.85
collectStringConstantsFunction · 0.85
extractMetadataFunction · 0.85
detectSignalsFunction · 0.85
detectFieldDecoratorsFunction · 0.85
extractConstructorDepsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected