mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-30 23:47:58 +00:00
* fix(impact): do not seed the owning file for a type the index recorded as not exported The #480 seed adds the file that DEFINES a Class or Interface to the walk, so the file's IMPORTS edges stand in for the type's importers. For a type recorded as isExported = false no importer can name it, and the file's importers came back as its direct dependants: a private interface used by one function in its file reported eight route files at depth 1, direct: 8, MEDIUM (#3602, second reproduction). The DEFINES seed query now also returns n.isExported, matched on the target's own label since not every node table has the column, and a row with false is left out of the frontier. true and NULL keep the seed. Refs #3602 * fix(impact): skip the owning-file seed only where a false export verdict is file-private `isExported = false` is a narrower fact than "no other file can name it" in most languages: Java package-private, C# and Kotlin `internal`, Go lowercase, Python and Dart `_name`, a Rust item seen from a child module, a C/C++ `static` in a header. Skipping the #480 file seed on every `false` turned the over-approximation into a false negative for them. The meaning of a stored verdict is a property of the language, so it lives on the provider: `LanguageProvider.notExportedIsFilePrivate`, set on TypeScript, JavaScript, Vue (an ES module is the file), Swift (false only for `private`/`fileprivate`) and Zig (no `pub`; `export fn` is recorded true). The seed resolves the provider from the file's path only for a `false` row and skips the file only when the flag is set. Two regressions in the same test file: a Java package-private class and a Kotlin `internal` class, both recorded `false`, keep their importers as direct dependants. Refs #3602 * fix(impact): require an ES export in the file before trusting a false verdict The stored verdict is the provider's export checker, which for an ECMAScript file answers "under an `export` statement?" whatever the module kind: a CommonJS class (`module.exports = Foo`) and a top-level declaration of a global script are both recorded `false`, and both can be named from other files. Trusting the provider flag alone skipped the owning-file seed for them. The index does not record the module kind, but it records the checker's `true`, which only ES `export` syntax produces. The skip now also requires a `true` declaration in the same file (Function, Class or Interface: the tables that carry the column and that a File DEFINES). A CommonJS file, a script, or a module whose exports all live in `Const`/`TypeAlias` keeps the seed, as before this fix. The Java and Kotlin cases now declare a public sibling class, so only the provider verdict keeps their seed; two new cases cover a CommonJS module and a global script. Refs #3602 * fix(impact): preserve uncertain type dependencies * fix(impact): retain exported type alias dependencies --------- Co-authored-by: Gergő Magyar <gergomagyar@icloud.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
import { expect, it } from 'vitest';
|
|
import { hasFilePrivateExportSemantics } from '../../src/core/ingestion/languages/typescript/file-private-exports.js';
|
|
|
|
it.each([
|
|
['plain module', 'entry.ts', 'interface Entry {}\nexport function verify() {}', true],
|
|
['JS module', 'entry.js', 'class Entry {}\nexport function verify() {}', true],
|
|
['TSX module', 'entry.tsx', 'interface Entry {}\nexport const View = () => <div/>;', true],
|
|
['JSX module', 'entry.jsx', 'class Entry {}\nexport const View = () => <div/>;', true],
|
|
['named export', 'entry.ts', 'interface Entry {}\nexport { Entry };', false],
|
|
['renamed export', 'entry.ts', 'interface Entry {}\nexport { Entry as Public };', false],
|
|
['default export', 'entry.ts', 'class Entry {}\nexport default Entry;', false],
|
|
['assignment export', 'entry.ts', 'class Entry {}\nexport = Entry;', false],
|
|
['type alias', 'entry.ts', 'interface Entry {}\nexport type Public = Entry;', false],
|
|
[
|
|
'wrapped type alias',
|
|
'entry.ts',
|
|
'class Entry {}\nexport type Public = Readonly<Entry>;',
|
|
false,
|
|
],
|
|
['CommonJS', 'entry.js', 'class Entry {}\nmodule.exports = Entry;', false],
|
|
['bracket CommonJS', 'entry.js', "class Entry {}\nmodule['exports'] = Entry;", false],
|
|
[
|
|
'mixed CommonJS',
|
|
'entry.js',
|
|
'class Entry {}\nexports.Entry = Entry;\nexport const n = 1;',
|
|
false,
|
|
],
|
|
['ambient', 'entry.d.ts', 'interface Entry {}\nexport const n: number;', false],
|
|
['ambient ESM', 'entry.d.mts', 'interface Entry {}\nexport const n: number;', false],
|
|
['script global', 'entry.ts', 'interface Entry {}', false],
|
|
[
|
|
'global augmentation',
|
|
'entry.ts',
|
|
"import './side'; declare global { interface Entry {} }",
|
|
false,
|
|
],
|
|
['missing retained source', 'entry.ts', '', false],
|
|
[
|
|
'normalized line comment',
|
|
'entry.ts',
|
|
'interface Entry {} export function verify() {} // comment export { Entry };',
|
|
false,
|
|
],
|
|
[
|
|
'truncated source',
|
|
'entry.ts',
|
|
'interface Entry {} export function verify() {} /* [truncated] */',
|
|
false,
|
|
],
|
|
['invalid source', 'entry.ts', 'interface Entry {\nexport const', false],
|
|
])('%s has conservative file privacy', (_label, filePath, content, expected) => {
|
|
expect(hasFilePrivateExportSemantics(filePath, content)).toBe(expected);
|
|
});
|