UNPKG

node-dependency-injection

Version:

The NodeDependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.

1 lines 4.88 kB
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _PassConfig=_interopRequireDefault(require("../PassConfig"));var _OptimizePass=_interopRequireDefault(require("./OptimizePass"));var _RemovePass=_interopRequireDefault(require("./RemovePass"));var _DecoratePass=_interopRequireDefault(require("./DecoratePass"));var _ProcessMethodNotFoundException=_interopRequireDefault(require("../Exception/ProcessMethodNotFoundException"));var _WrongCompilerPassTypeException=_interopRequireDefault(require("../Exception/WrongCompilerPassTypeException"));function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}var CompilerPass=exports["default"]=function(){function CompilerPass(container){(0,_classCallCheck2["default"])(this,CompilerPass);this._container=container;this.beforeOptimization=[];this.optimize=[];this.beforeRemoving=[];this.remove=[];this.afterRemoving=[];}return(0,_createClass2["default"])(CompilerPass,[{key:"_getCompilerPassPriorityNumber",value:function _getCompilerPassPriorityNumber(type,priority){if(this[type][priority]){return this._getCompilerPassPriorityNumber(type,priority+1);}return priority;}},{key:"register",value:function register(compilerPass,type,priority){if(typeof compilerPass.process!=='function'){throw new _ProcessMethodNotFoundException["default"](compilerPass.constructor.name);}if(!_PassConfig["default"].isValidType(type)){throw new _WrongCompilerPassTypeException["default"](type);}var arrayLevel=this._getCompilerPassPriorityNumber(type,priority);this[type][arrayLevel]=compilerPass;}},{key:"_checkAndAdd",value:(function(){var _checkAndAdd2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(type){return _regenerator["default"].wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(this._container._compilerPass[type].length===0){if(type===_PassConfig["default"].TYPE_BEFORE_OPTIMIZATION){this.register(new _DecoratePass["default"](),type,0);}else if(type===_PassConfig["default"].TYPE_OPTIMIZE){this.register(new _OptimizePass["default"](),type,0);}else if(type===_PassConfig["default"].TYPE_REMOVE){this.register(new _RemovePass["default"](),type,0);}}case 1:case"end":return _context.stop();}},_callee,this);}));function _checkAndAdd(_x){return _checkAndAdd2.apply(this,arguments);}return _checkAndAdd;}())},{key:"process",value:(function(){var _process=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(type){var promises,_iterator,_step,compilerPass;return _regenerator["default"].wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:_context2.next=2;return this._checkAndAdd(type);case 2:this[type]=this[type].filter(function(i){return i!==null;});promises=[];_iterator=_createForOfIteratorHelper(this[type]);try{for(_iterator.s();!(_step=_iterator.n()).done;){compilerPass=_step.value;this._container.loggerHelper.debug("Executing compiler pass: ".concat(compilerPass.constructor.name));promises.push(compilerPass.process(this._container));}}catch(err){_iterator.e(err);}finally{_iterator.f();}_context2.next=8;return Promise.all(promises);case 8:case"end":return _context2.stop();}},_callee2,this);}));function process(_x2){return _process.apply(this,arguments);}return process;}())}]);}();