Skip to content

Commit db62b5f

Browse files
mheveryatscott
authored andcommitted
refactor(core): Remove circular dependency on render3 and ng_module (#39710)
Extracted `NgModeDef` into a separate file to break the circular dependency. PR Close #39710
1 parent 05b22a9 commit db62b5f

File tree

12 files changed

+205
-714
lines changed

12 files changed

+205
-714
lines changed

goldens/circular-deps/packages.json

Lines changed: 111 additions & 639 deletions
Large diffs are not rendered by default.

packages/core/src/core_render3_private_export.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ export {
5656
SWITCH_COMPILE_PIPE__POST_R3__ as ɵSWITCH_COMPILE_PIPE__POST_R3__,
5757
} from './metadata/directives';
5858
export {
59-
NgModuleDef as ɵNgModuleDef,
60-
NgModuleTransitiveScopes as ɵNgModuleTransitiveScopes,
6159
ɵɵNgModuleDefWithMeta,
6260
} from './metadata/ng_module';
6361
export {
6462
SWITCH_COMPILE_NGMODULE__POST_R3__ as ɵSWITCH_COMPILE_NGMODULE__POST_R3__,
6563
} from './metadata/ng_module';
64+
export {
65+
NgModuleDef as ɵNgModuleDef,
66+
NgModuleTransitiveScopes as ɵNgModuleTransitiveScopes,
67+
} from './metadata/ng_module_def';
6668
export {
6769
SWITCH_RENDERER2_FACTORY__POST_R3__ as ɵSWITCH_RENDERER2_FACTORY__POST_R3__,
6870
} from './render/api';

packages/core/src/linker/ng_module_factory_loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {NgModuleFactory as R3NgModuleFactory, NgModuleType} from '../render3/ng_module_ref';
9+
import {NgModuleType} from '../metadata/ng_module_def';
10+
import {NgModuleFactory as R3NgModuleFactory} from '../render3/ng_module_ref';
1011

1112
import {NgModuleFactory} from './ng_module_factory';
1213
import {getRegisteredNgModuleType} from './ng_module_factory_registration';

packages/core/src/linker/ng_module_factory_registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
import {Type} from '../interface/type';
11+
import {NgModuleType} from '../metadata/ng_module_def';
1112
import {autoRegisterModuleById, getNgModuleDef} from '../render3/definition';
12-
import {NgModuleType} from '../render3/ng_module_ref';
1313
import {maybeUnwrapFn} from '../render3/util/misc_utils';
1414
import {stringify} from '../util/stringify';
1515

packages/core/src/metadata/ng_module.ts

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,14 @@ import {Type} from '../interface/type';
1313
import {SchemaMetadata} from '../metadata/schema';
1414
import {compileNgModule as render3CompileNgModule} from '../render3/jit/module';
1515
import {makeDecorator, TypeDecorator} from '../util/decorators';
16+
import {NgModuleDef} from './ng_module_def';
1617

1718

18-
/**
19-
* Represents the expansion of an `NgModule` into its scopes.
20-
*
21-
* A scope is a set of directives and pipes that are visible in a particular context. Each
22-
* `NgModule` has two scopes. The `compilation` scope is the set of directives and pipes that will
23-
* be recognized in the templates of components declared by the module. The `exported` scope is the
24-
* set of directives and pipes exported by a module (that is, module B's exported scope gets added
25-
* to module A's compilation scope when module A imports B).
26-
*/
27-
export interface NgModuleTransitiveScopes {
28-
compilation: {directives: Set<any>; pipes: Set<any>;};
29-
exported: {directives: Set<any>; pipes: Set<any>;};
30-
schemas: SchemaMetadata[]|null;
31-
}
32-
3319
/**
3420
* @publicApi
3521
*/
3622
export type ɵɵNgModuleDefWithMeta<T, Declarations, Imports, Exports> = NgModuleDef<T>;
3723

38-
/**
39-
* Runtime link information for NgModules.
40-
*
41-
* This is the internal data structure used by the runtime to assemble components, directives,
42-
* pipes, and injectors.
43-
*
44-
* NOTE: Always use `ɵɵdefineNgModule` function to create this object,
45-
* never create the object directly since the shape of this object
46-
* can change between versions.
47-
*/
48-
export interface NgModuleDef<T> {
49-
/** Token representing the module. Used by DI. */
50-
type: T;
51-
52-
/** List of components to bootstrap. */
53-
bootstrap: Type<any>[]|(() => Type<any>[]);
54-
55-
/** List of components, directives, and pipes declared by this module. */
56-
declarations: Type<any>[]|(() => Type<any>[]);
57-
58-
/** List of modules or `ModuleWithProviders` imported by this module. */
59-
imports: Type<any>[]|(() => Type<any>[]);
60-
61-
/**
62-
* List of modules, `ModuleWithProviders`, components, directives, or pipes exported by this
63-
* module.
64-
*/
65-
exports: Type<any>[]|(() => Type<any>[]);
66-
67-
/**
68-
* Cached value of computed `transitiveCompileScopes` for this module.
69-
*
70-
* This should never be read directly, but accessed via `transitiveScopesFor`.
71-
*/
72-
transitiveCompileScopes: NgModuleTransitiveScopes|null;
73-
74-
/** The set of schemas that declare elements to be allowed in the NgModule. */
75-
schemas: SchemaMetadata[]|null;
76-
77-
/** Unique ID for the module with which it should be registered. */
78-
id: string|null;
79-
}
8024

8125
/**
8226
* A wrapper around an NgModule that associates it with [providers](guide/glossary#provider
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 {Type} from '../interface/type';
10+
import {SchemaMetadata} from './schema';
11+
12+
13+
export interface NgModuleType<T = any> extends Type<T> {
14+
ɵmod: NgModuleDef<T>;
15+
}
16+
17+
/**
18+
* Represents the expansion of an `NgModule` into its scopes.
19+
*
20+
* A scope is a set of directives and pipes that are visible in a particular context. Each
21+
* `NgModule` has two scopes. The `compilation` scope is the set of directives and pipes that will
22+
* be recognized in the templates of components declared by the module. The `exported` scope is the
23+
* set of directives and pipes exported by a module (that is, module B's exported scope gets added
24+
* to module A's compilation scope when module A imports B).
25+
*/
26+
export interface NgModuleTransitiveScopes {
27+
compilation: {directives: Set<any>; pipes: Set<any>;};
28+
exported: {directives: Set<any>; pipes: Set<any>;};
29+
schemas: SchemaMetadata[]|null;
30+
}
31+
32+
/**
33+
* Runtime link information for NgModules.
34+
*
35+
* This is the internal data structure used by the runtime to assemble components, directives,
36+
* pipes, and injectors.
37+
*
38+
* NOTE: Always use `ɵɵdefineNgModule` function to create this object,
39+
* never create the object directly since the shape of this object
40+
* can change between versions.
41+
*/
42+
export interface NgModuleDef<T> {
43+
/** Token representing the module. Used by DI. */
44+
type: T;
45+
46+
/** List of components to bootstrap. */
47+
bootstrap: Type<any>[]|(() => Type<any>[]);
48+
49+
/** List of components, directives, and pipes declared by this module. */
50+
declarations: Type<any>[]|(() => Type<any>[]);
51+
52+
/** List of modules or `ModuleWithProviders` imported by this module. */
53+
imports: Type<any>[]|(() => Type<any>[]);
54+
55+
/**
56+
* List of modules, `ModuleWithProviders`, components, directives, or pipes exported by this
57+
* module.
58+
*/
59+
exports: Type<any>[]|(() => Type<any>[]);
60+
61+
/**
62+
* Cached value of computed `transitiveCompileScopes` for this module.
63+
*
64+
* This should never be read directly, but accessed via `transitiveScopesFor`.
65+
*/
66+
transitiveCompileScopes: NgModuleTransitiveScopes|null;
67+
68+
/** The set of schemas that declare elements to be allowed in the NgModule. */
69+
schemas: SchemaMetadata[]|null;
70+
71+
/** Unique ID for the module with which it should be registered. */
72+
id: string|null;
73+
}

packages/core/src/r3_symbols.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
export {ɵɵinject} from './di/injector_compatibility';
2525
export {ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵInjectableDef, ɵɵInjectorDef} from './di/interface/defs';
26-
export {NgModuleDef, ɵɵNgModuleDefWithMeta} from './metadata/ng_module';
26+
export {ɵɵNgModuleDefWithMeta} from './metadata/ng_module';
27+
export {NgModuleDef} from './metadata/ng_module_def';
2728
export {ɵɵdefineNgModule} from './render3/definition';
2829
export {ɵɵFactoryDef} from './render3/interfaces/definition';
2930
export {setClassMetadata} from './render3/metadata';

packages/core/src/render3/definition.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {ChangeDetectionStrategy} from '../change_detection/constants';
1010
import {Mutable, Type} from '../interface/type';
11-
import {NgModuleDef} from '../metadata/ng_module';
11+
import {NgModuleDef, NgModuleType} from '../metadata/ng_module_def';
1212
import {SchemaMetadata} from '../metadata/schema';
1313
import {ViewEncapsulation} from '../metadata/view';
1414
import {noSideEffects} from '../util/closure';
@@ -20,7 +20,6 @@ import {NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF, NG_LOC_ID_DEF, NG_MOD_DEF, NG_P
2020
import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, DirectiveTypesOrFactory, FactoryFn, HostBindingsFunction, PipeDef, PipeType, PipeTypesOrFactory, ViewQueriesFunction} from './interfaces/definition';
2121
import {AttributeMarker, TAttributes, TConstantsOrFactory} from './interfaces/node';
2222
import {CssSelectorList, SelectorFlags} from './interfaces/projection';
23-
import {NgModuleType} from './ng_module_ref';
2423

2524
let _renderCompCount = 0;
2625

packages/core/src/render3/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {ɵɵProvidersFeature} from './features/providers_feature';
1414
import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveType, PipeDef, ɵɵComponentDefWithMeta, ɵɵDirectiveDefWithMeta, ɵɵFactoryDef, ɵɵPipeDefWithMeta} from './interfaces/definition';
1515
import {getComponent, getDirectives, getHostElement, getRenderedText} from './util/discovery_utils';
1616

