From e6e590479e4fc398b5e7509cb0ad4699e3613f38 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Mon, 12 Nov 2018 18:52:51 -0800 Subject: [PATCH] fix(ivy): support forward refs in @Inject annotations (#27069) PR Close #27069 --- packages/core/src/render3/instructions.ts | 2 ++ .../animation_world/bundle.golden_symbols.json | 9 +++++++++ .../test/bundling/todo/bundle.golden_symbols.json | 9 +++++++++ packages/core/test/render3/providers_spec.ts | 11 +++++++++++ 4 files changed, 31 insertions(+) diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index 5a6222329f..91eea29ae0 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -8,6 +8,7 @@ import './ng_dev_mode'; +import {resolveForwardRef} from '../di/forward_ref'; import {InjectionToken} from '../di/injection_token'; import {InjectFlags} from '../di/injector_compatibility'; import {QueryList} from '../linker'; @@ -2653,6 +2654,7 @@ export function directiveInject(token: Type| InjectionToken): T; export function directiveInject(token: Type| InjectionToken, flags: InjectFlags): T; export function directiveInject( token: Type| InjectionToken, flags = InjectFlags.Default): T|null { + token = resolveForwardRef(token); return getOrCreateInjectable( getPreviousOrParentTNode() as TElementNode | TContainerNode | TElementContainerNode, getViewData(), token, flags); diff --git a/packages/core/test/bundling/animation_world/bundle.golden_symbols.json b/packages/core/test/bundling/animation_world/bundle.golden_symbols.json index a8bfcb4658..ac48a8cfd4 100644 --- a/packages/core/test/bundling/animation_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/animation_world/bundle.golden_symbols.json @@ -248,6 +248,9 @@ { "name": "__extends" }, + { + "name": "__forward_ref__" + }, { "name": "__read" }, @@ -557,6 +560,9 @@ { "name": "firstTemplatePass" }, + { + "name": "forwardRef" + }, { "name": "generateExpandoInstructionBlock" }, @@ -1040,6 +1046,9 @@ { "name": "resolveDirectives" }, + { + "name": "resolveForwardRef" + }, { "name": "saveNameToExportMap" }, diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 72aad76bbb..8d17e05d2b 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -260,6 +260,9 @@ { "name": "__extends" }, + { + "name": "__forward_ref__" + }, { "name": "__read" }, @@ -602,6 +605,9 @@ { "name": "firstTemplatePass" }, + { + "name": "forwardRef" + }, { "name": "generateExpandoInstructionBlock" }, @@ -1061,6 +1067,9 @@ { "name": "resolveDirectives" }, + { + "name": "resolveForwardRef" + }, { "name": "restoreView" }, diff --git a/packages/core/test/render3/providers_spec.ts b/packages/core/test/render3/providers_spec.ts index 997c59b3cf..0f7caf5e0c 100644 --- a/packages/core/test/render3/providers_spec.ts +++ b/packages/core/test/render3/providers_spec.ts @@ -215,6 +215,17 @@ describe('providers', () => { }); }); + it('@Inject annotation wrapped in forwardRef', () => { + // @Inject(forwardRef(() => GREETER)) + expectProvidersScenario({ + parent: { + providers: [{provide: GREETER, useValue: {greet: 'Value'}}], + componentAssertion: + () => { expect(directiveInject(forwardRef(() => GREETER)).greet).toEqual('Value'); } + } + }); + }); + }); });