UNPKG

ember-material-icons

Version:

Google Material icons for your ember-cli app

142 lines (121 loc) 5.53 kB
define('@glimmer/resolver', ['exports', '@glimmer/di'], function (exports, _glimmer_di) { 'use strict'; function assert(description, test) { if (!test) { throw new Error('Assertion Failed: ' + description); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Resolver = function () { function Resolver(config, registry) { _classCallCheck(this, Resolver); this.config = config; this.registry = registry; } Resolver.prototype.identify = function identify(specifier, referrer) { if (_glimmer_di.isSpecifierStringAbsolute(specifier)) { return specifier; } var s = _glimmer_di.deserializeSpecifier(specifier); var result = void 0; if (referrer) { var r = _glimmer_di.deserializeSpecifier(referrer); if (_glimmer_di.isSpecifierObjectAbsolute(r)) { assert('Specifier must not include a rootName, collection, or namespace when combined with an absolute referrer', s.rootName === undefined && s.collection === undefined && s.namespace === undefined); // Look locally in the referrer's namespace s.rootName = r.rootName; s.collection = r.collection; if (s.name) { s.namespace = r.namespace ? r.namespace + '/' + r.name : r.name; } else { s.namespace = r.namespace; s.name = r.name; } if (result = this._serializeAndVerify(s)) { return result; } // Look for a private collection in the referrer's namespace var privateCollection = this._definitiveCollection(s.type); if (privateCollection) { s.namespace += '/-' + privateCollection; if (result = this._serializeAndVerify(s)) { return result; } } // Because local and private resolution has failed, clear all but `name` and `type` // to proceed with top-level resolution s.rootName = s.collection = s.namespace = undefined; } else { assert('Referrer must either be "absolute" or include a `type` to determine the associated type', r.type); // Look in the definitive collection for the associated type s.collection = this._definitiveCollection(r.type); assert('\'' + r.type + '\' does not have a definitive collection', s.collection); } } // If the collection is unspecified, use the definitive collection for the `type` if (!s.collection) { s.collection = this._definitiveCollection(s.type); assert('\'' + s.type + '\' does not have a definitive collection', s.collection); } if (!s.rootName) { // If the root name is unspecified, try the app's `rootName` first s.rootName = this.config.app.rootName || 'app'; if (result = this._serializeAndVerify(s)) { return result; } // Then look for an addon with a matching `rootName` var addonDef = void 0; if (s.namespace) { addonDef = this.config.addons && this.config.addons[s.namespace]; s.rootName = s.namespace; s.namespace = undefined; } else { addonDef = this.config.addons && this.config.addons[s.name]; s.rootName = s.name; s.name = 'main'; } } if (result = this._serializeAndVerify(s)) { return result; } }; Resolver.prototype.retrieve = function retrieve(specifier) { return this.registry.get(specifier); }; Resolver.prototype.resolve = function resolve(specifier, referrer) { var id = this.identify(specifier, referrer); if (id) { return this.retrieve(id); } }; Resolver.prototype._definitiveCollection = function _definitiveCollection(type) { var typeDef = this.config.types[type]; assert('\'' + type + '\' is not a recognized type', typeDef); return typeDef.definitiveCollection; }; Resolver.prototype._serializeAndVerify = function _serializeAndVerify(specifier) { var serialized = _glimmer_di.serializeSpecifier(specifier); if (this.registry.has(serialized)) { return serialized; } }; return Resolver; }(); function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var BasicRegistry = function () { function BasicRegistry() { var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck$1(this, BasicRegistry); this._entries = entries; } BasicRegistry.prototype.has = function has(specifier) { return specifier in this._entries; }; BasicRegistry.prototype.get = function get(specifier) { return this._entries[specifier]; }; return BasicRegistry; }(); exports['default'] = Resolver; exports.BasicModuleRegistry = BasicRegistry; Object.defineProperty(exports, '__esModule', { value: true }); });