diff --git a/goldens/circular-deps/packages.json b/goldens/circular-deps/packages.json index 18f105b46f..3e9bf12faa 100644 --- a/goldens/circular-deps/packages.json +++ b/goldens/circular-deps/packages.json @@ -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" diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 358a4316c3..8c01e0540f 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -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__, diff --git a/packages/core/src/di/jit/util.ts b/packages/core/src/di/jit/util.ts index 0f4da27806..7fa1880016 100644 --- a/packages/core/src/di/jit/util.ts +++ b/packages/core/src/di/jit/util.ts @@ -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; diff --git a/packages/core/src/di/metadata.ts b/packages/core/src/di/metadata.ts index 658a39ef62..d3e9275f03 100644 --- a/packages/core/src/di/metadata.ts +++ b/packages/core/src/di/metadata.ts @@ -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 `` element and want to know its `type`. - * - * ```html - * - * ``` - * - * 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(); diff --git a/packages/core/src/di/metadata_attr.ts b/packages/core/src/di/metadata_attr.ts new file mode 100644 index 0000000000..bee9d66c42 --- /dev/null +++ b/packages/core/src/di/metadata_attr.ts @@ -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 `` element and want to know its `type`. + * + * ```html + * + * ``` + * + * 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(); diff --git a/packages/core/src/metadata.ts b/packages/core/src/metadata.ts index 357e6f46cf..857ca07c61 100644 --- a/packages/core/src/metadata.ts +++ b/packages/core/src/metadata.ts @@ -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'; diff --git a/packages/core/src/render3/instructions/all.ts b/packages/core/src/render3/instructions/all.ts index 182c1541e0..3d4d86a11d 100644 --- a/packages/core/src/render3/instructions/all.ts +++ b/packages/core/src/render3/instructions/all.ts @@ -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'; diff --git a/packages/core/src/render3/instructions/di.ts b/packages/core/src/render3/instructions/di.ts index bb08814e5a..3e84551a28 100644 --- a/packages/core/src/render3/instructions/di.ts +++ b/packages/core/src/render3/instructions/di.ts @@ -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( 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. diff --git a/packages/core/src/render3/instructions/di_attr.ts b/packages/core/src/render3/instructions/di_attr.ts new file mode 100644 index 0000000000..cbaaf1f3f1 --- /dev/null +++ b/packages/core/src/render3/instructions/di_attr.ts @@ -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); +}