Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
2b6a00d
fix: scope codegraph batch complexity targets to file paths
carlos-alm Jul 5, 2026
b28051a
fix: exclude parameters and interface/type members from dead-role cla…
carlos-alm Jul 5, 2026
17fbcba
fix: credit import-type usages as exports consumers
carlos-alm Jul 5, 2026
26918bb
fix: prevent fn-impact/query crash when -f/--file is passed
carlos-alm Jul 5, 2026
be6432c
fix: correct exported-symbol detection for literal and object-literal…
carlos-alm Jul 5, 2026
4ead840
fix: exclude primitive type keywords from ast --kind string matching
carlos-alm Jul 5, 2026
f6326bf
fix: resolve call edges through renamed import specifiers
carlos-alm Jul 5, 2026
590f560
fix: couple file_hashes updates with edge regeneration in incremental…
carlos-alm Jul 5, 2026
d3ea4a4
fix: compare signature-change diffs using new-file line ranges
carlos-alm Jul 5, 2026
c306812
feat: add environment doctor check for stale native binary and missin…
carlos-alm Jul 5, 2026
8bb5893
fix: eliminate non-deterministic ordering in community detection
carlos-alm Jul 6, 2026
46037b1
fix: sync update-graph.sh hook extension allowlist with EXTENSIONS
carlos-alm Jul 6, 2026
6a84cf9
fix: recompute directory structure metrics for affected directories o…
carlos-alm Jul 6, 2026
8d936d1
refactor: register hardcoded execFileSync/execSync maxBuffer values i…
carlos-alm Jul 6, 2026
11c84be
fix: gate blast-radius check on newly introduced risk, not pre-existi…
carlos-alm Jul 6, 2026
963301a
fix: gate identifier-argument dynamic call edges on callback-acceptin…
carlos-alm Jul 6, 2026
3e8035d
fix: gate Array.from's callback arg by position, not just callee name
carlos-alm Jul 6, 2026
879635e
fix: scope reexportedSymbols to actually-named re-export specifiers
carlos-alm Jul 6, 2026
0fe9fc3
fix: stop CFG block/edge count from overriding AST-derived cyclomatic…
carlos-alm Jul 6, 2026
ccf3c19
fix: backfill edges.technique for incrementally-inserted calls edges
carlos-alm Jul 6, 2026
d5b1162
fix: wrap remote embedding JSON parse failure in EngineError
carlos-alm Jul 6, 2026
8971017
refactor: extract shared platform-default-path helper in config.ts
carlos-alm Jul 6, 2026
056c5e4
refactor: decompose loadConfig and related high-effort functions in c…
carlos-alm Jul 6, 2026
0738171
refactor: decompose findDbPath and openRepo in db/connection.ts (docs…
carlos-alm Jul 6, 2026
6f2423c
refactor: dedupe busy/locked error detection into isBusyOrLockedError
carlos-alm Jul 6, 2026
4c02378
fix: log statSync failures in findDbPath instead of silently swallowi…
carlos-alm Jul 6, 2026
0698e16
test: add direct unit coverage for closeDbPair/closeDbPairDeferred/cl…
carlos-alm Jul 6, 2026
4ac3b99
fix: correct blast-radius/fn-impact computation for line-shifted decl…
carlos-alm Jul 6, 2026
6767f09
feat: wire points-to solver max-iterations cap through DEFAULTS.analy…
carlos-alm Jul 6, 2026
5f6f30a
refactor: route console.log calls in domain/search through logger
carlos-alm Jul 6, 2026
b479318
refactor: reduce cyclomatic complexity of computeDeltaModularityDirected
carlos-alm Jul 6, 2026
c39ac40
refactor: unify impact-level rendering format between audit and fn-im…
carlos-alm Jul 6, 2026
067674f
refactor: dedupe computeSavings via pct helper and persist partial to…
carlos-alm Jul 6, 2026
f6807b4
fix: add main.rs driver to rust dynamic tracer fixture
carlos-alm Jul 6, 2026
1c07a54
fix: scope diff file-header detection to between-hunk positions
carlos-alm Jul 6, 2026
bf82aa2
fix: update titan-grind's dead-symbol script for current roles --json…
carlos-alm Jul 6, 2026
cd02d27
fix: thread configured busyTimeoutMs through remaining read-only quer…
carlos-alm Jul 6, 2026
980b5dc
fix: resolve computed string-literal keys in object-literal extractio…
carlos-alm Jul 6, 2026
4a873a3
fix: add same-class bare-call fallback to incremental rebuild path (d…
carlos-alm Jul 6, 2026
8f3348a
fix: unify Object.defineProperty accessor fallback kind-filtering bet…
carlos-alm Jul 6, 2026
acf804c
refactor: share chunked statement-cache primitive between builder and…
carlos-alm Jul 6, 2026
986c851
refactor: cache prepared statements in applyEdgeTechniquesAfterNative…
carlos-alm Jul 6, 2026
71e9174
fix: replace fixed-depth directory-proximity check with symmetric dis…
carlos-alm Jul 6, 2026
d2935cc
refactor: remove unreachable Partition delta-computation interface me…
carlos-alm Jul 6, 2026
6515186
fix: emit reference edges for function identifiers used as object-lit…
carlos-alm Jul 6, 2026
30c491a
refactor: unify call-ref and tests rendering format between audit and…
carlos-alm Jul 6, 2026
9db911b
fix: classify destructured bindings as constant, not function (docs c…
carlos-alm Jul 6, 2026
70559fc
refactor: adopt timeMedian in remaining benchmark timing loops
carlos-alm Jul 6, 2026
822e0eb
refactor: decompose runPerfBenchmarks in token-benchmark.ts
carlos-alm Jul 6, 2026
fcdfe7d
fix: attribute liveness to Lua functions assigned to global/builtin i…
carlos-alm Jul 6, 2026
ee6362c
refactor: extract shared sedi() helper for tracer scripts
carlos-alm Jul 6, 2026
d4e6212
fix: restore reflection dynamicKind for .call/.apply/.bind (docs chec…
carlos-alm Jul 6, 2026
aec5d2b
fix: restrict entry-role classification to function/method-kind symbo…
carlos-alm Jul 6, 2026
d250f8d
fix: credit destructured dynamic import() bindings as exports consumers
carlos-alm Jul 6, 2026
75978e2
fix: recognize Lua function nodes in complexity metrics computation (…
carlos-alm Jul 6, 2026
af17b6d
fix: scope global call-resolution fallback to same-language candidate…
carlos-alm Jul 6, 2026
dd447bc
fix: credit instanceof ClassName checks as exports consumers
carlos-alm Jul 6, 2026
a79a8a1
fix: update automated-review workflow to use current claude-code-acti…
carlos-alm Jul 6, 2026
d84f6b5
refactor: widen outputResult signature, remove redundant casts at cal…
carlos-alm Jul 6, 2026
e7a2255
fix: port Leiden algorithm to native Rust for cross-engine community-…
carlos-alm Jul 7, 2026
b54972a
feat: detect exported-symbol loss from full file deletion in checkNoS…
carlos-alm Jul 7, 2026
1821a8b
fix(complexity): scope summary stats to file/target/kind filters
carlos-alm Jul 7, 2026
d45aba7
fix(extractors): label property_signature interface/type members as k…
carlos-alm Jul 7, 2026
69d8a6f
fix(roles): exclude genuine class/struct properties from dead-role cl…
carlos-alm Jul 7, 2026
db08219
fix(resolver): scope extends/implements edges to same-file/import/lan…
carlos-alm Jul 7, 2026
79cd761
fix: track inline per-specifier type-only import modifier
carlos-alm Jul 7, 2026
cbfa954
fix(native): widen NativeRepository file filters to accept string[]
carlos-alm Jul 7, 2026
c0e7eae
fix(native): remove unused source param from get_first_call_arg
carlos-alm Jul 7, 2026
2dabe21
fix(extractors): align native/WASM definitions order for object-liter…
carlos-alm Jul 7, 2026
b1eb9af
fix(extractors): capture top-level const definitions regardless of in…
carlos-alm Jul 7, 2026
9d116b9
fix: resolve merge conflicts with main (docs check acknowledged)
carlos-alm Jul 9, 2026
360bc3a
fix: hoist in_function_scope out of handle_var_decl's declarator loop…
carlos-alm Jul 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 101 additions & 29 deletions crates/codegraph-core/src/extractors/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,7 @@ fn is_eligible_object_literal_declarator(declarator: &Node) -> bool {
if declarator.kind() != "variable_declarator" { return false; }
let Some(name_n) = declarator.child_by_field_name("name") else { return false };
if name_n.kind() != "identifier" { return false; }
find_parent_of_types(declarator, &[
"function_declaration", "arrow_function", "function_expression",
"method_definition", "generator_function_declaration", "generator_function",
]).is_none()
find_parent_of_types(declarator, &VAR_DECL_FN_SCOPE_TYPES).is_none()
}

/// True when `method_node` (a method_definition) is a shorthand method whose enclosing object
Expand Down Expand Up @@ -1303,17 +1300,27 @@ fn handle_enum_decl(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
}
}

/// Node types marking a function-body scope; declarations inside these are skipped by
/// the top-level-constant/destructuring branches below (parity with TS `FUNCTION_SCOPE_TYPES`).
const VAR_DECL_FN_SCOPE_TYPES: [&str; 6] = [
"function_declaration", "arrow_function",
"function_expression", "method_definition",
"generator_function_declaration", "generator_function",
];

fn handle_var_decl(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
let is_const = node.child(0)
.map(|c| node_text(&c, source) == "const")
.unwrap_or(false);
let in_function_scope = find_parent_of_types(node, &VAR_DECL_FN_SCOPE_TYPES).is_some();
for i in 0..node.child_count() {
let Some(declarator) = node.child(i) else { continue };
if declarator.kind() != "variable_declarator" { continue; }
let name_n = declarator.child_by_field_name("name");
let value_n = declarator.child_by_field_name("value");
let (Some(name_n), Some(value_n)) = (name_n, value_n) else { continue };
let vt = value_n.kind();

if vt == "arrow_function" || vt == "function_expression" || vt == "function" || vt == "generator_function" {
let children = extract_js_parameters(&value_n, source);
symbols.definitions.push(Definition {
Expand All @@ -1326,13 +1333,7 @@ fn handle_var_decl(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
cfg: build_function_cfg(&value_n, "javascript", source),
children: opt_children(children),
});
} else if is_const && name_n.kind() == "object_pattern"
&& find_parent_of_types(node, &[
"function_declaration", "arrow_function",
"function_expression", "method_definition",
"generator_function_declaration", "generator_function",
]).is_none()
{
} else if is_const && name_n.kind() == "object_pattern" && !in_function_scope {
// Parity with TS query path (extractDestructuredBindingsWalk):
// skip destructured const bindings inside function scopes so the
// Rust walk path matches FUNCTION_SCOPE_TYPES behaviour.
Expand Down Expand Up @@ -1362,13 +1363,14 @@ fn handle_var_decl(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
}
}
}
} else if is_const && is_js_literal(&value_n)
&& find_parent_of_types(node, &[
"function_declaration", "arrow_function",
"function_expression", "method_definition",
"generator_function_declaration", "generator_function",
]).is_none()
} else if is_const
&& (name_n.kind() == "identifier" || name_n.kind() == "array_pattern")
&& !in_function_scope
{
// Any other initializer shape becomes a "constant" Definition, regardless of
// complexity (call/member/parenthesized expressions, etc.) — mirroring how
// function declarations are captured regardless of body complexity, and the
// WASM/TS extractor's unconditional identifier + array_pattern branches (#1819).
symbols.definitions.push(Definition {
name: node_text(&name_n, source).to_string(),
kind: "constant".to_string(),
Expand Down Expand Up @@ -1397,7 +1399,13 @@ fn handle_var_decl(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
// definitions in the wrong relative position.
let var_name = node_text(&name_n, source);
extract_object_literal_functions(&value_n, source, var_name, symbols);
} else if name_n.kind() == "identifier" && value_n.kind() == "identifier" {
}

// pts fn_ref_binding tracking runs independently of the Definition-shape branching
// above (mirrors WASM's collectFnRefBindings, which always runs before any
// Definition-related early return) so `const alias = handler` still seeds a pts
// alias even though `alias` now also gets its own "constant" Definition (#1819).
if name_n.kind() == "identifier" && value_n.kind() == "identifier" {
// Phase 8.3: `const alias = handler` — record for pts analysis.
// Mirror the JS BUILTIN_GLOBALS guard: skip well-known JS globals so
// they are never seeded as pts targets (e.g. `const a = Array`).
Expand Down Expand Up @@ -1737,8 +1745,8 @@ fn handle_export_declaration(node: &Node, decl: &Node, source: &[u8], symbols: &
/// field (handled above); a lexical/variable declaration doesn't, so each
/// declarator's value is classified the same way `handle_var_decl` classifies
/// it when creating the matching `Definition`: function-valued declarators
/// become kind "function", `const` declarators with a literal/array/object/
/// new-expression value (per `is_js_literal`) become kind "constant".
/// become kind "function"; any other `const` declarator becomes kind "constant",
/// regardless of initializer complexity (#1819).
/// Mirrors the WASM/TS extractor's `collectExportedDeclarations`.
///
/// This predicate must stay identical to `handle_var_decl`'s: `insert_nodes.rs`
Expand Down Expand Up @@ -1770,7 +1778,7 @@ fn collect_exported_var_declarations(
kind: "function".to_string(),
line,
});
} else if is_const && is_js_literal(&value_n) {
} else if is_const {
symbols.exports.push(ExportInfo {
name: node_text(&name_n, source).to_string(),
Comment on lines 1778 to 1783

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 object_pattern export creates a phantom export entry that can never match a definition

collect_exported_var_declarations now accepts any is_const declarator and pushes name_n's raw text as the export name. For export const {a, b} = callExpr(), that name is {a, b}. But handle_var_decl's object_pattern branch calls extract_destructured_bindings, which emits separate definitions for a and b — so the UPDATE keyed on (name="{a, b}", kind="constant", …) silently no-ops and neither a nor b gets marked exported. This mismatch existed before for literal-valued object_pattern consts, so the practical outcome is unchanged, but the PR now adds the phantom export record for non-literal initializers too. A guard like name_n.kind() != "object_pattern" would prevent the spurious entry.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this closely — I don't think the phantom {a, b} entry actually reaches symbols.exports. collect_exported_var_declarations has an early if name_n.kind() != "identifier" { continue; } a few lines above the branch you flagged, and this guard is unchanged by this PR (present identically on both parents). For export const { a, b } = callExpr();, name_n.kind() is object_pattern, so that declarator is skipped entirely before reaching the is_const push — I verified this empirically with a throwaway test (EXPORTS: []). The TS/WASM mirror has the identical guard (if (nameN?.type !== 'identifier' || !valueN) continue;), so both engines agree.

There is a real, separate gap here though: since the declarator is skipped outright, a and b (which do get real Definition rows via extract_destructured_bindings) never get credited as exported at all — not a phantom entry, but a missing one. That's pre-existing on both engines (unchanged by this PR), so I filed it separately as #2070 rather than fixing it here.

kind: "constant".to_string(),
Expand Down Expand Up @@ -2176,14 +2184,6 @@ fn extract_ts_enum_members(node: &Node, source: &[u8]) -> Vec<Definition> {
members
}

fn is_js_literal(node: &Node) -> bool {
matches!(node.kind(),
"number" | "string" | "true" | "false" | "null" | "undefined"
| "template_string" | "regex" | "array" | "object"
| "unary_expression" | "binary_expression" | "new_expression"
)
}

// ── Existing helpers ────────────────────────────────────────────────────────

fn extract_interface_methods(
Expand Down Expand Up @@ -4131,6 +4131,78 @@ mod tests {
assert_eq!(s.definitions[0].name, "main");
}

// ── #1819: top-level const with a non-"literal-shaped" initializer ────────

#[test]
fn extracts_const_with_member_expression_initializer_as_constant() {
// Repro from #1819: a parenthesized member-expression initializer
// (`(...).version`) was not one of the recognized "literal" shapes, so
// the whole declaration was silently dropped — not just unexported,
// absent from `definitions` entirely.
let s = parse_js(
"const CODEGRAPH_VERSION = (JSON.parse(readFileSync(pkgPath, 'utf-8'))).version;",
);
let def = s
.definitions
.iter()
.find(|d| d.name == "CODEGRAPH_VERSION")
.unwrap_or_else(|| panic!("CODEGRAPH_VERSION should be extracted as a definition"));
assert_eq!(def.kind, "constant");
}

#[test]
fn extracts_const_with_call_expression_initializer_as_constant() {
let s = parse_js("const config = loadConfig();");
let def = s
.definitions
.iter()
.find(|d| d.name == "config")
.unwrap_or_else(|| panic!("config should be extracted as a definition"));
assert_eq!(def.kind, "constant");
}

#[test]
fn exports_const_with_call_expression_initializer() {
let s = parse_js("export const config = loadConfig();");
assert!(
s.exports.iter().any(|e| e.name == "config" && e.kind == "constant"),
"config should be listed as an exported constant; got: {:?}",
s.exports
);
}

#[test]
fn extracts_const_array_pattern_with_call_expression_initializer() {
// Parity with the identifier case above: array-pattern names must also
// be discoverable regardless of initializer complexity.
let s = parse_js("const [a, b] = computePair();");
let def = s
.definitions
.iter()
.find(|d| d.name == "[a, b]")
.unwrap_or_else(|| panic!("[a, b] should be extracted as a definition"));
assert_eq!(def.kind, "constant");
}

#[test]
fn const_alias_gets_both_definition_and_fn_ref_binding() {
// The new "constant" Definition for an identifier-aliased const must not
// come at the expense of the existing pts fn_ref_binding tracking — the
// two concerns are independent (mirrors the WASM/TS extractor's
// decoupled fnRefBindings pass).
let s = parse_js("const alias = handler;");
assert!(
s.definitions.iter().any(|d| d.name == "alias" && d.kind == "constant"),
"alias should be extracted as a constant definition; got: {:?}",
s.definitions
);
assert!(
s.fn_ref_bindings.iter().any(|b| b.lhs == "alias" && b.rhs == "handler"),
"alias -> handler fn_ref_binding should still be recorded; got: {:?}",
s.fn_ref_bindings
);
}

// ── AST node extraction tests ────────────────────────────────────────────

#[test]
Expand Down
75 changes: 28 additions & 47 deletions src/extractors/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,13 @@ const EXPORT_DECL_KIND: Record<string, string> = {
* Named function/class/interface/type declarations carry their own `name`
* field. `export const/let/var …` has no such field — each declarator's value
* is classified the same way `handleVariableDeclarator` classifies it when
* building the matching Definition (function-valued → kind 'function',
* literal/array/object/new-expression-valued `const` → kind 'constant').
* This predicate must stay identical to the Definition-building one: the
* exported=1 UPDATE it feeds matches DB rows by (name, kind, file, line), so
* a mismatched kind silently no-ops instead of marking the symbol exported (#1728).
* building the matching Definition (function-valued → kind 'function'; any
* other `const` initializer shape → kind 'constant', regardless of complexity —
* mirroring how function declarations are captured regardless of body
* complexity, #1819). This predicate must stay identical to the
* Definition-building one: the exported=1 UPDATE it feeds matches DB rows by
* (name, kind, file, line), so a mismatched kind silently no-ops instead of
* marking the symbol exported (#1728).
*/
function collectExportedDeclarations(
decl: TreeSitterNode,
Expand Down Expand Up @@ -241,7 +243,7 @@ function collectExportedDeclarations(
valType === 'generator_function'
) {
exps.push({ name: nameN.text, kind: 'function', line: exportLine });
} else if (isConst && isConstantValue(valueN)) {
} else if (isConst) {
exps.push({ name: nameN.text, kind: 'constant', line: exportLine });
}
}
Expand Down Expand Up @@ -737,21 +739,22 @@ function extractConstDeclarators(declNode: TreeSitterNode, definitions: Definiti
valType === 'generator_function'
)
continue;
if (isConstantValue(valueN)) {
definitions.push({
name: nameN.text,
kind: 'constant',
line: nodeStartLine(declNode),
endLine: nodeEndLine(declNode),
});
// Phase 8.3f: extract function/arrow properties from object literals.
// Scope guard: extractConstDeclarators is only called from extractConstantsWalk, which
// already skips const declarations inside function scopes (line ~412). So these definitions
// are always top-level. Any new call site must add a hasFunctionScopeAncestor guard
// (the walk path at handleVariableDecl does this).
if (valueN.type === 'object') {
extractObjectLiteralFunctions(valueN, nameN.text, definitions);
}
// Any other initializer shape becomes a 'constant' Definition, regardless of
// complexity (call/member/parenthesized expressions, etc.) — mirroring how
// function declarations are captured regardless of body complexity (#1819).
definitions.push({
name: nameN.text,
kind: 'constant',
line: nodeStartLine(declNode),
endLine: nodeEndLine(declNode),
});
// Phase 8.3f: extract function/arrow properties from object literals.
// Scope guard: extractConstDeclarators is only called from extractConstantsWalk, which
// already skips const declarations inside function scopes (line ~412). So these definitions
// are always top-level. Any new call site must add a hasFunctionScopeAncestor guard
// (the walk path at handleVariableDecl does this).
if (valueN.type === 'object') {
extractObjectLiteralFunctions(valueN, nameN.text, definitions);
}
}
}
Expand Down Expand Up @@ -1234,12 +1237,10 @@ function handleVariableDeclarator(
valType === 'generator_function'
) {
handleVarFnAssignment(node, nameN, valueN, ctx);
} else if (
isConst &&
nameN.type === 'identifier' &&
isConstantValue(valueN) &&
!hasFunctionScopeAncestor(node)
) {
} else if (isConst && nameN.type === 'identifier' && !hasFunctionScopeAncestor(node)) {
// Any other initializer shape becomes a 'constant' Definition, regardless of
// complexity (call/member/parenthesized expressions, etc.) — mirroring how
// function declarations are captured regardless of body complexity (#1819).
handleConstIdentifierAssignment(node, nameN, valueN, ctx);
} else if (
!isConst &&
Expand Down Expand Up @@ -1705,26 +1706,6 @@ function extractVisibility(node: TreeSitterNode): 'public' | 'private' | 'protec
return undefined;
}

function isConstantValue(valueNode: TreeSitterNode): boolean {
if (!valueNode) return false;
const t = valueNode.type;
return (
t === 'number' ||
t === 'string' ||
t === 'template_string' ||
t === 'true' ||
t === 'false' ||
t === 'null' ||
t === 'undefined' ||
t === 'array' ||
t === 'object' ||
t === 'regex' ||
t === 'unary_expression' ||
t === 'binary_expression' ||
t === 'new_expression'
);
}

// ── Shared helpers ──────────────────────────────────────────────────────────

function extractInterfaceMethods(
Expand Down
55 changes: 55 additions & 0 deletions tests/parsers/javascript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,61 @@ describe('JavaScript parser', () => {
});
});

describe('top-level const with a non-"literal-shaped" initializer (#1819)', () => {
it('extracts a const with a parenthesized member-expression initializer as a definition (repro)', () => {
// Repro from #1819: `(...).version` isn't one of the recognized "literal"
// shapes, so the whole declaration was previously dropped — not just
// unexported, absent from `definitions` entirely.
const symbols = parseJS(
`export const CODEGRAPH_VERSION = (\n JSON.parse(readFileSync(pkgPath, 'utf-8'))\n).version;`,
);
expect(symbols.definitions).toContainEqual(
expect.objectContaining({ name: 'CODEGRAPH_VERSION', kind: 'constant' }),
);
expect(symbols.exports).toContainEqual(
expect.objectContaining({ name: 'CODEGRAPH_VERSION', kind: 'constant' }),
);
});

it('extracts a const with a call-expression initializer as a definition', () => {
const symbols = parseJS(`const config = loadConfig();`);
expect(symbols.definitions).toContainEqual(
expect.objectContaining({ name: 'config', kind: 'constant' }),
);
});

it('extracts an exported const with a call-expression initializer', () => {
const symbols = parseJS(`export const config = loadConfig();`);
expect(symbols.exports).toContainEqual(
expect.objectContaining({ name: 'config', kind: 'constant' }),
);
});

it('extracts a const with a bare identifier initializer as a definition', () => {
const symbols = parseJS(`const alias = handler;`);
expect(symbols.definitions).toContainEqual(
expect.objectContaining({ name: 'alias', kind: 'constant' }),
);
// The new Definition must not come at the expense of the existing pts
// fnRefBindings tracking (they're independent passes).
expect(symbols.fnRefBindings).toContainEqual(
expect.objectContaining({ lhs: 'alias', rhs: 'handler' }),
);
});

it('still skips a non-top-level const with a non-literal initializer', () => {
const symbols = parseJS(`function f() { const x = compute(); }`);
expect(symbols.definitions.some((d) => d.name === 'x')).toBe(false);
});

it('extracts a const array pattern with a call-expression initializer (parity with identifier case)', () => {
const symbols = parseJS(`const [a, b] = computePair();`);
expect(symbols.definitions).toContainEqual(
expect.objectContaining({ name: '[a, b]', kind: 'constant' }),
);
});
});

describe('interface member kind labeling (#1809)', () => {
function parseTS(code) {
const parser = parsers.get('typescript');
Expand Down
Loading