@interlace/eslint-devkit 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interlace/eslint-devkit",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "ESLint plugin toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
5
5
  "type": "commonjs",
6
6
  "sideEffects": false,
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ interface FallbackOptions {
7
+ extensions?: string[];
8
+ conditionNames?: string[];
9
+ mainFields?: string[];
10
+ }
11
+ /**
12
+ * Resolve a non-relative specifier without `oxc-resolver`.
13
+ * Order matches oxc-resolver: tsconfig paths / baseUrl first, then node_modules.
14
+ */
15
+ export declare function resolveWithoutOxc(specifier: string, fromFile: string, tsconfigPath: string | null, options?: FallbackOptions): string | null;
16
+ export declare function clearFallbackCache(): void;
17
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.resolveWithoutOxc=resolveWithoutOxc;exports.clearFallbackCache=clearFallbackCache;const node_module_1=require("node:module");const fs_1=require("../node/fs");const path_1=require("../node/path");const DEFAULT_EXTENSIONS=[".ts",".tsx",".js",".jsx",".d.ts",".json"];const DEFAULT_CONDITIONS=["import","require","node","default","types"];function isFile(p){const s=(0,fs_1.statSync)(p);return!!s&&s.isFile()}function probe(p,extensions){if(isFile(p))return p;for(const ext of extensions)if(isFile(p+ext))return p+ext;for(const ext of extensions){const idx=(0,path_1.joinPath)(p,`index${ext}`);if(isFile(idx))return idx}return null}function parseJsonc(text){let out="";let i=0;while(i<text.length){const c=text[i];if(c==='"'){let j=i+1;while(j<text.length&&text[j]!=='"')j+=text[j]==="\\"?2:1;out+=text.slice(i,j+1);i=j+1}else if(c==="/"&&text[i+1]==="/"){while(i<text.length&&text[i]!=="\n")i++}else if(c==="/"&&text[i+1]==="*"){const end=text.indexOf("*/",i+2);i=end===-1?text.length:end+2}else{out+=c;i++}}try{return JSON.parse(out.replace(/,(\s*[}\]])/g,"$1"))}catch{return null}}const tsconfigCache=new Map;function loadPathsConfig(tsconfigPath,depth=0){const cached=tsconfigCache.get(tsconfigPath);if(cached)return cached;const dir=(0,path_1.getDirname)(tsconfigPath);const empty={baseUrl:null,paths:null,pathsDir:dir};const text=(0,fs_1.readFileSync)(tsconfigPath);const json=text===null?null:parseJsonc(text);if(!json)return empty;let result={...empty};const ext=json["extends"];if(typeof ext==="string"&&ext.startsWith(".")&&depth<8){const target=(0,path_1.resolvePath)(dir,ext.endsWith(".json")?ext:ext+".json");result={...loadPathsConfig(target,depth+1)}}const co=json["compilerOptions"]??{};if(typeof co["baseUrl"]==="string"){result.baseUrl=(0,path_1.resolvePath)(dir,co["baseUrl"])}if(co["paths"]&&typeof co["paths"]==="object"){result.paths=co["paths"];result.pathsDir=result.baseUrl??dir}tsconfigCache.set(tsconfigPath,result);return result}function resolveViaTsconfig(specifier,tsconfigPath,extensions){const cfg=loadPathsConfig(tsconfigPath);if(cfg.paths){for(const[pattern,targets]of Object.entries(cfg.paths)){const star=pattern.indexOf("*");let captured=null;if(star===-1){if(pattern===specifier)captured=""}else{const pre=pattern.slice(0,star);const post=pattern.slice(star+1);if(specifier.length>=pre.length+post.length&&specifier.startsWith(pre)&&specifier.endsWith(post)){captured=specifier.slice(pre.length,specifier.length-post.length)}}if(captured===null)continue;for(const target of targets){const hit=probe((0,path_1.resolvePath)(cfg.pathsDir,target.replace("*",captured)),extensions);if(hit)return hit}}}if(cfg.baseUrl){const hit=probe((0,path_1.resolvePath)(cfg.baseUrl,specifier),extensions);if(hit)return hit}return null}function splitPackage(spec){const parts=spec.split("/");const n=spec.startsWith("@")?2:1;if(parts.length<n||parts.slice(0,n).some(p=>!p))return null;return{name:parts.slice(0,n).join("/"),sub:parts.slice(n).join("/")}}function pickExport(target,conditions,star){if(typeof target==="string"){return star===null?target:target.replace("*",star)}if(Array.isArray(target)){for(const t of target){const r=pickExport(t,conditions,star);if(r)return r}return null}if(target&&typeof target==="object"){for(const[key,value]of Object.entries(target)){if(conditions.includes(key)){const r=pickExport(value,conditions,star);if(r)return r}}}return null}function matchSubpathMap(map,key,conditions){if(key in map)return pickExport(map[key],conditions,null);for(const[pattern,target]of Object.entries(map)){const star=pattern.indexOf("*");if(star===-1)continue;const pre=pattern.slice(0,star);const post=pattern.slice(star+1);if(key.startsWith(pre)&&key.endsWith(post)&&key.length>=pre.length+post.length){const rel=pickExport(target,conditions,key.slice(pre.length,key.length-post.length));if(rel)return rel}}return null}function resolveFromPackageDir(pkgDir,sub,opts){const pkgJsonText=(0,fs_1.readFileSync)((0,path_1.joinPath)(pkgDir,"package.json"));let pkg={};if(pkgJsonText){try{pkg=JSON.parse(pkgJsonText)}catch{return null}}const key=sub?`./${sub}`:".";const exportsField=pkg["exports"];if(exportsField!==void 0&&exportsField!==null){const isSubpathMap=typeof exportsField==="object"&&!Array.isArray(exportsField)&&Object.keys(exportsField).some(k=>k.startsWith("."));const map=isSubpathMap?exportsField:{".":exportsField};const rel=matchSubpathMap(map,key,opts.conditionNames);return rel?probe((0,path_1.resolvePath)(pkgDir,rel),[]):null}if(sub)return probe((0,path_1.joinPath)(pkgDir,sub),opts.extensions);for(const field of[...opts.mainFields,"types","typings"]){const v=pkg[field];if(typeof v==="string"){const hit=probe((0,path_1.resolvePath)(pkgDir,v),opts.extensions);if(hit)return hit}}return probe(pkgDir,opts.extensions)}const RELATIVE=/^\.\.?(\/|$)/;function resolveRelative(specifier,fromFile,extensions){const cut=specifier.search(/[?#]/);const bare=cut===-1?specifier:specifier.slice(0,cut);const hit=probe((0,path_1.resolvePath)((0,path_1.getDirname)(fromFile),bare),extensions);return hit===null||cut===-1?hit:hit+specifier.slice(cut)}function resolveViaNodeModules(specifier,fromFile,opts){try{return(0,node_module_1.createRequire)(fromFile).resolve(specifier)}catch{}const parts=splitPackage(specifier);if(!parts)return null;let dir=(0,path_1.getDirname)(fromFile);for(;;){const pkgDir=(0,path_1.joinPath)(dir,"node_modules",parts.name);if((0,fs_1.fileExistsSync)(pkgDir)){const hit=resolveFromPackageDir(pkgDir,parts.sub,opts);if(hit)return hit}const parent=(0,path_1.getDirname)(dir);if(parent===dir)return null;dir=parent}}function resolveViaImportsMap(specifier,fromFile,opts){const pkgPath=(0,fs_1.findFileUpward)("package.json",(0,path_1.getDirname)(fromFile));const text=pkgPath===null?null:(0,fs_1.readFileSync)(pkgPath);if(pkgPath===null||text===null)return null;let imports;try{imports=JSON.parse(text)["imports"]}catch{return null}if(!imports||typeof imports!=="object")return null;const rel=matchSubpathMap(imports,specifier,opts.conditionNames);if(rel===null)return null;return rel.startsWith(".")?probe((0,path_1.resolvePath)((0,path_1.getDirname)(pkgPath),rel),[]):resolveViaNodeModules(rel,pkgPath,opts)}function resolveWithoutOxc(specifier,fromFile,tsconfigPath,options={}){const opts={extensions:options.extensions??DEFAULT_EXTENSIONS,conditionNames:options.conditionNames??DEFAULT_CONDITIONS,mainFields:options.mainFields??["module","main"]};if((0,node_module_1.isBuiltin)(specifier))return null;if(specifier.startsWith("#")){return resolveViaImportsMap(specifier,fromFile,opts)}if(RELATIVE.test(specifier)){return resolveRelative(specifier,fromFile,opts.extensions)}if(specifier.startsWith("/"))return probe(specifier,opts.extensions);if(tsconfigPath){const hit=resolveViaTsconfig(specifier,tsconfigPath,opts.extensions);if(hit)return hit}return resolveViaNodeModules(specifier,fromFile,opts)}function clearFallbackCache(){tsconfigCache.clear()}
@@ -20,12 +20,9 @@ export interface ResolverOptions {
20
20
  cssSupport?: boolean;
21
21
  }
22
22
  /**
23
- * Thrown when the optional `oxc-resolver` peer is not installed.
24
- *
25
- * This is deliberately its own class: `resolveModule` swallows resolution
26
- * failures and returns `null` (an unresolvable import is normal), and a
27
- * missing peer must NOT disappear down that path — it would turn every
28
- * import into a silent non-resolution instead of a fixable install error.
23
+ * @deprecated The resolver no longer throws this; it falls back to a
24
+ * dependency-free resolver when `oxc-resolver` is absent. Kept only so
25
+ * existing imports keep compiling.
29
26
  */
30
27
  export declare class MissingResolverPeerError extends Error {
31
28
  readonly name = "MissingResolverPeerError";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.MissingResolverPeerError=void 0;exports.getResolverPerformanceMetrics=getResolverPerformanceMetrics;exports.resolveModule=resolveModule;exports.clearResolverCache=clearResolverCache;const fs_1=require("../node/fs");const path_1=require("../node/path");const resolver_adapter_1=require("./resolver-adapter");const oxcResolverCache=new Map;let factoryRef;class MissingResolverPeerError extends Error{name="MissingResolverPeerError"}exports.MissingResolverPeerError=MissingResolverPeerError;function loadResolverFactory(){if(factoryRef){return factoryRef}try{factoryRef=require("oxc-resolver").ResolverFactory}catch(cause){throw new MissingResolverPeerError('Import resolution requires the optional peer dependency "oxc-resolver", which is not installed. Install it alongside this plugin:\n\n npm install --save-dev oxc-resolver\n',{cause})}return factoryRef}const tsconfigPathCache=new Map;function findTsconfigPath(fromFile){const startDir=(0,path_1.getDirname)(fromFile);const cached=tsconfigPathCache.get(startDir);if(cached!==void 0){return cached}const result=(0,fs_1.findFileUpward)("tsconfig.json",startDir);let dir=startDir;const root=(0,path_1.resolvePath)("/");while(dir!==root){tsconfigPathCache.set(dir,result);if(result&&(0,path_1.getDirname)(result)===dir)break;const parent=(0,path_1.getDirname)(dir);if(parent===dir)break;dir=parent}return result}function getOxcResolver(options,fromFile){const extensions=options.extensions||[".ts",".tsx",".js",".jsx",".d.ts",".json",".node"];const conditionNames=options.conditionNames||["import","require","node","default","types"];const mainFields=options.mainFields||["module","main"];const tsconfigPath=findTsconfigPath(fromFile);const key=`${extensions.join(",")}|${conditionNames.join(",")}|${mainFields.join(",")}|${tsconfigPath||""}`;const cached=oxcResolverCache.get(key);if(cached){return cached}const resolverOptions={extensions,conditionNames,mainFields,mainFiles:["index"],modules:["node_modules"]};if(tsconfigPath){resolverOptions["tsconfig"]={configFile:tsconfigPath,references:"auto"}}const ResolverFactory=loadResolverFactory();const resolver=new ResolverFactory(resolverOptions);oxcResolverCache.set(key,resolver);return resolver}function isCssImport(importPath){if(/\.(css|scss|sass|less|styl)$/i.test(importPath)){return true}if(importPath.startsWith("./")||importPath.startsWith("../")){return!/\.\w+$/.test(importPath)}return false}function resolveCssImport(importPath,fromFile){const fromDir=(0,path_1.getDirname)(fromFile);if(importPath.startsWith(".")){const resolved=(0,path_1.resolvePath)(fromDir,importPath);if((0,fs_1.fileExistsSync)(resolved)){const stats=(0,fs_1.statSync)(resolved);if(stats&&stats.isFile()){return resolved}}const cssExtensions=[".css",".scss",".sass",".less",".styl"];for(const ext of cssExtensions){const withExt=resolved+ext;if((0,fs_1.fileExistsSync)(withExt)){const stats=(0,fs_1.statSync)(withExt);if(stats&&stats.isFile()){return withExt}}}for(const ext of cssExtensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){const stats=(0,fs_1.statSync)(indexFile);if(stats&&stats.isFile()){return indexFile}}}}return null}function getResolverPerformanceMetrics(){return[]}const NODENEXT_SOURCE_EXTENSIONS={".js":[".ts",".tsx"],".mjs":[".mts"],".cjs":[".cts"]};function resolveModule(importPath,fromFile,options={}){try{if(importPath.startsWith(".")&&!(options.cssSupport&&isCssImport(importPath))){const context2=(0,path_1.getDirname)(fromFile);const defaultExtensions=[".ts",".tsx",".js",".jsx",".d.ts",".json"];const extensions=options.extensions||defaultExtensions;const resolved=(0,path_1.resolvePath)(context2,importPath);const exactStats=(0,fs_1.statSync)(resolved);if(exactStats&&exactStats.isFile()){return resolved}for(const[outputExt,sourceExts]of Object.entries(NODENEXT_SOURCE_EXTENSIONS)){if(!resolved.endsWith(outputExt))continue;const stem=resolved.slice(0,-outputExt.length);for(const ext of sourceExts){if((0,fs_1.fileExistsSync)(stem+ext)){return stem+ext}}}for(const ext of extensions){if((0,fs_1.fileExistsSync)(resolved+ext)){return resolved+ext}}for(const ext of extensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){return indexFile}}}if(options.resolverSettings){const externalResult=(0,resolver_adapter_1.resolveWithExternalResolvers)(importPath,fromFile,options.resolverSettings);if(externalResult){return externalResult}}if(options.cssSupport&&isCssImport(importPath)){const cssResult=resolveCssImport(importPath,fromFile);if(cssResult){return cssResult}}const resolver=getOxcResolver(options,fromFile);const context=(0,path_1.getDirname)(fromFile);try{const result=resolver.sync(context,importPath);if(result&&result.path){return result.path}}catch{}return null}catch(error){if(error instanceof MissingResolverPeerError){throw error}return null}}function clearResolverCache(){for(const resolver of oxcResolverCache.values()){resolver.clearCache()}oxcResolverCache.clear();tsconfigPathCache.clear()}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.MissingResolverPeerError=void 0;exports.getResolverPerformanceMetrics=getResolverPerformanceMetrics;exports.resolveModule=resolveModule;exports.clearResolverCache=clearResolverCache;const fs_1=require("../node/fs");const path_1=require("../node/path");const resolver_fallback_1=require("./resolver-fallback");const resolver_adapter_1=require("./resolver-adapter");const oxcResolverCache=new Map;let factoryRef;let factoryMissing=false;class MissingResolverPeerError extends Error{name="MissingResolverPeerError"}exports.MissingResolverPeerError=MissingResolverPeerError;function loadResolverFactory(){if(factoryRef){return factoryRef}if(factoryMissing){return null}try{factoryRef=require("oxc-resolver").ResolverFactory;return factoryRef}catch{factoryMissing=true;return null}}const tsconfigPathCache=new Map;function findTsconfigPath(fromFile){const startDir=(0,path_1.getDirname)(fromFile);const cached=tsconfigPathCache.get(startDir);if(cached!==void 0){return cached}const result=(0,fs_1.findFileUpward)("tsconfig.json",startDir);let dir=startDir;const root=(0,path_1.resolvePath)("/");while(dir!==root){tsconfigPathCache.set(dir,result);if(result&&(0,path_1.getDirname)(result)===dir)break;const parent=(0,path_1.getDirname)(dir);if(parent===dir)break;dir=parent}return result}function getOxcResolver(options,fromFile){const extensions=options.extensions||[".ts",".tsx",".js",".jsx",".d.ts",".json",".node"];const conditionNames=options.conditionNames||["import","require","node","default","types"];const mainFields=options.mainFields||["module","main"];const tsconfigPath=findTsconfigPath(fromFile);const key=`${extensions.join(",")}|${conditionNames.join(",")}|${mainFields.join(",")}|${tsconfigPath||""}`;const cached=oxcResolverCache.get(key);if(cached){return cached}const resolverOptions={extensions,conditionNames,mainFields,mainFiles:["index"],modules:["node_modules"]};if(tsconfigPath){resolverOptions["tsconfig"]={configFile:tsconfigPath,references:"auto"}}const ResolverFactory=loadResolverFactory();if(!ResolverFactory)return null;const resolver=new ResolverFactory(resolverOptions);oxcResolverCache.set(key,resolver);return resolver}function isCssImport(importPath){if(/\.(css|scss|sass|less|styl)$/i.test(importPath)){return true}if(importPath.startsWith("./")||importPath.startsWith("../")){return!/\.\w+$/.test(importPath)}return false}function resolveCssImport(importPath,fromFile){const fromDir=(0,path_1.getDirname)(fromFile);if(importPath.startsWith(".")){const resolved=(0,path_1.resolvePath)(fromDir,importPath);if((0,fs_1.fileExistsSync)(resolved)){const stats=(0,fs_1.statSync)(resolved);if(stats&&stats.isFile()){return resolved}}const cssExtensions=[".css",".scss",".sass",".less",".styl"];for(const ext of cssExtensions){const withExt=resolved+ext;if((0,fs_1.fileExistsSync)(withExt)){const stats=(0,fs_1.statSync)(withExt);if(stats&&stats.isFile()){return withExt}}}for(const ext of cssExtensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){const stats=(0,fs_1.statSync)(indexFile);if(stats&&stats.isFile()){return indexFile}}}}return null}function getResolverPerformanceMetrics(){return[]}const NODENEXT_SOURCE_EXTENSIONS={".js":[".ts",".tsx"],".mjs":[".mts"],".cjs":[".cts"]};function resolveModule(importPath,fromFile,options={}){try{if(importPath.startsWith(".")&&!(options.cssSupport&&isCssImport(importPath))){const context2=(0,path_1.getDirname)(fromFile);const defaultExtensions=[".ts",".tsx",".js",".jsx",".d.ts",".json"];const extensions=options.extensions||defaultExtensions;const resolved=(0,path_1.resolvePath)(context2,importPath);const exactStats=(0,fs_1.statSync)(resolved);if(exactStats&&exactStats.isFile()){return resolved}for(const[outputExt,sourceExts]of Object.entries(NODENEXT_SOURCE_EXTENSIONS)){if(!resolved.endsWith(outputExt))continue;const stem=resolved.slice(0,-outputExt.length);for(const ext of sourceExts){if((0,fs_1.fileExistsSync)(stem+ext)){return stem+ext}}}for(const ext of extensions){if((0,fs_1.fileExistsSync)(resolved+ext)){return resolved+ext}}for(const ext of extensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){return indexFile}}}if(options.resolverSettings){const externalResult=(0,resolver_adapter_1.resolveWithExternalResolvers)(importPath,fromFile,options.resolverSettings);if(externalResult){return externalResult}}if(options.cssSupport&&isCssImport(importPath)){const cssResult=resolveCssImport(importPath,fromFile);if(cssResult){return cssResult}}const resolver=getOxcResolver(options,fromFile);const context=(0,path_1.getDirname)(fromFile);if(!resolver){return(0,resolver_fallback_1.resolveWithoutOxc)(importPath,fromFile,findTsconfigPath(fromFile),options)}try{const result=resolver.sync(context,importPath);if(result&&result.path){return result.path}}catch{}return null}catch{return null}}function clearResolverCache(){for(const resolver of oxcResolverCache.values()){resolver.clearCache()}oxcResolverCache.clear();tsconfigPathCache.clear();(0,resolver_fallback_1.clearFallbackCache)()}
@@ -19,3 +19,4 @@ export * from './message-source';
19
19
  export * from './raw-identifier-rule';
20
20
  export * from './module-evidence';
21
21
  export * from './sdk-flow';
22
+ export * as valueFollow from './value-follow';
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});__exportStar(require("./generated-file"),exports);__exportStar(require("./minified-file"),exports);__exportStar(require("./rule-creator"),exports);__exportStar(require("./mock-context"),exports);__exportStar(require("./sql-injection-rule"),exports);__exportStar(require("./unscoped-mutation-rule"),exports);__exportStar(require("./require-tls-rule"),exports);__exportStar(require("./mass-assignment-rule"),exports);__exportStar(require("./hardcoded-credentials-rule"),exports);__exportStar(require("./sdk-api-key-rule"),exports);__exportStar(require("./browser-escape-hatch-rule"),exports);__exportStar(require("./system-prompt-injection-rule"),exports);__exportStar(require("./message-source"),exports);__exportStar(require("./raw-identifier-rule"),exports);__exportStar(require("./module-evidence"),exports);__exportStar(require("./sdk-flow"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,v){Object.defineProperty(o,"default",{enumerable:true,value:v})}):function(o,v){o["default"]=v});var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};var __importStar=this&&this.__importStar||(function(){var ownKeys=function(o){ownKeys=Object.getOwnPropertyNames||function(o2){var ar=[];for(var k in o2)if(Object.prototype.hasOwnProperty.call(o2,k))ar[ar.length]=k;return ar};return ownKeys(o)};return function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null){for(var k=ownKeys(mod),i=0;i<k.length;i++)if(k[i]!=="default")__createBinding(result,mod,k[i])}__setModuleDefault(result,mod);return result}})();Object.defineProperty(exports,"__esModule",{value:true});exports.valueFollow=void 0;__exportStar(require("./generated-file"),exports);__exportStar(require("./minified-file"),exports);__exportStar(require("./rule-creator"),exports);__exportStar(require("./mock-context"),exports);__exportStar(require("./sql-injection-rule"),exports);__exportStar(require("./unscoped-mutation-rule"),exports);__exportStar(require("./require-tls-rule"),exports);__exportStar(require("./mass-assignment-rule"),exports);__exportStar(require("./hardcoded-credentials-rule"),exports);__exportStar(require("./sdk-api-key-rule"),exports);__exportStar(require("./browser-escape-hatch-rule"),exports);__exportStar(require("./system-prompt-injection-rule"),exports);__exportStar(require("./message-source"),exports);__exportStar(require("./raw-identifier-rule"),exports);__exportStar(require("./module-evidence"),exports);__exportStar(require("./sdk-flow"),exports);exports.valueFollow=__importStar(require("./value-follow"));
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,v){Object.defineProperty(o,"default",{enumerable:true,value:v})}):function(o,v){o["default"]=v});var __importStar=this&&this.__importStar||(function(){var ownKeys=function(o){ownKeys=Object.getOwnPropertyNames||function(o2){var ar=[];for(var k in o2)if(Object.prototype.hasOwnProperty.call(o2,k))ar[ar.length]=k;return ar};return ownKeys(o)};return function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null){for(var k=ownKeys(mod),i=0;i<k.length;i++)if(k[i]!=="default")__createBinding(result,mod,k[i])}__setModuleDefault(result,mod);return result}})();Object.defineProperty(exports,"__esModule",{value:true});exports.MAX_CACHED_MODULES=exports.MAX_FOLLOW_DEPTH=void 0;exports.cachedModuleCount=cachedModuleCount;exports.isRelativeSpecifier=isRelativeSpecifier;exports.envOf=envOf;exports.valueAt=valueAt;exports.resolveRelative=resolveRelative;exports.parseModule=parseModule;exports.loadModule=loadModule;exports.scopeIn=scopeIn;exports.moduleEnv=moduleEnv;exports.lookup=lookup;exports.requiredSpecifier=requiredSpecifier;exports.findProperty=findProperty;exports.exportedValue=exportedValue;exports.importOrigin=importOrigin;exports.importSpecifierOf=importSpecifierOf;exports.returnedValue=returnedValue;exports.returnedValues=returnedValues;exports.singleWrite=singleWrite;exports.follow=follow;const fs=__importStar(require("node:fs"));const path=__importStar(require("node:path"));const node_module_1=require("node:module");const ast_node_types_1=require("../ast-node-types");const spellings_1=require("../ast/spellings");const type_syntax_1=require("../ast/type-syntax");const dependency_analysis_1=require("../resolver/dependency-analysis");exports.MAX_FOLLOW_DEPTH=8;const EXTENSIONS=[".ts",".tsx",".js",".mjs",".cjs",".json"];const RELATIVE=/^\.{1,2}(?:\/|$)/;const JS_EXTENSION=/\.[cm]?js$/;exports.MAX_CACHED_MODULES=512;const modules=(0,dependency_analysis_1.createLRUCache)(exports.MAX_CACHED_MODULES);function cachedModuleCount(){return modules.size}function isRelativeSpecifier(specifier){return RELATIVE.test(specifier)}function envOf(context){return{file:path.resolve(context.physicalFilename),parser:context.languageOptions?.parser,module:null,scopeOf:node=>context.sourceCode.getScope(node)}}function valueAt(node,env){return{node,scope:env.scopeOf(node),env}}function isFile(candidate){return fs.statSync(candidate,{throwIfNoEntry:false})?.isFile()===true}function resolveRelative(fromFile,specifier){if(!isRelativeSpecifier(specifier))return null;const base=path.resolve(path.dirname(fromFile),specifier);const candidates=[base,...EXTENSIONS.map(extension=>`${base}${extension}`),...EXTENSIONS.map(extension=>path.join(base,`index${extension}`))];if(JS_EXTENSION.test(base)){const stem=base.replace(JS_EXTENSION,"");candidates.push(`${stem}.ts`,`${stem}.tsx`)}return candidates.find(isFile)??null}function fallbackParser(){try{const fromEslint=(0,node_module_1.createRequire)((0,node_module_1.createRequire)(path.join(process.cwd(),"package.json")).resolve("eslint"));const espree=fromEslint("espree");const{analyze}=fromEslint("eslint-scope");return{parseForESLint(code){const ast=espree.parse(code,{ecmaVersion:"latest",sourceType:"module",range:true,loc:true});return{ast,scopeManager:analyze(ast,{ecmaVersion:espree.latestEcmaVersion,sourceType:"module"})}}}}catch{return null}}function linkParents(node,parent){node.parent=parent;for(const[key,value]of Object.entries(node)){if(key==="parent")continue;const children=Array.isArray(value)?value:[value];for(const child of children){if(typeof child==="object"&&child!==null&&typeof child.type==="string"){linkParents(child,node)}}}}function parseModule(text,file,parser){for(const candidate of[parser,fallbackParser()]){const parseForESLint=candidate?.parseForESLint;if(typeof parseForESLint!=="function")continue;try{const result=parseForESLint(text,{filePath:file,sourceType:"module",ecmaVersion:"latest",range:true,loc:true});if(!result.scopeManager)continue;linkParents(result.ast,void 0);return{file,ast:result.ast,scopeManager:result.scopeManager}}catch{}}return null}function loadModule(file,parser){const stat=fs.statSync(file,{throwIfNoEntry:false});if(stat===void 0||!stat.isFile())return null;const cached=modules.get(file);if(cached!==void 0&&cached.mtimeMs===stat.mtimeMs)return cached.info;let info=null;try{const text=fs.readFileSync(file,"utf8");if(path.extname(file)===".json"){JSON.parse(text);info=parseModule(`export default (${text});`,`${file}.ts`,parser)}else{info=parseModule(text,file,parser)}}catch{info=null}modules.set(file,{mtimeMs:stat.mtimeMs,info});return info}function scopeIn(module,node){let current=node;for(;current.parent;current=current.parent){const scope=module.scopeManager.acquire(current,true);if(scope!==null)return scope}return module.scopeManager.acquire(current,true)}function moduleEnv(module,parser){return{file:module.file,parser,module,scopeOf:node=>scopeIn(module,node)}}function lookup(name,scope){for(let current=scope;current;current=current.upper){const variable=current.set.get(name);if(variable!==void 0)return variable}return null}function requiredSpecifier(node){if(node?.type!==ast_node_types_1.AST_NODE_TYPES.CallExpression||node.callee.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||node.callee.name!=="require"){return null}const[argument]=node.arguments;return argument?.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof argument.value==="string"?argument.value:null}function moduleExportName(node){return node.type===ast_node_types_1.AST_NODE_TYPES.Identifier?node.name:node.value}function memberChain(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return node.name;if(node.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return null;const key=(0,spellings_1.propertyName)(node);const head=memberChain(node.object);return key===null||head===null?null:`${head}.${key}`}function findProperty(object,key){for(const property of object.properties){if(property.type===ast_node_types_1.AST_NODE_TYPES.Property&&(0,spellings_1.objectKeyName)(property)===key){return property.value}}return null}function exportedValue(module,name,parser,depth=0){if(depth>exports.MAX_FOLLOW_DEPTH)return null;const env=moduleEnv(module,parser);for(const statement of module.ast.body){if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExportDefaultDeclaration){if(name==="default")return valueAt(statement.declaration,env);continue}if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExportNamedDeclaration){const declaration=statement.declaration;if(declaration?.type===ast_node_types_1.AST_NODE_TYPES.VariableDeclaration){const declarator=declaration.declarations.find(d=>d.id.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&d.id.name===name);if(declarator?.init)return valueAt(declarator.init,env)}else if((declaration?.type===ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration||declaration?.type===ast_node_types_1.AST_NODE_TYPES.ClassDeclaration||declaration?.type===ast_node_types_1.AST_NODE_TYPES.TSTypeAliasDeclaration||declaration?.type===ast_node_types_1.AST_NODE_TYPES.TSInterfaceDeclaration)&&declaration.id?.name===name){return valueAt(declaration,env)}for(const specifier of statement.specifiers){if(moduleExportName(specifier.exported)!==name)continue;const local=moduleExportName(specifier.local);if(statement.source!==null){const target=resolveRelative(module.file,String(statement.source.value));const next=target===null?null:loadModule(target,parser);return next===null?null:exportedValue(next,local,parser,depth+1)}const variable=lookup(local,env.scopeOf(module.ast));return variable===null?null:follow(valueAt(variable.identifiers[0],env),depth+1)}continue}if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExpressionStatement&&statement.expression.type===ast_node_types_1.AST_NODE_TYPES.AssignmentExpression&&statement.expression.operator==="="){const{left,right}=statement.expression;const target=memberChain(left);if(target==="module.exports"){if(name==="default")return valueAt(right,env);const object=follow(valueAt(right,env),depth+1);if(object.node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){const property=findProperty(object.node,name);if(property!==null)return valueAt(property,object.env)}}else if(target===`module.exports.${name}`||target===`exports.${name}`){return valueAt(right,env)}}}return null}function importOrigin(variable,env){const specifier=importSpecifierOf(variable);if(specifier===null)return null;const file=resolveRelative(env.file,specifier.source);const module=file===null?null:loadModule(file,env.parser);return module===null?null:{module,name:specifier.name}}function importSpecifierOf(variable){const def=variable.defs[0];if(def===void 0)return null;if(def.type==="ImportBinding"){if(def.node.type===ast_node_types_1.AST_NODE_TYPES.TSImportEqualsDeclaration){const reference=def.node.moduleReference;return reference.type===ast_node_types_1.AST_NODE_TYPES.TSExternalModuleReference&&reference.expression.type===ast_node_types_1.AST_NODE_TYPES.Literal?{source:String(reference.expression.value),name:"*"}:null}const declaration=def.parent;const source2=String(declaration.source.value);if(def.node.type===ast_node_types_1.AST_NODE_TYPES.ImportSpecifier)return{source:source2,name:moduleExportName(def.node.imported)};if(def.node.type===ast_node_types_1.AST_NODE_TYPES.ImportNamespaceSpecifier)return{source:source2,name:"*"};return{source:source2,name:"default"}}if(def.type!=="Variable")return null;const declarator=def.node;const init=declarator.init?.type===ast_node_types_1.AST_NODE_TYPES.AwaitExpression?declarator.init.argument:declarator.init;const source=requiredSpecifier(init)??(init?.type===ast_node_types_1.AST_NODE_TYPES.ImportExpression&&init.source.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof init.source.value==="string"?init.source.value:null);if(source===null)return null;if(declarator.id.type!==ast_node_types_1.AST_NODE_TYPES.ObjectPattern)return{source,name:"*"};const property=declarator.id.properties.find(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&p.value.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&p.value.name===variable.name);const name=property===void 0?null:(0,spellings_1.objectKeyName)(property);return name===null?null:{source,name}}function returnedValue(fn){if(fn.type!==ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration&&fn.type!==ast_node_types_1.AST_NODE_TYPES.FunctionExpression&&fn.type!==ast_node_types_1.AST_NODE_TYPES.ArrowFunctionExpression){return null}if(fn.body.type!==ast_node_types_1.AST_NODE_TYPES.BlockStatement)return fn.body;const last=fn.body.body.at(-1);return last?.type===ast_node_types_1.AST_NODE_TYPES.ReturnStatement?last.argument:null}function returnedValues(fn){if(fn.body===null||fn.body===void 0)return null;if(fn.body.type!==ast_node_types_1.AST_NODE_TYPES.BlockStatement)return[fn.body];const found=[];let bare=false;const visit=node=>{if(node.type===ast_node_types_1.AST_NODE_TYPES.ReturnStatement){if(node.argument===null)bare=true;else found.push(node.argument);return}for(const[key,value]of Object.entries(node)){if(key==="parent")continue;const children=Array.isArray(value)?value:[value];for(const child of children){if(typeof child!=="object"||child===null||typeof child.type!=="string")continue;const type=child.type;if(type===ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration||type===ast_node_types_1.AST_NODE_TYPES.FunctionExpression||type===ast_node_types_1.AST_NODE_TYPES.ArrowFunctionExpression)continue;visit(child)}}};visit(fn.body);if(bare||!alwaysLeaves(fn.body)||found.length===0)return null;return found}function alwaysLeaves(statement){switch(statement.type){case ast_node_types_1.AST_NODE_TYPES.ReturnStatement:case ast_node_types_1.AST_NODE_TYPES.ThrowStatement:return true;case ast_node_types_1.AST_NODE_TYPES.BlockStatement:{const last=statement.body.at(-1);return last!==void 0&&alwaysLeaves(last)}case ast_node_types_1.AST_NODE_TYPES.IfStatement:return statement.alternate!==null&&alwaysLeaves(statement.consequent)&&alwaysLeaves(statement.alternate);default:return false}}function singleWrite(variable){if(variable.defs.some(def=>def.type==="Parameter"))return null;const writes=variable.references.filter(reference=>reference.isWrite());if(writes.length!==1)return null;return writes[0].writeExpr??null}function follow(start,depth=0,seen=new Set){if(depth>exports.MAX_FOLLOW_DEPTH||seen.has(start.node))return start;seen.add(start.node);const{scope,env}=start;const node=(0,type_syntax_1.unwrapTypeSyntax)(start.node);const next=(target,nextEnv=env)=>follow(valueAt(target,nextEnv),depth+1,seen);if(node!==start.node)return next(node);if(node.type===ast_node_types_1.AST_NODE_TYPES.AwaitExpression)return next(node.argument);if(node.type===ast_node_types_1.AST_NODE_TYPES.ChainExpression)return next(node.expression);if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier){const variable=lookup(node.name,scope);if(variable===null)return start;const def=variable.defs[0];if(def?.type==="FunctionName"||def?.type==="ClassName")return next(def.node);const origin=importOrigin(variable,env);if(origin!==null){const commonJs=origin.name==="*"&&def?.type==="Variable"?exportedValue(origin.module,"default",env.parser,depth+1):null;if(commonJs!==null)return follow(commonJs,depth+1,seen);if(origin.name==="*"){return valueAt(origin.module.ast,moduleEnv(origin.module,env.parser))}const exported=exportedValue(origin.module,origin.name,env.parser,depth+1);return exported===null?start:follow(exported,depth+1,seen)}if(def?.type==="Variable"&&def.node.id.type===ast_node_types_1.AST_NODE_TYPES.ObjectPattern){const property=def.node.id.properties.find(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&p.value.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&p.value.name===node.name);const key=property===void 0?null:(0,spellings_1.objectKeyName)(property);if(key===null||def.node.init===null)return start;const object=next(def.node.init);if(object.node.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)return start;const value=findProperty(object.node,key);return value===null?start:next(value,object.env)}const written=singleWrite(variable);return written===null?start:next(written)}if(node.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){const key=(0,spellings_1.propertyName)(node);if(key===null)return start;const object=next(node.object);if(object.node.type===ast_node_types_1.AST_NODE_TYPES.Program&&object.env.module!==null){const exported=exportedValue(object.env.module,key,env.parser,depth+1);return exported===null?start:follow(exported,depth+1,seen)}if(object.node.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)return start;const value=findProperty(object.node,key);return value===null?start:next(value,object.env)}if(node.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){const callee=next(node.callee);const returned=returnedValue(callee.node);return returned===null?start:next(returned,callee.env)}return start}
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,v){Object.defineProperty(o,"default",{enumerable:true,value:v})}):function(o,v){o["default"]=v});var __importStar=this&&this.__importStar||(function(){var ownKeys=function(o){ownKeys=Object.getOwnPropertyNames||function(o2){var ar=[];for(var k in o2)if(Object.prototype.hasOwnProperty.call(o2,k))ar[ar.length]=k;return ar};return ownKeys(o)};return function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null){for(var k=ownKeys(mod),i=0;i<k.length;i++)if(k[i]!=="default")__createBinding(result,mod,k[i])}__setModuleDefault(result,mod);return result}})();Object.defineProperty(exports,"__esModule",{value:true});exports.MAX_CACHED_MODULES=exports.MAX_FOLLOW_DEPTH=void 0;exports.cachedModuleCount=cachedModuleCount;exports.isRelativeSpecifier=isRelativeSpecifier;exports.envOf=envOf;exports.valueAt=valueAt;exports.resolveRelative=resolveRelative;exports.parseModule=parseModule;exports.loadModule=loadModule;exports.scopeIn=scopeIn;exports.moduleEnv=moduleEnv;exports.lookup=lookup;exports.requiredSpecifier=requiredSpecifier;exports.findProperty=findProperty;exports.exportedValue=exportedValue;exports.importOrigin=importOrigin;exports.importSpecifierOf=importSpecifierOf;exports.returnedValue=returnedValue;exports.returnedValues=returnedValues;exports.singleWrite=singleWrite;exports.follow=follow;const fs=__importStar(require("node:fs"));const path=__importStar(require("node:path"));const node_module_1=require("node:module");const ast_node_types_1=require("../ast-node-types");const spellings_1=require("../ast/spellings");const type_syntax_1=require("../ast/type-syntax");const dependency_analysis_1=require("../resolver/dependency-analysis");exports.MAX_FOLLOW_DEPTH=8;const EXTENSIONS=[".ts",".tsx",".js",".mjs",".cjs",".json"];const RELATIVE=/^\.{1,2}(?:\/|$)/;const JS_EXTENSION=/\.[cm]?js$/;exports.MAX_CACHED_MODULES=512;const modules=(0,dependency_analysis_1.createLRUCache)(exports.MAX_CACHED_MODULES);function cachedModuleCount(){return modules.size}function isRelativeSpecifier(specifier){return RELATIVE.test(specifier)}function envOf(context){return{file:path.resolve(context.physicalFilename),parser:context.languageOptions?.parser,module:null,scopeOf:node=>context.sourceCode.getScope(node)}}function valueAt(node,env){return{node,scope:env.scopeOf(node),env}}function isFile(candidate){return fs.statSync(candidate,{throwIfNoEntry:false})?.isFile()===true}function resolveRelative(fromFile,specifier){if(!isRelativeSpecifier(specifier))return null;const base=path.resolve(path.dirname(fromFile),specifier);const candidates=[base,...EXTENSIONS.map(extension=>`${base}${extension}`),...EXTENSIONS.map(extension=>path.join(base,`index${extension}`))];if(JS_EXTENSION.test(base)){const stem=base.replace(JS_EXTENSION,"");candidates.push(`${stem}.ts`,`${stem}.tsx`)}return candidates.find(isFile)??null}function fallbackParser(){try{const fromEslint=(0,node_module_1.createRequire)((0,node_module_1.createRequire)(path.join(process.cwd(),"package.json")).resolve("eslint"));const espree=fromEslint("espree");const{analyze}=fromEslint("eslint-scope");return{parseForESLint(code){const ast=espree.parse(code,{ecmaVersion:"latest",sourceType:"module",range:true,loc:true});return{ast,scopeManager:analyze(ast,{ecmaVersion:espree.latestEcmaVersion,sourceType:"module"})}}}}catch{return null}}function linkParents(node,parent){node.parent=parent;for(const[key,value]of Object.entries(node)){if(key==="parent")continue;const children=Array.isArray(value)?value:[value];for(const child of children){if(typeof child==="object"&&child!==null&&typeof child.type==="string"){linkParents(child,node)}}}}function parseModule(text,file,parser){for(const candidate of[parser,fallbackParser()]){const parseForESLint=candidate?.parseForESLint;if(typeof parseForESLint!=="function")continue;try{const result=parseForESLint(text,{filePath:file,sourceType:"module",ecmaVersion:"latest",range:true,loc:true});if(!result.scopeManager)continue;linkParents(result.ast,void 0);return{file,ast:result.ast,scopeManager:result.scopeManager}}catch{}}return null}function loadModule(file,parser){const stat=fs.statSync(file,{throwIfNoEntry:false});if(stat===void 0||!stat.isFile())return null;const cached=modules.get(file);if(cached!==void 0&&cached.mtimeMs===stat.mtimeMs)return cached.info;let info=null;try{const text=fs.readFileSync(file,"utf8");if(path.extname(file)===".json"){JSON.parse(text);info=parseModule(`export default (${text});`,`${file}.ts`,parser)}else{info=parseModule(text,file,parser)}}catch{info=null}modules.set(file,{mtimeMs:stat.mtimeMs,info});return info}function scopeIn(module,node){let current=node;for(;current.parent;current=current.parent){const scope=module.scopeManager.acquire(current,true);if(scope!==null)return scope}return module.scopeManager.acquire(current,true)}function moduleEnv(module,parser){return{file:module.file,parser,module,scopeOf:node=>scopeIn(module,node)}}function lookup(name,scope){for(let current=scope;current;current=current.upper){const variable=current.set.get(name);if(variable!==void 0)return variable}return null}function requiredSpecifier(node){if(node?.type!==ast_node_types_1.AST_NODE_TYPES.CallExpression||node.callee.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||node.callee.name!=="require"){return null}const[argument]=node.arguments;return argument?.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof argument.value==="string"?argument.value:null}function moduleExportName(node){return node.type===ast_node_types_1.AST_NODE_TYPES.Identifier?node.name:node.value}function memberChain(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return node.name;if(node.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return null;const key=(0,spellings_1.propertyName)(node);const head=memberChain(node.object);return key===null||head===null?null:`${head}.${key}`}function findProperty(object,key){for(const property of object.properties){if(property.type===ast_node_types_1.AST_NODE_TYPES.Property&&(0,spellings_1.objectKeyName)(property)===key){return property.value}}return null}function writesTo(name,module,env){const variable=lookup(name,env.scopeOf(module.ast));return variable.references.filter(reference=>reference.isWrite()).length}function exportedValue(module,name,parser,depth=0){if(depth>exports.MAX_FOLLOW_DEPTH)return null;const env=moduleEnv(module,parser);for(const statement of module.ast.body){if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExportDefaultDeclaration){if(name==="default")return valueAt(statement.declaration,env);continue}if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExportNamedDeclaration){const declaration=statement.declaration;if(declaration?.type===ast_node_types_1.AST_NODE_TYPES.VariableDeclaration){const declarator=declaration.declarations.find(d=>d.id.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&d.id.name===name);if(declarator!==void 0){return declarator.init&&writesTo(name,module,env)<=1?valueAt(declarator.init,env):null}}else if((declaration?.type===ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration||declaration?.type===ast_node_types_1.AST_NODE_TYPES.ClassDeclaration||declaration?.type===ast_node_types_1.AST_NODE_TYPES.TSTypeAliasDeclaration||declaration?.type===ast_node_types_1.AST_NODE_TYPES.TSInterfaceDeclaration)&&declaration.id?.name===name){return writesTo(name,module,env)===0?valueAt(declaration,env):null}for(const specifier of statement.specifiers){if(moduleExportName(specifier.exported)!==name)continue;const local=moduleExportName(specifier.local);if(statement.source!==null){const target=resolveRelative(module.file,String(statement.source.value));const next=target===null?null:loadModule(target,parser);return next===null?null:exportedValue(next,local,parser,depth+1)}const variable=lookup(local,env.scopeOf(module.ast));return variable===null?null:follow(valueAt(variable.identifiers[0],env),depth+1)}continue}if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExportAllDeclaration&&statement.exported!==null){if(moduleExportName(statement.exported)!==name)continue;const target=resolveRelative(module.file,String(statement.source.value));const next=target===null?null:loadModule(target,parser);return next===null?null:valueAt(next.ast,moduleEnv(next,parser))}if(statement.type===ast_node_types_1.AST_NODE_TYPES.ExpressionStatement&&statement.expression.type===ast_node_types_1.AST_NODE_TYPES.AssignmentExpression&&statement.expression.operator==="="){const{left,right}=statement.expression;const target=memberChain(left);if(target==="module.exports"){if(name==="default")return valueAt(right,env);const object=follow(valueAt(right,env),depth+1);if(object.node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){const property=findProperty(object.node,name);if(property!==null)return valueAt(property,object.env)}}else if(target===`module.exports.${name}`||target===`exports.${name}`){return valueAt(right,env)}}}if(name==="default")return null;let starred=null;for(const statement of module.ast.body){if(statement.type!==ast_node_types_1.AST_NODE_TYPES.ExportAllDeclaration||statement.exported!==null)continue;const target=resolveRelative(module.file,String(statement.source.value));const next=target===null?null:loadModule(target,parser);const found=next===null?null:exportedValue(next,name,parser,depth+1);if(found===null)continue;if(starred!==null&&starred.node!==found.node)return null;starred=found}return starred}function importOrigin(variable,env){const specifier=importSpecifierOf(variable);if(specifier===null)return null;const file=resolveRelative(env.file,specifier.source);const module=file===null?null:loadModule(file,env.parser);return module===null?null:{module,name:specifier.name}}function importSpecifierOf(variable){const def=variable.defs[0];if(def===void 0)return null;if(def.type==="ImportBinding"){if(def.node.type===ast_node_types_1.AST_NODE_TYPES.TSImportEqualsDeclaration){const reference=def.node.moduleReference;return reference.type===ast_node_types_1.AST_NODE_TYPES.TSExternalModuleReference&&reference.expression.type===ast_node_types_1.AST_NODE_TYPES.Literal?{source:String(reference.expression.value),name:"*"}:null}const declaration=def.parent;const source2=String(declaration.source.value);if(def.node.type===ast_node_types_1.AST_NODE_TYPES.ImportSpecifier)return{source:source2,name:moduleExportName(def.node.imported)};if(def.node.type===ast_node_types_1.AST_NODE_TYPES.ImportNamespaceSpecifier)return{source:source2,name:"*"};return{source:source2,name:"default"}}if(def.type!=="Variable")return null;const declarator=def.node;const init=declarator.init?.type===ast_node_types_1.AST_NODE_TYPES.AwaitExpression?declarator.init.argument:declarator.init;const source=requiredSpecifier(init)??(init?.type===ast_node_types_1.AST_NODE_TYPES.ImportExpression&&init.source.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof init.source.value==="string"?init.source.value:null);if(source===null)return null;if(declarator.id.type!==ast_node_types_1.AST_NODE_TYPES.ObjectPattern)return{source,name:"*"};const property=declarator.id.properties.find(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&p.value.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&p.value.name===variable.name);const name=property===void 0?null:(0,spellings_1.objectKeyName)(property);return name===null?null:{source,name}}function returnedValue(fn){if(fn.type!==ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration&&fn.type!==ast_node_types_1.AST_NODE_TYPES.FunctionExpression&&fn.type!==ast_node_types_1.AST_NODE_TYPES.ArrowFunctionExpression){return null}if(fn.body.type!==ast_node_types_1.AST_NODE_TYPES.BlockStatement)return fn.body;const last=fn.body.body.at(-1);return last?.type===ast_node_types_1.AST_NODE_TYPES.ReturnStatement?last.argument:null}function returnedValues(fn){if(fn.body===null||fn.body===void 0)return null;if(fn.body.type!==ast_node_types_1.AST_NODE_TYPES.BlockStatement)return[fn.body];const found=[];let bare=false;const visit=node=>{if(node.type===ast_node_types_1.AST_NODE_TYPES.ReturnStatement){if(node.argument===null)bare=true;else found.push(node.argument);return}for(const[key,value]of Object.entries(node)){if(key==="parent")continue;const children=Array.isArray(value)?value:[value];for(const child of children){if(typeof child!=="object"||child===null||typeof child.type!=="string")continue;const type=child.type;if(type===ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration||type===ast_node_types_1.AST_NODE_TYPES.FunctionExpression||type===ast_node_types_1.AST_NODE_TYPES.ArrowFunctionExpression)continue;visit(child)}}};visit(fn.body);if(bare||!alwaysLeaves(fn.body)||found.length===0)return null;return found}function alwaysLeaves(statement){switch(statement.type){case ast_node_types_1.AST_NODE_TYPES.ReturnStatement:case ast_node_types_1.AST_NODE_TYPES.ThrowStatement:return true;case ast_node_types_1.AST_NODE_TYPES.BlockStatement:{const last=statement.body.at(-1);return last!==void 0&&alwaysLeaves(last)}case ast_node_types_1.AST_NODE_TYPES.IfStatement:return statement.alternate!==null&&alwaysLeaves(statement.consequent)&&alwaysLeaves(statement.alternate);default:return false}}function singleWrite(variable){if(variable.defs.some(def=>def.type==="Parameter"))return null;const writes=variable.references.filter(reference=>reference.isWrite());if(writes.length!==1)return null;return writes[0].writeExpr??null}function follow(start,depth=0,seen=new Set){if(depth>exports.MAX_FOLLOW_DEPTH||seen.has(start.node))return start;seen.add(start.node);const{scope,env}=start;const node=(0,type_syntax_1.unwrapTypeSyntax)(start.node);const next=(target,nextEnv=env)=>follow(valueAt(target,nextEnv),depth+1,seen);if(node!==start.node)return next(node);if(node.type===ast_node_types_1.AST_NODE_TYPES.AwaitExpression)return next(node.argument);if(node.type===ast_node_types_1.AST_NODE_TYPES.ChainExpression)return next(node.expression);if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier){const variable=lookup(node.name,scope);if(variable===null)return start;const def=variable.defs[0];if(def?.type==="FunctionName"||def?.type==="ClassName"){if(variable.references.some(reference=>reference.isWrite())){return start}return next(def.node)}const origin=importOrigin(variable,env);if(origin!==null){const commonJs=origin.name==="*"&&def?.type==="Variable"?exportedValue(origin.module,"default",env.parser,depth+1):null;if(commonJs!==null)return follow(commonJs,depth+1,seen);if(origin.name==="*"){return valueAt(origin.module.ast,moduleEnv(origin.module,env.parser))}const exported=exportedValue(origin.module,origin.name,env.parser,depth+1);return exported===null?start:follow(exported,depth+1,seen)}if(def?.type==="Variable"&&def.node.id.type===ast_node_types_1.AST_NODE_TYPES.ObjectPattern){const property=def.node.id.properties.find(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&p.value.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&p.value.name===node.name);const key=property===void 0?null:(0,spellings_1.objectKeyName)(property);if(key===null||def.node.init===null)return start;const object=next(def.node.init);if(object.node.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)return start;const value=findProperty(object.node,key);return value===null?start:next(value,object.env)}const written=singleWrite(variable);return written===null?start:next(written)}if(node.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){const key=(0,spellings_1.propertyName)(node);if(key===null)return start;const object=next(node.object);if(object.node.type===ast_node_types_1.AST_NODE_TYPES.Program&&object.env.module!==null){const exported=exportedValue(object.env.module,key,env.parser,depth+1);return exported===null?start:follow(exported,depth+1,seen)}if(object.node.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)return start;const value=findProperty(object.node,key);return value===null?start:next(value,object.env)}if(node.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){const callee=next(node.callee);const returned=returnedValue(callee.node);return returned===null?start:next(returned,callee.env)}return start}