Code coverage report for src/origin.js

Statements: 71.43% (25 / 35)      Branches: 50% (7 / 14)      Functions: 90% (9 / 10)      Lines: 72.73% (24 / 33)      Ignored: none     

All files » src/ » origin.js
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 941     1   2   1   1     1 1   1       1 1                       1 1 2   2 2                       1 3   3 1                               3                         1 2     1     1        
System.register(['core-js'], function (_export) {
  'use strict';
 
  var core, originStorage, unknownOrigin, Origin;
 
  function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
 
  return {
    setters: [function (_coreJs) {
      core = _coreJs['default'];
    }],
    execute: function () {
      originStorage = new Map();
      unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined });
 
      Iif (!window.System) {
        window.System = {};
      }
 
      Eif (!System.forEachModule) {
        System.forEachModule = function () {};
      }
 
      /**
      * A metadata annotation that describes the origin module of the function to which it's attached.
      *
      * @class Origin
      * @constructor
      * @param {string} moduleId The origin module id.
      * @param {string} moduleMember The name of the export in the origin module.
      */
 
      Origin = (function () {
        function Origin(moduleId, moduleMember) {
          _classCallCheck(this, Origin);
 
          this.moduleId = moduleId;
          this.moduleMember = moduleMember;
        }
 
        /**
        * Get the Origin annotation for the specified function.
        *
        * @method get
        * @static
        * @param {Function} fn The function to inspect for Origin metadata.
        * @return {Origin} Returns the Origin metadata.
        */
 
        Origin.get = function get(fn) {
          var origin = originStorage.get(fn);
 
          if (origin === undefined) {
            System.forEachModule(function (key, value) {
              for (var name in value) {
                var exp = value[name];
                if (exp === fn) {
                  originStorage.set(fn, origin = new Origin(key, name));
                  return;
                }
              }
 
              if (value === fn) {
                originStorage.set(fn, origin = new Origin(key, 'default'));
                return;
              }
            });
          }
 
          return origin || unknownOrigin;
        };
 
        /**
        * Set the Origin annotation for the specified function.
        *
        * @method set
        * @static
        * @param {Function} fn The function to set the Origin metadata on.
        * @param {origin} fn The Origin metadata to store on the function.
        * @return {Origin} Returns the Origin metadata.
        */
 
        Origin.set = function set(fn, origin) {
          originStorage.set(fn, origin);
        };
 
        return Origin;
      })();
 
      _export('Origin', Origin);
    }
  };
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9FaXNlbmJlcmdFZmZlY3QvRG9jdW1lbnRzL0dpdEh1Yi9UaGUgRHVyYW5kYWwgUHJvamVjdC9hdXJlbGlhL21ldGFkYXRhL3NyYy9vcmlnaW4uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O1lBRUksYUFBYSxFQUNiLGFBQWEsRUFrQkosTUFBTTs7Ozs7Ozs7O0FBbkJmLG1CQUFhLEdBQUcsSUFBSSxHQUFHLEVBQUU7QUFDekIsbUJBQWEsR0FBRyxNQUFNLENBQUMsTUFBTSxDQUFDLEVBQUMsUUFBUSxFQUFDLFNBQVMsRUFBQyxZQUFZLEVBQUMsU0FBUyxFQUFDLENBQUM7O0FBRTlFLFVBQUcsQ0FBQyxNQUFNLENBQUMsTUFBTSxFQUFDO0FBQ2hCLGNBQU0sQ0FBQyxNQUFNLEdBQUcsRUFBRSxDQUFDO09BQ3BCOztBQUVELFVBQUcsQ0FBQyxNQUFNLENBQUMsYUFBYSxFQUFDO0FBQ3ZCLGNBQU0sQ0FBQyxhQUFhLEdBQUcsWUFBVSxFQUFFLENBQUM7T0FDckM7Ozs7Ozs7Ozs7O0FBVVksWUFBTTtBQUNOLGlCQURBLE1BQU0sQ0FDTCxRQUFRLEVBQUUsWUFBWSxFQUFDO2dDQUR4QixNQUFNOztBQUVmLGNBQUksQ0FBQyxRQUFRLEdBQUcsUUFBUSxDQUFDO0FBQ3pCLGNBQ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