From 84e311038d076251777ef617f04c5d1bf0c30ba2 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 30 Oct 2018 10:18:30 -0700 Subject: [PATCH] feat(ivy): capture the identifier of a decorator during reflection (#26860) Previously the ReflectionHost API only returned the names of decorators and not a reference to their TypeScript Identifier. This commit adds the identifier itself, so that a consumer can write references to the decorator. Testing strategy: this commit is trivial, and the functionality will be exercised by downstream tests. PR Close #26860 --- packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts | 2 ++ packages/compiler-cli/src/ngtsc/host/src/reflection.ts | 5 +++++ packages/compiler-cli/src/ngtsc/metadata/src/reflector.ts | 1 + 3 files changed, 8 insertions(+) diff --git a/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts b/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts index 453d65b2cb..87ea6c8f4d 100644 --- a/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts +++ b/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts @@ -572,6 +572,7 @@ export class Fesm2015ReflectionHost extends TypeScriptReflectionHost implements const decoratorIdentifier = decoratorExpression; return { name: decoratorIdentifier.text, + identifier: decoratorIdentifier, import: this.getImportOfIdentifier(decoratorIdentifier), node: call, args: Array.from(call.arguments) @@ -634,6 +635,7 @@ export class Fesm2015ReflectionHost extends TypeScriptReflectionHost implements if (typeIdentifier && ts.isIdentifier(typeIdentifier)) { decorators.push({ name: typeIdentifier.text, + identifier: typeIdentifier, import: this.getImportOfIdentifier(typeIdentifier), node, args: getDecoratorArgs(node), }); diff --git a/packages/compiler-cli/src/ngtsc/host/src/reflection.ts b/packages/compiler-cli/src/ngtsc/host/src/reflection.ts index 37c6e8d5e5..49722ed448 100644 --- a/packages/compiler-cli/src/ngtsc/host/src/reflection.ts +++ b/packages/compiler-cli/src/ngtsc/host/src/reflection.ts @@ -20,6 +20,11 @@ export interface Decorator { */ name: string; + /** + * Identifier which refers to the decorator in source. + */ + identifier: ts.Identifier; + /** * `Import` by which the decorator was brought into the module in which it was invoked, or `null` * if the decorator was declared in the same module and not imported. diff --git a/packages/compiler-cli/src/ngtsc/metadata/src/reflector.ts b/packages/compiler-cli/src/ngtsc/metadata/src/reflector.ts index 782ae5e40c..48472794ec 100644 --- a/packages/compiler-cli/src/ngtsc/metadata/src/reflector.ts +++ b/packages/compiler-cli/src/ngtsc/metadata/src/reflector.ts @@ -245,6 +245,7 @@ export class TypeScriptReflectionHost implements ReflectionHost { return { name: decoratorExpr.text, + identifier: decoratorExpr, import: importDecl, node, args, }; }