refactor(core): rename ngInjectorDef to ɵinj (#33151)
Injector defs are not considered public API, so the property that contains them should be prefixed with Angular's marker for "private" ('ɵ') to discourage apps from relying on def APIs directly. This commit adds the prefix and shortens the name from ngInjectorDef to inj. This is because property names cannot be minified by Uglify without turning on property mangling (which most apps have turned off) and are thus size-sensitive. PR Close #33151
This commit is contained in:
parent
3e14c2d02c
commit
cda9248b33
|
@ -179,7 +179,7 @@ module.exports =
|
||||||
|
|
||||||
.config(function(filterMembers) {
|
.config(function(filterMembers) {
|
||||||
filterMembers.notAllowedPatterns.push(
|
filterMembers.notAllowedPatterns.push(
|
||||||
/^ng[A-Z].*Def$/
|
/^ng[A-Z].*Def$/, /^ɵ/
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,8 @@ assertSucceeded "Expected 'ngcc' to log 'Compiling'."
|
||||||
grep "import [*] as ɵngcc0 from './src/r3_symbols';" node_modules/@angular/core/core.d.ts
|
grep "import [*] as ɵngcc0 from './src/r3_symbols';" node_modules/@angular/core/core.d.ts
|
||||||
assertSucceeded "Expected 'ngcc' to add an import for 'src/r3_symbols' in '@angular/core' typings."
|
assertSucceeded "Expected 'ngcc' to add an import for 'src/r3_symbols' in '@angular/core' typings."
|
||||||
|
|
||||||
grep "static ngInjectorDef: ɵngcc0.ɵɵInjectorDef<ApplicationModule>;" node_modules/@angular/core/core.d.ts
|
grep "static ɵinj: ɵngcc0.ɵɵInjectorDef<ApplicationModule>;" node_modules/@angular/core/core.d.ts
|
||||||
assertSucceeded "Expected 'ngcc' to add a definition for 'ApplicationModule.ngInjectorDef' in '@angular/core' typings."
|
assertSucceeded "Expected 'ngcc' to add a definition for 'ApplicationModule.ɵinj' in '@angular/core' typings."
|
||||||
|
|
||||||
|
|
||||||
# Did it generate a base factory call for synthesized constructors correctly?
|
# Did it generate a base factory call for synthesized constructors correctly?
|
||||||
|
|
|
@ -270,14 +270,14 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
|
||||||
const definitions: string = addDefinitionsSpy.calls.first().args[2];
|
const definitions: string = addDefinitionsSpy.calls.first().args[2];
|
||||||
const ngModuleDef = definitions.indexOf('ɵmod');
|
const ngModuleDef = definitions.indexOf('ɵmod');
|
||||||
expect(ngModuleDef).not.toEqual(-1, 'ɵmod should exist');
|
expect(ngModuleDef).not.toEqual(-1, 'ɵmod should exist');
|
||||||
const ngInjectorDef = definitions.indexOf('ngInjectorDef');
|
const ngInjectorDef = definitions.indexOf('ɵinj');
|
||||||
expect(ngInjectorDef).not.toEqual(-1, 'ngInjectorDef should exist');
|
expect(ngInjectorDef).not.toEqual(-1, 'ɵinj should exist');
|
||||||
const setClassMetadata = definitions.indexOf('setClassMetadata');
|
const setClassMetadata = definitions.indexOf('setClassMetadata');
|
||||||
expect(setClassMetadata).not.toEqual(-1, 'setClassMetadata call should exist');
|
expect(setClassMetadata).not.toEqual(-1, 'setClassMetadata call should exist');
|
||||||
expect(setClassMetadata)
|
expect(setClassMetadata)
|
||||||
.toBeGreaterThan(ngModuleDef, 'setClassMetadata should follow ɵmod');
|
.toBeGreaterThan(ngModuleDef, 'setClassMetadata should follow ɵmod');
|
||||||
expect(setClassMetadata)
|
expect(setClassMetadata)
|
||||||
.toBeGreaterThan(ngInjectorDef, 'setClassMetadata should follow ngInjectorDef');
|
.toBeGreaterThan(ngInjectorDef, 'setClassMetadata should follow ɵinj');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render classes without decorators if handler matches', () => {
|
it('should render classes without decorators if handler matches', () => {
|
||||||
|
|
|
@ -24,8 +24,8 @@ import {ReferencesRegistry} from './references_registry';
|
||||||
import {combineResolvers, findAngularDecorator, forwardRefResolver, getValidConstructorDependencies, isExpressionForwardReference, toR3Reference, unwrapExpression} from './util';
|
import {combineResolvers, findAngularDecorator, forwardRefResolver, getValidConstructorDependencies, isExpressionForwardReference, toR3Reference, unwrapExpression} from './util';
|
||||||
|
|
||||||
export interface NgModuleAnalysis {
|
export interface NgModuleAnalysis {
|
||||||
ɵmod: R3NgModuleMetadata;
|
mod: R3NgModuleMetadata;
|
||||||
ngInjectorDef: R3InjectorMetadata;
|
inj: R3InjectorMetadata;
|
||||||
metadataStmt: Statement|null;
|
metadataStmt: Statement|null;
|
||||||
declarations: Reference<ClassDeclaration>[];
|
declarations: Reference<ClassDeclaration>[];
|
||||||
exports: Reference<ClassDeclaration>[];
|
exports: Reference<ClassDeclaration>[];
|
||||||
|
@ -236,7 +236,8 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
return {
|
return {
|
||||||
analysis: {
|
analysis: {
|
||||||
id,
|
id,
|
||||||
ɵmod: ngModuleDef, ngInjectorDef,
|
mod: ngModuleDef,
|
||||||
|
inj: ngInjectorDef,
|
||||||
declarations: declarationRefs,
|
declarations: declarationRefs,
|
||||||
exports: exportRefs,
|
exports: exportRefs,
|
||||||
metadataStmt: generateSetClassMetadataCall(
|
metadataStmt: generateSetClassMetadataCall(
|
||||||
|
@ -256,7 +257,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
const context = getSourceFile(node);
|
const context = getSourceFile(node);
|
||||||
for (const exportRef of analysis.exports) {
|
for (const exportRef of analysis.exports) {
|
||||||
if (isNgModule(exportRef.node, scope.compilation)) {
|
if (isNgModule(exportRef.node, scope.compilation)) {
|
||||||
analysis.ngInjectorDef.imports.push(this.refEmitter.emit(exportRef, context));
|
analysis.inj.imports.push(this.refEmitter.emit(exportRef, context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,8 +281,8 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
}
|
}
|
||||||
|
|
||||||
compile(node: ClassDeclaration, analysis: NgModuleAnalysis): CompileResult[] {
|
compile(node: ClassDeclaration, analysis: NgModuleAnalysis): CompileResult[] {
|
||||||
const ngInjectorDef = compileInjector(analysis.ngInjectorDef);
|
const ngInjectorDef = compileInjector(analysis.inj);
|
||||||
const ngModuleDef = compileNgModule(analysis.ɵmod);
|
const ngModuleDef = compileNgModule(analysis.mod);
|
||||||
const ngModuleStatements = ngModuleDef.additionalStatements;
|
const ngModuleStatements = ngModuleDef.additionalStatements;
|
||||||
if (analysis.metadataStmt !== null) {
|
if (analysis.metadataStmt !== null) {
|
||||||
ngModuleStatements.push(analysis.metadataStmt);
|
ngModuleStatements.push(analysis.metadataStmt);
|
||||||
|
@ -314,7 +315,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
type: ngModuleDef.type,
|
type: ngModuleDef.type,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ngInjectorDef',
|
name: 'ɵinj',
|
||||||
initializer: ngInjectorDef.expression,
|
initializer: ngInjectorDef.expression,
|
||||||
statements: ngInjectorDef.statements,
|
statements: ngInjectorDef.statements,
|
||||||
type: ngInjectorDef.type,
|
type: ngInjectorDef.type,
|
||||||
|
|
|
@ -77,7 +77,7 @@ runInEachFileSystem(() => {
|
||||||
if (detected === undefined) {
|
if (detected === undefined) {
|
||||||
return fail('Failed to recognize @NgModule');
|
return fail('Failed to recognize @NgModule');
|
||||||
}
|
}
|
||||||
const moduleDef = handler.analyze(TestModule, detected.metadata).analysis !.ɵmod;
|
const moduleDef = handler.analyze(TestModule, detected.metadata).analysis !.mod;
|
||||||
|
|
||||||
expect(getReferenceIdentifierTexts(moduleDef.declarations)).toEqual(['TestComp']);
|
expect(getReferenceIdentifierTexts(moduleDef.declarations)).toEqual(['TestComp']);
|
||||||
expect(getReferenceIdentifierTexts(moduleDef.exports)).toEqual(['TestComp']);
|
expect(getReferenceIdentifierTexts(moduleDef.exports)).toEqual(['TestComp']);
|
||||||
|
|
|
@ -23,7 +23,7 @@ const R3_DEF_NAME_PATTERN = [
|
||||||
'ɵcmp',
|
'ɵcmp',
|
||||||
'ɵdir',
|
'ɵdir',
|
||||||
'ngInjectableDef',
|
'ngInjectableDef',
|
||||||
'ngInjectorDef',
|
'ɵinj',
|
||||||
'ɵmod',
|
'ɵmod',
|
||||||
'ɵpipe',
|
'ɵpipe',
|
||||||
'ɵfac',
|
'ɵfac',
|
||||||
|
|
|
@ -377,7 +377,7 @@ runInEachFileSystem(os => {
|
||||||
expect(jsContents).toContain('TestPipe.ɵpipe = i0.ɵɵdefinePipe');
|
expect(jsContents).toContain('TestPipe.ɵpipe = i0.ɵɵdefinePipe');
|
||||||
expect(jsContents).toContain('TestInjectable.ngInjectableDef = i0.ɵɵdefineInjectable');
|
expect(jsContents).toContain('TestInjectable.ngInjectableDef = i0.ɵɵdefineInjectable');
|
||||||
expect(jsContents).toContain('MyModule.ɵmod = i0.ɵɵdefineNgModule');
|
expect(jsContents).toContain('MyModule.ɵmod = i0.ɵɵdefineNgModule');
|
||||||
expect(jsContents).toContain('MyModule.ngInjectorDef = i0.ɵɵdefineInjector');
|
expect(jsContents).toContain('MyModule.ɵinj = i0.ɵɵdefineInjector');
|
||||||
expect(jsContents).toContain('inputs: { input: "input" }');
|
expect(jsContents).toContain('inputs: { input: "input" }');
|
||||||
expect(jsContents).toContain('outputs: { output: "output" }');
|
expect(jsContents).toContain('outputs: { output: "output" }');
|
||||||
});
|
});
|
||||||
|
@ -650,7 +650,7 @@ runInEachFileSystem(os => {
|
||||||
expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');
|
expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');
|
||||||
expect(jsContents)
|
expect(jsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
`TestModule.ngInjectorDef = i0.ɵɵdefineInjector({ factory: ` +
|
`TestModule.ɵinj = i0.ɵɵdefineInjector({ factory: ` +
|
||||||
`function TestModule_Factory(t) { return new (t || TestModule)(); }, providers: [{ provide: ` +
|
`function TestModule_Factory(t) { return new (t || TestModule)(); }, providers: [{ provide: ` +
|
||||||
`Token, useValue: 'test' }], imports: [[OtherModule]] });`);
|
`Token, useValue: 'test' }], imports: [[OtherModule]] });`);
|
||||||
|
|
||||||
|
@ -658,7 +658,7 @@ runInEachFileSystem(os => {
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
|
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
|
||||||
expect(dtsContents).toContain('static ngInjectorDef: i0.ɵɵInjectorDef');
|
expect(dtsContents).toContain('static ɵinj: i0.ɵɵInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should compile NgModules with factory providers without errors', () => {
|
it('should compile NgModules with factory providers without errors', () => {
|
||||||
|
@ -690,7 +690,7 @@ runInEachFileSystem(os => {
|
||||||
expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');
|
expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');
|
||||||
expect(jsContents)
|
expect(jsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
`TestModule.ngInjectorDef = i0.ɵɵdefineInjector({ factory: ` +
|
`TestModule.ɵinj = i0.ɵɵdefineInjector({ factory: ` +
|
||||||
`function TestModule_Factory(t) { return new (t || TestModule)(); }, providers: [{ provide: ` +
|
`function TestModule_Factory(t) { return new (t || TestModule)(); }, providers: [{ provide: ` +
|
||||||
`Token, useFactory: function () { return new Token(); } }], imports: [[OtherModule]] });`);
|
`Token, useFactory: function () { return new Token(); } }], imports: [[OtherModule]] });`);
|
||||||
|
|
||||||
|
@ -698,7 +698,7 @@ runInEachFileSystem(os => {
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
|
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
|
||||||
expect(dtsContents).toContain('static ngInjectorDef: i0.ɵɵInjectorDef');
|
expect(dtsContents).toContain('static ɵinj: i0.ɵɵInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should compile NgModules with factory providers and deps without errors', () => {
|
it('should compile NgModules with factory providers and deps without errors', () => {
|
||||||
|
@ -734,7 +734,7 @@ runInEachFileSystem(os => {
|
||||||
expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');
|
expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');
|
||||||
expect(jsContents)
|
expect(jsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
`TestModule.ngInjectorDef = i0.ɵɵdefineInjector({ factory: ` +
|
`TestModule.ɵinj = i0.ɵɵdefineInjector({ factory: ` +
|
||||||
`function TestModule_Factory(t) { return new (t || TestModule)(); }, providers: [{ provide: ` +
|
`function TestModule_Factory(t) { return new (t || TestModule)(); }, providers: [{ provide: ` +
|
||||||
`Token, useFactory: function (dep) { return new Token(dep); }, deps: [Dep] }], imports: [[OtherModule]] });`);
|
`Token, useFactory: function (dep) { return new Token(dep); }, deps: [Dep] }], imports: [[OtherModule]] });`);
|
||||||
|
|
||||||
|
@ -742,7 +742,7 @@ runInEachFileSystem(os => {
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
|
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], [typeof OtherModule], never>');
|
||||||
expect(dtsContents).toContain('static ngInjectorDef: i0.ɵɵInjectorDef');
|
expect(dtsContents).toContain('static ɵinj: i0.ɵɵInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should compile NgModules with references to local components', () => {
|
it('should compile NgModules with references to local components', () => {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {nocollapseHack} from '../../src/transformers/nocollapse_hack';
|
||||||
|
|
||||||
describe('@nocollapse hack', () => {
|
describe('@nocollapse hack', () => {
|
||||||
it('should add @nocollapse to a basic class', () => {
|
it('should add @nocollapse to a basic class', () => {
|
||||||
const decl = `Foo.ngInjectorDef = define(...);`;
|
const decl = `Foo.ɵinj = define(...);`;
|
||||||
expect(nocollapseHack(decl)).toEqual('/** @nocollapse */ ' + decl);
|
expect(nocollapseHack(decl)).toEqual('/** @nocollapse */ ' + decl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ describe('@nocollapse hack', () => {
|
||||||
const decl = `
|
const decl = `
|
||||||
if (false) {
|
if (false) {
|
||||||
/** @type {?} */
|
/** @type {?} */
|
||||||
Foo.ngInjectorDef;
|
Foo.ɵinj;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
expect(nocollapseHack(decl)).toContain('/** @nocollapse @type {?} */');
|
expect(nocollapseHack(decl)).toContain('/** @nocollapse @type {?} */');
|
||||||
|
|
|
@ -73,7 +73,7 @@ class:
|
||||||
| `hostListeners` | `ɵdir` |
|
| `hostListeners` | `ɵdir` |
|
||||||
| `hostProperties` | `ɵdir` |
|
| `hostProperties` | `ɵdir` |
|
||||||
| `hostAttributes` | `ɵdir` |
|
| `hostAttributes` | `ɵdir` |
|
||||||
| `providers` | `ngInjectorDef` |
|
| `providers` | `ɵinj` |
|
||||||
| `viewProviders` | `ɵcmp` |
|
| `viewProviders` | `ɵcmp` |
|
||||||
| `queries` | `ɵdir` |
|
| `queries` | `ɵdir` |
|
||||||
| `guards` | not used |
|
| `guards` | not used |
|
||||||
|
@ -282,7 +282,7 @@ export class MyPipe {
|
||||||
The metadata for a module is transformed by:
|
The metadata for a module is transformed by:
|
||||||
|
|
||||||
1. Remove the `@NgModule` directive.
|
1. Remove the `@NgModule` directive.
|
||||||
2. Add `"ngInjectorDef": {}` static field.
|
2. Add `"ɵinj": {}` static field.
|
||||||
3. Add `"ngModuleScope": <module-scope>` static field.
|
3. Add `"ngModuleScope": <module-scope>` static field.
|
||||||
|
|
||||||
The scope value is an array the following type:
|
The scope value is an array the following type:
|
||||||
|
@ -329,7 +329,7 @@ export class MyModule {}
|
||||||
*my.module.js*
|
*my.module.js*
|
||||||
```js
|
```js
|
||||||
export class MyModule {
|
export class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector(...);
|
static ɵinj = ɵɵdefineInjector(...);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ export class MyModule {
|
||||||
"MyModule": {
|
"MyModule": {
|
||||||
"__symbolic": "class",
|
"__symbolic": "class",
|
||||||
"statics": {
|
"statics": {
|
||||||
"ngInjectorDef": {},
|
"ɵinj": {},
|
||||||
"ngModuleScope": [
|
"ngModuleScope": [
|
||||||
{
|
{
|
||||||
"type": {
|
"type": {
|
||||||
|
@ -389,7 +389,7 @@ manually written as:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
export class MyModule {
|
export class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
providers: [{
|
providers: [{
|
||||||
provide: Service, useClass: ServiceImpl
|
provide: Service, useClass: ServiceImpl
|
||||||
}],
|
}],
|
||||||
|
@ -440,7 +440,7 @@ properties by including a `// @__BUILD_OPTIMIZER_REMOVE_` comment:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
export class MyModule {
|
export class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
providers: [{
|
providers: [{
|
||||||
provide: Service, useClass: ServiceImpl
|
provide: Service, useClass: ServiceImpl
|
||||||
}],
|
}],
|
||||||
|
|
|
@ -204,7 +204,7 @@ export class ConstantPool {
|
||||||
case DefinitionKind.Directive:
|
case DefinitionKind.Directive:
|
||||||
return 'ɵdir';
|
return 'ɵdir';
|
||||||
case DefinitionKind.Injector:
|
case DefinitionKind.Injector:
|
||||||
return 'ngInjectorDef';
|
return 'ɵinj';
|
||||||
case DefinitionKind.Pipe:
|
case DefinitionKind.Pipe:
|
||||||
return 'ɵpipe';
|
return 'ɵpipe';
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ export function compileNgModuleFromRender2(
|
||||||
/* name */ className,
|
/* name */ className,
|
||||||
/* parent */ null,
|
/* parent */ null,
|
||||||
/* fields */[new o.ClassField(
|
/* fields */[new o.ClassField(
|
||||||
/* name */ 'ngInjectorDef',
|
/* name */ 'ɵinj',
|
||||||
/* type */ o.INFERRED_TYPE,
|
/* type */ o.INFERRED_TYPE,
|
||||||
/* modifiers */[o.StmtModifier.Static],
|
/* modifiers */[o.StmtModifier.Static],
|
||||||
/* initializer */ injectorDef, )],
|
/* initializer */ injectorDef, )],
|
||||||
|
|
|
@ -230,7 +230,7 @@ export {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
NG_INJECTABLE_DEF as ɵNG_INJECTABLE_DEF,
|
NG_INJECTABLE_DEF as ɵNG_INJECTABLE_DEF,
|
||||||
NG_INJECTOR_DEF as ɵNG_INJECTOR_DEF,
|
NG_INJ_DEF as ɵNG_INJ_DEF,
|
||||||
} from './di/interface/defs';
|
} from './di/interface/defs';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -104,7 +104,7 @@ export interface InjectorType<T> extends Type<T> {
|
||||||
/**
|
/**
|
||||||
* Opaque type whose structure is highly version dependent. Do not rely on any properties.
|
* Opaque type whose structure is highly version dependent. Do not rely on any properties.
|
||||||
*/
|
*/
|
||||||
ngInjectorDef: never;
|
ɵinj: never;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +159,7 @@ export const defineInjectable = ɵɵdefineInjectable;
|
||||||
/**
|
/**
|
||||||
* Construct an `InjectorDef` which configures an injector.
|
* Construct an `InjectorDef` which configures an injector.
|
||||||
*
|
*
|
||||||
* This should be assigned to a static `ngInjectorDef` field on a type, which will then be an
|
* This should be assigned to a static injector def (`ɵinj`) field on a type, which will then be an
|
||||||
* `InjectorType`.
|
* `InjectorType`.
|
||||||
*
|
*
|
||||||
* Options:
|
* Options:
|
||||||
|
@ -223,13 +223,13 @@ export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|nu
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the `ngInjectorDef` type in a way which is immune to accidentally reading inherited value.
|
* Read the injector def type in a way which is immune to accidentally reading inherited value.
|
||||||
*
|
*
|
||||||
* @param type type which may have `ngInjectorDef`
|
* @param type type which may have an injector def (`ɵinj`)
|
||||||
*/
|
*/
|
||||||
export function getInjectorDef<T>(type: any): ɵɵInjectorDef<T>|null {
|
export function getInjectorDef<T>(type: any): ɵɵInjectorDef<T>|null {
|
||||||
return type && type.hasOwnProperty(NG_INJECTOR_DEF) ? (type as any)[NG_INJECTOR_DEF] : null;
|
return type && type.hasOwnProperty(NG_INJ_DEF) ? (type as any)[NG_INJ_DEF] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
||||||
export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty});
|
export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty});
|
||||||
|
|
|
@ -251,11 +251,11 @@ export class R3Injector {
|
||||||
defOrWrappedDef = resolveForwardRef(defOrWrappedDef);
|
defOrWrappedDef = resolveForwardRef(defOrWrappedDef);
|
||||||
if (!defOrWrappedDef) return false;
|
if (!defOrWrappedDef) return false;
|
||||||
|
|
||||||
// Either the defOrWrappedDef is an InjectorType (with ngInjectorDef) or an
|
// Either the defOrWrappedDef is an InjectorType (with injector def) or an
|
||||||
// InjectorDefTypeWithProviders (aka ModuleWithProviders). Detecting either is a megamorphic
|
// InjectorDefTypeWithProviders (aka ModuleWithProviders). Detecting either is a megamorphic
|
||||||
// read, so care is taken to only do the read once.
|
// read, so care is taken to only do the read once.
|
||||||
|
|
||||||
// First attempt to read the ngInjectorDef.
|
// First attempt to read the injector def (`ɵinj`).
|
||||||
let def = getInjectorDef(defOrWrappedDef);
|
let def = getInjectorDef(defOrWrappedDef);
|
||||||
|
|
||||||
// If that's not present, then attempt to read ngModule from the InjectorDefTypeWithProviders.
|
// If that's not present, then attempt to read ngModule from the InjectorDefTypeWithProviders.
|
||||||
|
@ -416,7 +416,8 @@ function injectableDefOrInjectorDefFactory(token: Type<any>| InjectionToken<any>
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the token is an NgModule, it's also injectable but the factory is on its ngInjectorDef.
|
// If the token is an NgModule, it's also injectable but the factory is on its injector def
|
||||||
|
// (`ɵinj`)
|
||||||
const injectorDef = getInjectorDef(token);
|
const injectorDef = getInjectorDef(token);
|
||||||
if (injectorDef !== null) {
|
if (injectorDef !== null) {
|
||||||
return injectorDef.factory;
|
return injectorDef.factory;
|
||||||
|
|
|
@ -350,7 +350,7 @@ function preR3NgModuleCompile(moduleType: Type<any>, metadata?: NgModule): void
|
||||||
imports = [...imports, metadata.exports];
|
imports = [...imports, metadata.exports];
|
||||||
}
|
}
|
||||||
|
|
||||||
(moduleType as InjectorType<any>).ngInjectorDef = ɵɵdefineInjector({
|
(moduleType as InjectorType<any>).ɵinj = ɵɵdefineInjector({
|
||||||
factory: convertInjectableProviderToFactory(moduleType, {useClass: moduleType}),
|
factory: convertInjectableProviderToFactory(moduleType, {useClass: moduleType}),
|
||||||
providers: metadata && metadata.providers,
|
providers: metadata && metadata.providers,
|
||||||
imports: imports,
|
imports: imports,
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {R3InjectorMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
|
import {R3InjectorMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
|
||||||
import {resolveForwardRef} from '../../di/forward_ref';
|
import {resolveForwardRef} from '../../di/forward_ref';
|
||||||
import {NG_INJECTOR_DEF} from '../../di/interface/defs';
|
import {NG_INJ_DEF} from '../../di/interface/defs';
|
||||||
import {reflectDependencies} from '../../di/jit/util';
|
import {reflectDependencies} from '../../di/jit/util';
|
||||||
import {Type} from '../../interface/type';
|
import {Type} from '../../interface/type';
|
||||||
import {Component} from '../../metadata';
|
import {Component} from '../../metadata';
|
||||||
|
@ -93,7 +93,7 @@ export function compileNgModule(moduleType: Type<any>, ngModule: NgModule = {}):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles and adds the `ɵmod` and `ngInjectorDef` properties to the module class.
|
* Compiles and adds the `ɵmod` and `ɵinj` properties to the module class.
|
||||||
*
|
*
|
||||||
* It's possible to compile a module via this API which will allow duplicate declarations in its
|
* It's possible to compile a module via this API which will allow duplicate declarations in its
|
||||||
* root.
|
* root.
|
||||||
|
@ -135,7 +135,7 @@ export function compileNgModuleDefs(
|
||||||
});
|
});
|
||||||
|
|
||||||
let ngInjectorDef: any = null;
|
let ngInjectorDef: any = null;
|
||||||
Object.defineProperty(moduleType, NG_INJECTOR_DEF, {
|
Object.defineProperty(moduleType, NG_INJ_DEF, {
|
||||||
get: () => {
|
get: () => {
|
||||||
if (ngInjectorDef === null) {
|
if (ngInjectorDef === null) {
|
||||||
ngDevMode && verifySemanticsOfNgModuleDef(
|
ngDevMode && verifySemanticsOfNgModuleDef(
|
||||||
|
@ -151,7 +151,7 @@ export function compileNgModuleDefs(
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
ngInjectorDef = getCompilerFacade().compileInjector(
|
ngInjectorDef = getCompilerFacade().compileInjector(
|
||||||
angularCoreEnv, `ng:///${moduleType.name}/ngInjectorDef.js`, meta);
|
angularCoreEnv, `ng:///${moduleType.name}/ɵinj.js`, meta);
|
||||||
}
|
}
|
||||||
return ngInjectorDef;
|
return ngInjectorDef;
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
"name": "NG_INJECTABLE_DEF"
|
"name": "NG_INJECTABLE_DEF"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "NG_INJECTOR_DEF"
|
"name": "NG_INJ_DEF"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "NG_TEMP_TOKEN_PATH"
|
"name": "NG_TEMP_TOKEN_PATH"
|
||||||
|
|
|
@ -30,7 +30,7 @@ export class ScopedService {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DefinedInjector {
|
export class DefinedInjector {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new DefinedInjector(),
|
factory: () => new DefinedInjector(),
|
||||||
providers: [ScopedService],
|
providers: [ScopedService],
|
||||||
});
|
});
|
||||||
|
|
|
@ -132,7 +132,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
class DeepModule {
|
class DeepModule {
|
||||||
constructor(eagerService: EagerService) { deepModuleCreated = true; }
|
constructor(eagerService: EagerService) { deepModuleCreated = true; }
|
||||||
|
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new DeepModule(ɵɵinject(EagerService)),
|
factory: () => new DeepModule(ɵɵinject(EagerService)),
|
||||||
imports: undefined,
|
imports: undefined,
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -150,7 +150,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntermediateModule {
|
class IntermediateModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new IntermediateModule(),
|
factory: () => new IntermediateModule(),
|
||||||
imports: [DeepModule.safe()],
|
imports: [DeepModule.safe()],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
@ -160,7 +160,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
class InjectorWithDep {
|
class InjectorWithDep {
|
||||||
constructor(readonly service: Service) {}
|
constructor(readonly service: Service) {}
|
||||||
|
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new InjectorWithDep(ɵɵinject(Service)),
|
factory: () => new InjectorWithDep(ɵɵinject(Service)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
class ChildService extends ServiceWithDep {}
|
class ChildService extends ServiceWithDep {}
|
||||||
|
|
||||||
class Module {
|
class Module {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new Module(),
|
factory: () => new Module(),
|
||||||
imports: [IntermediateModule],
|
imports: [IntermediateModule],
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -191,7 +191,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
class OtherModule {
|
class OtherModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new OtherModule(),
|
factory: () => new OtherModule(),
|
||||||
imports: undefined,
|
imports: undefined,
|
||||||
providers: [],
|
providers: [],
|
||||||
|
@ -199,7 +199,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ModuleWithMissingDep {
|
class ModuleWithMissingDep {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new ModuleWithMissingDep(),
|
factory: () => new ModuleWithMissingDep(),
|
||||||
imports: undefined,
|
imports: undefined,
|
||||||
providers: [ServiceWithMissingDep],
|
providers: [ServiceWithMissingDep],
|
||||||
|
@ -209,7 +209,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
class NotAModule {}
|
class NotAModule {}
|
||||||
|
|
||||||
class ImportsNotAModule {
|
class ImportsNotAModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new ImportsNotAModule(),
|
factory: () => new ImportsNotAModule(),
|
||||||
imports: [NotAModule],
|
imports: [NotAModule],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
@ -236,21 +236,21 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultiProviderA {
|
class MultiProviderA {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new MultiProviderA(),
|
factory: () => new MultiProviderA(),
|
||||||
providers: [{provide: LOCALE, multi: true, useValue: 'A'}],
|
providers: [{provide: LOCALE, multi: true, useValue: 'A'}],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultiProviderB {
|
class MultiProviderB {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new MultiProviderB(),
|
factory: () => new MultiProviderB(),
|
||||||
providers: [{provide: LOCALE, multi: true, useValue: 'B'}],
|
providers: [{provide: LOCALE, multi: true, useValue: 'B'}],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithProvidersTest {
|
class WithProvidersTest {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new WithProvidersTest(),
|
factory: () => new WithProvidersTest(),
|
||||||
imports: [
|
imports: [
|
||||||
{ngModule: MultiProviderA, providers: [{provide: LOCALE, multi: true, useValue: 'C'}]},
|
{ngModule: MultiProviderA, providers: [{provide: LOCALE, multi: true, useValue: 'C'}]},
|
||||||
|
@ -402,7 +402,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
.toThrowError('Injector has already been destroyed.');
|
.toThrowError('Injector has already been destroyed.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not crash when importing something that has no ngInjectorDef', () => {
|
it('should not crash when importing something that has no ɵinj', () => {
|
||||||
injector = createInjector(ImportsNotAModule);
|
injector = createInjector(ImportsNotAModule);
|
||||||
expect(injector.get(ImportsNotAModule)).toBeDefined();
|
expect(injector.get(ImportsNotAModule)).toBeDefined();
|
||||||
});
|
});
|
||||||
|
@ -419,7 +419,7 @@ describe('InjectorDef-based createInjector()', () => {
|
||||||
constructor(missingType: any) {}
|
constructor(missingType: any) {}
|
||||||
}
|
}
|
||||||
class ErrorModule {
|
class ErrorModule {
|
||||||
static ngInjectorDef =
|
static ɵinj =
|
||||||
ɵɵdefineInjector({factory: () => new ErrorModule(), providers: [MissingArgumentType]});
|
ɵɵdefineInjector({factory: () => new ErrorModule(), providers: [MissingArgumentType]});
|
||||||
}
|
}
|
||||||
expect(() => createInjector(ErrorModule).get(MissingArgumentType))
|
expect(() => createInjector(ErrorModule).get(MissingArgumentType))
|
||||||
|
|
|
@ -90,7 +90,7 @@ describe('component', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyModule {
|
class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new MyModule(),
|
factory: () => new MyModule(),
|
||||||
providers: [{provide: MyService, useValue: new MyService('injector')}]
|
providers: [{provide: MyService, useValue: new MyService('injector')}]
|
||||||
});
|
});
|
||||||
|
|
|
@ -165,7 +165,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
expect(moduleDef.declarations[0]).toBe(Cmp);
|
expect(moduleDef.declarations[0]).toBe(Cmp);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('compiles a module to an ngInjectorDef with the providers', () => {
|
it('compiles a module to an ɵinj with the providers', () => {
|
||||||
class Token {
|
class Token {
|
||||||
static ngInjectableDef = ɵɵdefineInjectable({
|
static ngInjectableDef = ɵɵdefineInjectable({
|
||||||
token: Token,
|
token: Token,
|
||||||
|
@ -181,7 +181,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
constructor(public token: Token) {}
|
constructor(public token: Token) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const injectorDef: ɵɵInjectorDef<Module> = (Module as any).ngInjectorDef;
|
const injectorDef: ɵɵInjectorDef<Module> = (Module as any).ɵinj;
|
||||||
const instance = injectorDef.factory();
|
const instance = injectorDef.factory();
|
||||||
|
|
||||||
// Since the instance was created outside of an injector using the module, the
|
// Since the instance was created outside of an injector using the module, the
|
||||||
|
|
|
@ -326,7 +326,7 @@ describe('providers', () => {
|
||||||
|
|
||||||
describe('single', () => {
|
describe('single', () => {
|
||||||
class MyModule {
|
class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector(
|
static ɵinj = ɵɵdefineInjector(
|
||||||
{factory: () => new MyModule(), providers: [{provide: String, useValue: 'From module'}]});
|
{factory: () => new MyModule(), providers: [{provide: String, useValue: 'From module'}]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ describe('providers', () => {
|
||||||
|
|
||||||
describe('multi', () => {
|
describe('multi', () => {
|
||||||
class MyModule {
|
class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new MyModule(),
|
factory: () => new MyModule(),
|
||||||
providers: [{provide: String, useValue: 'From module', multi: true}]
|
providers: [{provide: String, useValue: 'From module', multi: true}]
|
||||||
});
|
});
|
||||||
|
@ -833,7 +833,7 @@ describe('providers', () => {
|
||||||
|
|
||||||
it('should work with a module', () => {
|
it('should work with a module', () => {
|
||||||
class MyModule {
|
class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new MyModule(),
|
factory: () => new MyModule(),
|
||||||
providers: [{provide: String, useValue: 'From module'}]
|
providers: [{provide: String, useValue: 'From module'}]
|
||||||
});
|
});
|
||||||
|
@ -1126,7 +1126,7 @@ describe('providers', () => {
|
||||||
expect(fixture.html).toEqual('<host-cmp>foo</host-cmp>');
|
expect(fixture.html).toEqual('<host-cmp>foo</host-cmp>');
|
||||||
|
|
||||||
class MyAppModule {
|
class MyAppModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector({
|
static ɵinj = ɵɵdefineInjector({
|
||||||
factory: () => new MyAppModule(),
|
factory: () => new MyAppModule(),
|
||||||
imports: [],
|
imports: [],
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -1210,7 +1210,7 @@ describe('providers', () => {
|
||||||
|
|
||||||
describe('injection flags', () => {
|
describe('injection flags', () => {
|
||||||
class MyModule {
|
class MyModule {
|
||||||
static ngInjectorDef = ɵɵdefineInjector(
|
static ɵinj = ɵɵdefineInjector(
|
||||||
{factory: () => new MyModule(), providers: [{provide: String, useValue: 'Module'}]});
|
{factory: () => new MyModule(), providers: [{provide: String, useValue: 'Module'}]});
|
||||||
}
|
}
|
||||||
it('should not fall through to ModuleInjector if flags limit the scope', () => {
|
it('should not fall through to ModuleInjector if flags limit the scope', () => {
|
||||||
|
|
|
@ -699,7 +699,7 @@ describe('TestBed', () => {
|
||||||
|
|
||||||
// The providers for the module should have been restored to the original array, with
|
// The providers for the module should have been restored to the original array, with
|
||||||
// no trace of the overridden providers.
|
// no trace of the overridden providers.
|
||||||
expect((Module as any).ngInjectorDef.providers).toEqual([Token]);
|
expect((Module as any).ɵinj.providers).toEqual([Token]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clean up overridden providers on components whose modules are compiled more than once',
|
it('should clean up overridden providers on components whose modules are compiled more than once',
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ResourceLoader} from '@angular/compiler';
|
import {ResourceLoader} from '@angular/compiler';
|
||||||
import {ApplicationInitStatus, COMPILER_OPTIONS, Compiler, Component, Directive, Injector, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, Type, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJECTOR_DEF as NG_INJECTOR_DEF, ɵNG_MOD_DEF as NG_MOD_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDef as InjectableDef} from '@angular/core';
|
import {ApplicationInitStatus, COMPILER_OPTIONS, Compiler, Component, Directive, Injector, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, Type, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJ_DEF as NG_INJ_DEF, ɵNG_MOD_DEF as NG_MOD_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDef as InjectableDef} from '@angular/core';
|
||||||
import {ModuleRegistrationMap, getRegisteredModulesState, restoreRegisteredModulesState} from '../../src/linker/ng_module_factory_registration';
|
import {ModuleRegistrationMap, getRegisteredModulesState, restoreRegisteredModulesState} from '../../src/linker/ng_module_factory_registration';
|
||||||
|
|
||||||
import {clearResolutionOfComponentResourcesQueue, isComponentDefPendingResolution, resolveComponentResources, restoreComponentResolutionQueue} from '../../src/metadata/resource_loading';
|
import {clearResolutionOfComponentResourcesQueue, isComponentDefPendingResolution, resolveComponentResources, restoreComponentResolutionQueue} from '../../src/metadata/resource_loading';
|
||||||
|
@ -362,7 +362,7 @@ export class R3TestBedCompiler {
|
||||||
}
|
}
|
||||||
this.moduleProvidersOverridden.add(moduleType);
|
this.moduleProvidersOverridden.add(moduleType);
|
||||||
|
|
||||||
const injectorDef: any = (moduleType as any)[NG_INJECTOR_DEF];
|
const injectorDef: any = (moduleType as any)[NG_INJ_DEF];
|
||||||
if (this.providerOverridesByToken.size > 0) {
|
if (this.providerOverridesByToken.size > 0) {
|
||||||
// Extract the list of providers from ModuleWithProviders, so we can define the final list of
|
// Extract the list of providers from ModuleWithProviders, so we can define the final list of
|
||||||
// providers that might have overrides.
|
// providers that might have overrides.
|
||||||
|
@ -373,9 +373,9 @@ export class R3TestBedCompiler {
|
||||||
isModuleWithProviders(imported) ? imported.providers : []));
|
isModuleWithProviders(imported) ? imported.providers : []));
|
||||||
const providers = [...providersFromModules, ...injectorDef.providers];
|
const providers = [...providersFromModules, ...injectorDef.providers];
|
||||||
if (this.hasProviderOverrides(providers)) {
|
if (this.hasProviderOverrides(providers)) {
|
||||||
this.maybeStoreNgDef(NG_INJECTOR_DEF, moduleType);
|
this.maybeStoreNgDef(NG_INJ_DEF, moduleType);
|
||||||
|
|
||||||
this.storeFieldOfDefOnType(moduleType, NG_INJECTOR_DEF, 'providers');
|
this.storeFieldOfDefOnType(moduleType, NG_INJ_DEF, 'providers');
|
||||||
injectorDef.providers = this.getOverriddenProviders(providers);
|
injectorDef.providers = this.getOverriddenProviders(providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ export class R3TestBedCompiler {
|
||||||
}
|
}
|
||||||
// Cache the initial ngModuleDef as it will be overwritten.
|
// Cache the initial ngModuleDef as it will be overwritten.
|
||||||
this.maybeStoreNgDef(NG_MOD_DEF, ngModule);
|
this.maybeStoreNgDef(NG_MOD_DEF, ngModule);
|
||||||
this.maybeStoreNgDef(NG_INJECTOR_DEF, ngModule);
|
this.maybeStoreNgDef(NG_INJ_DEF, ngModule);
|
||||||
|
|
||||||
compileNgModuleDefs(ngModule as NgModuleType<any>, metadata);
|
compileNgModuleDefs(ngModule as NgModuleType<any>, metadata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -471,7 +471,7 @@ export declare abstract class Injector {
|
||||||
export declare const INJECTOR: InjectionToken<Injector>;
|
export declare const INJECTOR: InjectionToken<Injector>;
|
||||||
|
|
||||||
export interface InjectorType<T> extends Type<T> {
|
export interface InjectorType<T> extends Type<T> {
|
||||||
ngInjectorDef: never;
|
ɵinj: never;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Input {
|
export interface Input {
|
||||||
|
|
Loading…
Reference in New Issue