You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
js-analyzer/src/frontend/circular-dependency-contain...

41 lines
1.0 KiB
JavaScript

'use strict';
/* This is a workaround for handling circular dependencies in CommonJS. */
// module.exports = function createDependencyContainer(cb) {
// let api = {
// _dependencies: new Map(),
// _moduleContents: undefined,
// get: function getModuleContents () {
// return this._moduleContents;
// },
// set: function setDependency(name, dependency) {
// this._dependencies.set(name, dependency);
// }
// };
//
// let getDependency = function getDependency(name) {
// return api._dependencies.get(name);
// };
//
// api._moduleContents = cb(getDependency);
//
// return api;
// };
module.exports = function createDependencyContainer() {
return {
_dependencies: new Map(),
get: function getDependency(name) {
if (this._dependencies.has(name)) {
return this._dependencies.get(name);
} else {
throw new Error(`No dependency named '${name}' exists in this dependency container`);
}
},
set: function setDependency(name, contents) {
return this._dependencies.set(name, contents);
}
};
};