MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / isSealedModule

Function isSealedModule

src/resolution/name-matcher.ts:1330–1357  ·  view source on GitHub ↗

* Whether `filePath` is a JS/TS module that exports NOTHING — an import * statement present, no export of any form. No reference from another file can * reach any binding in such a file, so every one of its symbols is a false * candidate for a cross-file name match. * * This is the general case

(filePath: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1328 * equivalent boundary, and several extractors hardcode `isExported`.
1329 */
1330function isSealedModule(filePath: string, context: ResolutionContext): boolean {
1331 let memo = SEALED_MODULES.get(context);
1332 if (!memo) {
1333 memo = new Map();
1334 SEALED_MODULES.set(context, memo);
1335 }
1336 const hit = memo.get(filePath);
1337 if (hit !== undefined) return hit;
1338 // CommonJS assignments can execute inside template interpolations, which the
1339 // masker blanks. Keep the conservative raw-source exemption for those forms.
1340 // Cheapest disqualifiers first: nearly every module exports a node (asked
1341 // without reading or decoding the file), and masking the source is only
1342 // needed to rule out the ones that don't. (The masker only blanks text, so
1343 // no `import` in the source means none in code.)
1344 const exportsNode = context.fileHasExportedNode
1345 ? context.fileHasExportedNode(filePath)
1346 : context.getNodesInFile(filePath).some((n) => n.isExported);
1347 const source = exportsNode ? null : context.readFile(filePath);
1348 const sealed =
1349 !exportsNode && source !== null && source.includes('import') &&
1350 !HAS_CJS_EXPORT.test(source) &&
1351 (() => {
1352 const code = blankStringContents(stripCommentsForRegex(source, 'typescript'));
1353 return HAS_IMPORT_STATEMENT.test(code) && !HAS_ESM_EXPORT.test(code);
1354 })();
1355 memo.set(filePath, sealed);
1356 return sealed;
1357}
1358
1359/**
1360 * Whether `candidate` can be named by a reference in `ref`'s file at all.

Callers 2

isCrossFileReachableFunction · 0.85
matchByExactNameFunction · 0.85

Calls 7

blankStringContentsFunction · 0.90
stripCommentsForRegexFunction · 0.90
readFileMethod · 0.80
getMethod · 0.65
fileHasExportedNodeMethod · 0.65
getNodesInFileMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected