Skip to content

Commit 2506c02

Browse files
sonukapoorAndrewKushnir
authored andcommitted
refactor(core): move injectAttributeImpl to avoid cycles (#37085)
This commit moves the `injectAttributeImpl` and other dependent code to avoid circular dependencies. PR Close #37085
1 parent aaa3111 commit 2506c02

File tree

9 files changed

+99
-142
lines changed

9 files changed

+99
-142
lines changed

Diff for: goldens/circular-deps/packages.json

-61
Original file line numberDiff line numberDiff line change
@@ -180,57 +180,6 @@
180180
"packages/core/src/change_detection/differs/default_keyvalue_differ.ts",
181181
"packages/core/src/change_detection/differs/keyvalue_differs.ts"
182182
],
183-
[
184-
"packages/core/src/di.ts",
185-
"packages/core/src/di/index.ts",
186-
"packages/core/src/di/injectable.ts",
187-
"packages/core/src/di/jit/injectable.ts",
188-
"packages/core/src/di/jit/environment.ts",
189-
"packages/core/src/di/injector_compatibility.ts",
190-
"packages/core/src/di/injector.ts",
191-
"packages/core/src/di/metadata.ts",
192-
"packages/core/src/render3/instructions/di.ts"
193-
],
194-
[
195-
"packages/core/src/di.ts",
196-
"packages/core/src/di/index.ts",
197-
"packages/core/src/di/injectable.ts",
198-
"packages/core/src/di/jit/injectable.ts",
199-
"packages/core/src/di/jit/environment.ts",
200-
"packages/core/src/di/injector_compatibility.ts",
201-
"packages/core/src/di/metadata.ts",
202-
"packages/core/src/render3/instructions/di.ts"
203-
],
204-
[
205-
"packages/core/src/di.ts",
206-
"packages/core/src/di/index.ts",
207-
"packages/core/src/di/injectable.ts",
208-
"packages/core/src/di/jit/injectable.ts",
209-
"packages/core/src/di/jit/util.ts",
210-
"packages/core/src/di/metadata.ts",
211-
"packages/core/src/render3/instructions/di.ts"
212-
],
213-
[
214-
"packages/core/src/di.ts",
215-
"packages/core/src/di/index.ts",
216-
"packages/core/src/di/metadata.ts",
217-
"packages/core/src/render3/instructions/di.ts"
218-
],
219-
[
220-
"packages/core/src/di.ts",
221-
"packages/core/src/di/index.ts",
222-
"packages/core/src/di/reflective_injector.ts",
223-
"packages/core/src/di/metadata.ts",
224-
"packages/core/src/render3/instructions/di.ts"
225-
],
226-
[
227-
"packages/core/src/di.ts",
228-
"packages/core/src/di/index.ts",
229-
"packages/core/src/di/reflective_injector.ts",
230-
"packages/core/src/di/reflective_provider.ts",
231-
"packages/core/src/di/metadata.ts",
232-
"packages/core/src/render3/instructions/di.ts"
233-
],
234183
[
235184
"packages/core/src/di/injectable.ts",
236185
"packages/core/src/di/jit/injectable.ts"
@@ -239,16 +188,6 @@
239188
"packages/core/src/di/injector_compatibility.ts",
240189
"packages/core/src/di/injector.ts"
241190
],
242-
[
243-
"packages/core/src/di/injector_compatibility.ts",
244-
"packages/core/src/di/injector.ts",
245-
"packages/core/src/di/null_injector.ts"
246-
],
247-
[
248-
"packages/core/src/di/injector_compatibility.ts",
249-
"packages/core/src/di/injector.ts",
250-
"packages/core/src/di/r3_injector.ts"
251-
],
252191
[
253192
"packages/core/src/di/injector_token.ts",
254193
"packages/core/src/di/injector.ts"

Diff for: packages/core/src/core_render3_private_export.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export {
2525
SWITCH_COMPILE_INJECTABLE__POST_R3__ as ɵSWITCH_COMPILE_INJECTABLE__POST_R3__,
2626
} from './di/injectable';
2727
export {INJECTOR_IMPL__POST_R3__ as ɵINJECTOR_IMPL__POST_R3__} from './di/injector';
28-
export {CREATE_ATTRIBUTE_DECORATOR__POST_R3__ as ɵCREATE_ATTRIBUTE_DECORATOR__POST_R3__} from './di/metadata';
2928
export {
3029
NG_INJ_DEF as ɵNG_INJ_DEF,
3130
NG_PROV_DEF as ɵNG_PROV_DEF,
3231
} from './di/interface/defs';
32+
export {CREATE_ATTRIBUTE_DECORATOR__POST_R3__ as ɵCREATE_ATTRIBUTE_DECORATOR__POST_R3__} from './di/metadata_attr';
3333
export {createInjector as ɵcreateInjector} from './di/r3_injector';
3434
export {
3535
SWITCH_IVY_ENABLED__POST_R3__ as ɵSWITCH_IVY_ENABLED__POST_R3__,

Diff for: packages/core/src/di/jit/util.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import {CompilerFacade, getCompilerFacade, R3DependencyMetadataFacade, R3ResolvedDependencyType} from '../../compiler/compiler_facade';
1010
import {Type} from '../../interface/type';
1111
import {ReflectionCapabilities} from '../../reflection/reflection_capabilities';
12-
import {Attribute, Host, Inject, Optional, Self, SkipSelf} from '../metadata';
12+
import {Host, Inject, Optional, Self, SkipSelf} from '../metadata';
13+
import {Attribute} from '../metadata_attr';
1314

1415
let _reflect: ReflectionCapabilities|null = null;
1516

Diff for: packages/core/src/di/metadata.ts

-68
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {makeParamDecorator} from '../util/decorators';
10-
import {ɵɵinjectAttribute} from '../render3/instructions/di';
1110

1211

1312
/**
@@ -229,70 +228,3 @@ export interface Host {}
229228
* @publicApi
230229
*/
231230
export const Host: HostDecorator = makeParamDecorator('Host');
232-
233-
234-
/**
235-
* Type of the Attribute decorator / constructor function.
236-
*
237-
* @publicApi
238-
*/
239-
export interface AttributeDecorator {
240-
/**
241-
* Parameter decorator for a directive constructor that designates
242-
* a host-element attribute whose value is injected as a constant string literal.
243-
*
244-
* @usageNotes
245-
*
246-
* Suppose we have an `<input>` element and want to know its `type`.
247-
*
248-
* ```html
249-
* <input type="text">
250-
* ```
251-
*
252-
* The following example uses the decorator to inject the string literal `text` in a directive.
253-
*
254-
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
255-
*
256-
* The following example uses the decorator in a component constructor.
257-
*
258-
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
259-
*
260-
*/
261-
(name: string): any;
262-
new(name: string): Attribute;
263-
}
264-
265-
/**
266-
* Type of the Attribute metadata.
267-
*
268-
* @publicApi
269-
*/
270-
export interface Attribute {
271-
/**
272-
* The name of the attribute whose value can be injected.
273-
*/
274-
attributeName: string;
275-
}
276-
277-
function CREATE_ATTRIBUTE_DECORATOR__PRE_R3__(): AttributeDecorator {
278-
return makeParamDecorator(
279-
'Attribute',
280-
(attributeName?: string) => ({attributeName}));
281-
}
282-
283-
export function CREATE_ATTRIBUTE_DECORATOR__POST_R3__(): AttributeDecorator {
284-
return makeParamDecorator(
285-
'Attribute',
286-
(attributeName?: string) =>
287-
({attributeName, __NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName!)}));
288-
}
289-
290-
const CREATE_ATTRIBUTE_DECORATOR_IMPL = CREATE_ATTRIBUTE_DECORATOR__PRE_R3__;
291-
292-
/**
293-
* Attribute decorator and metadata.
294-
*
295-
* @Annotation
296-
* @publicApi
297-
*/
298-
export const Attribute: AttributeDecorator = CREATE_ATTRIBUTE_DECORATOR_IMPL();

Diff for: packages/core/src/di/metadata_attr.ts

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
9+
import {ɵɵinjectAttribute} from '../render3/instructions/di_attr';
10+
import {makeParamDecorator} from '../util/decorators';
11+
12+
13+
/**
14+
* Type of the Attribute decorator / constructor function.
15+
*
16+
* @publicApi
17+
*/
18+
export interface AttributeDecorator {
19+
/**
20+
* Parameter decorator for a directive constructor that designates
21+
* a host-element attribute whose value is injected as a constant string literal.
22+
*
23+
* @usageNotes
24+
*
25+
* Suppose we have an `<input>` element and want to know its `type`.
26+
*
27+
* ```html
28+
* <input type="text">
29+
* ```
30+
*
31+
* The following example uses the decorator to inject the string literal `text` in a directive.
32+
*
33+
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
34+
*
35+
* The following example uses the decorator in a component constructor.
36+
*
37+
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
38+
*
39+
*/
40+
(name: string): any;
41+
new(name: string): Attribute;
42+
}
43+
44+
/**
45+
* Type of the Attribute metadata.
46+
*
47+
* @publicApi
48+
*/
49+
export interface Attribute {
50+
/**
51+
* The name of the attribute whose value can be injected.
52+
*/
53+
attributeName: string;
54+
}
55+
56+
function CREATE_ATTRIBUTE_DECORATOR__PRE_R3__(): AttributeDecorator {
57+
return makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));
58+
}
59+
60+
export function CREATE_ATTRIBUTE_DECORATOR__POST_R3__(): AttributeDecorator {
61+
return makeParamDecorator(
62+
'Attribute',
63+
(attributeName?: string) =>
64+
({attributeName, __NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName!)}));
65+
}
66+
67+
const CREATE_ATTRIBUTE_DECORATOR_IMPL = CREATE_ATTRIBUTE_DECORATOR__PRE_R3__;
68+
69+
/**
70+
* Attribute decorator and metadata.
71+
*
72+
* @Annotation
73+
* @publicApi
74+
*/
75+
export const Attribute: AttributeDecorator = CREATE_ATTRIBUTE_DECORATOR_IMPL();

Diff for: packages/core/src/metadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414

15-
export {Attribute} from './di/metadata';
15+
export {Attribute, AttributeDecorator} from './di/metadata_attr';
1616
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './interface/lifecycle_hooks';
1717
export {ANALYZE_FOR_ENTRY_COMPONENTS, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di';
1818
export {Component, ComponentDecorator, Directive, DirectiveDecorator, HostBinding, HostBindingDecorator, HostListener, HostListenerDecorator, Input, InputDecorator, Output, OutputDecorator, Pipe, PipeDecorator} from './metadata/directives';

Diff for: packages/core/src/render3/instructions/all.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export * from './change_detection';
3131
export * from './template';
3232
export * from './storage';
3333
export * from './di';
34+
export * from './di_attr';
3435
export * from './element';
3536
export * from './element_container';
3637
export * from './get_current_view';

Diff for: packages/core/src/render3/instructions/di.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {InjectFlags, InjectionToken, resolveForwardRef} from '../../di';
99
import {assertInjectImplementationNotEqual} from '../../di/inject_switch';
1010
import {ɵɵinject} from '../../di/injector_compatibility';
1111
import {Type} from '../../interface/type';
12-
import {getOrCreateInjectable, injectAttributeImpl} from '../di';
12+
import {getOrCreateInjectable} from '../di';
1313
import {TDirectiveHostNode} from '../interfaces/node';
1414
import {getCurrentTNode, getLView} from '../state';
1515

@@ -54,15 +54,6 @@ export function ɵɵdirectiveInject<T>(
5454
tNode as TDirectiveHostNode, lView, resolveForwardRef(token), flags);
5555
}
5656

57-
/**
58-
* Facade for the attribute injection from DI.
59-
*
60-
* @codeGenApi
61-
*/
62-
export function ɵɵinjectAttribute(attrNameToInject: string): string|null {
63-
return injectAttributeImpl(getCurrentTNode()!, attrNameToInject);
64-
}
65-
6657
/**
6758
* Throws an error indicating that a factory function could not be generated by the compiler for a
6859
* particular class.

Diff for: packages/core/src/render3/instructions/di_attr.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 {injectAttributeImpl} from '../di';
9+
import {getCurrentTNode} from '../state';
10+
11+
/**
12+
* Facade for the attribute injection from DI.
13+
*
14+
* @codeGenApi
15+
*/
16+
export function ɵɵinjectAttribute(attrNameToInject: string): string|null {
17+
return injectAttributeImpl(getCurrentTNode()!, attrNameToInject);
18+
}

0 commit comments

Comments
 (0)