* 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)
| 1328 | * equivalent boundary, and several extractors hardcode `isExported`. |
| 1329 | */ |
| 1330 | function 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. |
no test coverage detected