(filePath: string, context: ResolutionContext)
| 290 | /^[ \t]*(?:exports\s*=\s*)?module\.exports\s*=\s*(?:exports\s*=\s*)?(?:require\(\s*['"]([^'"]+)['"]\s*\)\s*;?[ \t]*$|(?:async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)\s*\(|class\s+([A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*)\s*;?[ \t]*$)/m; |
| 291 | |
| 292 | function commonJsDefaultExport(filePath: string, context: ResolutionContext): { source?: string; name?: string } | null { |
| 293 | if (!JS_FAMILY_FILE.test(filePath)) return null; |
| 294 | if (context.fileContains && !context.fileContains(filePath, 'module.exports')) return null; |
| 295 | const idx = getFileExportIndex(filePath, context); |
| 296 | if (idx.commonJsDefault !== undefined) return idx.commonJsDefault; |
| 297 | const source = context.readFile(filePath); |
| 298 | const m = source && source.includes('module.exports') ? COMMONJS_DEFAULT_EXPORT.exec(source) : null; |
| 299 | idx.commonJsDefault = !m ? null : m[1] ? { source: m[1] } : { name: m[2] ?? m[3] ?? m[4] }; |
| 300 | return idx.commonJsDefault; |
| 301 | } |
| 302 | |
| 303 | function getFileExportIndex(filePath: string, context: ResolutionContext): FileExportIndex { |
| 304 | let perFile = fileExportIndexes.get(context); |
no test coverage detected