angular/packages/compiler/testing/src/pipe_resolver_mock.ts
Tobias Bosch 0cc77b4a69 refactor(compiler): split compiler and core (#18683)
After this, neither @angular/compiler nor @angular/comnpiler-cli depend
on @angular/core.

This add a duplication of some interfaces and enums which is stored
in @angular/compiler/src/core.ts

BREAKING CHANGE:
- `@angular/platform-server` now additionally depends on
  `@angular/platform-browser-dynamic` as a peer dependency.


PR Close #18683
2017-08-16 17:58:53 -05:00

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