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.

104 lines
14 KiB

  1. 'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}(); /**
  2. * @fileOverview Ensures that no imported module imports the linted module.
  3. * @author Ben Mosher
  4. */
  5. var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
  6. var _importType = require('../core/importType');
  7. var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
  8. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  9. // todo: cache cycles / deep relationships for faster repeat evaluation
  10. module.exports = {
  11. meta: {
  12. type: 'suggestion',
  13. docs: { url: (0, _docsUrl2.default)('no-cycle') },
  14. schema: [(0, _moduleVisitor.makeOptionsSchema)({
  15. maxDepth: {
  16. oneOf: [
  17. {
  18. description: 'maximum dependency depth to traverse',
  19. type: 'integer',
  20. minimum: 1 },
  21. {
  22. enum: ['∞'],
  23. type: 'string' }] },
  24. ignoreExternal: {
  25. description: 'ignore external modules',
  26. type: 'boolean',
  27. default: false } })] },
  28. create: function (context) {
  29. const myPath = context.getFilename();
  30. if (myPath === '<text>') return {}; // can't cycle-check a non-file
  31. const options = context.options[0] || {};
  32. const maxDepth = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity;
  33. const ignoreModule = name => options.ignoreExternal ? (0, _importType.isExternalModule)(name) : false;
  34. function checkSourceValue(sourceNode, importer) {
  35. if (ignoreModule(sourceNode.value)) {
  36. return; // ignore external modules
  37. }
  38. const imported = _ExportMap2.default.get(sourceNode.value, context);
  39. if (importer.importKind === 'type') {
  40. return; // no Flow import resolution
  41. }
  42. if (imported == null) {
  43. return; // no-unresolved territory
  44. }
  45. if (imported.path === myPath) {
  46. return; // no-self-import territory
  47. }
  48. const untraversed = [{ mget: () => imported, route: [] }];
  49. const traversed = new Set();
  50. function detectCycle(_ref) {let mget = _ref.mget,route = _ref.route;
  51. const m = mget();
  52. if (m == null) return;
  53. if (traversed.has(m.path)) return;
  54. traversed.add(m.path);
  55. for (let _ref2 of m.imports) {var _ref3 = _slicedToArray(_ref2, 2);let path = _ref3[0];var _ref3$ = _ref3[1];let getter = _ref3$.getter;let source = _ref3$.source;
  56. if (path === myPath) return true;
  57. if (traversed.has(path)) continue;
  58. if (ignoreModule(source.value)) continue;
  59. if (route.length + 1 < maxDepth) {
  60. untraversed.push({
  61. mget: getter,
  62. route: route.concat(source) });
  63. }
  64. }
  65. }
  66. while (untraversed.length > 0) {
  67. const next = untraversed.shift(); // bfs!
  68. if (detectCycle(next)) {
  69. const message = next.route.length > 0 ?
  70. `Dependency cycle via ${routeString(next.route)}` :
  71. 'Dependency cycle detected.';
  72. context.report(importer, message);
  73. return;
  74. }
  75. }
  76. }
  77. return (0, _moduleVisitor2.default)(checkSourceValue, context.options[0]);
  78. } };
  79. function routeString(route) {
  80. return route.map(s => `${s.value}:${s.loc.start.line}`).join('=>');
  81. }
  82. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jeWNsZS5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwibWF4RGVwdGgiLC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