the-forest/client/node_modules/eslint-plugin-import/lib/scc.js

86 lines
12 KiB
JavaScript
Raw Normal View History

2024-09-17 20:35:18 -04:00
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _scc = require('@rtsao/scc');var _scc2 = _interopRequireDefault(_scc);
var _hash = require('eslint-module-utils/hash');
var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
var _builder = require('./exportMap/builder');var _builder2 = _interopRequireDefault(_builder);
var _childContext = require('./exportMap/childContext');var _childContext2 = _interopRequireDefault(_childContext);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);}}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}
var cache = new Map();var
StronglyConnectedComponentsBuilder = function () {function StronglyConnectedComponentsBuilder() {_classCallCheck(this, StronglyConnectedComponentsBuilder);}_createClass(StronglyConnectedComponentsBuilder, null, [{ key: 'clearCache', value: function () {function clearCache()
{
cache = new Map();
}return clearCache;}() }, { key: 'get', value: function () {function get(
source, context) {
var path = (0, _resolve2['default'])(source, context);
if (path == null) {return null;}
return StronglyConnectedComponentsBuilder['for']((0, _childContext2['default'])(path, context));
}return get;}() }, { key: 'for', value: function () {function _for(
context) {
var cacheKey = context.cacheKey || (0, _hash.hashObject)(context).digest('hex');
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
var scc = StronglyConnectedComponentsBuilder.calculate(context);
cache.set(cacheKey, scc);
return scc;
}return _for;}() }, { key: 'calculate', value: function () {function calculate(
context) {
var exportMap = _builder2['default']['for'](context);
var adjacencyList = this.exportMapToAdjacencyList(exportMap);
var calculatedScc = (0, _scc2['default'])(adjacencyList);
return StronglyConnectedComponentsBuilder.calculatedSccToPlainObject(calculatedScc);
}return calculate;}()
/** @returns {Map<string, Set<string>>} for each dep, what are its direct deps */ }, { key: 'exportMapToAdjacencyList', value: function () {function exportMapToAdjacencyList(
initialExportMap) {
var adjacencyList = new Map();
// BFS
function visitNode(exportMap) {
if (!exportMap) {
return;
}
exportMap.imports.forEach(function (v, importedPath) {
var from = exportMap.path;
var to = importedPath;
// Ignore type-only imports, because we care only about SCCs of value imports
var toTraverse = [].concat(_toConsumableArray(v.declarations)).filter(function (_ref) {var isOnlyImportingTypes = _ref.isOnlyImportingTypes;return !isOnlyImportingTypes;});
if (toTraverse.length === 0) {return;}
if (!adjacencyList.has(from)) {
adjacencyList.set(from, new Set());
}
if (adjacencyList.get(from).has(to)) {
return; // prevent endless loop
}
adjacencyList.get(from).add(to);
visitNode(v.getter());
});
}
visitNode(initialExportMap);
// Fill gaps
adjacencyList.forEach(function (values) {
values.forEach(function (value) {
if (!adjacencyList.has(value)) {
adjacencyList.set(value, new Set());
}
});
});
return adjacencyList;
}return exportMapToAdjacencyList;}()
/** @returns {Record<string, number>} for each key, its SCC's index */ }, { key: 'calculatedSccToPlainObject', value: function () {function calculatedSccToPlainObject(
sccs) {
var obj = {};
sccs.forEach(function (scc, index) {
scc.forEach(function (node) {
obj[node] = index;
});
});
return obj;
}return calculatedSccToPlainObject;}() }]);return StronglyConnectedComponentsBuilder;}();exports['default'] = StronglyConnectedComponentsBuilder;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9zY2MuanMiXSwibmFtZXMiOlsiY2FjaGUiLCJNYXAiLCJTdHJvbmdseU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