angular/packages/compiler/testing/src/ng_module_resolver_mock.ts
Alex Rickabaugh cbed582a1a style(compiler): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler tree using the new version of
clang-format.

PR Close #36520
2020-04-08 14:51:08 -07:00

35 lines
1006 B
TypeScript

/**
* @license
* Copyright Google Inc. 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 {CompileReflector, core, NgModuleResolver} from '@angular/compiler';
export class MockNgModuleResolver extends NgModuleResolver {
private _ngModules = new Map<core.Type, core.NgModule>();
constructor(reflector: CompileReflector) {
super(reflector);
}
/**
* Overrides the {@link NgModule} for a module.
*/
setNgModule(type: core.Type, metadata: core.NgModule): void {
this._ngModules.set(type, metadata);
}
/**
* Returns the {@link NgModule} for a module:
* - Set the {@link NgModule} to the overridden view when it exists or fallback to the
* default
* `NgModuleResolver`, see `setNgModule`.
*/
resolve(type: core.Type, throwIfNotFound = true): core.NgModule {
return this._ngModules.get(type) || super.resolve(type, throwIfNotFound)!;
}
}