refactor(core): move injectAttributeImpl to avoid cycles (#37085)

This commit moves the `injectAttributeImpl` and other dependent code
to avoid circular dependencies.

PR Close #37085
This commit is contained in:
Sonu Kapoor 2020-09-09 21:43:42 -04:00 committed by Andrew Kushnir
parent f5cbf0bb54
commit be998e830b
9 changed files with 99 additions and 142 deletions

View File

@ -176,57 +176,6 @@
"packages/core/src/change_detection/differs/default_keyvalue_differ.ts",
"packages/core/src/change_detection/differs/keyvalue_differs.ts"
],
[
"packages/core/src/di.ts",
"packages/core/src/di/index.ts",
"packages/core/src/di/injectable.ts",
"packages/core/src/di/jit/injectable.ts",
"packages/core/src/di/jit/environment.ts",
"packages/core/src/di/injector_compatibility.ts",
"packages/core/src/di/injector.ts",
"packages/core/src/di/metadata.ts",
"packages/core/src/render3/instructions/di.ts"
],
[
"packages/core/src/di.ts",
"packages/core/src/di/index.ts",
"packages/core/src/di/injectable.ts",
"packages/core/src/di/jit/injectable.ts",
"packages/core/src/di/jit/environment.ts",
"packages/core/src/di/injector_compatibility.ts",
"packages/core/src/di/metadata.ts",
"packages/core/src/render3/instructions/di.ts"
],
[
"packages/core/src/di.ts",
"packages/core/src/di/index.ts",
"packages/core/src/di/injectable.ts",
"packages/core/src/di/jit/injectable.ts",
"packages/core/src/di/jit/util.ts",
"packages/core/src/di/metadata.ts",
"packages/core/src/render3/instructions/di.ts"
],
[
"packages/core/src/di.ts",
"packages/core/src/di/index.ts",
"packages/core/src/di/metadata.ts",
"packages/core/src/render3/instructions/di.ts"
],
[
"packages/core/src/di.ts",
"packages/core/src/di/index.ts",
"packages/core/src/di/reflective_injector.ts",
"packages/core/src/di/metadata.ts",
"packages/core/src/render3/instructions/di.ts"
],
[
"packages/core/src/di.ts",
"packages/core/src/di/index.ts",
"packages/core/src/di/reflective_injector.ts",
"packages/core/src/di/reflective_provider.ts",
"packages/core/src/di/metadata.ts",
"packages/core/src/render3/instructions/di.ts"
],
[
"packages/core/src/di/injectable.ts",
"packages/core/src/di/jit/injectable.ts"
@ -235,16 +184,6 @@
"packages/core/src/di/injector_compatibility.ts",
"packages/core/src/di/injector.ts"
],
[
"packages/core/src/di/injector_compatibility.ts",
"packages/core/src/di/injector.ts",
"packages/core/src/di/null_injector.ts"
],
[
"packages/core/src/di/injector_compatibility.ts",
"packages/core/src/di/injector.ts",
"packages/core/src/di/r3_injector.ts"
],
[
"packages/core/src/di/injector_token.ts",
"packages/core/src/di/injector.ts"

View File

@ -25,11 +25,11 @@ export {
SWITCH_COMPILE_INJECTABLE__POST_R3__ as ɵSWITCH_COMPILE_INJECTABLE__POST_R3__,
} from './di/injectable';
export {INJECTOR_IMPL__POST_R3__ as ɵINJECTOR_IMPL__POST_R3__} from './di/injector';
export {CREATE_ATTRIBUTE_DECORATOR__POST_R3__ as ɵCREATE_ATTRIBUTE_DECORATOR__POST_R3__} from './di/metadata';
export {
NG_INJ_DEF as ɵNG_INJ_DEF,
NG_PROV_DEF as ɵNG_PROV_DEF,
} from './di/interface/defs';
export {CREATE_ATTRIBUTE_DECORATOR__POST_R3__ as ɵCREATE_ATTRIBUTE_DECORATOR__POST_R3__} from './di/metadata_attr';
export {createInjector as ɵcreateInjector} from './di/r3_injector';
export {
SWITCH_IVY_ENABLED__POST_R3__ as ɵSWITCH_IVY_ENABLED__POST_R3__,

View File

@ -9,7 +9,8 @@
import {CompilerFacade, getCompilerFacade, R3DependencyMetadataFacade, R3ResolvedDependencyType} from '../../compiler/compiler_facade';
import {Type} from '../../interface/type';
import {ReflectionCapabilities} from '../../reflection/reflection_capabilities';
import {Attribute, Host, Inject, Optional, Self, SkipSelf} from '../metadata';
import {Host, Inject, Optional, Self, SkipSelf} from '../metadata';
import {Attribute} from '../metadata_attr';
let _reflect: ReflectionCapabilities|null = null;

View File

@ -7,7 +7,6 @@
*/
import {makeParamDecorator} from '../util/decorators';
import {ɵɵinjectAttribute} from '../render3/instructions/di';
/**
@ -229,70 +228,3 @@ export interface Host {}
* @publicApi
*/
export const Host: HostDecorator = makeParamDecorator('Host');
/**
* Type of the Attribute decorator / constructor function.
*
* @publicApi
*/
export interface AttributeDecorator {
/**
* Parameter decorator for a directive constructor that designates
* a host-element attribute whose value is injected as a constant string literal.
*
* @usageNotes
*
* Suppose we have an `<input>` element and want to know its `type`.
*
* ```html
* <input type="text">
* ```
*
* The following example uses the decorator to inject the string literal `text` in a directive.
*
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
*
* The following example uses the decorator in a component constructor.
*
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
*
*/
(name: string): any;
new(name: string): Attribute;
}
/**
* Type of the Attribute metadata.
*
* @publicApi
*/
export interface Attribute {
/**
* The name of the attribute whose value can be injected.
*/
attributeName: string;
}
function CREATE_ATTRIBUTE_DECORATOR__PRE_R3__(): AttributeDecorator {
return makeParamDecorator(
'Attribute',
(attributeName?: string) => ({attributeName}));
}
export function CREATE_ATTRIBUTE_DECORATOR__POST_R3__(): AttributeDecorator {
return makeParamDecorator(
'Attribute',
(attributeName?: string) =>
({attributeName, __NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName!)}));
}
const CREATE_ATTRIBUTE_DECORATOR_IMPL = CREATE_ATTRIBUTE_DECORATOR__PRE_R3__;
/**
* Attribute decorator and metadata.
*
* @Annotation
* @publicApi
*/
export const Attribute: AttributeDecorator = CREATE_ATTRIBUTE_DECORATOR_IMPL();

View File

@ -0,0 +1,75 @@
/**
* @license
* Copyright Google LLC 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 {ɵɵinjectAttribute} from '../render3/instructions/di_attr';
import {makeParamDecorator} from '../util/decorators';
/**
* Type of the Attribute decorator / constructor function.
*
* @publicApi
*/
export interface AttributeDecorator {
/**
* Parameter decorator for a directive constructor that designates
* a host-element attribute whose value is injected as a constant string literal.
*
* @usageNotes
*
* Suppose we have an `<input>` element and want to know its `type`.
*
* ```html
* <input type="text">
* ```
*
* The following example uses the decorator to inject the string literal `text` in a directive.
*
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
*
* The following example uses the decorator in a component constructor.
*
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
*
*/
(name: string): any;
new(name: string): Attribute;
}
/**
* Type of the Attribute metadata.
*
* @publicApi
*/
export interface Attribute {
/**
* The name of the attribute whose value can be injected.
*/
attributeName: string;
}
function CREATE_ATTRIBUTE_DECORATOR__PRE_R3__(): AttributeDecorator {
return makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));
}
export function CREATE_ATTRIBUTE_DECORATOR__POST_R3__(): AttributeDecorator {
return makeParamDecorator(
'Attribute',
(attributeName?: string) =>
({attributeName, __NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName!)}));
}
const CREATE_ATTRIBUTE_DECORATOR_IMPL = CREATE_ATTRIBUTE_DECORATOR__PRE_R3__;
/**
* Attribute decorator and metadata.
*
* @Annotation
* @publicApi
*/
export const Attribute: AttributeDecorator = CREATE_ATTRIBUTE_DECORATOR_IMPL();

View File

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

View File

@ -31,6 +31,7 @@ export * from './change_detection';
export * from './template';
export * from './storage';
export * from './di';
export * from './di_attr';
export * from './element';
export * from './element_container';
export * from './get_current_view';

View File

@ -9,7 +9,7 @@ import {InjectFlags, InjectionToken, resolveForwardRef} from '../../di';
import {assertInjectImplementationNotEqual} from '../../di/inject_switch';
import {ɵɵinject} from '../../di/injector_compatibility';
import {Type} from '../../interface/type';
import {getOrCreateInjectable, injectAttributeImpl} from '../di';
import {getOrCreateInjectable} from '../di';
import {TDirectiveHostNode} from '../interfaces/node';
import {getCurrentTNode, getLView} from '../state';
@ -54,15 +54,6 @@ export function ɵɵdirectiveInject<T>(
tNode as TDirectiveHostNode, lView, resolveForwardRef(token), flags);
}
/**
* Facade for the attribute injection from DI.
*
* @codeGenApi
*/
export function ɵɵinjectAttribute(attrNameToInject: string): string|null {
return injectAttributeImpl(getCurrentTNode()!, attrNameToInject);
}
/**
* Throws an error indicating that a factory function could not be generated by the compiler for a
* particular class.

View File

@ -0,0 +1,18 @@
/**
* @license
* Copyright Google LLC 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 {injectAttributeImpl} from '../di';
import {getCurrentTNode} from '../state';
/**
* Facade for the attribute injection from DI.
*
* @codeGenApi
*/
export function ɵɵinjectAttribute(attrNameToInject: string): string|null {
return injectAttributeImpl(getCurrentTNode()!, attrNameToInject);
}