recursivePatternCapture=recursivePatternCapture;var_fs=require('fs');var_fs2=_interopRequireDefault(_fs);var_path=require('path');var_doctrine=require('doctrine');var_doctrine2=_interopRequireDefault(_doctrine);var_debug=require('debug');var_debug2=_interopRequireDefault(_debug);var_eslint=require('eslint');var_parse=require('eslint-module-utils/parse');var_parse2=_interopRequireDefault(_parse);var_visit=require('eslint-module-utils/visit');var_visit2=_interopRequireDefault(_visit);var_resolve=require('eslint-module-utils/resolve');var_resolve2=_interopRequireDefault(_resolve);var_ignore=require('eslint-module-utils/ignore');var_ignore2=_interopRequireDefault(_ignore);var_hash=require('eslint-module-utils/hash');var_unambiguous=require('eslint-module-utils/unambiguous');varunambiguous=_interopRequireWildcard(_unambiguous);var_tsconfigLoader=require('tsconfig-paths/lib/tsconfig-loader');var_arrayIncludes=require('array-includes');var_arrayIncludes2=_interopRequireDefault(_arrayIncludes);function_interopRequireWildcard(obj){if(obj&&obj.__esModule){returnobj;}else{varnewObj={};if(obj!=null){for(varkeyinobj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key];}}newObj['default']=obj;returnnewObj;}}function_interopRequireDefault(obj){returnobj&&obj.__esModule?obj:{'default':obj};}function_classCallCheck(instance,Constructor){if(!(instanceinstanceofConstructor)){thrownewTypeError("Cannot call a class as a function");}}varts=void0;varlog=(0,_debug2['default'])('eslint-plugin-import:ExportMap');varexportCache=newMap();vartsConfigCache=newMap();varExportMap=function(){functionExportMap(path){_classCallCheck(this,ExportMap);this.path=path;this.namespace=newMap();// todo: restructure to key on path, value is resolver + map of names
if(name!=='default'){var_iteratorNormalCompletion=true;var_didIteratorError=false;var_iteratorError=undefined;try{for(var_iterator=this.dependencies[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){vardep=_step.value;varinnerMap=dep();// todo: report as unresolved?
if(imported==null)return{found:true,path:[this]};// safeguard against cycles, only if name matches
if(imported.path===this.path&&reexports.local===name){return{found:false,path:[this]};}vardeep=imported.hasDeep(reexports.local);deep.path.unshift(this);returndeep;}// default exports must be explicitly re-exported (#328)
if(name!=='default'){var_iteratorNormalCompletion2=true;var_didIteratorError2=false;var_iteratorError2=undefined;try{for(var_iterator2=this.dependencies[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){vardep=_step2.value;varinnerMap=dep();if(innerMap==null)return{found:true,path:[this]};// todo: report as unresolved?
if(!innerMap)continue;// safeguard against cycles
if(innerMap.path===this.path)continue;varinnerValue=innerMap.hasDeep(name);if(innerValue.found){innerValue.path.unshift(this);returninnerValue;}}}catch(err){_didIteratorError2=true;_iteratorError2=err;}finally{try{if(!_iteratorNormalCompletion2&&_iterator2['return']){_iterator2['return']();}}finally{if(_didIteratorError2){throw_iteratorError2;}}}}return{found:false,path:[this]};}returnhasDeep;}()},{key:'get',value:function(){functionget(name){if(this.namespace.has(name))returnthis.namespace.get(name);if(this.reexports.has(name)){varreexports=this.reexports.get(name);varimported=reexports.getImport();// if import is ignored, return explicit 'null'
if(imported==null)returnnull;// safeguard against cycles, only if name matches
if(imported.path===this.path&&reexports.local===name)returnundefined;returnimported.get(reexports.local);}// default exports must be explicitly re-exported (#328)
if(name!=='default'){var_iteratorNormalCompletion3=true;var_didIteratorError3=false;var_iteratorError3=undefined;try{for(var_iterator3=this.dependencies[Symbol.iterator](),_step3;!(_iteratorNormalCompletion3=(_step3=_iterator3.next()).done);_iteratorNormalCompletion3=true){vardep=_step3.value;varinnerMap=dep();// todo: report as unresolved?
if(!innerMap)continue;// safeguard against cycles
if(innerMap.path===this.path)continue;varinnerValue=innerMap.get(name);if(innerValue!==undefined)returninnerValue;}}catch(err){_didIteratorError3=true;_iteratorError3=err;}finally{try{if(!_iteratorNormalCompletion3&&_iterator3['return']){_iterator3['return']();}}finally{if(_didIteratorError3){throw_iteratorError3;}}}}returnundefined;}returnget;}()},{key:'forEach',value:function(){functionforEach(callback,thisArg){var_this=this;this.namespace.forEach(function(v,n){returncallback.call(thisArg,v,n,_this);});this.reexports.forEach(function(reexports,name){varreexported=reexports.getImport();// can't look up meta for ignored re-exports (#348)
if(comment.type!=='Block')return;try{doc=_doctrine2['default'].parse(comment.value,{unwrap:true});}catch(err){/* don't care, for now? maybe add to `errors?` */}});returndoc;}/**
if((0,_ignore2['default'])(path,context)){log('ignored path due to ignore settings:',path);exportCache.set(cacheKey,null);returnnull;}varcontent=_fs2['default'].readFileSync(path,{encoding:'utf8'});// check for and cache unambiguous modules
}m.visitorKeys=visitorKeys;varhasDynamicImports=false;functionprocessDynamicImport(source){hasDynamicImports=true;if(source.type!=='Literal'){returnnull;}varp=remotePath(source.value);if(p==null){returnnull;}varimportedSpecifiers=newSet();importedSpecifiers.add('ImportNamespaceSpecifier');vargetter=thunkFor(p,context);m.imports.set(p,{getter:getter,declarations:newSet([{source:{// capturing actual node reference holds full AST in memory!
value:source.value,loc:source.loc},importedSpecifiers:importedSpecifiers}])});}(0,_visit2['default'])(ast,visitorKeys,{ImportExpression:function(){functionImportExpression(node){processDynamicImport(node.source);}returnImportExpression;}(),CallExpression:function(){functionCallExpression(node){if(node.callee.type==='Import'){processDynamicImport(node.arguments[0]);}}returnCallExpression;}()});varunambiguouslyESM=unambiguous.isModule(ast);if(!unambiguouslyESM&&!hasDynamicImports)returnnull;vardocstyle=context.settings&&context.settings['import/docstyle']||['jsdoc'];vardocStyleParsers={};docstyle.forEach(function(style){docStyleParsers[style]=availableDocStyleParsers[style];});// attempt to collect module doc
if(ast.comments){ast.comments.some(function(c){if(c.type!=='Block')returnfalse;try{vardoc=_doctrine2['default'].parse(c.value,{unwrap:true});if(doc.tags.some(function(t){returnt.title==='module';})){m.doc=doc;returntrue;}}catch(err){/* ignore */}returnfalse;});}varnamespaces=newMap();functionremotePath(value){return_resolve2['default'].relative(value,path,context.settings);}functionresolveImport(value){varrp=remotePath(value);if(rp==null)returnnull;returnExportMap['for'](childContext(rp,context));}functiongetNamespace(identifier){if(!namespaces.has(identifier.name))return;returnfunction(){returnresolveImport(namespaces.get(identifier.name));};}functionaddNamespace(object,identifier){varnsfn=getNamespace(identifier);if(nsfn){Object.defineProperty(object,'namespace',{get:nsfn});}returnobject;}functionprocessSpecifier(s,n,m){varnsource=n.source&&n.source.value;varexportMeta={};varlocal=void0;switch(s.type){case'ExportDefaultSpecifier':if(!nsource)return;local='default';break;case'ExportNamespaceSpecifier':m.namespace.set(s.exported.name,Object.defineProperty(exportMeta,'namespace',{get:function(){functionget(){returnresolveImport(nsource);}returnget;}()}));return;case'ExportAllDeclaration':m.namespace.set(s.exported.name||s.exported.value,addNamespace(exportMeta,s.source.value));return;case'ExportSpecifier':if(!n.source){m.namespace.set(s.exported.name||s.exported.value,addNamespace(exportMeta,s.local));return;}// else falls through
default:local=s.local.name;break;}// todo: JSDoc
m.reexports.set(s.exported.name,{local:local,getImport:function(){functiongetImport(){returnresolveImport(nsource);}returngetImport;}()});}functioncaptureDependency(_ref,isOnlyImportingTypes){varsource=_ref.source;varimportedSpecifiers=arguments.length>2&&arguments[2]!==undefined?arguments[2]:newSet();if(source==null)returnnull;varp=remotePath(source.value);if(p==null)returnnull;vardeclarationMetadata={// capturing actual node reference holds full AST in memory!
source:{value:source.value,loc:source.loc},isOnlyImportingTypes:isOnlyImportingTypes,importedSpecifiers:importedSpecifiers};varexisting=m.imports.get(p);if(existing!=null){existing.declarations.add(declarationMetadata);returnexisting.getter;}vargetter=thunkFor(p,context);m.imports.set(p,{getter:getter,declarations:newSet([declarationMetadata])});returngetter;}varsource=makeSourceCode(content,ast);functionreadTsConfig(){vartsConfigInfo=(0,_tsconfigLoader.tsConfigLoader)({cwd:context.parserOptions&&context.parserOptions.tsconfigRootDir||process.cwd(),getEnv:function(){functiongetEnv(key){returnprocess.env[key];}returngetEnv;}()});try{if(tsConfigInfo.tsConfigPath!==undefined){// Projects not using TypeScript won't have `typescript` installed.
if(!ts){ts=require('typescript');}varconfigFile=ts.readConfigFile(tsConfigInfo.tsConfigPath,ts.sys.readFile);returnts.parseJsonConfigFileContent(configFile.config,ts.sys,(0,_path.dirname)(tsConfigInfo.tsConfigPath));}}catch(e){// Catch any errors
}returnnull;}functionisEsModuleInterop(){varcacheKey=(0,_hash.hashObject)({tsconfigRootDir:context.parserOptions&&context.parserOptions.tsconfigRootDir}).digest('hex');vartsConfig=tsConfigCache.get(cacheKey);if(typeoftsConfig==='undefined'){tsConfig=readTsConfig(context);tsConfigCache.set(cacheKey,tsConfig);}returntsConfig&&tsConfig.options?tsConfig.options.esModuleInterop:false;}ast.body.forEach(function(n){if(n.type==='ExportDefaultDeclaration'){varexportMeta=captureDoc(source,docStyleParsers,n);if(n.declaration.type==='Identifier'){addNamespace(exportMeta,n.declaration);}m.namespace.set('default',exportMeta);return;}if(n.type==='ExportAllDeclaration'){vargetter=captureDependency(n,n.exportKind==='type');if(getter)m.dependencies.add(getter);if(n.exported){processSpecifier(n,n.exported,m);}return;}// capture namespaces in case of later export
if(n.type==='ImportDeclaration'){// import type { Foo } (TS and Flow)
vardeclarationIsType=n.importKind==='type';// import './foo' or import {} from './foo' (both 0 specifiers) is a side effect and
// shouldn't be considered to be just importing types
varspecifiersOnlyImportingTypes=n.specifiers.length;varimportedSpecifiers=newSet();n.specifiers.forEach(function(specifier){if(supportedImportTypes.has(specifier.type)){importedSpecifiers.add(specifier.type);}if(specifier.type==='ImportSpecifier'){importedSpecifiers.add(specifier.imported.name||specifier.imported.value);}// import { type Foo } (Flow)
if(n.declaration!=null){switch(n.declaration.type){case'FunctionDeclaration':case'ClassDeclaration':case'TypeAlias':// flowtype with babel-eslint parser
case'InterfaceDeclaration':case'DeclareFunction':case'TSDeclareFunction':case'TSEnumDeclaration':case'TSTypeAliasDeclaration':case'TSInterfaceDeclaration':case'TSAbstractClassDeclaration':case'TSModuleDeclaration':m.namespace.set(n.declaration.id.name,captureDoc(source,docStyleParsers,n));break;case'VariableDeclaration':n.declaration.declarations.forEach(function(d){returnrecursivePatternCapture(d.id,function(id){returnm.namespace.set(id.name,captureDoc(source,docStyleParsers,d,n));});});break;}}n.specifiers.forEach(function(s){returnprocessSpecifier(s,n,m);});}varexports=['TSExportAssignment'];if(isEsModuleInteropTrue){exports.push('TSNamespaceExportDeclaration');}// This doesn't declare anything, but changes what's being exported.
if((0,_arrayIncludes2['default'])(exports,n.type)){varexportedName=n.type==='TSNamespaceExportDeclaration'?(n.id||n.name).name:n.expression&&n.expression.name||n.expression.id&&n.expression.id.name||null;vardeclTypes=['VariableDeclaration','ClassDeclaration','TSDeclareFunction','TSEnumDeclaration','TSTypeAliasDeclaration','TSInterfaceDeclaration','TSAbstractClassDeclaration','TSModuleDeclaration'];varexportedDecls=ast.body.filter(function(_ref2){vartype=_ref2.type,id=_ref2.id,declarations=_ref2.declarations;return(0,_arrayIncludes2['default'])(declTypes,type)&&(id&&id.name===exportedName||declarations&&declarations.find(function(d){returnd.id.name===exportedName;}));});if(exportedDecls.length===0){// Export is not referencing any local declaration, must be re-exporting
m.namespace.set('default',captureDoc(source,docStyleParsers,n));return;}if(isEsModuleInteropTrue// esModuleInterop is on in tsconfig
&&!m.namespace.has('default')// and default isn't added already
}exportedDecls.forEach(function(decl){if(decl.type==='TSModuleDeclaration'){if(decl.body&&decl.body.type==='TSModuleDeclaration'){m.namespace.set(decl.body.id.name,captureDoc(source,docStyleParsers,decl.body));}elseif(decl.body&&decl.body.body){decl.body.body.forEach(function(moduleBlockNode){// Export-assignment exports all members in the namespace,
varnamespaceDecl=moduleBlockNode.type==='ExportNamedDeclaration'?moduleBlockNode.declaration:moduleBlockNode;if(!namespaceDecl){// TypeScript can check this for us; we needn't
}elseif(namespaceDecl.type==='VariableDeclaration'){namespaceDecl.declarations.forEach(function(d){returnrecursivePatternCapture(d.id,function(id){returnm.namespace.set(id.name,captureDoc(source,docStyleParsers,decl,namespaceDecl,moduleBlockNode));});});}else{m.namespace.set(namespaceDecl.id.name,captureDoc(source,docStyleParsers,moduleBlockNode));}});}}else{// Export as default
m.namespace.set('default',captureDoc(source,docStyleParsers,decl));}});}});if(isEsModuleInteropTrue// esModuleInterop is on in tsconfig
&&m.namespace.size>0// anything is exported
&&!m.namespace.has('default')// and default isn't added already