angular-cn/packages/compiler/testing/src/pipe_resolver_mock.ts

39 lines
1010 B
TypeScript
Raw Normal View History

2016-07-28 06:40:50 -07:00
/**
* @license
* Copyright Google LLC All Rights Reserved.
2016-07-28 06:40:50 -07:00
*
* 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, PipeResolver} from '@angular/compiler';
2016-07-28 06:40:50 -07:00
export class MockPipeResolver extends PipeResolver {
private _pipes = new Map<core.Type, core.Pipe>();
2016-07-28 06:40:50 -07:00
constructor(refector: CompileReflector) {
super(refector);
}
2016-07-28 06:40:50 -07:00
/**
* Overrides the {@link Pipe} for a pipe.
2016-07-28 06:40:50 -07:00
*/
setPipe(type: core.Type, metadata: core.Pipe): void {
this._pipes.set(type, metadata);
}
2016-07-28 06:40:50 -07:00
/**
* Returns the {@link Pipe} for a pipe:
* - Set the {@link Pipe} to the overridden view when it exists or fallback to the
2016-07-28 06:40:50 -07:00
* default
* `PipeResolver`, see `setPipe`.
*/
resolve(type: core.Type, throwIfNotFound = true): core.Pipe {
let metadata = this._pipes.get(type);
2016-07-28 06:40:50 -07:00
if (!metadata) {
metadata = super.resolve(type, throwIfNotFound)!;
2016-07-28 06:40:50 -07:00
}
return metadata;
}
}