/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { stringify } from '../util/stringify'; /** * Map of module-id to the corresponding NgModule. */ const modules = new Map(); /** * Whether to check for duplicate NgModule registrations. * * This can be disabled for testing. */ let checkForDuplicateNgModules = true; function assertSameOrNotExisting(id, type, incoming) { if (type && type !== incoming && checkForDuplicateNgModules) { throw new Error(`Duplicate module registered for ${id} - ${stringify(type)} vs ${stringify(type.name)}`); } } /** * Adds the given NgModule type to Angular's NgModule registry. * * This is generated as a side-effect of NgModule compilation. Note that the `id` is passed in * explicitly and not read from the NgModule definition. This is for two reasons: it avoids a * megamorphic read, and in JIT there's a chicken-and-egg problem where the NgModule may not be * fully resolved when it's registered. * * @codeGenApi */ export function registerNgModuleType(ngModuleType, id) { const existing = modules.get(id) || null; assertSameOrNotExisting(id, existing, ngModuleType); modules.set(id, ngModuleType); } export function clearModulesForTest() { modules.clear(); } export function getRegisteredNgModuleType(id) { return modules.get(id); } /** * Control whether the NgModule registration system enforces that each NgModule type registered has * a unique id. * * This is useful for testing as the NgModule registry cannot be properly reset between tests with * Angular's current API. */ export function setAllowDuplicateNgModuleIdsForTest(allowDuplicates) { checkForDuplicateNgModules = !allowDuplicates; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdfbW9kdWxlX3JlZ2lzdHJhdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvcmUvc3JjL2xpbmtlci9uZ19tb2R1bGVfcmVnaXN0cmF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQU1ILE9BQU8sRUFBQyxTQUFTLEVBQUMsTUFBTSxtQkFBbUIsQ0FBQztBQUU1Qzs7R0FFRztBQUNILE1BQU0sT0FBTyxHQUFHLElBQUks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