Key sites vs dynamic detection
Two complementary pipelines:
Key sites (scanProjectKeyObservations)
Per source file:
- Build a const string map from top-level-ish
const X = '...'patterns (buildConstStringMap). - Comment ranges — line and block comments (
commentRangesForJsLikeText); translation calls whose start falls inside a range are skipped (not treated as runtime key usage). - Observations:
literal— first arg is a single quoted string.template_resolved— after${ident}substitution from the const map, the template is a full static dotted key.template_partial— still has unresolved placeholders; may setuncertainPrefix(longest static path segment before the first unknown${…}) for prefix-based protection inreferencepolicy.
Code: packages/cli/src/core/extractor/keySites/scan.ts, orchestrate.ts.
Dynamic sites (scanProjectDynamicKeySites)
Per file extension, providers run (e.g. JavaScript-like: providers/javascript.ts):
- Non-literal first args, empty calls, template interpolation where the full key cannot be rebuilt from the const map.
- May attach
resolvedPrefixfor partial static segments. - Comment offsets flip
kindtocommented/isCommentedwhentreatCommentedCallSitesAsRuntimeis false inreference— those sites do not contribute uncertain prefixes.
Unified context
buildKeyReferenceContext ( packages/cli/src/core/reference/context.ts ) merges:
- Proven keys —
resolvedKeysFromObservations(literal + template_resolved only). - Uncertain prefixes — from
template_partial.uncertainPrefixand dynamicresolvedPrefix, filtered byreferencetoggles.
Merged source text
Some helpers use one concatenated blob (e.g. tests or older merged-text call paths). In those modes per-file metadata is missing: comment suppression and file paths may be omitted. Prefer per-file scanProjectKeyObservations / scanProjectDynamicKeySites for accurate locations. See Per-file const maps.
Accuracy
There is no single global percentage: results depend on coding style, framework, and how much logic is indirect. Defaults in reference prefer safe behavior (protect under uncertain prefixes) over aggressive cleanup.
See also Detection limits in the overview.