From 99bfbabe50b47c97aaca1a32f4f27e7eef39b79f Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Mon, 5 Feb 2024 16:27:23 -0800 Subject: [PATCH] refactor(core): break circular dependencies in preparation for queries as signals (#54103) Break circular dependencies by using type imports and code moves. PR Close #54103 --- goldens/circular-deps/packages.json | 73 --------- .../core/src/core_render3_private_export.ts | 2 +- packages/core/src/di/create_injector.ts | 4 +- .../core/src/di/injector_compatibility.ts | 2 +- packages/core/src/di/injector_token.ts | 2 +- packages/core/src/di/null_injector.ts | 2 +- packages/core/src/di/r3_injector.ts | 2 +- packages/core/src/hydration/utils.ts | 2 +- packages/core/src/render3/component_ref.ts | 3 +- packages/core/src/render3/definition.ts | 5 +- packages/core/src/render3/di.ts | 3 +- .../render3/features/ng_onchanges_feature.ts | 2 +- packages/core/src/render3/index.ts | 2 +- .../core/src/render3/instructions/shared.ts | 6 +- .../core/src/render3/instructions/styling.ts | 3 +- .../instructions/write_to_directive_input.ts | 3 +- .../render3/interfaces/attribute_marker.ts | 142 ++++++++++++++++++ .../core/src/render3/interfaces/definition.ts | 10 +- .../src/render3/interfaces/input_flags.ts | 14 ++ packages/core/src/render3/interfaces/node.ts | 140 +---------------- packages/core/src/render3/interfaces/view.ts | 2 +- packages/core/src/render3/jit/environment.ts | 2 +- .../core/src/render3/node_selector_matcher.ts | 3 +- .../src/render3/styling/static_styling.ts | 3 +- packages/core/src/render3/util/attrs_utils.ts | 3 +- .../core/src/render3/util/discovery_utils.ts | 2 +- .../bundling/defer/bundle.golden_symbols.json | 6 +- .../test/render3/instructions/styling_spec.ts | 4 +- .../core/test/render3/instructions_spec.ts | 2 +- .../render3/node_selector_matcher_spec.ts | 3 +- .../styling_next/static_styling_spec.ts | 3 +- 31 files changed, 205 insertions(+), 250 deletions(-) create mode 100644 packages/core/src/render3/interfaces/attribute_marker.ts create mode 100644 packages/core/src/render3/interfaces/input_flags.ts diff --git a/goldens/circular-deps/packages.json b/goldens/circular-deps/packages.json index fa2cce80fb4..5ed3cb5a827 100644 --- a/goldens/circular-deps/packages.json +++ b/goldens/circular-deps/packages.json @@ -33,64 +33,10 @@ "packages/core/src/change_detection/differs/default_keyvalue_differ.ts", "packages/core/src/change_detection/differs/keyvalue_differs.ts" ], - [ - "packages/core/src/di/create_injector.ts", - "packages/core/src/di/injector.ts" - ], - [ - "packages/core/src/di/create_injector.ts", - "packages/core/src/di/provider_collection.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/di/injector_compatibility.ts", - "packages/core/src/di/injector.ts" - ], - [ - "packages/core/src/di/create_injector.ts", - "packages/core/src/di/provider_collection.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/di/injector_token.ts", - "packages/core/src/di/injector.ts" - ], - [ - "packages/core/src/di/create_injector.ts", - "packages/core/src/di/provider_collection.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/di/injector.ts" - ], - [ - "packages/core/src/di/create_injector.ts", - "packages/core/src/di/provider_collection.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/di/null_injector.ts", - "packages/core/src/di/injector.ts" - ], - [ - "packages/core/src/di/create_injector.ts", - "packages/core/src/di/provider_collection.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts", - "packages/core/src/di/injector.ts" - ], [ "packages/core/src/di/injectable.ts", "packages/core/src/di/jit/injectable.ts" ], - [ - "packages/core/src/di/provider_collection.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/di/r3_injector.ts" - ], [ "packages/core/src/linker/component_factory_resolver.ts", "packages/core/src/linker/component_factory.ts", @@ -120,27 +66,8 @@ ], [ "packages/core/src/render3/interfaces/container.ts", - "packages/core/src/render3/interfaces/node.ts", "packages/core/src/render3/interfaces/view.ts" ], - [ - "packages/core/src/render3/interfaces/container.ts", - "packages/core/src/render3/interfaces/view.ts" - ], - [ - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts" - ], - [ - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts" - ], - [ - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts", - "packages/core/src/render3/interfaces/query.ts" - ], [ "packages/core/src/render3/interfaces/query.ts", "packages/core/src/render3/interfaces/view.ts" diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 97e2938df50..87385cf7021 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -322,6 +322,6 @@ export { AfterRenderEventManager as ɵAfterRenderEventManager, internalAfterNext export {depsTracker as ɵdepsTracker, USE_RUNTIME_DEPS_TRACKER_FOR_JIT as ɵUSE_RUNTIME_DEPS_TRACKER_FOR_JIT} from './render3/deps_tracker/deps_tracker'; export {generateStandaloneInDeclarationsError as ɵgenerateStandaloneInDeclarationsError} from './render3/jit/module'; export {getAsyncClassMetadataFn as ɵgetAsyncClassMetadataFn} from './render3/metadata'; -export {InputFlags as ɵɵInputFlags} from './render3/interfaces/definition'; +export {InputFlags as ɵɵInputFlags} from './render3/interfaces/input_flags'; // clang-format on diff --git a/packages/core/src/di/create_injector.ts b/packages/core/src/di/create_injector.ts index 143e46e90a0..d26401fcc9f 100644 --- a/packages/core/src/di/create_injector.ts +++ b/packages/core/src/di/create_injector.ts @@ -9,8 +9,8 @@ import {EMPTY_ARRAY} from '../util/empty'; import {stringify} from '../util/stringify'; -import {Injector} from './injector'; -import {Provider, StaticProvider} from './interface/provider'; +import type {Injector} from './injector'; +import type {Provider, StaticProvider} from './interface/provider'; import {importProvidersFrom} from './provider_collection'; import {getNullInjector, R3Injector} from './r3_injector'; import {InjectorScope} from './scope'; diff --git a/packages/core/src/di/injector_compatibility.ts b/packages/core/src/di/injector_compatibility.ts index e23bbcce9eb..46aef910deb 100644 --- a/packages/core/src/di/injector_compatibility.ts +++ b/packages/core/src/di/injector_compatibility.ts @@ -15,7 +15,7 @@ import {stringify} from '../util/stringify'; import {resolveForwardRef} from './forward_ref'; import {getInjectImplementation, injectRootLimpMode} from './inject_switch'; -import {Injector} from './injector'; +import type {Injector} from './injector'; import {DecoratorFlags, InjectFlags, InjectOptions, InternalInjectFlags} from './interface/injector'; import {ProviderToken} from './provider_token'; diff --git a/packages/core/src/di/injector_token.ts b/packages/core/src/di/injector_token.ts index ff37a5a7f8c..b6f5f7a7040 100644 --- a/packages/core/src/di/injector_token.ts +++ b/packages/core/src/di/injector_token.ts @@ -7,7 +7,7 @@ */ import {InjectionToken} from './injection_token'; -import {Injector} from './injector'; +import type {Injector} from './injector'; import {InjectorMarkers} from './injector_marker'; diff --git a/packages/core/src/di/null_injector.ts b/packages/core/src/di/null_injector.ts index 37f0b32db6c..86c87dca920 100644 --- a/packages/core/src/di/null_injector.ts +++ b/packages/core/src/di/null_injector.ts @@ -7,7 +7,7 @@ */ import {stringify} from '../util/stringify'; -import {Injector} from './injector'; +import type {Injector} from './injector'; import {THROW_IF_NOT_FOUND} from './injector_compatibility'; export class NullInjector implements Injector { diff --git a/packages/core/src/di/r3_injector.ts b/packages/core/src/di/r3_injector.ts index d3f680c80cd..43e2d71f534 100644 --- a/packages/core/src/di/r3_injector.ts +++ b/packages/core/src/di/r3_injector.ts @@ -23,7 +23,7 @@ import {resolveForwardRef} from './forward_ref'; import {ENVIRONMENT_INITIALIZER} from './initializer_token'; import {setInjectImplementation} from './inject_switch'; import {InjectionToken} from './injection_token'; -import {Injector} from './injector'; +import type {Injector} from './injector'; import {catchInjectorError, convertToBitFlags, injectArgs, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, ɵɵinject} from './injector_compatibility'; import {INJECTOR} from './injector_token'; import {getInheritedInjectableDef, getInjectableDef, InjectorType, ɵɵInjectableDeclaration} from './interface/defs'; diff --git a/packages/core/src/hydration/utils.ts b/packages/core/src/hydration/utils.ts index d987e6b29d8..a883899d247 100644 --- a/packages/core/src/hydration/utils.ts +++ b/packages/core/src/hydration/utils.ts @@ -7,7 +7,7 @@ */ import {Injector} from '../di/injector'; -import {ViewRef} from '../linker/view_ref'; +import type {ViewRef} from '../linker/view_ref'; import {LContainer} from '../render3/interfaces/container'; import {getDocument} from '../render3/interfaces/document'; import {RElement, RNode} from '../render3/interfaces/renderer_dom'; diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index cf6477c03b9..a168834c0f3 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -37,7 +37,8 @@ import {reportUnknownPropertyError} from './instructions/element_validation'; import {markViewDirty} from './instructions/mark_view_dirty'; import {renderView} from './instructions/render'; import {addToViewTree, createLView, createTView, executeContentQueries, getOrCreateComponentTView, getOrCreateTNode, initializeDirectives, invokeDirectivesHostBindings, locateHostElement, markAsComponentHost, setInputsForProperty} from './instructions/shared'; -import {ComponentDef, DirectiveDef, HostDirectiveDefs, InputFlags} from './interfaces/definition'; +import {ComponentDef, DirectiveDef, HostDirectiveDefs} from './interfaces/definition'; +import {InputFlags} from './interfaces/input_flags'; import {NodeInputBindings, TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node'; import {Renderer} from './interfaces/renderer'; import {RElement, RNode} from './interfaces/renderer_dom'; diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index 6922d451838..771d654ab7c 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -18,8 +18,9 @@ import {initNgDevMode} from '../util/ng_dev_mode'; import {stringify} from '../util/stringify'; import {NG_COMP_DEF, NG_DIR_DEF, NG_MOD_DEF, NG_PIPE_DEF} from './fields'; -import {ComponentDef, ComponentDefFeature, ComponentTemplate, ContentQueriesFunction, DependencyTypeList, DirectiveDef, DirectiveDefFeature, DirectiveDefListOrFactory, HostBindingsFunction, InputFlags, InputTransformFunction, PipeDef, PipeDefListOrFactory, TypeOrFactory, ViewQueriesFunction} from './interfaces/definition'; -import {TAttributes, TConstantsOrFactory} from './interfaces/node'; +import type {ComponentDef, ComponentDefFeature, ComponentTemplate, ContentQueriesFunction, DependencyTypeList, DirectiveDef, DirectiveDefFeature, DirectiveDefListOrFactory, HostBindingsFunction, InputTransformFunction, PipeDef, PipeDefListOrFactory, TypeOrFactory, ViewQueriesFunction} from './interfaces/definition'; +import { InputFlags } from './interfaces/input_flags'; +import type {TAttributes, TConstantsOrFactory} from './interfaces/node'; import {CssSelectorList} from './interfaces/projection'; import {stringifyCSSSelectorList} from './node_selector_matcher'; diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index e118e4ff015..ddcf50f5522 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -23,9 +23,10 @@ import {getFactoryDef} from './definition_factory'; import {throwCyclicDependencyError, throwProviderNotFoundError} from './errors_di'; import {NG_ELEMENT_ID, NG_FACTORY_DEF} from './fields'; import {registerPreOrderHooks} from './hooks'; +import { AttributeMarker } from './interfaces/attribute_marker'; import {ComponentDef, DirectiveDef} from './interfaces/definition'; import {isFactory, NO_PARENT_INJECTOR, NodeInjectorFactory, NodeInjectorOffset, RelativeInjectorLocation, RelativeInjectorLocationFlags} from './interfaces/injector'; -import {AttributeMarker, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeProviderIndexes, TNodeType} from './interfaces/node'; +import {TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeProviderIndexes, TNodeType} from './interfaces/node'; import {isComponentDef, isComponentHost} from './interfaces/type_checks'; import {DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, EMBEDDED_VIEW_INJECTOR, FLAGS, INJECTOR, LView, LViewFlags, T_HOST, TData, TVIEW, TView, TViewType} from './interfaces/view'; import {assertTNodeType} from './node_assert'; diff --git a/packages/core/src/render3/features/ng_onchanges_feature.ts b/packages/core/src/render3/features/ng_onchanges_feature.ts index d5d0e166cb9..962a2a882f4 100644 --- a/packages/core/src/render3/features/ng_onchanges_feature.ts +++ b/packages/core/src/render3/features/ng_onchanges_feature.ts @@ -12,7 +12,7 @@ import {SimpleChange, SimpleChanges} from '../../interface/simple_change'; import {assertString} from '../../util/assert'; import {EMPTY_OBJ} from '../../util/empty'; import {applyValueToInputField} from '../apply_value_input_field'; -import {DirectiveDef, DirectiveDefFeature, InputFlags} from '../interfaces/definition'; +import {DirectiveDef, DirectiveDefFeature} from '../interfaces/definition'; /** * The NgOnChangesFeature decorates a component with support for the ngOnChanges diff --git a/packages/core/src/render3/index.ts b/packages/core/src/render3/index.ts index 0844c65855f..03e07ffadc3 100644 --- a/packages/core/src/render3/index.ts +++ b/packages/core/src/render3/index.ts @@ -185,7 +185,7 @@ export {ɵɵi18n, ɵɵi18nApply, ɵɵi18nAttributes, ɵɵi18nEnd, ɵɵi18nExp,ɵ export {RenderFlags} from './interfaces/definition'; export { AttributeMarker -} from './interfaces/node'; +} from './interfaces/attribute_marker'; export {CssSelectorList, ProjectionSlots} from './interfaces/projection'; export { setClassMetadata, diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 923c5d12e7a..1a0045b56b3 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -31,10 +31,10 @@ import {getFactoryDef} from '../definition_factory'; import {diPublicInInjector, getNodeInjectable, getOrCreateNodeInjectorForNode} from '../di'; import {throwMultipleComponentError} from '../errors'; import {CONTAINER_HEADER_OFFSET, LContainer} from '../interfaces/container'; -import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefListOrFactory, HostBindingsFunction, HostDirectiveBindingMap, HostDirectiveDefs, InputFlags, PipeDefListOrFactory, RenderFlags, ViewQueriesFunction} from '../interfaces/definition'; +import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefListOrFactory, HostBindingsFunction, HostDirectiveBindingMap, HostDirectiveDefs, PipeDefListOrFactory, RenderFlags, ViewQueriesFunction} from '../interfaces/definition'; import {NodeInjectorFactory} from '../interfaces/injector'; import {getUniqueLViewId} from '../interfaces/lview_tracking'; -import {AttributeMarker, InitialInputData, InitialInputs, LocalRefExtractor, NodeInputBindings, NodeOutputBindings, TAttributes, TConstantsOrFactory, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TIcuContainerNode, TNode, TNodeFlags, TNodeType, TProjectionNode} from '../interfaces/node'; +import {InitialInputData, InitialInputs, LocalRefExtractor, NodeInputBindings, NodeOutputBindings, TAttributes, TConstantsOrFactory, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TIcuContainerNode, TNode, TNodeFlags, TNodeType, TProjectionNode} from '../interfaces/node'; import {Renderer} from '../interfaces/renderer'; import {RComment, RElement, RNode, RText} from '../interfaces/renderer_dom'; import {SanitizerFn} from '../interfaces/sanitization'; @@ -56,6 +56,8 @@ import {selectIndexInternal} from './advance'; import {ɵɵdirectiveInject} from './di'; import {handleUnknownPropertyError, isPropertyValid, matchingSchemas} from './element_validation'; import {writeToDirectiveInput} from './write_to_directive_input'; +import { AttributeMarker } from '../interfaces/attribute_marker'; +import { InputFlags } from '../interfaces/input_flags'; /** * Invoke `HostBindingsFunction`s for view. diff --git a/packages/core/src/render3/instructions/styling.ts b/packages/core/src/render3/instructions/styling.ts index c7ebce5b48a..449f3d8f4cb 100644 --- a/packages/core/src/render3/instructions/styling.ts +++ b/packages/core/src/render3/instructions/styling.ts @@ -13,8 +13,9 @@ import {EMPTY_ARRAY} from '../../util/empty'; import {concatStringsWithSpace, stringify} from '../../util/stringify'; import {assertFirstUpdatePass} from '../assert'; import {bindingUpdated} from '../bindings'; +import { AttributeMarker } from '../interfaces/attribute_marker'; import {DirectiveDef} from '../interfaces/definition'; -import {AttributeMarker, TAttributes, TNode, TNodeFlags, TNodeType} from '../interfaces/node'; +import {TAttributes, TNode, TNodeFlags, TNodeType} from '../interfaces/node'; import {Renderer} from '../interfaces/renderer'; import {RElement} from '../interfaces/renderer_dom'; import {getTStylingRangeNext, getTStylingRangeNextDuplicate, getTStylingRangePrev, getTStylingRangePrevDuplicate, TStylingKey, TStylingRange} from '../interfaces/styling'; diff --git a/packages/core/src/render3/instructions/write_to_directive_input.ts b/packages/core/src/render3/instructions/write_to_directive_input.ts index fa9479b99b1..47dadd1c2c4 100644 --- a/packages/core/src/render3/instructions/write_to_directive_input.ts +++ b/packages/core/src/render3/instructions/write_to_directive_input.ts @@ -11,7 +11,8 @@ import {setActiveConsumer, SIGNAL} from '@angular/core/primitives/signals'; import {InputSignalWithTransform} from '../../authoring/input/input_signal'; import {InputSignalNode} from '../../authoring/input/input_signal_node'; import {applyValueToInputField} from '../apply_value_input_field'; -import {DirectiveDef, InputFlags} from '../interfaces/definition'; +import {DirectiveDef} from '../interfaces/definition'; +import { InputFlags } from '../interfaces/input_flags'; export function writeToDirectiveInput( def: DirectiveDef, instance: T, publicName: string, privateName: string, flags: InputFlags, diff --git a/packages/core/src/render3/interfaces/attribute_marker.ts b/packages/core/src/render3/interfaces/attribute_marker.ts new file mode 100644 index 00000000000..efb38d771f7 --- /dev/null +++ b/packages/core/src/render3/interfaces/attribute_marker.ts @@ -0,0 +1,142 @@ +/** + * @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 + */ + +/** + * A set of marker values to be used in the attributes arrays. These markers indicate that some + * items are not regular attributes and the processing should be adapted accordingly. + */ +export const enum AttributeMarker { + /** + * An implicit marker which indicates that the value in the array are of `attributeKey`, + * `attributeValue` format. + * + * NOTE: This is implicit as it is the type when no marker is present in array. We indicate that + * it should not be present at runtime by the negative number. + */ + ImplicitAttributes = -1, + + /** + * Marker indicates that the following 3 values in the attributes array are: + * namespaceUri, attributeName, attributeValue + * in that order. + */ + NamespaceURI = 0, + + /** + * Signals class declaration. + * + * Each value following `Classes` designates a class name to include on the element. + * ## Example: + * + * Given: + * ``` + *
... + * ``` + * + * the generated code is: + * ``` + * var _c1 = [AttributeMarker.Classes, 'foo', 'bar', 'baz']; + * ``` + */ + Classes = 1, + + /** + * Signals style declaration. + * + * Each pair of values following `Styles` designates a style name and value to include on the + * element. + * ## Example: + * + * Given: + * ``` + *
...
+ * ``` + * + * the generated code is: + * ``` + * var _c1 = [AttributeMarker.Styles, 'width', '100px', 'height'. '200px', 'color', 'red']; + * ``` + */ + Styles = 2, + + /** + * Signals that the following attribute names were extracted from input or output bindings. + * + * For example, given the following HTML: + * + * ``` + *
+ * ``` + * + * the generated code is: + * + * ``` + * var _c1 = ['moo', 'car', AttributeMarker.Bindings, 'foo', 'bar']; + * ``` + */ + Bindings = 3, + + /** + * Signals that the following attribute names were hoisted from an inline-template declaration. + * + * For example, given the following HTML: + * + * ``` + *
+ * ``` + * + * the generated code for the `template()` instruction would include: + * + * ``` + * ['dirA', '', AttributeMarker.Bindings, 'dirB', AttributeMarker.Template, 'ngFor', 'ngForOf', + * 'ngForTrackBy', 'let-value'] + * ``` + * + * while the generated code for the `element()` instruction inside the template function would + * include: + * + * ``` + * ['dirA', '', AttributeMarker.Bindings, 'dirB'] + * ``` + */ + Template = 4, + + /** + * Signals that the following attribute is `ngProjectAs` and its value is a parsed + * `CssSelector`. + * + * For example, given the following HTML: + * + * ``` + *

+ * ``` + * + * the generated code for the `element()` instruction would include: + * + * ``` + * ['attr', 'value', AttributeMarker.ProjectAs, ['', 'title', '']] + * ``` + */ + ProjectAs = 5, + + /** + * Signals that the following attribute will be translated by runtime i18n + * + * For example, given the following HTML: + * + * ``` + *
+ * ``` + * + * the generated code is: + * + * ``` + * var _c1 = ['moo', 'car', AttributeMarker.I18n, 'foo', 'bar']; + */ + I18n = 6, +} diff --git a/packages/core/src/render3/interfaces/definition.ts b/packages/core/src/render3/interfaces/definition.ts index f7547924aba..0e51ce40567 100644 --- a/packages/core/src/render3/interfaces/definition.ts +++ b/packages/core/src/render3/interfaces/definition.ts @@ -16,7 +16,8 @@ import {FactoryFn} from '../definition_factory'; import {TAttributes, TConstantsOrFactory} from './node'; import {CssSelectorList} from './projection'; -import {TView} from './view'; +import type {TView} from './view'; +import {InputFlags} from './input_flags'; /** @@ -88,13 +89,6 @@ export interface PipeType extends Type { ɵpipe: unknown; } -/** Flags describing an input for a directive. */ -export enum InputFlags { - None = 0, - SignalBased = 1 << 0, - HasDecoratorInputTransform = 1 << 1, -} - /** * Runtime link information for Directives. * diff --git a/packages/core/src/render3/interfaces/input_flags.ts b/packages/core/src/render3/interfaces/input_flags.ts new file mode 100644 index 00000000000..b931a5fcb7b --- /dev/null +++ b/packages/core/src/render3/interfaces/input_flags.ts @@ -0,0 +1,14 @@ +/** + * @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 + */ + +/** Flags describing an input for a directive. */ +export enum InputFlags { + None = 0, + SignalBased = 1 << 0, + HasDecoratorInputTransform = 1 << 1, +} diff --git a/packages/core/src/render3/interfaces/node.ts b/packages/core/src/render3/interfaces/node.ts index 32e1982c33e..17c711f959f 100644 --- a/packages/core/src/render3/interfaces/node.ts +++ b/packages/core/src/render3/interfaces/node.ts @@ -7,12 +7,13 @@ */ import {KeyValueArray} from '../../util/array_utils'; import {TStylingRange} from '../interfaces/styling'; +import { AttributeMarker } from './attribute_marker'; -import type {InputFlags} from './definition'; +import {InputFlags} from './input_flags'; import {TIcu} from './i18n'; import {CssSelector} from './projection'; import {RNode} from './renderer_dom'; -import {LView, TView} from './view'; +import type {LView, TView} from './view'; /** @@ -164,141 +165,6 @@ export const enum TNodeProviderIndexes { CptViewProvidersCountShifter = 0b00000000000100000000000000000000, } -/** - * A set of marker values to be used in the attributes arrays. These markers indicate that some - * items are not regular attributes and the processing should be adapted accordingly. - */ -export const enum AttributeMarker { - /** - * An implicit marker which indicates that the value in the array are of `attributeKey`, - * `attributeValue` format. - * - * NOTE: This is implicit as it is the type when no marker is present in array. We indicate that - * it should not be present at runtime by the negative number. - */ - ImplicitAttributes = -1, - - /** - * Marker indicates that the following 3 values in the attributes array are: - * namespaceUri, attributeName, attributeValue - * in that order. - */ - NamespaceURI = 0, - - /** - * Signals class declaration. - * - * Each value following `Classes` designates a class name to include on the element. - * ## Example: - * - * Given: - * ``` - *
... - * ``` - * - * the generated code is: - * ``` - * var _c1 = [AttributeMarker.Classes, 'foo', 'bar', 'baz']; - * ``` - */ - Classes = 1, - - /** - * Signals style declaration. - * - * Each pair of values following `Styles` designates a style name and value to include on the - * element. - * ## Example: - * - * Given: - * ``` - *
...
- * ``` - * - * the generated code is: - * ``` - * var _c1 = [AttributeMarker.Styles, 'width', '100px', 'height'. '200px', 'color', 'red']; - * ``` - */ - Styles = 2, - - /** - * Signals that the following attribute names were extracted from input or output bindings. - * - * For example, given the following HTML: - * - * ``` - *
- * ``` - * - * the generated code is: - * - * ``` - * var _c1 = ['moo', 'car', AttributeMarker.Bindings, 'foo', 'bar']; - * ``` - */ - Bindings = 3, - - /** - * Signals that the following attribute names were hoisted from an inline-template declaration. - * - * For example, given the following HTML: - * - * ``` - *
- * ``` - * - * the generated code for the `template()` instruction would include: - * - * ``` - * ['dirA', '', AttributeMarker.Bindings, 'dirB', AttributeMarker.Template, 'ngFor', 'ngForOf', - * 'ngForTrackBy', 'let-value'] - * ``` - * - * while the generated code for the `element()` instruction inside the template function would - * include: - * - * ``` - * ['dirA', '', AttributeMarker.Bindings, 'dirB'] - * ``` - */ - Template = 4, - - /** - * Signals that the following attribute is `ngProjectAs` and its value is a parsed - * `CssSelector`. - * - * For example, given the following HTML: - * - * ``` - *

- * ``` - * - * the generated code for the `element()` instruction would include: - * - * ``` - * ['attr', 'value', AttributeMarker.ProjectAs, ['', 'title', '']] - * ``` - */ - ProjectAs = 5, - - /** - * Signals that the following attribute will be translated by runtime i18n - * - * For example, given the following HTML: - * - * ``` - *
- * ``` - * - * the generated code is: - * - * ``` - * var _c1 = ['moo', 'car', AttributeMarker.I18n, 'foo', 'bar']; - */ - I18n = 6, -} - /** * A combination of: * - Attribute names and values. diff --git a/packages/core/src/render3/interfaces/view.ts b/packages/core/src/render3/interfaces/view.ts index 2ed5f69e036..89ea1f82cd6 100644 --- a/packages/core/src/render3/interfaces/view.ts +++ b/packages/core/src/render3/interfaces/view.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Injector} from '../../di/injector'; +import type {Injector} from '../../di/injector'; import {ProviderToken} from '../../di/provider_token'; import {DehydratedView} from '../../hydration/interfaces'; import {SchemaMetadata} from '../../metadata/schema'; diff --git a/packages/core/src/render3/jit/environment.ts b/packages/core/src/render3/jit/environment.ts index a38119d5870..4ccb8b62a72 100644 --- a/packages/core/src/render3/jit/environment.ts +++ b/packages/core/src/render3/jit/environment.ts @@ -10,7 +10,7 @@ import {forwardRef, resolveForwardRef} from '../../di/forward_ref'; import {ɵɵinject, ɵɵinvalidFactoryDep} from '../../di/injector_compatibility'; import {ɵɵdefineInjectable, ɵɵdefineInjector} from '../../di/interface/defs'; import {registerNgModuleType} from '../../linker/ng_module_registration'; -import {InputFlags} from '../../render3/interfaces/definition'; +import {InputFlags} from '../../render3/interfaces/input_flags'; import * as iframe_attrs_validation from '../../sanitization/iframe_attrs_validation'; import * as sanitization from '../../sanitization/sanitization'; import * as r3 from '../index'; diff --git a/packages/core/src/render3/node_selector_matcher.ts b/packages/core/src/render3/node_selector_matcher.ts index 68120f447f6..f85ce3dafa0 100644 --- a/packages/core/src/render3/node_selector_matcher.ts +++ b/packages/core/src/render3/node_selector_matcher.ts @@ -10,10 +10,11 @@ import '../util/ng_dev_mode'; import {assertDefined, assertEqual, assertNotEqual} from '../util/assert'; -import {AttributeMarker, TAttributes, TNode, TNodeType} from './interfaces/node'; +import {TAttributes, TNode, TNodeType} from './interfaces/node'; import {CssSelector, CssSelectorList, SelectorFlags} from './interfaces/projection'; import {classIndexOf} from './styling/class_differ'; import {isNameOnlyAttributeMarker} from './util/attrs_utils'; +import { AttributeMarker } from './interfaces/attribute_marker'; const NG_TEMPLATE_SELECTOR = 'ng-template'; diff --git a/packages/core/src/render3/styling/static_styling.ts b/packages/core/src/render3/styling/static_styling.ts index c055b661b05..3bf5ecbded6 100644 --- a/packages/core/src/render3/styling/static_styling.ts +++ b/packages/core/src/render3/styling/static_styling.ts @@ -8,7 +8,8 @@ import {concatStringsWithSpace} from '../../util/stringify'; import {assertFirstCreatePass} from '../assert'; -import {AttributeMarker, TAttributes, TNode} from '../interfaces/node'; +import { AttributeMarker } from '../interfaces/attribute_marker'; +import {TAttributes, TNode} from '../interfaces/node'; import {getTView} from '../state'; /** diff --git a/packages/core/src/render3/util/attrs_utils.ts b/packages/core/src/render3/util/attrs_utils.ts index e1b9d4d8eac..aaa870c2b73 100644 --- a/packages/core/src/render3/util/attrs_utils.ts +++ b/packages/core/src/render3/util/attrs_utils.ts @@ -6,7 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ import {CharCode} from '../../util/char_code'; -import {AttributeMarker, TAttributes} from '../interfaces/node'; +import { AttributeMarker } from '../interfaces/attribute_marker'; +import {TAttributes} from '../interfaces/node'; import {CssSelector} from '../interfaces/projection'; import {Renderer} from '../interfaces/renderer'; import {RElement} from '../interfaces/renderer_dom'; diff --git a/packages/core/src/render3/util/discovery_utils.ts b/packages/core/src/render3/util/discovery_utils.ts index 4dc06747ebf..e777fce394c 100644 --- a/packages/core/src/render3/util/discovery_utils.ts +++ b/packages/core/src/render3/util/discovery_utils.ts @@ -13,7 +13,7 @@ import {assertLView} from '../assert'; import {discoverLocalRefs, getComponentAtNodeIndex, getDirectivesAtNodeIndex, getLContext, readPatchedLView} from '../context_discovery'; import {getComponentDef, getDirectiveDef} from '../definition'; import {NodeInjector} from '../di'; -import {DirectiveDef, InputFlags} from '../interfaces/definition'; +import {DirectiveDef} from '../interfaces/definition'; import {TElementNode, TNode, TNodeProviderIndexes} from '../interfaces/node'; import {CLEANUP, CONTEXT, FLAGS, LView, LViewFlags, TVIEW, TViewType} from '../interfaces/view'; diff --git a/packages/core/test/bundling/defer/bundle.golden_symbols.json b/packages/core/test/bundling/defer/bundle.golden_symbols.json index c553df78117..7f62da22b46 100644 --- a/packages/core/test/bundling/defer/bundle.golden_symbols.json +++ b/packages/core/test/bundling/defer/bundle.golden_symbols.json @@ -1217,9 +1217,6 @@ { "name": "init_definition" }, - { - "name": "init_definition2" - }, { "name": "init_definition_factory" }, @@ -1463,6 +1460,9 @@ { "name": "init_input" }, + { + "name": "init_input_flags" + }, { "name": "init_input_signal" }, diff --git a/packages/core/test/render3/instructions/styling_spec.ts b/packages/core/test/render3/instructions/styling_spec.ts index c8883fa8e00..0308b69d481 100644 --- a/packages/core/test/render3/instructions/styling_spec.ts +++ b/packages/core/test/render3/instructions/styling_spec.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {DirectiveDef} from '@angular/core/src/render3'; +import {AttributeMarker, DirectiveDef} from '@angular/core/src/render3'; import {ɵɵdefineDirective} from '@angular/core/src/render3/definition'; import {classStringParser, styleStringParser, toStylingKeyValueArray, ɵɵclassProp, ɵɵstyleMap, ɵɵstyleProp} from '@angular/core/src/render3/instructions/styling'; -import {AttributeMarker, TAttributes} from '@angular/core/src/render3/interfaces/node'; +import {TAttributes} from '@angular/core/src/render3/interfaces/node'; import {getTStylingRangeNext, getTStylingRangeNextDuplicate, getTStylingRangePrev, getTStylingRangePrevDuplicate, setTStylingRangeNext, setTStylingRangePrev, StylingRange, toTStylingRange, TStylingKey, TStylingRange} from '@angular/core/src/render3/interfaces/styling'; import {HEADER_OFFSET, TVIEW} from '@angular/core/src/render3/interfaces/view'; import {getLView, leaveView, setBindingRootForHostBindings} from '@angular/core/src/render3/state'; diff --git a/packages/core/test/render3/instructions_spec.ts b/packages/core/test/render3/instructions_spec.ts index f7d94138899..5d32ce7e0dd 100644 --- a/packages/core/test/render3/instructions_spec.ts +++ b/packages/core/test/render3/instructions_spec.ts @@ -13,7 +13,7 @@ import {TestBed} from '@angular/core/testing'; import {getSortedClassName} from '@angular/core/testing/src/styling'; import {ɵɵadvance, ɵɵattribute, ɵɵclassMap, ɵɵelement, ɵɵproperty, ɵɵstyleMap, ɵɵstyleProp} from '../../src/render3/index'; -import {AttributeMarker} from '../../src/render3/interfaces/node'; +import {AttributeMarker} from '../../src/render3/interfaces/attribute_marker'; import {bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl, getSanitizationBypassType, SafeValue, unwrapSafeValue} from '../../src/sanitization/bypass'; import {ɵɵsanitizeHtml, ɵɵsanitizeResourceUrl, ɵɵsanitizeScript, ɵɵsanitizeStyle, ɵɵsanitizeUrl} from '../../src/sanitization/sanitization'; import {Sanitizer} from '../../src/sanitization/sanitizer'; diff --git a/packages/core/test/render3/node_selector_matcher_spec.ts b/packages/core/test/render3/node_selector_matcher_spec.ts index c1f6494f738..14e8e902682 100644 --- a/packages/core/test/render3/node_selector_matcher_spec.ts +++ b/packages/core/test/render3/node_selector_matcher_spec.ts @@ -8,7 +8,8 @@ import {createTNode} from '@angular/core/src/render3/instructions/shared'; -import {AttributeMarker, TAttributes, TNode, TNodeType} from '../../src/render3/interfaces/node'; +import {AttributeMarker} from '../../src/render3/interfaces/attribute_marker'; +import {TAttributes, TNode, TNodeType} from '../../src/render3/interfaces/node'; import {CssSelector, CssSelectorList, SelectorFlags} from '../../src/render3/interfaces/projection'; import {extractAttrsAndClassesFromSelector, getProjectAsAttrValue, isNodeMatchingSelector, isNodeMatchingSelectorList, stringifyCSSSelectorList} from '../../src/render3/node_selector_matcher'; diff --git a/packages/core/test/render3/styling_next/static_styling_spec.ts b/packages/core/test/render3/styling_next/static_styling_spec.ts index 1596e96db69..3c2ff9a52fa 100644 --- a/packages/core/test/render3/styling_next/static_styling_spec.ts +++ b/packages/core/test/render3/styling_next/static_styling_spec.ts @@ -7,7 +7,8 @@ */ import {createTNode} from '@angular/core/src/render3/instructions/shared'; -import {AttributeMarker, TAttributes, TNode, TNodeType} from '@angular/core/src/render3/interfaces/node'; +import {AttributeMarker} from '@angular/core/src/render3/interfaces/attribute_marker'; +import {TAttributes, TNode, TNodeType} from '@angular/core/src/render3/interfaces/node'; import {LView} from '@angular/core/src/render3/interfaces/view'; import {enterView} from '@angular/core/src/render3/state'; import {computeStaticStyling} from '@angular/core/src/render3/styling/static_styling';