Last change
on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
4.4 KB
|
Line | |
---|
1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { createPipe } from './core';
|
---|
9 | import { findLast } from './directive_resolver';
|
---|
10 | import { resolveForwardRef, stringify } from './util';
|
---|
11 | /**
|
---|
12 | * Resolve a `Type` for {@link Pipe}.
|
---|
13 | *
|
---|
14 | * This interface can be overridden by the application developer to create custom behavior.
|
---|
15 | *
|
---|
16 | * See {@link Compiler}
|
---|
17 | */
|
---|
18 | export class PipeResolver {
|
---|
19 | constructor(_reflector) {
|
---|
20 | this._reflector = _reflector;
|
---|
21 | }
|
---|
22 | isPipe(type) {
|
---|
23 | const typeMetadata = this._reflector.annotations(resolveForwardRef(type));
|
---|
24 | return typeMetadata && typeMetadata.some(createPipe.isTypeOf);
|
---|
25 | }
|
---|
26 | /**
|
---|
27 | * Return {@link Pipe} for a given `Type`.
|
---|
28 | */
|
---|
29 | resolve(type, throwIfNotFound = true) {
|
---|
30 | const metas = this._reflector.annotations(resolveForwardRef(type));
|
---|
31 | if (metas) {
|
---|
32 | const annotation = findLast(metas, createPipe.isTypeOf);
|
---|
33 | if (annotation) {
|
---|
34 | return annotation;
|
---|
35 | }
|
---|
36 | }
|
---|
37 | if (throwIfNotFound) {
|
---|
38 | throw new Error(`No Pipe decorator found on ${stringify(type)}`);
|
---|
39 | }
|
---|
40 | return null;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGlwZV9yZXNvbHZlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3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mVmbGVjdG9yKSB7fVxuXG4gIGlzUGlwZSh0eXBlOiBUeXBlKSB7XG4gICAgY29uc3QgdHlwZU1ldGFkYXRhID0gdGhpcy5fcmVmbGVjdG9yLmFubm90YXRpb25zKHJlc29sdmVGb3J3YXJkUmVmKHR5cGUpKTtcbiAgICByZXR1cm4gdHlwZU1ldGFkYXRhICYmIHR5cGVNZXRhZGF0YS5zb21lKGNyZWF0ZVBpcGUuaXNUeXBlT2YpO1xuICB9XG5cbiAgLyoqXG4gICAqIFJldHVybiB7QGxpbmsgUGlwZX0gZm9yIGEgZ2l2ZW4gYFR5cGVgLlxuICAgKi9cbiAgcmVzb2x2ZSh0eXBlOiBUeXBlLCB0aHJvd0lmTm90Rm91bmQgPSB0cnVlKTogUGlwZXxudWxsIHtcbiAgICBjb25zdCBtZXRhcyA9IHRoaXMuX3JlZmxlY3Rvci5hbm5vdGF0aW9ucyhyZXNvbHZlRm9yd2FyZFJlZih0eXBlKSk7XG4gICAgaWYgKG1ldGFzKSB7XG4gICAgICBjb25zdCBhbm5vdGF0aW9uID0gZmluZExhc3QobWV0YXMsIGNyZWF0ZVBpcGUuaXNUeXBlT2YpO1xuICAgICAgaWYgKGFubm90YXRpb24pIHtcbiAgICAgICAgcmV0dXJuIGFubm90YXRpb247XG4gICAgICB9XG4gICAgfVxuICAgIGlmICh0aHJvd0lmTm90Rm91bmQpIHtcbiAgICAgIHRocm93IG5ldyBFcnJvcihgTm8gUGlwZSBkZWNvcmF0b3IgZm91bmQgb24gJHtzdHJpbmdpZnkodHlwZSl9YCk7XG4gICAgfVxuICAgIHJldHVybiBudWxsO1xuICB9XG59XG4iXX0= |
---|
Note:
See
TracBrowser
for help on using the repository browser.