17+
export {NgModuleType} from '../metadata/ng_module_def';
1718
export {ComponentFactory, ComponentFactoryResolver, ComponentRef, injectComponentFactoryResolver} from './component_ref';
1819
export {ɵɵgetFactoryOf, ɵɵgetInheritedFactory} from './di';
1920
export {getLocaleId, setLocaleId} from './i18n/i18n_locale_id';
@@ -136,7 +137,7 @@ export {CssSelectorList, ProjectionSlots} from './interfaces/projection';
136137
export {
137138
setClassMetadata,
138139
} from './metadata';
139-
export {NgModuleFactory, NgModuleRef, NgModuleType} from './ng_module_ref';
140+
export {NgModuleFactory, NgModuleRef} from './ng_module_ref';
140141
export {
141142
ɵɵpipe,
142143
ɵɵpipeBind1,

packages/core/src/render3/jit/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {NG_INJ_DEF} from '../../di/interface/defs';
1212
import {reflectDependencies} from '../../di/jit/util';
1313
import {Type} from '../../interface/type';
1414
import {Component} from '../../metadata/directives';
15-
import {ModuleWithProviders, NgModule, NgModuleDef, NgModuleTransitiveScopes} from '../../metadata/ng_module';
15+
import {ModuleWithProviders, NgModule} from '../../metadata/ng_module';
16+
import {NgModuleDef, NgModuleTransitiveScopes, NgModuleType} from '../../metadata/ng_module_def';
1617
import {deepForEach, flatten} from '../../util/array_utils';
1718
import {assertDefined} from '../../util/assert';
1819
import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition';
1920
import {NG_COMP_DEF, NG_DIR_DEF, NG_MOD_DEF, NG_PIPE_DEF} from '../fields';
2021
import {ComponentDef} from '../interfaces/definition';
21-
import {NgModuleType} from '../ng_module_ref';
2222
import {maybeUnwrapFn, stringifyForError} from '../util/misc_utils';
2323

2424
import {angularCoreEnv} from './environment';

packages/core/src/render3/ng_module_ref.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {Type} from '../interface/type';
1414
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
1515
import {InternalNgModuleRef, NgModuleFactory as viewEngine_NgModuleFactory, NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
1616
import {registerNgModuleType} from '../linker/ng_module_factory_registration';
17-
import {NgModuleDef} from '../metadata/ng_module';
17+
import {NgModuleType} from '../metadata/ng_module_def';
1818
import {assertDefined} from '../util/assert';
1919
import {stringify} from '../util/stringify';
2020

@@ -23,10 +23,6 @@ import {getNgLocaleIdDef, getNgModuleDef} from './definition';
2323
import {setLocaleId} from './i18n/i18n_locale_id';
2424
import {maybeUnwrapFn} from './util/misc_utils';
2525

26-
export interface NgModuleType<T = any> extends Type<T> {
27-
ɵmod: NgModuleDef<T>;
28-
}
29-
3026
export class NgModuleRef<T> extends viewEngine_NgModuleRef<T> implements InternalNgModuleRef<T> {
3127
// tslint:disable-next-line:require-internal-with-underscore
3228
_bootstrapComponents: Type<any>[] = [];

packages/core/test/render3/ivy/jit_spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
*/
88
import 'reflect-metadata';
99

10-
import {ElementRef, QueryList, ɵɵsetComponentScope as setComponentScope} from '@angular/core';
10+
import {ElementRef, QueryList} from '@angular/core';
1111
import {Injectable} from '@angular/core/src/di/injectable';
1212
import {setCurrentInjector, ɵɵinject} from '@angular/core/src/di/injector_compatibility';
1313
import {ɵɵdefineInjectable, ɵɵInjectorDef} from '@angular/core/src/di/interface/defs';
1414
import {ivyEnabled} from '@angular/core/src/ivy_switch';
1515
import {ContentChild, ContentChildren, ViewChild, ViewChildren} from '@angular/core/src/metadata/di';
16-
import {Component, Directive, HostBinding, HostListener, Input, Output, Pipe} from '@angular/core/src/metadata/directives';
17-
import {NgModule, NgModuleDef} from '@angular/core/src/metadata/ng_module';
16+
import {Component, Directive, HostBinding, HostListener, Input, Pipe} from '@angular/core/src/metadata/directives';
17+
import {NgModule} from '@angular/core/src/metadata/ng_module';
18+
import {NgModuleDef} from '@angular/core/src/metadata/ng_module_def';
1819
import {ComponentDef, FactoryFn, PipeDef} from '@angular/core/src/render3/interfaces/definition';
1920

2021

22+
2123
ivyEnabled && describe('render3 jit', () => {
2224
let injector: any;
2325
beforeAll(() => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy