diff --git a/AGENTS.md b/AGENTS.md index dba25c5e..06824a3b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,7 +22,11 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i negatives, byte-for-byte), `reference/golden/kotlin/` (corpus `crates/codegraph-bench/fixtures/kotlin/`; guards #1495 Kotlin callable signatures for explicit, inferred, generic, multiline nullable, and extension - returns, plus a primary-constructor negative — byte-for-byte), and `reference/golden/cpp/` + returns, plus a primary-constructor negative — byte-for-byte), + `reference/golden/typescript/` (corpus `crates/codegraph-bench/fixtures/typescript/`; + guards #1482 local export aliases and #1482b TypeScript `.js`-specifier + substitution, including TS-over-JS collision precedence — byte-for-byte), and + `reference/golden/cpp/` (corpus `crates/codegraph-bench/fixtures/cpp/`; guards #1043 C++ class/struct inheritance incl. templated-base stripping byte-for-byte, and retroactively the earlier C++ extraction work). @@ -30,7 +34,7 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i import Gate 3b is deliberately unreachable for real Python nodes because the extractor does not mark them exported. Regen recipe: `docs/equivalence.md` "Godot fixture" / "Ruby fixture" / "Python fixture" / "Kotlin fixture" / - "C++ fixture" sections. + "TypeScript resolution fixture" / "C++ fixture" sections. - **node-id formula**: `{kind}:{sha256("{filePath}:{kind}:{name}:{line}").hex[:32]}`; file nodes are the literal `file:{relpath}`; lines are 1-based; paths relative with `/`. - **No AI / vector / LLM crates** — enforced by `scripts/guardrail.sh` (CI gate): diff --git a/crates/codegraph-bench/fixtures/typescript/collision.js b/crates/codegraph-bench/fixtures/typescript/collision.js new file mode 100644 index 00000000..12fe9f05 --- /dev/null +++ b/crates/codegraph-bench/fixtures/typescript/collision.js @@ -0,0 +1 @@ +export function collisionTarget() {} diff --git a/crates/codegraph-bench/fixtures/typescript/collision.ts b/crates/codegraph-bench/fixtures/typescript/collision.ts new file mode 100644 index 00000000..12fe9f05 --- /dev/null +++ b/crates/codegraph-bench/fixtures/typescript/collision.ts @@ -0,0 +1 @@ +export function collisionTarget() {} diff --git a/crates/codegraph-bench/fixtures/typescript/consumer.ts b/crates/codegraph-bench/fixtures/typescript/consumer.ts new file mode 100644 index 00000000..93dab287 --- /dev/null +++ b/crates/codegraph-bench/fixtures/typescript/consumer.ts @@ -0,0 +1,17 @@ +import { constAlias as viaConstAlias } from './exports'; +import { namedAlias as viaNamedAlias } from './exports'; +import defaultExportAlias from './exports'; +import { jsTarget as viaJsSpecifier } from './js_target.js'; +import { collisionTarget as viaCollision } from './collision.js'; +import { extensionlessTarget as viaExtensionless } from './extensionless'; +import { missingTarget as viaMissing } from './missing.js'; + +export function runAll() { + viaConstAlias(); + viaNamedAlias(); + defaultExportAlias(); + viaJsSpecifier(); + viaCollision(); + viaExtensionless(); + viaMissing(); +} diff --git a/crates/codegraph-bench/fixtures/typescript/exports.ts b/crates/codegraph-bench/fixtures/typescript/exports.ts new file mode 100644 index 00000000..9e8dcfa1 --- /dev/null +++ b/crates/codegraph-bench/fixtures/typescript/exports.ts @@ -0,0 +1,11 @@ +function constTarget() {} + +export const constAlias = constTarget; + +function namedTarget() {} + +export { namedTarget as namedAlias }; + +function defaultTarget() {} + +export default defaultTarget; diff --git a/crates/codegraph-bench/fixtures/typescript/extensionless.ts b/crates/codegraph-bench/fixtures/typescript/extensionless.ts new file mode 100644 index 00000000..4b888239 --- /dev/null +++ b/crates/codegraph-bench/fixtures/typescript/extensionless.ts @@ -0,0 +1 @@ +export function extensionlessTarget() {} diff --git a/crates/codegraph-bench/fixtures/typescript/js_target.ts b/crates/codegraph-bench/fixtures/typescript/js_target.ts new file mode 100644 index 00000000..fbfa3cd3 --- /dev/null +++ b/crates/codegraph-bench/fixtures/typescript/js_target.ts @@ -0,0 +1 @@ +export function jsTarget() {} diff --git a/crates/codegraph-bench/tests/equivalence.rs b/crates/codegraph-bench/tests/equivalence.rs index c8ad731a..e42afef0 100644 --- a/crates/codegraph-bench/tests/equivalence.rs +++ b/crates/codegraph-bench/tests/equivalence.rs @@ -142,6 +142,22 @@ fn kotlin_db_is_self_equivalent_to_kotlin_golden() { assert_equivalent(&kotlin_db(), &kotlin_golden_dir()).unwrap(); } +#[test] +fn generated_golden_matches_committed_typescript_fixture() { + let tempdir = TestDir::new("generated-golden-typescript"); + write_golden(&typescript_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&typescript_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn typescript_db_is_self_equivalent_to_typescript_golden() { + assert_equivalent(&typescript_db(), &typescript_golden_dir()).unwrap(); +} + #[test] fn generated_golden_matches_committed_metal_fixture() { // Guards Metal (#1121): `.metal`→cpp mapping + the `[[attribute]]` blank that @@ -412,6 +428,14 @@ fn kotlin_golden_dir() -> PathBuf { workspace_root().join("reference/golden/kotlin") } +fn typescript_db() -> PathBuf { + workspace_root().join("reference/golden/typescript/colby.db") +} + +fn typescript_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/typescript") +} + fn metal_db() -> PathBuf { workspace_root().join("reference/golden/metal/colby.db") } diff --git a/crates/codegraph-resolve/src/import_resolver.rs b/crates/codegraph-resolve/src/import_resolver.rs index 10ac25cc..4e6fcc42 100644 --- a/crates/codegraph-resolve/src/import_resolver.rs +++ b/crates/codegraph-resolve/src/import_resolver.rs @@ -79,6 +79,54 @@ fn extension_resolution(language: Language) -> &'static [&'static str] { } } +fn resolve_source_candidate( + base_path: &str, + language: Language, + context: &dyn ResolutionContext, +) -> Option { + let substitution = if matches!(language, Language::TypeScript | Language::Tsx) { + if let Some(stem) = base_path.strip_suffix(".mjs") { + Some((stem, &[".mts", ".d.mts"][..])) + } else if let Some(stem) = base_path.strip_suffix(".cjs") { + Some((stem, &[".cts", ".d.cts"][..])) + } else if let Some(stem) = base_path + .strip_suffix(".jsx") + .or_else(|| base_path.strip_suffix(".js")) + { + let extensions = if language == Language::Tsx { + &[".tsx", ".ts", ".d.ts"][..] + } else { + &[".ts", ".tsx", ".d.ts"][..] + }; + Some((stem, extensions)) + } else { + None + } + } else { + None + }; + + if let Some((stem, extensions)) = substitution { + for extension in extensions { + let candidate = format!("{stem}{extension}"); + if context.file_exists(&candidate) { + return Some(candidate); + } + } + } + + for extension in extension_resolution(language) { + let candidate = format!("{base_path}{extension}"); + if context.file_exists(&candidate) { + return Some(candidate); + } + } + + context + .file_exists(base_path) + .then(|| base_path.to_string()) +} + /// Resolve an import path to an actual file (`resolveImportPath`, /// `import-resolver.ts:42-76`). pub fn resolve_import_path( @@ -375,10 +423,9 @@ fn resolve_relative_import( language: Language, context: &dyn ResolutionContext, ) -> Option { - let extensions = extension_resolution(language); - // Python dotted-relative imports (import-resolver.ts:221-232). if language == Language::Python && import_path.starts_with('.') { + let extensions = extension_resolution(language); let dots = import_path.len() - import_path.trim_start_matches('.').len(); let up = "../".repeat(dots.saturating_sub(1)); let rest = import_path[dots..].replace('.', "/"); @@ -398,19 +445,7 @@ fn resolve_relative_import( let base_path = pathutil::resolve(from_dir, import_path); let relative_path = pathutil::relative(project_root, &base_path); - - for ext in extensions { - let candidate = format!("{relative_path}{ext}"); - if context.file_exists(&candidate) { - return Some(candidate); - } - } - - if context.file_exists(&relative_path) { - return Some(relative_path); - } - - None + resolve_source_candidate(&relative_path, language, context) } /// Resolve an aliased/absolute import (`resolveAliasedImport`, @@ -421,19 +456,7 @@ fn resolve_aliased_import( language: Language, context: &dyn ResolutionContext, ) -> Option { - let extensions = extension_resolution(language); - let try_with_ext = |base_path: &str| -> Option { - for ext in extensions { - let candidate = format!("{base_path}{ext}"); - if context.file_exists(&candidate) { - return Some(candidate); - } - } - if context.file_exists(base_path) { - return Some(base_path.to_string()); - } - None - }; + let try_with_ext = |base_path: &str| resolve_source_candidate(base_path, language, context); // 1. Project tsconfig/jsconfig paths (import-resolver.ts:282-289). if let Some(alias_map) = context.get_project_aliases() { @@ -919,8 +942,8 @@ fn strip_js_comments(content: &str) -> String { out } -/// Extract JS/TS re-export declarations (`extractReExports`, -/// `import-resolver.ts:989-1042`). +/// Extract JS/TS cross-file re-exports and explicit local export aliases +/// (`extractReExports`, `import-resolver.ts:989-1042`). pub fn extract_re_exports(content: &str, language: Language) -> Vec { if !matches!( language, @@ -933,6 +956,9 @@ pub fn extract_re_exports(content: &str, language: Language) -> Vec { static WILDCARD_RE: OnceLock = OnceLock::new(); static NAMED_RE: OnceLock = OnceLock::new(); + static LOCAL_CONST_RE: OnceLock = OnceLock::new(); + static LOCAL_NAMED_RE: OnceLock = OnceLock::new(); + static LOCAL_DEFAULT_RE: OnceLock = OnceLock::new(); let wildcard_re = WILDCARD_RE.get_or_init(|| { Regex::new(r#"export\s*\*(?:\s+as\s+\w+)?\s*from\s*['"]([^'"]+)['"]"#) .expect("reexport wildcard") @@ -940,6 +966,18 @@ pub fn extract_re_exports(content: &str, language: Language) -> Vec { let named_re = NAMED_RE.get_or_init(|| { Regex::new(r#"export\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]"#).expect("reexport named") }); + let local_const_re = LOCAL_CONST_RE.get_or_init(|| { + Regex::new(r"(?m)\bexport[ \t]+const[ \t]+(\w+)[ \t]*=[ \t]*(\w+)[ \t]*(?:;[ \t]*)?$") + .expect("local const export alias") + }); + let local_named_re = LOCAL_NAMED_RE.get_or_init(|| { + Regex::new(r"(?m)\bexport[ \t]*\{([^}]+)\}[ \t]*;?[ \t]*$") + .expect("local named export alias") + }); + let local_default_re = LOCAL_DEFAULT_RE.get_or_init(|| { + Regex::new(r"(?m)\bexport[ \t]+default[ \t]+(\w+)[ \t]*;?[ \t]*$") + .expect("local default export alias") + }); for caps in wildcard_re.captures_iter(&cleaned) { out.push(ReExport::Wildcard { @@ -971,6 +1009,37 @@ pub fn extract_re_exports(content: &str, language: Language) -> Vec { } } + for caps in local_const_re.captures_iter(&cleaned) { + out.push(ReExport::LocalAlias { + exported_name: caps[1].to_string(), + original_name: caps[2].to_string(), + }); + } + + for caps in local_named_re.captures_iter(&cleaned) { + for raw in caps[1].split(',') { + let item = raw.trim(); + if let Some((original_name, exported_name)) = parse_as_alias(item) { + out.push(ReExport::LocalAlias { + exported_name, + original_name, + }); + } else if is_word(item) { + out.push(ReExport::LocalAlias { + exported_name: item.to_string(), + original_name: item.to_string(), + }); + } + } + } + + for caps in local_default_re.captures_iter(&cleaned) { + out.push(ReExport::LocalAlias { + exported_name: "default".to_string(), + original_name: caps[1].to_string(), + }); + } + out } @@ -1450,8 +1519,8 @@ struct Want { member_name: Option, } -/// Find an exported symbol, following re-export chains (`findExportedSymbol`, -/// `import-resolver.ts:1810-1896`). +/// Find an exported symbol through explicit local aliases and re-export chains +/// (`findExportedSymbol`, `import-resolver.ts:1810-1896`). fn find_exported_symbol( file_path: &str, want: &Want, @@ -1469,8 +1538,35 @@ fn find_exported_symbol( visited.insert(file_path.to_string()); let nodes_in_file = context.get_nodes_in_file(file_path); + let re_exports = context.get_re_exports(file_path, language); + + let requested_name = if want.is_default { + Some("default") + } else if want.is_namespace { + want.member_name.as_deref() + } else { + Some(want.exported_name.as_str()) + }; + if let Some(requested_name) = requested_name { + for rex in &re_exports { + if let ReExport::LocalAlias { + exported_name, + original_name, + } = rex + { + if exported_name == requested_name { + if let Some(target) = nodes_in_file + .iter() + .find(|node| node.name == *original_name && node.kind == NodeKind::Function) + { + return Some(target.clone()); + } + } + } + } + } - // 1. Direct hit (import-resolver.ts:1829-1853). + // Direct hit (import-resolver.ts:1829-1853). if want.is_default { if let Some(direct) = nodes_in_file .iter() @@ -1499,8 +1595,7 @@ fn find_exported_symbol( return Some(direct.clone()); } - // 2 + 3. Re-export hits (import-resolver.ts:1855-1893). - let re_exports = context.get_re_exports(file_path, language); + // Cross-file re-export hits (import-resolver.ts:1855-1893). if re_exports.is_empty() { return None; } @@ -1511,44 +1606,49 @@ fn find_exported_symbol( &want.exported_name }; for rex in &re_exports { - if let ReExport::Named { - exported_name, - original_name, - source, - } = rex - { - if exported_name == target_name { - if let Some(next) = resolve_import_path(source, file_path, language, context) { - let chained = find_exported_symbol( - &next, - &Want { - is_default: original_name == "default", - is_namespace: false, - exported_name: original_name.clone(), - member_name: None, - }, - language, - context, - visited, - depth + 1, - ); - if chained.is_some() { - return chained; + match rex { + ReExport::Named { + exported_name, + original_name, + source, + } => { + if exported_name == target_name { + if let Some(next) = resolve_import_path(source, file_path, language, context) { + let chained = find_exported_symbol( + &next, + &Want { + is_default: original_name == "default", + is_namespace: false, + exported_name: original_name.clone(), + member_name: None, + }, + language, + context, + visited, + depth + 1, + ); + if chained.is_some() { + return chained; + } } } } + ReExport::Wildcard { .. } | ReExport::LocalAlias { .. } => {} } } for rex in &re_exports { - if let ReExport::Wildcard { source } = rex { - if let Some(next) = resolve_import_path(source, file_path, language, context) { - let chained = - find_exported_symbol(&next, want, language, context, visited, depth + 1); - if chained.is_some() { - return chained; + match rex { + ReExport::Wildcard { source } => { + if let Some(next) = resolve_import_path(source, file_path, language, context) { + let chained = + find_exported_symbol(&next, want, language, context, visited, depth + 1); + if chained.is_some() { + return chained; + } } } + ReExport::Named { .. } | ReExport::LocalAlias { .. } => {} } } @@ -2468,6 +2568,80 @@ export { } from './empty'; ))); } + #[test] + fn extract_re_exports_captures_local_function_alias_forms() { + let content = r#" +function constTarget() {} +export const constAlias = constTarget; +function namedTarget() {} +export { namedTarget as namedAlias }; +function defaultTarget() {} +export default defaultTarget; +export { Remote as RenamedRemote } from './remote'; +export let mutableLetAlias = constTarget; +export var mutableVarAlias = constTarget; +export const callAlias = factory(); +export const memberAlias = namespace.target; +"#; + + let out = extract_re_exports(content, Language::TypeScript); + + assert!(out.iter().any(|r| matches!( + r, + ReExport::LocalAlias { exported_name, original_name } + if exported_name == "constAlias" && original_name == "constTarget" + ))); + assert!(out.iter().any(|r| matches!( + r, + ReExport::LocalAlias { exported_name, original_name } + if exported_name == "namedAlias" && original_name == "namedTarget" + ))); + assert!(out.iter().any(|r| matches!( + r, + ReExport::LocalAlias { exported_name, original_name } + if exported_name == "default" && original_name == "defaultTarget" + ))); + assert!(out.iter().any(|r| matches!( + r, + ReExport::Named { exported_name, original_name, source } + if exported_name == "RenamedRemote" + && original_name == "Remote" + && source == "./remote" + ))); + assert!(!out.iter().any(|r| matches!( + r, + ReExport::LocalAlias { exported_name, .. } + if ["mutableLetAlias", "mutableVarAlias", "callAlias", "memberAlias"] + .contains(&exported_name.as_str()) + ))); + } + + #[test] + fn extract_re_exports_stays_empty_for_non_ecmascript_languages() { + let content = r#" +function constTarget() {} +export const constAlias = constTarget; +function namedTarget() {} +export { namedTarget as namedAlias }; +function defaultTarget() {} +export default defaultTarget; +"#; + + for language in Language::ALL { + if matches!( + language, + Language::TypeScript | Language::JavaScript | Language::Tsx | Language::Jsx + ) { + continue; + } + assert_eq!( + extract_re_exports(content, language), + Vec::new(), + "local aliases leaked into {language:?}" + ); + } + } + #[test] fn is_external_import_relative_is_local() { let ctx = TestContext::default(); @@ -2635,6 +2809,173 @@ export { } from './empty'; assert!(resolve_import_path("./missing", "src/a.ts", Language::TypeScript, &ctx).is_none()); } + #[test] + fn resolve_import_path_typescript_js_specifier_substitution() { + for (language, specifier, existing, expected) in [ + (Language::TypeScript, "./foo.js", "src/foo.ts", "src/foo.ts"), + (Language::Tsx, "./foo.js", "src/foo.tsx", "src/foo.tsx"), + ( + Language::TypeScript, + "./foo.jsx", + "src/foo.ts", + "src/foo.ts", + ), + ( + Language::TypeScript, + "./foo.mjs", + "src/foo.mts", + "src/foo.mts", + ), + ( + Language::TypeScript, + "./foo.cjs", + "src/foo.cts", + "src/foo.cts", + ), + ] { + let ctx = TestContext { + project_root: "/proj".to_string(), + existing_files: BTreeSet::from([existing.to_string()]), + ..Default::default() + }; + assert_eq!( + resolve_import_path(specifier, "src/a.ts", language, &ctx), + Some(expected.to_string()), + "specifier {specifier} for {language:?}" + ); + } + + let controls = TestContext { + project_root: "/proj".to_string(), + existing_files: BTreeSet::from([ + "src/extensionless.ts".to_string(), + "src/data.json".to_string(), + ]), + ..Default::default() + }; + assert_eq!( + resolve_import_path( + "./extensionless", + "src/a.ts", + Language::TypeScript, + &controls, + ), + Some("src/extensionless.ts".to_string()) + ); + assert_eq!( + resolve_import_path("./data.json", "src/a.ts", Language::TypeScript, &controls), + Some("src/data.json".to_string()) + ); + assert!( + resolve_import_path("./missing.js", "src/a.ts", Language::TypeScript, &controls,) + .is_none() + ); + } + + #[test] + fn resolve_import_path_typescript_js_specifier_prefers_typescript_source() { + let ctx = TestContext { + project_root: "/proj".to_string(), + existing_files: BTreeSet::from(["src/foo.ts".to_string(), "src/foo.js".to_string()]), + ..Default::default() + }; + + assert_eq!( + resolve_import_path("./foo.js", "src/a.ts", Language::TypeScript, &ctx), + Some("src/foo.ts".to_string()) + ); + } + + #[test] + fn resolve_import_path_alias_js_specifier_substitution() { + for language in [Language::TypeScript, Language::Tsx] { + let ctx = TestContext { + project_root: "/proj".to_string(), + existing_files: BTreeSet::from(["src/foo.ts".to_string()]), + project_aliases: Some(AliasMap { + base_url: "/proj".to_string(), + patterns: vec![AliasPattern { + prefix: "@/".to_string(), + suffix: String::new(), + has_wildcard: true, + replacements: vec!["src/*".to_string()], + }], + }), + ..Default::default() + }; + + assert_eq!( + resolve_import_path("@/foo.js", "src/a.ts", language, &ctx), + Some("src/foo.ts".to_string()), + "alias substitution for {language:?}" + ); + } + } + + #[test] + fn resolve_import_path_js_specifier_substitution_stays_scoped_by_language() { + let ctx = TestContext { + project_root: "/proj".to_string(), + existing_files: BTreeSet::from(["src/foo.ts".to_string()]), + ..Default::default() + }; + let non_target_languages_with_extensions = [ + Language::JavaScript, + Language::Jsx, + Language::Svelte, + Language::Vue, + Language::Python, + Language::Go, + Language::Rust, + Language::Java, + Language::C, + Language::Cpp, + Language::CSharp, + Language::Php, + Language::Ruby, + Language::ObjC, + ]; + + // A leading `.` is always local, so every non-Python relative row reaches + // the shared candidate helper; Python stays on its dedicated dotted path. + for language in non_target_languages_with_extensions { + if language != Language::Python { + assert_eq!( + resolve_import_path("./foo.js", "src/a.ts", language, &ctx), + None, + "relative TS substitution leaked into {language:?}" + ); + } + // Without a go.mod, Go is rejected as external before the alias helper; + // the remaining rows exercise the shared aliased candidate path. + assert_eq!( + resolve_import_path("@/foo.js", "src/a.ts", language, &ctx), + None, + "alias TS substitution leaked into {language:?}" + ); + } + + for language in Language::ALL { + if !matches!( + language, + Language::TypeScript | Language::Tsx | Language::Python + ) { + assert_eq!( + resolve_import_path("./foo.js", "src/a.ts", language, &ctx), + None, + "relative TS substitution leaked into {language:?}" + ); + } + if !matches!(language, Language::TypeScript | Language::Tsx) { + assert_eq!( + resolve_import_path("@/foo.js", "src/a.ts", language, &ctx), + None, + "alias TS substitution leaked into {language:?}" + ); + } + } + } + #[test] fn resolve_import_path_python_dotted_relative() { let mut existing = BTreeSet::new(); @@ -3412,6 +3753,188 @@ export { } from './empty'; assert_eq!(resolved.target_node_id, "method:doIt"); } + #[test] + fn find_exported_symbol_local_alias_const_form_prefers_original_function() { + let target = node( + "function:fn", + "fn", + NodeKind::Function, + "src/mod.ts", + Language::TypeScript, + ); + let alias = exported(node( + "constant:a", + "a", + NodeKind::Constant, + "src/mod.ts", + Language::TypeScript, + )); + let mut re_exports = BTreeMap::new(); + re_exports.insert( + "src/mod.ts".to_string(), + vec![ReExport::LocalAlias { + exported_name: "a".to_string(), + original_name: "fn".to_string(), + }], + ); + let ctx = TestContext { + nodes: vec![alias, target], + re_exports, + ..Default::default() + }; + let want = Want { + is_default: false, + is_namespace: false, + exported_name: "a".to_string(), + member_name: None, + }; + + let found = find_exported_symbol( + "src/mod.ts", + &want, + Language::TypeScript, + &ctx, + &mut BTreeSet::new(), + 0, + ) + .expect("local const alias resolves"); + + assert_eq!(found.id, "function:fn"); + } + + #[test] + fn find_exported_symbol_local_alias_named_form_targets_unexported_function() { + let target = node( + "function:fn", + "fn", + NodeKind::Function, + "src/mod.ts", + Language::TypeScript, + ); + let mut re_exports = BTreeMap::new(); + re_exports.insert( + "src/mod.ts".to_string(), + vec![ReExport::LocalAlias { + exported_name: "a".to_string(), + original_name: "fn".to_string(), + }], + ); + let ctx = TestContext { + nodes: vec![target], + re_exports, + ..Default::default() + }; + let want = Want { + is_default: false, + is_namespace: false, + exported_name: "a".to_string(), + member_name: None, + }; + + let found = find_exported_symbol( + "src/mod.ts", + &want, + Language::TypeScript, + &ctx, + &mut BTreeSet::new(), + 0, + ) + .expect("local named alias resolves"); + + assert_eq!(found.id, "function:fn"); + } + + #[test] + fn find_exported_symbol_local_alias_default_form_targets_unexported_function() { + let target = node( + "function:fn", + "fn", + NodeKind::Function, + "src/mod.ts", + Language::TypeScript, + ); + let mut re_exports = BTreeMap::new(); + re_exports.insert( + "src/mod.ts".to_string(), + vec![ReExport::LocalAlias { + exported_name: "default".to_string(), + original_name: "fn".to_string(), + }], + ); + let ctx = TestContext { + nodes: vec![target], + re_exports, + ..Default::default() + }; + let want = Want { + is_default: true, + is_namespace: false, + exported_name: "default".to_string(), + member_name: None, + }; + + let found = find_exported_symbol( + "src/mod.ts", + &want, + Language::TypeScript, + &ctx, + &mut BTreeSet::new(), + 0, + ) + .expect("local default alias resolves"); + + assert_eq!(found.id, "function:fn"); + } + + #[test] + fn find_exported_symbol_local_alias_default_form_ignores_unrelated_exported_function() { + let target = node( + "function:fn", + "fn", + NodeKind::Function, + "src/mod.ts", + Language::TypeScript, + ); + let unrelated = exported(node( + "function:other", + "other", + NodeKind::Function, + "src/mod.ts", + Language::TypeScript, + )); + let mut re_exports = BTreeMap::new(); + re_exports.insert( + "src/mod.ts".to_string(), + vec![ReExport::LocalAlias { + exported_name: "default".to_string(), + original_name: "fn".to_string(), + }], + ); + let ctx = TestContext { + nodes: vec![unrelated, target], + re_exports, + ..Default::default() + }; + let want = Want { + is_default: true, + is_namespace: false, + exported_name: "default".to_string(), + member_name: None, + }; + + let found = find_exported_symbol( + "src/mod.ts", + &want, + Language::TypeScript, + &ctx, + &mut BTreeSet::new(), + 0, + ) + .expect("local default alias resolves"); + + assert_eq!(found.id, "function:fn"); + } + #[test] fn find_exported_symbol_follows_named_reexport_chain() { let mut existing = BTreeSet::new(); diff --git a/crates/codegraph-resolve/src/types.rs b/crates/codegraph-resolve/src/types.rs index 87b9ce48..9cd7fa3c 100644 --- a/crates/codegraph-resolve/src/types.rs +++ b/crates/codegraph-resolve/src/types.rs @@ -139,8 +139,8 @@ pub struct ImportMapping { /// A re-export declared by a file. /// /// Ports the upstream `ReExport` union (`types.ts:222-235`): -/// `export { x } from './other'` (named) or `export * from './other'` -/// (wildcard). +/// Cross-file re-exports (`export { x } from './other'` / `export * from +/// './other'`) and explicit local export aliases. #[derive(Debug, Clone, PartialEq, Eq)] pub enum ReExport { /// `export { originalName as exportedName } from 'source'`. @@ -157,6 +157,13 @@ pub enum ReExport { /// Module specifier of the upstream module. source: String, }, + /// An explicit local export alias such as `export { original as alias }`. + LocalAlias { + /// Name as exported by THIS file. + exported_name: String, + /// Name of the local declaration. + original_name: String, + }, } /// Result of a [`FrameworkResolver`] extension's file extraction. diff --git a/crates/codegraph-store/src/index_state.rs b/crates/codegraph-store/src/index_state.rs index 86393b3e..66014ee7 100644 --- a/crates/codegraph-store/src/index_state.rs +++ b/crates/codegraph-store/src/index_state.rs @@ -115,7 +115,7 @@ pub const CURRENT_STORAGE_PROTOCOL: u64 = 2; /// The extraction-pipeline version this binary produces. This is the single /// source of truth: no other crate may define its own copy. -pub const CURRENT_EXTRACTION_VERSION: u64 = 4; +pub const CURRENT_EXTRACTION_VERSION: u64 = 5; /// The `project_metadata` key under which a built index records the extraction /// version it was produced with. Single source of truth for the key spelling. diff --git a/crates/codegraph-store/tests/index_state.rs b/crates/codegraph-store/tests/index_state.rs index 7b31d982..998c24f6 100644 --- a/crates/codegraph-store/tests/index_state.rs +++ b/crates/codegraph-store/tests/index_state.rs @@ -117,8 +117,12 @@ fn assert_corrupt( #[test] fn index_state_constants_and_canonical_payload_are_exact() { + /// The extraction version the immediately preceding release wrote. Read from + /// `index_state.rs` at implementation time; see plan decision C1 step 0. + const PREVIOUS_EXTRACTION_VERSION: u64 = 4; + assert_eq!(CURRENT_STORAGE_PROTOCOL, 2); - assert_eq!(CURRENT_EXTRACTION_VERSION, 4); + assert_eq!(CURRENT_EXTRACTION_VERSION, PREVIOUS_EXTRACTION_VERSION + 1); assert_eq!(EXTRACTION_VERSION_KEY, "indexed_with_extraction_version"); assert_eq!( canonical_checksum_payload(7, 2, 4, "future-phase", OWNER), @@ -176,6 +180,7 @@ fn index_state_current_protocol_maps_each_phase() { #[test] fn index_state_extraction_version_maps_outdated_and_future_for_every_phase() { + let previous_extraction = CURRENT_EXTRACTION_VERSION - 1; let future_extraction = CURRENT_EXTRACTION_VERSION + 1; for phase in ["building", "current", "uninitialized"] { let old = TempTree::new("outdated"); @@ -197,13 +202,15 @@ fn index_state_extraction_version_maps_outdated_and_future_for_every_phase() { &previous.slots()[0], 1, CURRENT_STORAGE_PROTOCOL, - 3, + previous_extraction, phase, OWNER, ); assert_eq!( classify_slots(&previous.slots(), OWNER).status(), - &ExtractionStatus::Outdated { built: 3 } + &ExtractionStatus::Outdated { + built: previous_extraction + } ); let future = TempTree::new("future-extraction"); diff --git a/docs/equivalence.md b/docs/equivalence.md index 2fbcdbaa..2850e097 100644 --- a/docs/equivalence.md +++ b/docs/equivalence.md @@ -815,6 +815,54 @@ The `generated_golden_matches_committed_cfml_fixture` and `cfml_db_is_self_equivalent_to_cfml_golden` tests in `crates/codegraph-bench/tests/equivalence.rs` enforce byte-stability. +### TypeScript resolution fixture + +The dedicated `reference/golden/typescript/` fixture guards TypeScript export +alias and explicit JavaScript-specifier resolution (#1482 / #1482b) without +changing the shared `mini` corpus. Its six-file source corpus lives at +`crates/codegraph-bench/fixtures/typescript/`; source lines are contractual +because node IDs include the declaration line. + +The `runAll` function pins six positive `Calls` edges, in source order: + +- `viaConstAlias()` → the local `constTarget` function behind + `export const constAlias = constTarget`; +- `viaNamedAlias()` → the local `namedTarget` function behind + `export { namedTarget as namedAlias }`; +- `defaultExportAlias()` → the local `defaultTarget` function behind + `export default defaultTarget`; +- `viaJsSpecifier()` from `./js_target.js` → `jsTarget` in `js_target.ts`; +- `viaCollision()` from `./collision.js` → `collisionTarget` in + `collision.ts`, ahead of the real `collision.js` file; +- `viaExtensionless()` → `extensionlessTarget` in `extensionless.ts`, preserving + the existing extensionless behavior. + +Two negative rules make false positives visible: `viaMissing` remains the only +unresolved call and import pair in `refs.json`, with no `Calls` edge; and no +`Calls` edge may target either the exported `Constant` `constAlias` or the +JavaScript `collisionTarget` in `collision.js`. + +Regenerate the committed database and canonical artifacts from a clean corpus: + +```bash +rm -rf /tmp/cg-fixture-typescript +cp -r crates/codegraph-bench/fixtures/typescript /tmp/cg-fixture-typescript +cargo build --release -p codegraph-rs +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 \ + ./target/release/codegraph init /tmp/cg-fixture-typescript +mkdir -p reference/golden/typescript +cp /tmp/cg-fixture-typescript/.codegraph/codegraph.db reference/golden/typescript/colby.db +cargo run -p codegraph-bench --bin bench -- \ + --gen-golden reference/golden/typescript/colby.db reference/golden/typescript +``` + +The `generated_golden_matches_committed_typescript_fixture` and +`typescript_db_is_self_equivalent_to_typescript_golden` tests in +`crates/codegraph-bench/tests/equivalence.rs` enforce artifact/database +self-equivalence. As for every fixture below the Godot caveats, do not compare +`colby.db` bytes; compare the four JSON artifacts byte-for-byte and compare +`schema.sql` as a normalized statement set when statement order differs. + ### KNOWN_DIFFS.md format Tier-3 differences are allowlisted by grep-able lines in diff --git a/reference/golden/typescript/colby.db b/reference/golden/typescript/colby.db new file mode 100644 index 00000000..2826b012 Binary files /dev/null and b/reference/golden/typescript/colby.db differ diff --git a/reference/golden/typescript/edges.json b/reference/golden/typescript/edges.json new file mode 100644 index 00000000..e19294b0 --- /dev/null +++ b/reference/golden/typescript/edges.json @@ -0,0 +1,387 @@ +[ + { + "col": 0, + "kind": "imports", + "line": 1, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:d34cfc18269336a2e853eed952aa430d" + }, + { + "col": 0, + "kind": "imports", + "line": 2, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:d34cfc18269336a2e853eed952aa430d" + }, + { + "col": 0, + "kind": "imports", + "line": 3, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:d34cfc18269336a2e853eed952aa430d" + }, + { + "col": 0, + "kind": "imports", + "line": 4, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:0b22b7f0be00f007f49feeb7c90a0878" + }, + { + "col": 0, + "kind": "imports", + "line": 5, + "metadata": { + "confidence": 0.7, + "resolvedBy": "file-path" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "file:collision.js" + }, + { + "col": 0, + "kind": "imports", + "line": 6, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:249a167e6db6cb653a2b598f05964d03" + }, + { + "col": 0, + "kind": "imports", + "line": 7, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:58ba30c67d247ca76af614a60b572c1c" + }, + { + "col": 2, + "kind": "calls", + "line": 10, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "function:f457dd2d5f87f1af2a87ff0989542423", + "target": "function:cdbcd95113ddd7cd4aff8ebf7e494ed2" + }, + { + "col": 2, + "kind": "calls", + "line": 11, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "function:f457dd2d5f87f1af2a87ff0989542423", + "target": "function:d9eba2bae70ed18576ba5ed96bc2b644" + }, + { + "col": 2, + "kind": "calls", + "line": 12, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "function:f457dd2d5f87f1af2a87ff0989542423", + "target": "function:d55a5266b864011bc34d8d3e40a60d5b" + }, + { + "col": 2, + "kind": "calls", + "line": 13, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "function:f457dd2d5f87f1af2a87ff0989542423", + "target": "function:b8fad7e972c96125f3204297e4b630e0" + }, + { + "col": 2, + "kind": "calls", + "line": 14, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "function:f457dd2d5f87f1af2a87ff0989542423", + "target": "function:a6d594ffd5d5f1daf20b2b6a38aa9d8a" + }, + { + "col": 2, + "kind": "calls", + "line": 15, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "function:f457dd2d5f87f1af2a87ff0989542423", + "target": "function:82178a7ebdc9958e76b3d6014789f799" + }, + { + "col": 21, + "kind": "imports", + "line": 4, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "function:b8fad7e972c96125f3204297e4b630e0" + }, + { + "col": 23, + "kind": "imports", + "line": 1, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "function:cdbcd95113ddd7cd4aff8ebf7e494ed2" + }, + { + "col": 23, + "kind": "imports", + "line": 2, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "function:d9eba2bae70ed18576ba5ed96bc2b644" + }, + { + "col": 26, + "kind": "references", + "line": 3, + "metadata": { + "confidence": 0.95, + "fnRef": true, + "resolvedBy": "function-ref" + }, + "provenance": null, + "source": "file:exports.ts", + "target": "function:cdbcd95113ddd7cd4aff8ebf7e494ed2" + }, + { + "col": 28, + "kind": "imports", + "line": 5, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "function:a6d594ffd5d5f1daf20b2b6a38aa9d8a" + }, + { + "col": 32, + "kind": "imports", + "line": 6, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "function:82178a7ebdc9958e76b3d6014789f799" + }, + { + "col": 7, + "kind": "imports", + "line": 3, + "metadata": { + "confidence": 0.9, + "resolvedBy": "import" + }, + "provenance": null, + "source": "file:consumer.ts", + "target": "file:exports.ts" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:collision.js", + "target": "function:3a28a361b6c9074981b560e0f11901f5" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:collision.ts", + "target": "function:a6d594ffd5d5f1daf20b2b6a38aa9d8a" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "function:f457dd2d5f87f1af2a87ff0989542423" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:0b22b7f0be00f007f49feeb7c90a0878" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:249a167e6db6cb653a2b598f05964d03" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:58ba30c67d247ca76af614a60b572c1c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:5eac6b1bb0ffbfd4f932dda317095565" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:6206d159d10d5c530bf6118d7a59dfa6" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:c5ca993266657ad192c6a7d55643f8e4" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.ts", + "target": "import:d34cfc18269336a2e853eed952aa430d" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:exports.ts", + "target": "constant:bc1551c21485869a4af357b17a0ba32a" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:exports.ts", + "target": "function:cdbcd95113ddd7cd4aff8ebf7e494ed2" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:exports.ts", + "target": "function:d55a5266b864011bc34d8d3e40a60d5b" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:exports.ts", + "target": "function:d9eba2bae70ed18576ba5ed96bc2b644" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:extensionless.ts", + "target": "function:82178a7ebdc9958e76b3d6014789f799" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:js_target.ts", + "target": "function:b8fad7e972c96125f3204297e4b630e0" + } +] diff --git a/reference/golden/typescript/files.json b/reference/golden/typescript/files.json new file mode 100644 index 00000000..7ecb899e --- /dev/null +++ b/reference/golden/typescript/files.json @@ -0,0 +1,50 @@ +[ + { + "content_hash": "5d91d0b374e6bbe30c01d7932f5554fbf02f1a3d1eea2f0aee046ae6a891c182", + "errors": null, + "language": "javascript", + "node_count": 2, + "path": "collision.js", + "size": 37 + }, + { + "content_hash": "5d91d0b374e6bbe30c01d7932f5554fbf02f1a3d1eea2f0aee046ae6a891c182", + "errors": null, + "language": "typescript", + "node_count": 2, + "path": "collision.ts", + "size": 37 + }, + { + "content_hash": "417ddd5bafc0993f53e32c05d91eef694f7ef6b3d99fda239ae893be0fcc7c9b", + "errors": null, + "language": "typescript", + "node_count": 9, + "path": "consumer.ts", + "size": 588 + }, + { + "content_hash": "1a81c274140423b2a2f7ce75e1f010817827acf00fdab3a5bfe87a1c0b3aacde", + "errors": null, + "language": "typescript", + "node_count": 5, + "path": "exports.ts", + "size": 192 + }, + { + "content_hash": "82f12c230dbce8f54af95b6050c1cb9286d876373a38ceccb7c5cb00add8df80", + "errors": null, + "language": "typescript", + "node_count": 2, + "path": "extensionless.ts", + "size": 41 + }, + { + "content_hash": "04c00befb179da7e0748d6338704f7953a0f419fc1b566168f68567d1cc5e52c", + "errors": null, + "language": "typescript", + "node_count": 2, + "path": "js_target.ts", + "size": 30 + } +] diff --git a/reference/golden/typescript/nodes.json b/reference/golden/typescript/nodes.json new file mode 100644 index 00000000..4fe4ece7 --- /dev/null +++ b/reference/golden/typescript/nodes.json @@ -0,0 +1,486 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 37, + "end_line": 3, + "file_path": "exports.ts", + "id": "constant:bc1551c21485869a4af357b17a0ba32a", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "constant", + "language": "typescript", + "name": "constAlias", + "qualified_name": "constAlias", + "return_type": null, + "signature": "= constTarget", + "start_column": 13, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 2, + "file_path": "collision.js", + "id": "file:collision.js", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "javascript", + "name": "collision.js", + "qualified_name": "collision.js", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 2, + "file_path": "collision.ts", + "id": "file:collision.ts", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "typescript", + "name": "collision.ts", + "qualified_name": "collision.ts", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 18, + "file_path": "consumer.ts", + "id": "file:consumer.ts", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "typescript", + "name": "consumer.ts", + "qualified_name": "consumer.ts", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 12, + "file_path": "exports.ts", + "id": "file:exports.ts", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "typescript", + "name": "exports.ts", + "qualified_name": "exports.ts", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 2, + "file_path": "extensionless.ts", + "id": "file:extensionless.ts", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "typescript", + "name": "extensionless.ts", + "qualified_name": "extensionless.ts", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 2, + "file_path": "js_target.ts", + "id": "file:js_target.ts", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "typescript", + "name": "js_target.ts", + "qualified_name": "js_target.ts", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 36, + "end_line": 1, + "file_path": "collision.js", + "id": "function:3a28a361b6c9074981b560e0f11901f5", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "javascript", + "name": "collisionTarget", + "qualified_name": "collisionTarget", + "return_type": null, + "signature": "()", + "start_column": 7, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 40, + "end_line": 1, + "file_path": "extensionless.ts", + "id": "function:82178a7ebdc9958e76b3d6014789f799", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "extensionlessTarget", + "qualified_name": "extensionlessTarget", + "return_type": null, + "signature": "()", + "start_column": 7, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 36, + "end_line": 1, + "file_path": "collision.ts", + "id": "function:a6d594ffd5d5f1daf20b2b6a38aa9d8a", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "collisionTarget", + "qualified_name": "collisionTarget", + "return_type": null, + "signature": "()", + "start_column": 7, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 29, + "end_line": 1, + "file_path": "js_target.ts", + "id": "function:b8fad7e972c96125f3204297e4b630e0", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "jsTarget", + "qualified_name": "jsTarget", + "return_type": null, + "signature": "()", + "start_column": 7, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 25, + "end_line": 1, + "file_path": "exports.ts", + "id": "function:cdbcd95113ddd7cd4aff8ebf7e494ed2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "constTarget", + "qualified_name": "constTarget", + "return_type": null, + "signature": "()", + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 27, + "end_line": 9, + "file_path": "exports.ts", + "id": "function:d55a5266b864011bc34d8d3e40a60d5b", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "defaultTarget", + "qualified_name": "defaultTarget", + "return_type": null, + "signature": "()", + "start_column": 0, + "start_line": 9, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 25, + "end_line": 5, + "file_path": "exports.ts", + "id": "function:d9eba2bae70ed18576ba5ed96bc2b644", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "namedTarget", + "qualified_name": "namedTarget", + "return_type": null, + "signature": "()", + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 17, + "file_path": "consumer.ts", + "id": "function:f457dd2d5f87f1af2a87ff0989542423", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "typescript", + "name": "runAll", + "qualified_name": "runAll", + "return_type": null, + "signature": "()", + "start_column": 7, + "start_line": 9, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 60, + "end_line": 4, + "file_path": "consumer.ts", + "id": "import:0b22b7f0be00f007f49feeb7c90a0878", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./js_target.js", + "qualified_name": "./js_target.js", + "return_type": null, + "signature": "import { jsTarget as viaJsSpecifier } from './js_target.js';", + "start_column": 0, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 74, + "end_line": 6, + "file_path": "consumer.ts", + "id": "import:249a167e6db6cb653a2b598f05964d03", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./extensionless", + "qualified_name": "./extensionless", + "return_type": null, + "signature": "import { extensionlessTarget as viaExtensionless } from './extensionless';", + "start_column": 0, + "start_line": 6, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 59, + "end_line": 7, + "file_path": "consumer.ts", + "id": "import:58ba30c67d247ca76af614a60b572c1c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./missing.js", + "qualified_name": "./missing.js", + "return_type": null, + "signature": "import { missingTarget as viaMissing } from './missing.js';", + "start_column": 0, + "start_line": 7, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 56, + "end_line": 2, + "file_path": "consumer.ts", + "id": "import:5eac6b1bb0ffbfd4f932dda317095565", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./exports", + "qualified_name": "./exports", + "return_type": null, + "signature": "import { namedAlias as viaNamedAlias } from './exports';", + "start_column": 0, + "start_line": 2, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 65, + "end_line": 5, + "file_path": "consumer.ts", + "id": "import:6206d159d10d5c530bf6118d7a59dfa6", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./collision.js", + "qualified_name": "./collision.js", + "return_type": null, + "signature": "import { collisionTarget as viaCollision } from './collision.js';", + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 43, + "end_line": 3, + "file_path": "consumer.ts", + "id": "import:c5ca993266657ad192c6a7d55643f8e4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./exports", + "qualified_name": "./exports", + "return_type": null, + "signature": "import defaultExportAlias from './exports';", + "start_column": 0, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 56, + "end_line": 1, + "file_path": "consumer.ts", + "id": "import:d34cfc18269336a2e853eed952aa430d", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "typescript", + "name": "./exports", + "qualified_name": "./exports", + "return_type": null, + "signature": "import { constAlias as viaConstAlias } from './exports';", + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + } +] diff --git a/reference/golden/typescript/refs.json b/reference/golden/typescript/refs.json new file mode 100644 index 00000000..87c4ceb7 --- /dev/null +++ b/reference/golden/typescript/refs.json @@ -0,0 +1,22 @@ +[ + { + "candidates": null, + "col": 2, + "file_path": "consumer.ts", + "from_node_id": "function:f457dd2d5f87f1af2a87ff0989542423", + "language": "typescript", + "line": 16, + "reference_kind": "calls", + "reference_name": "viaMissing" + }, + { + "candidates": null, + "col": 26, + "file_path": "consumer.ts", + "from_node_id": "file:consumer.ts", + "language": "typescript", + "line": 7, + "reference_kind": "imports", + "reference_name": "viaMissing" + } +] diff --git a/reference/golden/typescript/schema.sql b/reference/golden/typescript/schema.sql new file mode 100644 index 00000000..d36218fe --- /dev/null +++ b/reference/golden/typescript/schema.sql @@ -0,0 +1,117 @@ +CREATE TABLE schema_versions ( +version INTEGER PRIMARY KEY, +applied_at INTEGER NOT NULL, +description TEXT +); +CREATE TABLE nodes ( +id TEXT PRIMARY KEY, +kind TEXT NOT NULL, +name TEXT NOT NULL, +qualified_name TEXT NOT NULL, +file_path TEXT NOT NULL, +language TEXT NOT NULL, +start_line INTEGER NOT NULL, +end_line INTEGER NOT NULL, +start_column INTEGER NOT NULL, +end_column INTEGER NOT NULL, +docstring TEXT, +signature TEXT, +visibility TEXT, +is_exported INTEGER DEFAULT 0, +is_async INTEGER DEFAULT 0, +is_static INTEGER DEFAULT 0, +is_abstract INTEGER DEFAULT 0, +decorators TEXT, -- JSON array +type_parameters TEXT, -- JSON array +return_type TEXT, -- normalized return/result type name (e.g. C++ method return, for receiver-type inference) +updated_at INTEGER NOT NULL +); +CREATE TABLE edges ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +source TEXT NOT NULL, +target TEXT NOT NULL, +kind TEXT NOT NULL, +metadata TEXT, -- JSON object +line INTEGER, +col INTEGER, +provenance TEXT DEFAULT NULL, +FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE, +FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE TABLE sqlite_sequence(name,seq); +CREATE TABLE files ( +path TEXT PRIMARY KEY, +content_hash TEXT NOT NULL, +language TEXT NOT NULL, +size INTEGER NOT NULL, +modified_at INTEGER NOT NULL, +indexed_at INTEGER NOT NULL, +node_count INTEGER DEFAULT 0, +errors TEXT -- JSON array +); +CREATE TABLE unresolved_refs ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +from_node_id TEXT NOT NULL, +reference_name TEXT NOT NULL, +reference_kind TEXT NOT NULL, +line INTEGER NOT NULL, +col INTEGER NOT NULL, +candidates TEXT, -- JSON array +file_path TEXT NOT NULL DEFAULT '', +language TEXT NOT NULL DEFAULT 'unknown', +reference_subkind TEXT, +FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE INDEX idx_nodes_kind ON nodes(kind); +CREATE INDEX idx_nodes_name ON nodes(name); +CREATE INDEX idx_nodes_qualified_name ON nodes(qualified_name); +CREATE INDEX idx_nodes_file_path ON nodes(file_path); +CREATE INDEX idx_nodes_language ON nodes(language); +CREATE INDEX idx_nodes_file_line ON nodes(file_path, start_line); +CREATE INDEX idx_nodes_lower_name ON nodes(lower(name)); +CREATE VIRTUAL TABLE nodes_fts USING fts5( +id, +name, +qualified_name, +docstring, +signature, +content='nodes', +content_rowid='rowid' +) +/* nodes_fts(id,name,qualified_name,docstring,signature) */; +CREATE TABLE 'nodes_fts_data'(id INTEGER PRIMARY KEY, block BLOB); +CREATE TABLE 'nodes_fts_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID; +CREATE TABLE 'nodes_fts_docsize'(id INTEGER PRIMARY KEY, sz BLOB); +CREATE TABLE 'nodes_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID; +CREATE TRIGGER nodes_ai AFTER INSERT ON nodes BEGIN +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE TRIGGER nodes_ad AFTER DELETE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +END; +CREATE TRIGGER nodes_au AFTER UPDATE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE INDEX idx_edges_kind ON edges(kind); +CREATE INDEX idx_edges_source_kind ON edges(source, kind); +CREATE INDEX idx_edges_target_kind ON edges(target, kind); +CREATE UNIQUE INDEX idx_edges_identity +ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); +CREATE INDEX idx_files_language ON files(language); +CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); +CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); +CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); +CREATE INDEX idx_unresolved_from_name ON unresolved_refs(from_node_id, reference_name); +CREATE INDEX idx_edges_provenance ON edges(provenance); +CREATE TABLE project_metadata ( +key TEXT PRIMARY KEY, +value TEXT NOT NULL, +updated_at INTEGER NOT NULL +); +CREATE TABLE sqlite_stat1(tbl,idx,stat);