UNPKG

lfr-amd-loader

Version:

AMD Loader with support for combo URL and conditional loading

688 lines (686 loc) 20.9 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for umd/dependency-builder.js</title> <meta charset="utf-8"> <link rel="stylesheet" href="../prettify.css"> <link rel="stylesheet" href="../base.css"> <style type='text/css'> div.coverage-summary .sorter { background-image: url(../sort-arrow-sprite.png); } </style> </head> <body> <div class="header high"> <h1>Code coverage report for <span class="entity">umd/dependency-builder.js</span></h1> <h2> Statements: <span class="metric">100% <small>(63 / 63)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Branches: <span class="metric">100% <small>(32 / 32)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Functions: <span class="metric">100% <small>(9 / 9)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Lines: <span class="metric">100% <small>(63 / 63)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Ignored: <span class="metric">1 statement, 5 branches</span> &nbsp;&nbsp;&nbsp;&nbsp; </h2> <div class="path"><a href="../index.html">All files</a> &#187; <a href="index.html">umd/</a> &#187; dependency-builder.js</div> </div> <div class="body"> <pre><table class="coverage"> <tr><td class="line-count">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215</td><td class="line-coverage"><span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">18</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">18</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">15</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">15</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-yes">180</span> <span class="cline-any cline-yes">180</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">180</span> <span class="cline-any cline-yes">180</span> <span class="cline-any cline-yes">180</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">4</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">19</span> <span class="cline-any cline-yes">22</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">22</span> <span class="cline-any cline-yes">21</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">60</span> <span class="cline-any cline-yes">3</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57</span> <span class="cline-any cline-yes">47</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">47</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">47</span> <span class="cline-any cline-yes">50</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">50</span> <span class="cline-any cline-yes">10</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">40</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">40</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">40</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">39</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">40</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">40</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">40</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">(function (global, factory) { 'use strict'; &nbsp; var built = factory(global); &nbsp; /* istanbul ignore else */ <span class="skip-if-branch" title="else path not taken" >E</span>if (typeof module === 'object' &amp;&amp; module) { module.exports = built; } &nbsp; /* istanbul ignore next */ <span class="skip-if-branch" title="if path not taken" >I</span>if (typeof define === 'function' &amp;&amp; <span class="branch-1 cbranch-skip" title="branch not covered" >define.amd)</span> { <span class="cstat-skip" title="statement not covered" > define(factory);</span> } &nbsp; global.DependencyBuilder = built; }(typeof global !== 'undefined' ? global : /* istanbul ignore next */ <span class="branch-1 cbranch-skip" title="branch not covered" >this,</span> function (global) { &nbsp; 'use strict'; &nbsp; var hasOwnProperty = Object.prototype.hasOwnProperty; &nbsp; /** * Creates an instance of DependencyBuilder class. * * @constructor * @param {object} - instance of {@link ConfigParser} object. */ &nbsp; function DependencyBuilder(configParser) { this._configParser = configParser; &nbsp; this._result = []; } &nbsp; DependencyBuilder.prototype = { constructor: DependencyBuilder, &nbsp; /** * Resolves modules dependencies. * * @param {array} modules List of modules which dependencies should be resolved. * @return {array} List of module names, representing module dependencies. Module name itself is being returned too. */ resolveDependencies: function (modules) { // Copy the passed modules to a resolving modules queue. // Modules may be added there during the process of resolving. this._queue = modules.slice(0); &nbsp; var result; &nbsp; try { this._resolveDependencies(); &nbsp; // Reorder the modules list so the modules without dependencies will // be moved upfront result = this._result.reverse().slice(0); } finally { this._cleanup(); } &nbsp; return result; }, &nbsp; /** * Clears the used resources during the process of resolving dependencies. * * @protected */ _cleanup: function () { var modules = this._configParser.getModules(); &nbsp; // Set to false all temporary markers which were set during the process of // dependencies resolving. for (var key in modules) { /* istanbul ignore else */ <span class="skip-if-branch" title="else path not taken" >E</span>if (hasOwnProperty.call(modules, key)) { var module = modules[key]; &nbsp; module.conditionalMark = false; module.mark = false; module.tmpMark = false; } } &nbsp; this._queue.length = 0; this._result.length = 0; }, &nbsp; /** * Processes conditional modules. If a module has conditional module as dependency, this module will be added to * the list of modules, which dependencies should be resolved. * * @protected * @param {object} module Module, which will be checked for conditional modules as dependencies. */ _processConditionalModules: function (module) { var conditionalModules = this._configParser.getConditionalModules()[module.name]; &nbsp; // If the current module has conditional modules as dependencies, // add them to the list (queue) of modules, which have to be resolved. if (conditionalModules &amp;&amp; !module.conditionalMark) { var modules = this._configParser.getModules(); &nbsp; for (var i = 0; i &lt; conditionalModules.length; i++) { var conditionalModule = modules[conditionalModules[i]]; &nbsp; if (this._queue.indexOf(conditionalModule.name) === -1 &amp;&amp; this._testConditionalModule(conditionalModule.condition.test)) { &nbsp; this._queue.push(conditionalModule.name); } } &nbsp; module.conditionalMark = true; } }, &nbsp; /** * Processes all modules in the {@link DependencyBuilder#_queue} and resolves their dependencies. The function * implements standard * [topological sorting based on depth-first search]{@link http://en.wikipedia.org/wiki/Topological_sorting}. * * @protected */ _resolveDependencies: function () { // Process all modules in the queue. // Note: modules may be added to the queue during the process of evaluating. var modules = this._configParser.getModules(); &nbsp; for (var i = 0; i &lt; this._queue.length; i++) { var module = modules[this._queue[i]]; &nbsp; if (!module.mark) { this._visit(module); } } }, &nbsp; /** * Executes the test function of an conditional module and adds it to the list of module dependencies if the * function returns true. * * @param {function|string} testFunction The function which have to be executed. May be Function object or string. * @return {boolean} The result of the execution of the test function. */ _testConditionalModule: function (testFunction) { if (typeof testFunction === 'function') { return testFunction(); } else { return eval('false || ' + testFunction)(); } }, &nbsp; /** * Visits a module during the process of resolving dependencies. The function will throw exception in case of * circular dependencies among modules. * * @protected * @param {object} module The module which have to be visited. */ _visit: function (module) { // Directed Acyclic Graph is supported only, throw exception if there are circular dependencies. if (module.tmpMark) { throw new Error('Error processing module: ' + module.name + '. ' + 'The provided configuration is not Directed Acyclic Graph.'); } &nbsp; // Check if this module has conditional modules and add them to the queue if so. this._processConditionalModules(module); &nbsp; if (!module.mark) { module.tmpMark = true; &nbsp; var modules = this._configParser.getModules(); &nbsp; for (var i = 0; i &lt; module.dependencies.length; i++) { var dependencyName = module.dependencies[i]; &nbsp; if (dependencyName === 'exports') { continue; } &nbsp; // Map the modules to their aliases dependencyName = this._configParser.mapModule(dependencyName); &nbsp; var moduleDependency = modules[dependencyName]; &nbsp; if (!moduleDependency) { throw new Error('Cannot resolve module: ' + module.name + ' ' + 'due to not yet registered or wrongly specified dependency: ' + dependencyName); } &nbsp; this._visit(moduleDependency, modules); } &nbsp; module.mark = true; &nbsp; module.tmpMark = false; &nbsp; this._result.unshift(module.name); } }, &nbsp; /** * @property {array} _queue List of modules, which dependencies should be resolved. Initially, it is copy of * the array of modules, passed for resolving; during the process more modules may be added to the queue. For * example, these might be conditional modules. * * @protected * @memberof! DependencyBuilder# * @default [] */ _queue: [] }; &nbsp; return DependencyBuilder; }));</pre></td></tr> </table></pre> </div> <div class="footer"> <div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Jun 16 2015 17:51:38 GMT+0200 (CEST)</div> </div> <script src="../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../sorter.js"></script> </body> </html>