web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

906 lines
98 KiB

  1. 'use strict';
  2. var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
  3. var _ignore = require('eslint-module-utils/ignore');
  4. var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
  5. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);
  6. var _path = require('path');
  7. var _readPkgUp = require('read-pkg-up');var _readPkgUp2 = _interopRequireDefault(_readPkgUp);
  8. var _object = require('object.values');var _object2 = _interopRequireDefault(_object);
  9. var _arrayIncludes = require('array-includes');var _arrayIncludes2 = _interopRequireDefault(_arrayIncludes);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];return arr2;} else {return Array.from(arr);}} /**
  10. * @fileOverview Ensures that modules contain exports and/or all
  11. * modules are consumed within other modules.
  12. * @author René Fermann
  13. */ // eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3
  14. // and has been moved to eslint/lib/cli-engine/file-enumerator in version 6
  15. let listFilesToProcess;try {const FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator;
  16. listFilesToProcess = function (src, extensions) {
  17. const e = new FileEnumerator({
  18. extensions: extensions });
  19. return Array.from(e.iterateFiles(src), (_ref) => {let filePath = _ref.filePath,ignored = _ref.ignored;return {
  20. ignored,
  21. filename: filePath };});
  22. };
  23. } catch (e1) {
  24. // Prevent passing invalid options (extensions array) to old versions of the function.
  25. // https://github.com/eslint/eslint/blob/v5.16.0/lib/util/glob-utils.js#L178-L280
  26. // https://github.com/eslint/eslint/blob/v5.2.0/lib/util/glob-util.js#L174-L269
  27. let originalListFilesToProcess;
  28. try {
  29. originalListFilesToProcess = require('eslint/lib/util/glob-utils').listFilesToProcess;
  30. listFilesToProcess = function (src, extensions) {
  31. return originalListFilesToProcess(src, {
  32. extensions: extensions });
  33. };
  34. } catch (e2) {
  35. originalListFilesToProcess = require('eslint/lib/util/glob-util').listFilesToProcess;
  36. listFilesToProcess = function (src, extensions) {
  37. const patterns = src.reduce((carry, pattern) => {
  38. return carry.concat(extensions.map(extension => {
  39. return (/\*\*|\*\./.test(pattern) ? pattern : `${pattern}/**/*${extension}`);
  40. }));
  41. }, src.slice());
  42. return originalListFilesToProcess(patterns);
  43. };
  44. }
  45. }
  46. const EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration';
  47. const EXPORT_NAMED_DECLARATION = 'ExportNamedDeclaration';
  48. const EXPORT_ALL_DECLARATION = 'ExportAllDeclaration';
  49. const IMPORT_DECLARATION = 'ImportDeclaration';
  50. const IMPORT_NAMESPACE_SPECIFIER = 'ImportNamespaceSpecifier';
  51. const IMPORT_DEFAULT_SPECIFIER = 'ImportDefaultSpecifier';
  52. const VARIABLE_DECLARATION = 'VariableDeclaration';
  53. const FUNCTION_DECLARATION = 'FunctionDeclaration';
  54. const CLASS_DECLARATION = 'ClassDeclaration';
  55. const INTERFACE_DECLARATION = 'InterfaceDeclaration';
  56. const TYPE_ALIAS = 'TypeAlias';
  57. const TS_INTERFACE_DECLARATION = 'TSInterfaceDeclaration';
  58. const TS_TYPE_ALIAS_DECLARATION = 'TSTypeAliasDeclaration';
  59. const TS_ENUM_DECLARATION = 'TSEnumDeclaration';
  60. const DEFAULT = 'default';
  61. function forEachDeclarationIdentifier(declaration, cb) {
  62. if (declaration) {
  63. if (
  64. declaration.type === FUNCTION_DECLARATION ||
  65. declaration.type === CLASS_DECLARATION ||
  66. declaration.type === INTERFACE_DECLARATION ||
  67. declaration.type === TYPE_ALIAS ||
  68. declaration.type === TS_INTERFACE_DECLARATION ||
  69. declaration.type === TS_TYPE_ALIAS_DECLARATION ||
  70. declaration.type === TS_ENUM_DECLARATION)
  71. {
  72. cb(declaration.id.name);
  73. } else if (declaration.type === VARIABLE_DECLARATION) {
  74. declaration.declarations.forEach((_ref2) => {let id = _ref2.id;
  75. cb(id.name);
  76. });
  77. }
  78. }
  79. }
  80. /**
  81. * List of imports per file.
  82. *
  83. * Represented by a two-level Map to a Set of identifiers. The upper-level Map
  84. * keys are the paths to the modules containing the imports, while the
  85. * lower-level Map keys are the paths to the files which are being imported
  86. * from. Lastly, the Set of identifiers contains either names being imported
  87. * or a special AST node name listed above (e.g ImportDefaultSpecifier).
  88. *
  89. * For example, if we have a file named foo.js containing:
  90. *
  91. * import { o2 } from './bar.js';
  92. *
  93. * Then we will have a structure that looks like:
  94. *
  95. * Map { 'foo.js' => Map { 'bar.js' => Set { 'o2' } } }
  96. *
  97. * @type {Map<string, Map<string, Set<string>>>}
  98. */
  99. const importList = new Map();
  100. /**
  101. * List of exports per file.
  102. *
  103. * Represented by a two-level Map to an object of metadata. The upper-level Map
  104. * keys are the paths to the modules containing the exports, while the
  105. * lower-level Map keys are the specific identifiers or special AST node names
  106. * being exported. The leaf-level metadata object at the moment only contains a
  107. * `whereUsed` propoerty, which contains a Set of paths to modules that import
  108. * the name.
  109. *
  110. * For example, if we have a file named bar.js containing the following exports:
  111. *
  112. * const o2 = 'bar';
  113. * export { o2 };
  114. *
  115. * And a file named foo.js containing the following import:
  116. *
  117. * import { o2 } from './bar.js';
  118. *
  119. * Then we will have a structure that looks like:
  120. *
  121. * Map { 'bar.js' => Map { 'o2' => { whereUsed: Set { 'foo.js' } } } }
  122. *
  123. * @type {Map<string, Map<string, object>>}
  124. */
  125. const exportList = new Map();
  126. const ignoredFiles = new Set();
  127. const filesOutsideSrc = new Set();
  128. const isNodeModule = path => {
  129. return (/\/(node_modules)\//.test(path));
  130. };
  131. /**
  132. * read all files matching the patterns in src and ignoreExports
  133. *
  134. * return all files matching src pattern, which are not matching the ignoreExports pattern
  135. */
  136. const resolveFiles = (src, ignoreExports, context) => {
  137. const extensions = Array.from((0, _ignore.getFileExtensions)(context.settings));
  138. const srcFiles = new Set();
  139. const srcFileList = listFilesToProcess(src, extensions);
  140. // prepare list of ignored files
  141. const ignoredFilesList = listFilesToProcess(ignoreExports, extensions);
  142. ignoredFilesList.forEach((_ref3) => {let filename = _ref3.filename;return ignoredFiles.add(filename);});
  143. // prepare list of source files, don't consider files from node_modules
  144. srcFileList.filter((_ref4) => {let filename = _ref4.filename;return !isNodeModule(filename);}).forEach((_ref5) => {let filename = _ref5.filename;
  145. srcFiles.add(filename);
  146. });
  147. return srcFiles;
  148. };
  149. /**
  150. * parse all source files and build up 2 maps containing the existing imports and exports
  151. */
  152. const prepareImportsAndExports = (srcFiles, context) => {
  153. const exportAll = new Map();
  154. srcFiles.forEach(file => {
  155. const exports = new Map();
  156. const imports = new Map();
  157. const currentExports = _ExportMap2.default.get(file, context);
  158. if (currentExports) {const
  159. dependencies = currentExports.dependencies,reexports = currentExports.reexports,localImportList = currentExports.imports,namespace = currentExports.namespace;
  160. // dependencies === export * from
  161. const currentExportAll = new Set();
  162. dependencies.forEach(getDependency => {
  163. const dependency = getDependency();
  164. if (dependency === null) {
  165. return;
  166. }
  167. currentExportAll.add(dependency.path);
  168. });
  169. exportAll.set(file, currentExportAll);
  170. reexports.forEach((value, key) => {
  171. if (key === DEFAULT) {
  172. exports.set(IMPORT_DEFAULT_SPECIFIER, { whereUsed: new Set() });
  173. } else {
  174. exports.set(key, { whereUsed: new Set() });
  175. }
  176. const reexport = value.getImport();
  177. if (!reexport) {
  178. return;
  179. }
  180. let localImport = imports.get(reexport.path);
  181. let currentValue;
  182. if (value.local === DEFAULT) {
  183. currentValue = IMPORT_DEFAULT_SPECIFIER;
  184. } else {
  185. currentValue = value.local;
  186. }
  187. if (typeof localImport !== 'undefined') {
  188. localImport = new Set([].concat(_toConsumableArray(localImport), [currentValue]));
  189. } else {
  190. localImport = new Set([currentValue]);
  191. }
  192. imports.set(reexport.path, localImport);
  193. });
  194. localImportList.forEach((value, key) => {
  195. if (isNodeModule(key)) {
  196. return;
  197. }
  198. let localImport = imports.get(key);
  199. if (typeof localImport !== 'undefined') {
  200. localImport = new Set([].concat(_toConsumableArray(localImport), _toConsumableArray(value.importedSpecifiers)));
  201. } else {
  202. localImport = value.importedSpecifiers;
  203. }
  204. imports.set(key, localImport);
  205. });
  206. importList.set(file, imports);
  207. // build up export list only, if file is not ignored
  208. if (ignoredFiles.has(file)) {
  209. return;
  210. }
  211. namespace.forEach((value, key) => {
  212. if (key === DEFAULT) {
  213. exports.set(IMPORT_DEFAULT_SPECIFIER, { whereUsed: new Set() });
  214. } else {
  215. exports.set(key, { whereUsed: new Set() });
  216. }
  217. });
  218. }
  219. exports.set(EXPORT_ALL_DECLARATION, { whereUsed: new Set() });
  220. exports.set(IMPORT_NAMESPACE_SPECIFIER, { whereUsed: new Set() });
  221. exportList.set(file, exports);
  222. });
  223. exportAll.forEach((value, key) => {
  224. value.forEach(val => {
  225. const currentExports = exportList.get(val);
  226. const currentExport = currentExports.get(EXPORT_ALL_DECLARATION);
  227. currentExport.whereUsed.add(key);
  228. });
  229. });
  230. };
  231. /**
  232. * traverse through all imports and add the respective path to the whereUsed-list
  233. * of the corresponding export
  234. */
  235. const determineUsage = () => {
  236. importList.forEach((listValue, listKey) => {
  237. listValue.forEach((value, key) => {
  238. const exports = exportList.get(key);
  239. if (typeof exports !== 'undefined') {
  240. value.forEach(currentImport => {
  241. let specifier;
  242. if (currentImport === IMPORT_NAMESPACE_SPECIFIER) {
  243. specifier = IMPORT_NAMESPACE_SPECIFIER;
  244. } else if (currentImport === IMPORT_DEFAULT_SPECIFIER) {
  245. specifier = IMPORT_DEFAULT_SPECIFIER;
  246. } else {
  247. specifier = currentImport;
  248. }
  249. if (typeof specifier !== 'undefined') {
  250. const exportStatement = exports.get(specifier);
  251. if (typeof exportStatement !== 'undefined') {const
  252. whereUsed = exportStatement.whereUsed;
  253. whereUsed.add(listKey);
  254. exports.set(specifier, { whereUsed });
  255. }
  256. }
  257. });
  258. }
  259. });
  260. });
  261. };
  262. const getSrc = src => {
  263. if (src) {
  264. return src;
  265. }
  266. return [process.cwd()];
  267. };
  268. /**
  269. * prepare the lists of existing imports and exports - should only be executed once at
  270. * the start of a new eslint run
  271. */
  272. let srcFiles;
  273. let lastPrepareKey;
  274. const doPreparation = (src, ignoreExports, context) => {
  275. const prepareKey = JSON.stringify({
  276. src: (src || []).sort(),
  277. ignoreExports: (ignoreExports || []).sort(),
  278. extensions: Array.from((0, _ignore.getFileExtensions)(context.settings)).sort() });
  279. if (prepareKey === lastPrepareKey) {
  280. return;
  281. }
  282. importList.clear();
  283. exportList.clear();
  284. ignoredFiles.clear();
  285. filesOutsideSrc.clear();
  286. srcFiles = resolveFiles(getSrc(src), ignoreExports, context);
  287. prepareImportsAndExports(srcFiles, context);
  288. determineUsage();
  289. lastPrepareKey = prepareKey;
  290. };
  291. const newNamespaceImportExists = specifiers =>
  292. specifiers.some((_ref6) => {let type = _ref6.type;return type === IMPORT_NAMESPACE_SPECIFIER;});
  293. const newDefaultImportExists = specifiers =>
  294. specifiers.some((_ref7) => {let type = _ref7.type;return type === IMPORT_DEFAULT_SPECIFIER;});
  295. const fileIsInPkg = file => {var _readPkgUp$sync =
  296. _readPkgUp2.default.sync({ cwd: file, normalize: false });const path = _readPkgUp$sync.path,pkg = _readPkgUp$sync.pkg;
  297. const basePath = (0, _path.dirname)(path);
  298. const checkPkgFieldString = pkgField => {
  299. if ((0, _path.join)(basePath, pkgField) === file) {
  300. return true;
  301. }
  302. };
  303. const checkPkgFieldObject = pkgField => {
  304. const pkgFieldFiles = (0, _object2.default)(pkgField).map(value => (0, _path.join)(basePath, value));
  305. if ((0, _arrayIncludes2.default)(pkgFieldFiles, file)) {
  306. return true;
  307. }
  308. };
  309. const checkPkgField = pkgField => {
  310. if (typeof pkgField === 'string') {
  311. return checkPkgFieldString(pkgField);
  312. }
  313. if (typeof pkgField === 'object') {
  314. return checkPkgFieldObject(pkgField);
  315. }
  316. };
  317. if (pkg.private === true) {
  318. return false;
  319. }
  320. if (pkg.bin) {
  321. if (checkPkgField(pkg.bin)) {
  322. return true;
  323. }
  324. }
  325. if (pkg.browser) {
  326. if (checkPkgField(pkg.browser)) {
  327. return true;
  328. }
  329. }
  330. if (pkg.main) {
  331. if (checkPkgFieldString(pkg.main)) {
  332. return true;
  333. }
  334. }
  335. return false;
  336. };
  337. module.exports = {
  338. meta: {
  339. type: 'suggestion',
  340. docs: { url: (0, _docsUrl2.default)('no-unused-modules') },
  341. schema: [{
  342. properties: {
  343. src: {
  344. description: 'files/paths to be analyzed (only for unused exports)',
  345. type: 'array',
  346. minItems: 1,
  347. items: {
  348. type: 'string',
  349. minLength: 1 } },
  350. ignoreExports: {
  351. description:
  352. 'files/paths for which unused exports will not be reported (e.g module entry points)',
  353. type: 'array',
  354. minItems: 1,
  355. items: {
  356. type: 'string',
  357. minLength: 1 } },
  358. missingExports: {
  359. description: 'report modules without any exports',
  360. type: 'boolean' },
  361. unusedExports: {
  362. description: 'report exports without any usage',
  363. type: 'boolean' } },
  364. not: {
  365. properties: {
  366. unusedExports: { enum: [false] },
  367. missingExports: { enum: [false] } } },
  368. anyOf: [{
  369. not: {
  370. properties: {
  371. unusedExports: { enum: [true] } } },
  372. required: ['missingExports'] },
  373. {
  374. not: {
  375. properties: {
  376. missingExports: { enum: [true] } } },
  377. required: ['unusedExports'] },
  378. {
  379. properties: {
  380. unusedExports: { enum: [true] } },
  381. required: ['unusedExports'] },
  382. {
  383. properties: {
  384. missingExports: { enum: [true] } },
  385. required: ['missingExports'] }] }] },
  386. create: context => {var _ref8 =
  387. context.options[0] || {};const src = _ref8.src;var _ref8$ignoreExports = _ref8.ignoreExports;const ignoreExports = _ref8$ignoreExports === undefined ? [] : _ref8$ignoreExports,missingExports = _ref8.missingExports,unusedExports = _ref8.unusedExports;
  388. if (unusedExports) {
  389. doPreparation(src, ignoreExports, context);
  390. }
  391. const file = context.getFilename();
  392. const checkExportPresence = node => {
  393. if (!missingExports) {
  394. return;
  395. }
  396. if (ignoredFiles.has(file)) {
  397. return;
  398. }
  399. const exportCount = exportList.get(file);
  400. const exportAll = exportCount.get(EXPORT_ALL_DECLARATION);
  401. const namespaceImports = exportCount.get(IMPORT_NAMESPACE_SPECIFIER);
  402. exportCount.delete(EXPORT_ALL_DECLARATION);
  403. exportCount.delete(IMPORT_NAMESPACE_SPECIFIER);
  404. if (exportCount.size < 1) {
  405. // node.body[0] === 'undefined' only happens, if everything is commented out in the file
  406. // being linted
  407. context.report(node.body[0] ? node.body[0] : node, 'No exports found');
  408. }
  409. exportCount.set(EXPORT_ALL_DECLARATION, exportAll);
  410. exportCount.set(IMPORT_NAMESPACE_SPECIFIER, namespaceImports);
  411. };
  412. const checkUsage = (node, exportedValue) => {
  413. if (!unusedExports) {
  414. return;
  415. }
  416. if (ignoredFiles.has(file)) {
  417. return;
  418. }
  419. if (fileIsInPkg(file)) {
  420. return;
  421. }
  422. if (filesOutsideSrc.has(file)) {
  423. return;
  424. }
  425. // make sure file to be linted is included in source files
  426. if (!srcFiles.has(file)) {
  427. srcFiles = resolveFiles(getSrc(src), ignoreExports, context);
  428. if (!srcFiles.has(file)) {
  429. filesOutsideSrc.add(file);
  430. return;
  431. }
  432. }
  433. exports = exportList.get(file);
  434. // special case: export * from
  435. const exportAll = exports.get(EXPORT_ALL_DECLARATION);
  436. if (typeof exportAll !== 'undefined' && exportedValue !== IMPORT_DEFAULT_SPECIFIER) {
  437. if (exportAll.whereUsed.size > 0) {
  438. return;
  439. }
  440. }
  441. // special case: namespace import
  442. const namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER);
  443. if (typeof namespaceImports !== 'undefined') {
  444. if (namespaceImports.whereUsed.size > 0) {
  445. return;
  446. }
  447. }
  448. // exportsList will always map any imported value of 'default' to 'ImportDefaultSpecifier'
  449. const exportsKey = exportedValue === DEFAULT ? IMPORT_DEFAULT_SPECIFIER : exportedValue;
  450. const exportStatement = exports.get(exportsKey);
  451. const value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey;
  452. if (typeof exportStatement !== 'undefined') {
  453. if (exportStatement.whereUsed.size < 1) {
  454. context.report(
  455. node,
  456. `exported declaration '${value}' not used within other modules`);
  457. }
  458. } else {
  459. context.report(
  460. node,
  461. `exported declaration '${value}' not used within other modules`);
  462. }
  463. };
  464. /**
  465. * only useful for tools like vscode-eslint
  466. *
  467. * update lists of existing exports during runtime
  468. */
  469. const updateExportUsage = node => {
  470. if (ignoredFiles.has(file)) {
  471. return;
  472. }
  473. let exports = exportList.get(file);
  474. // new module has been created during runtime
  475. // include it in further processing
  476. if (typeof exports === 'undefined') {
  477. exports = new Map();
  478. }
  479. const newExports = new Map();
  480. const newExportIdentifiers = new Set();
  481. node.body.forEach((_ref9) => {let type = _ref9.type,declaration = _ref9.declaration,specifiers = _ref9.specifiers;
  482. if (type === EXPORT_DEFAULT_DECLARATION) {
  483. newExportIdentifiers.add(IMPORT_DEFAULT_SPECIFIER);
  484. }
  485. if (type === EXPORT_NAMED_DECLARATION) {
  486. if (specifiers.length > 0) {
  487. specifiers.forEach(specifier => {
  488. if (specifier.exported) {
  489. newExportIdentifiers.add(specifier.exported.name);
  490. }
  491. });
  492. }
  493. forEachDeclarationIdentifier(declaration, name => {
  494. newExportIdentifiers.add(name);
  495. });
  496. }
  497. });
  498. // old exports exist within list of new exports identifiers: add to map of new exports
  499. exports.forEach((value, key) => {
  500. if (newExportIdentifiers.has(key)) {
  501. newExports.set(key, value);
  502. }
  503. });
  504. // new export identifiers added: add to map of new exports
  505. newExportIdentifiers.forEach(key => {
  506. if (!exports.has(key)) {
  507. newExports.set(key, { whereUsed: new Set() });
  508. }
  509. });
  510. // preserve information about namespace imports
  511. let exportAll = exports.get(EXPORT_ALL_DECLARATION);
  512. let namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER);
  513. if (typeof namespaceImports === 'undefined') {
  514. namespaceImports = { whereUsed: new Set() };
  515. }
  516. newExports.set(EXPORT_ALL_DECLARATION, exportAll);
  517. newExports.set(IMPORT_NAMESPACE_SPECIFIER, namespaceImports);
  518. exportList.set(file, newExports);
  519. };
  520. /**
  521. * only useful for tools like vscode-eslint
  522. *
  523. * update lists of existing imports during runtime
  524. */
  525. const updateImportUsage = node => {
  526. if (!unusedExports) {
  527. return;
  528. }
  529. let oldImportPaths = importList.get(file);
  530. if (typeof oldImportPaths === 'undefined') {
  531. oldImportPaths = new Map();
  532. }
  533. const oldNamespaceImports = new Set();
  534. const newNamespaceImports = new Set();
  535. const oldExportAll = new Set();
  536. const newExportAll = new Set();
  537. const oldDefaultImports = new Set();
  538. const newDefaultImports = new Set();
  539. const oldImports = new Map();
  540. const newImports = new Map();
  541. oldImportPaths.forEach((value, key) => {
  542. if (value.has(EXPORT_ALL_DECLARATION)) {
  543. oldExportAll.add(key);
  544. }
  545. if (value.has(IMPORT_NAMESPACE_SPECIFIER)) {
  546. oldNamespaceImports.add(key);
  547. }
  548. if (value.has(IMPORT_DEFAULT_SPECIFIER)) {
  549. oldDefaultImports.add(key);
  550. }
  551. value.forEach(val => {
  552. if (val !== IMPORT_NAMESPACE_SPECIFIER &&
  553. val !== IMPORT_DEFAULT_SPECIFIER) {
  554. oldImports.set(val, key);
  555. }
  556. });
  557. });
  558. node.body.forEach(astNode => {
  559. let resolvedPath;
  560. // support for export { value } from 'module'
  561. if (astNode.type === EXPORT_NAMED_DECLARATION) {
  562. if (astNode.source) {
  563. resolvedPath = (0, _resolve2.default)(astNode.source.raw.replace(/('|")/g, ''), context);
  564. astNode.specifiers.forEach(specifier => {
  565. const name = specifier.local.name;
  566. if (specifier.local.name === DEFAULT) {
  567. newDefaultImports.add(resolvedPath);
  568. } else {
  569. newImports.set(name, resolvedPath);
  570. }
  571. });
  572. }
  573. }
  574. if (astNode.type === EXPORT_ALL_DECLARATION) {
  575. resolvedPath = (0, _resolve2.default)(astNode.source.raw.replace(/('|")/g, ''), context);
  576. newExportAll.add(resolvedPath);
  577. }
  578. if (astNode.type === IMPORT_DECLARATION) {
  579. resolvedPath = (0, _resolve2.default)(astNode.source.raw.replace(/('|")/g, ''), context);
  580. if (!resolvedPath) {
  581. return;
  582. }
  583. if (isNodeModule(resolvedPath)) {
  584. return;
  585. }
  586. if (newNamespaceImportExists(astNode.specifiers)) {
  587. newNamespaceImports.add(resolvedPath);
  588. }
  589. if (newDefaultImportExists(astNode.specifiers)) {
  590. newDefaultImports.add(resolvedPath);
  591. }
  592. astNode.specifiers.forEach(specifier => {
  593. if (specifier.type === IMPORT_DEFAULT_SPECIFIER ||
  594. specifier.type === IMPORT_NAMESPACE_SPECIFIER) {
  595. return;
  596. }
  597. newImports.set(specifier.imported.name, resolvedPath);
  598. });
  599. }
  600. });
  601. newExportAll.forEach(value => {
  602. if (!oldExportAll.has(value)) {
  603. let imports = oldImportPaths.get(value);
  604. if (typeof imports === 'undefined') {
  605. imports = new Set();
  606. }
  607. imports.add(EXPORT_ALL_DECLARATION);
  608. oldImportPaths.set(value, imports);
  609. let exports = exportList.get(value);
  610. let currentExport;
  611. if (typeof exports !== 'undefined') {
  612. currentExport = exports.get(EXPORT_ALL_DECLARATION);
  613. } else {
  614. exports = new Map();
  615. exportList.set(value, exports);
  616. }
  617. if (typeof currentExport !== 'undefined') {
  618. currentExport.whereUsed.add(file);
  619. } else {
  620. const whereUsed = new Set();
  621. whereUsed.add(file);
  622. exports.set(EXPORT_ALL_DECLARATION, { whereUsed });
  623. }
  624. }
  625. });
  626. oldExportAll.forEach(value => {
  627. if (!newExportAll.has(value)) {
  628. const imports = oldImportPaths.get(value);
  629. imports.delete(EXPORT_ALL_DECLARATION);
  630. const exports = exportList.get(value);
  631. if (typeof exports !== 'undefined') {
  632. const currentExport = exports.get(EXPORT_ALL_DECLARATION);
  633. if (typeof currentExport !== 'undefined') {
  634. currentExport.whereUsed.delete(file);
  635. }
  636. }
  637. }
  638. });
  639. newDefaultImports.forEach(value => {
  640. if (!oldDefaultImports.has(value)) {
  641. let imports = oldImportPaths.get(value);
  642. if (typeof imports === 'undefined') {
  643. imports = new Set();
  644. }
  645. imports.add(IMPORT_DEFAULT_SPECIFIER);
  646. oldImportPaths.set(value, imports);
  647. let exports = exportList.get(value);
  648. let currentExport;
  649. if (typeof exports !== 'undefined') {
  650. currentExport = exports.get(IMPORT_DEFAULT_SPECIFIER);
  651. } else {
  652. exports = new Map();
  653. exportList.set(value, exports);
  654. }
  655. if (typeof currentExport !== 'undefined') {
  656. currentExport.whereUsed.add(file);
  657. } else {
  658. const whereUsed = new Set();
  659. whereUsed.add(file);
  660. exports.set(IMPORT_DEFAULT_SPECIFIER, { whereUsed });
  661. }
  662. }
  663. });
  664. oldDefaultImports.forEach(value => {
  665. if (!newDefaultImports.has(value)) {
  666. const imports = oldImportPaths.get(value);
  667. imports.delete(IMPORT_DEFAULT_SPECIFIER);
  668. const exports = exportList.get(value);
  669. if (typeof exports !== 'undefined') {
  670. const currentExport = exports.get(IMPORT_DEFAULT_SPECIFIER);
  671. if (typeof currentExport !== 'undefined') {
  672. currentExport.whereUsed.delete(file);
  673. }
  674. }
  675. }
  676. });
  677. newNamespaceImports.forEach(value => {
  678. if (!oldNamespaceImports.has(value)) {
  679. let imports = oldImportPaths.get(value);
  680. if (typeof imports === 'undefined') {
  681. imports = new Set();
  682. }
  683. imports.add(IMPORT_NAMESPACE_SPECIFIER);
  684. oldImportPaths.set(value, imports);
  685. let exports = exportList.get(value);
  686. let currentExport;
  687. if (typeof exports !== 'undefined') {
  688. currentExport = exports.get(IMPORT_NAMESPACE_SPECIFIER);
  689. } else {
  690. exports = new Map();
  691. exportList.set(value, exports);
  692. }
  693. if (typeof currentExport !== 'undefined') {
  694. currentExport.whereUsed.add(file);
  695. } else {
  696. const whereUsed = new Set();
  697. whereUsed.add(file);
  698. exports.set(IMPORT_NAMESPACE_SPECIFIER, { whereUsed });
  699. }
  700. }
  701. });
  702. oldNamespaceImports.forEach(value => {
  703. if (!newNamespaceImports.has(value)) {
  704. const imports = oldImportPaths.get(value);
  705. imports.delete(IMPORT_NAMESPACE_SPECIFIER);
  706. const exports = exportList.get(value);
  707. if (typeof exports !== 'undefined') {
  708. const currentExport = exports.get(IMPORT_NAMESPACE_SPECIFIER);
  709. if (typeof currentExport !== 'undefined') {
  710. currentExport.whereUsed.delete(file);
  711. }
  712. }
  713. }
  714. });
  715. newImports.forEach((value, key) => {
  716. if (!oldImports.has(key)) {
  717. let imports = oldImportPaths.get(value);
  718. if (typeof imports === 'undefined') {
  719. imports = new Set();
  720. }
  721. imports.add(key);
  722. oldImportPaths.set(value, imports);
  723. let exports = exportList.get(value);
  724. let currentExport;
  725. if (typeof exports !== 'undefined') {
  726. currentExport = exports.get(key);
  727. } else {
  728. exports = new Map();
  729. exportList.set(value, exports);
  730. }
  731. if (typeof currentExport !== 'undefined') {
  732. currentExport.whereUsed.add(file);
  733. } else {
  734. const whereUsed = new Set();
  735. whereUsed.add(file);
  736. exports.set(key, { whereUsed });
  737. }
  738. }
  739. });
  740. oldImports.forEach((value, key) => {
  741. if (!newImports.has(key)) {
  742. const imports = oldImportPaths.get(value);
  743. imports.delete(key);
  744. const exports = exportList.get(value);
  745. if (typeof exports !== 'undefined') {
  746. const currentExport = exports.get(key);
  747. if (typeof currentExport !== 'undefined') {
  748. currentExport.whereUsed.delete(file);
  749. }
  750. }
  751. }
  752. });
  753. };
  754. return {
  755. 'Program:exit': node => {
  756. updateExportUsage(node);
  757. updateImportUsage(node);
  758. checkExportPresence(node);
  759. },
  760. 'ExportDefaultDeclaration': node => {
  761. checkUsage(node, IMPORT_DEFAULT_SPECIFIER);
  762. },
  763. 'ExportNamedDeclaration': node => {
  764. node.specifiers.forEach(specifier => {
  765. checkUsage(node, specifier.exported.name);
  766. });
  767. forEachDeclarationIdentifier(node.declaration, name => {
  768. checkUsage(node, name);
  769. });
  770. } };
  771. } };
  772. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby11bnVzZWQtbW9kdWxlcy5qcyJdLC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