refactor(core): rename ngModuleDef to ɵmod (#33142)
Module 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 ngModuleDef to mod. 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 #33142
This commit is contained in:
parent
d62eff7316
commit
fc93dafab1
|
@ -66,16 +66,16 @@ assertSucceeded "Expected 'ngcc' to log 'Compiling'."
|
||||||
|
|
||||||
|
|
||||||
# Did it compile @angular/core/ApplicationModule correctly?
|
# Did it compile @angular/core/ApplicationModule correctly?
|
||||||
grep "ApplicationModule.ngModuleDef = ɵɵdefineNgModule" node_modules/@angular/core/fesm2015/core.js
|
grep "ApplicationModule.ɵmod = ɵɵdefineNgModule" node_modules/@angular/core/fesm2015/core.js
|
||||||
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (fesm2015)."
|
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (fesm2015)."
|
||||||
|
|
||||||
grep "ApplicationModule.ngModuleDef = ɵɵdefineNgModule" node_modules/@angular/core/fesm5/core.js
|
grep "ApplicationModule.ɵmod = ɵɵdefineNgModule" node_modules/@angular/core/fesm5/core.js
|
||||||
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (fesm5)."
|
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (fesm5)."
|
||||||
|
|
||||||
grep "ApplicationModule.ngModuleDef = ɵngcc0.ɵɵdefineNgModule" node_modules/@angular/core/esm2015/src/application_module.js
|
grep "ApplicationModule.ɵmod = ɵngcc0.ɵɵdefineNgModule" node_modules/@angular/core/esm2015/src/application_module.js
|
||||||
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (esm2015)."
|
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (esm2015)."
|
||||||
|
|
||||||
grep "ApplicationModule.ngModuleDef = ɵngcc0.ɵɵdefineNgModule" node_modules/@angular/core/esm5/src/application_module.js
|
grep "ApplicationModule.ɵmod = ɵngcc0.ɵɵdefineNgModule" node_modules/@angular/core/esm5/src/application_module.js
|
||||||
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (esm5)."
|
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (esm5)."
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {platformBrowser} from '@angular/platform-browser';
|
||||||
import {ExpandingRowBenchmarkModule} from './benchmark';
|
import {ExpandingRowBenchmarkModule} from './benchmark';
|
||||||
import {ExpandingRowBenchmarkModuleNgFactory} from './benchmark.ngfactory';
|
import {ExpandingRowBenchmarkModuleNgFactory} from './benchmark.ngfactory';
|
||||||
|
|
||||||
setMode(ExpandingRowBenchmarkModule.hasOwnProperty('ngModuleDef') ? 'Ivy' : 'ViewEngine');
|
setMode(ExpandingRowBenchmarkModule.hasOwnProperty('ɵmod') ? 'Ivy' : 'ViewEngine');
|
||||||
enableProdMode();
|
enableProdMode();
|
||||||
platformBrowser().bootstrapModuleFactory(ExpandingRowBenchmarkModuleNgFactory);
|
platformBrowser().bootstrapModuleFactory(ExpandingRowBenchmarkModuleNgFactory);
|
||||||
|
|
||||||
|
|
|
@ -268,14 +268,14 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
|
||||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||||
const definitions: string = addDefinitionsSpy.calls.first().args[2];
|
const definitions: string = addDefinitionsSpy.calls.first().args[2];
|
||||||
const ngModuleDef = definitions.indexOf('ngModuleDef');
|
const ngModuleDef = definitions.indexOf('ɵmod');
|
||||||
expect(ngModuleDef).not.toEqual(-1, 'ngModuleDef should exist');
|
expect(ngModuleDef).not.toEqual(-1, 'ɵmod should exist');
|
||||||
const ngInjectorDef = definitions.indexOf('ngInjectorDef');
|
const ngInjectorDef = definitions.indexOf('ngInjectorDef');
|
||||||
expect(ngInjectorDef).not.toEqual(-1, 'ngInjectorDef should exist');
|
expect(ngInjectorDef).not.toEqual(-1, 'ngInjectorDef 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 ngModuleDef');
|
.toBeGreaterThan(ngModuleDef, 'setClassMetadata should follow ɵmod');
|
||||||
expect(setClassMetadata)
|
expect(setClassMetadata)
|
||||||
.toBeGreaterThan(ngInjectorDef, 'setClassMetadata should follow ngInjectorDef');
|
.toBeGreaterThan(ngInjectorDef, 'setClassMetadata should follow ngInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,7 @@ 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 {
|
||||||
ngModuleDef: R3NgModuleMetadata;
|
ɵmod: R3NgModuleMetadata;
|
||||||
ngInjectorDef: R3InjectorMetadata;
|
ngInjectorDef: R3InjectorMetadata;
|
||||||
metadataStmt: Statement|null;
|
metadataStmt: Statement|null;
|
||||||
declarations: Reference<ClassDeclaration>[];
|
declarations: Reference<ClassDeclaration>[];
|
||||||
|
@ -236,8 +236,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
return {
|
return {
|
||||||
analysis: {
|
analysis: {
|
||||||
id,
|
id,
|
||||||
ngModuleDef,
|
ɵmod: ngModuleDef, ngInjectorDef,
|
||||||
ngInjectorDef,
|
|
||||||
declarations: declarationRefs,
|
declarations: declarationRefs,
|
||||||
exports: exportRefs,
|
exports: exportRefs,
|
||||||
metadataStmt: generateSetClassMetadataCall(
|
metadataStmt: generateSetClassMetadataCall(
|
||||||
|
@ -282,7 +281,7 @@ 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.ngInjectorDef);
|
||||||
const ngModuleDef = compileNgModule(analysis.ngModuleDef);
|
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);
|
||||||
|
@ -309,7 +308,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||||
}
|
}
|
||||||
const res: CompileResult[] = [
|
const res: CompileResult[] = [
|
||||||
{
|
{
|
||||||
name: 'ngModuleDef',
|
name: 'ɵmod',
|
||||||
initializer: ngModuleDef.expression,
|
initializer: ngModuleDef.expression,
|
||||||
statements: ngModuleStatements,
|
statements: ngModuleStatements,
|
||||||
type: ngModuleDef.type,
|
type: ngModuleDef.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 !.ngModuleDef;
|
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']);
|
||||||
|
|
|
@ -38,7 +38,7 @@ export class DtsMetadataReader implements MetadataReader {
|
||||||
// This operation is explicitly not memoized, as it depends on `ref.ownedByModuleGuess`.
|
// This operation is explicitly not memoized, as it depends on `ref.ownedByModuleGuess`.
|
||||||
// TODO(alxhub): investigate caching of .d.ts module metadata.
|
// TODO(alxhub): investigate caching of .d.ts module metadata.
|
||||||
const ngModuleDef = this.reflector.getMembersOfClass(clazz).find(
|
const ngModuleDef = this.reflector.getMembersOfClass(clazz).find(
|
||||||
member => member.name === 'ngModuleDef' && member.isStatic);
|
member => member.name === 'ɵmod' && member.isStatic);
|
||||||
if (ngModuleDef === undefined) {
|
if (ngModuleDef === undefined) {
|
||||||
return null;
|
return null;
|
||||||
} else if (
|
} else if (
|
||||||
|
|
|
@ -90,7 +90,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class Module {
|
export declare class Module {
|
||||||
static ngModuleDef: ModuleMeta<Module, [typeof Dir], never, [typeof Dir]>;
|
static ɵmod: ModuleMeta<Module, [typeof Dir], never, [typeof Dir]>;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
|
@ -107,11 +107,11 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ModuleA {
|
export declare class ModuleA {
|
||||||
static ngModuleDef: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
static ɵmod: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ModuleB {
|
export declare class ModuleB {
|
||||||
static ngModuleDef: ModuleMeta<ModuleB, never, never, [typeof ModuleA]>;
|
static ɵmod: ModuleMeta<ModuleB, never, never, [typeof ModuleA]>;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
|
@ -128,14 +128,14 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ModuleA {
|
export declare class ModuleA {
|
||||||
static ngModuleDef: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
static ɵmod: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
'exported': `
|
'exported': `
|
||||||
import * as d from 'declaration';
|
import * as d from 'declaration';
|
||||||
|
|
||||||
export declare class ModuleB {
|
export declare class ModuleB {
|
||||||
static ngModuleDef: ModuleMeta<ModuleB, never, never, [typeof d.ModuleA]>;
|
static ɵmod: ModuleMeta<ModuleB, never, never, [typeof d.ModuleA]>;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
|
@ -156,7 +156,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class DeepModule {
|
export declare class DeepModule {
|
||||||
static ngModuleDef: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
static ɵmod: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
'middle': `
|
'middle': `
|
||||||
|
@ -167,7 +167,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class MiddleModule {
|
export declare class MiddleModule {
|
||||||
static ngModuleDef: ModuleMeta<MiddleModule, [typeof MiddleDir], never, [typeof MiddleDir, typeof deep.DeepModule]>;
|
static ɵmod: ModuleMeta<MiddleModule, [typeof MiddleDir], never, [typeof MiddleDir, typeof deep.DeepModule]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
'shallow': `
|
'shallow': `
|
||||||
|
@ -178,7 +178,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ShallowModule {
|
export declare class ShallowModule {
|
||||||
static ngModuleDef: ModuleMeta<ShallowModule, [typeof ShallowDir], never, [typeof ShallowDir, typeof middle.MiddleModule]>;
|
static ɵmod: ModuleMeta<ShallowModule, [typeof ShallowDir], never, [typeof ShallowDir, typeof middle.MiddleModule]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
@ -206,7 +206,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class DeepModule {
|
export declare class DeepModule {
|
||||||
static ngModuleDef: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
static ɵmod: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
'middle': `
|
'middle': `
|
||||||
|
@ -217,7 +217,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class MiddleModule {
|
export declare class MiddleModule {
|
||||||
static ngModuleDef: ModuleMeta<MiddleModule, [typeof MiddleDir], [typeof deep.DeepModule], [typeof MiddleDir, typeof deep.DeepDir]>;
|
static ɵmod: ModuleMeta<MiddleModule, [typeof MiddleDir], [typeof deep.DeepModule], [typeof MiddleDir, typeof deep.DeepDir]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
'shallow': `
|
'shallow': `
|
||||||
|
@ -228,7 +228,7 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ShallowModule {
|
export declare class ShallowModule {
|
||||||
static ngModuleDef: ModuleMeta<ShallowModule, [typeof ShallowDir], never, [typeof ShallowDir, typeof middle.MiddleModule]>;
|
static ɵmod: ModuleMeta<ShallowModule, [typeof ShallowDir], never, [typeof ShallowDir, typeof middle.MiddleModule]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
@ -257,11 +257,11 @@ runInEachFileSystem(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class DeepModule {
|
export declare class DeepModule {
|
||||||
static ngModuleDef: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
static ɵmod: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class DeepExportModule {
|
export declare class DeepExportModule {
|
||||||
static ngModuleDef: ModuleMeta<DeepExportModule, never, never, [typeof DeepModule]>;
|
static ɵmod: ModuleMeta<DeepExportModule, never, never, [typeof DeepModule]>;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,7 @@ const R3_DEF_NAME_PATTERN = [
|
||||||
'ɵdir',
|
'ɵdir',
|
||||||
'ngInjectableDef',
|
'ngInjectableDef',
|
||||||
'ngInjectorDef',
|
'ngInjectorDef',
|
||||||
'ngModuleDef',
|
'ɵmod',
|
||||||
'ɵpipe',
|
'ɵpipe',
|
||||||
'ɵfac',
|
'ɵfac',
|
||||||
].join('|');
|
].join('|');
|
||||||
|
|
|
@ -376,7 +376,7 @@ runInEachFileSystem(os => {
|
||||||
expect(jsContents).toContain('TestDirective.ɵdir = i0.ɵɵdefineDirective');
|
expect(jsContents).toContain('TestDirective.ɵdir = i0.ɵɵdefineDirective');
|
||||||
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.ngModuleDef = i0.ɵɵdefineNgModule');
|
expect(jsContents).toContain('MyModule.ɵmod = i0.ɵɵdefineNgModule');
|
||||||
expect(jsContents).toContain('MyModule.ngInjectorDef = i0.ɵɵdefineInjector');
|
expect(jsContents).toContain('MyModule.ngInjectorDef = 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" }');
|
||||||
|
@ -512,7 +512,7 @@ runInEachFileSystem(os => {
|
||||||
'static ɵcmp: i0.ɵɵComponentDefWithMeta<TestCmp, "test-cmp", never, {}, {}, never>');
|
'static ɵcmp: i0.ɵɵComponentDefWithMeta<TestCmp, "test-cmp", never, {}, {}, never>');
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ngModuleDef: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], never, never>');
|
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, [typeof TestCmp], never, never>');
|
||||||
expect(dtsContents).not.toContain('__decorate');
|
expect(dtsContents).not.toContain('__decorate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -607,7 +607,7 @@ runInEachFileSystem(os => {
|
||||||
|
|
||||||
declare class RouterModule {
|
declare class RouterModule {
|
||||||
static forRoot(): ModuleWithProviders<RouterModule>;
|
static forRoot(): ModuleWithProviders<RouterModule>;
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<RouterModule, [typeof RouterComp], never, [typeof RouterComp]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<RouterModule, [typeof RouterComp], never, [typeof RouterComp]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -657,7 +657,7 @@ runInEachFileSystem(os => {
|
||||||
const dtsContents = env.getContents('test.d.ts');
|
const dtsContents = env.getContents('test.d.ts');
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ngModuleDef: 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 ngInjectorDef: i0.ɵɵInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -697,7 +697,7 @@ runInEachFileSystem(os => {
|
||||||
const dtsContents = env.getContents('test.d.ts');
|
const dtsContents = env.getContents('test.d.ts');
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ngModuleDef: 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 ngInjectorDef: i0.ɵɵInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -741,7 +741,7 @@ runInEachFileSystem(os => {
|
||||||
const dtsContents = env.getContents('test.d.ts');
|
const dtsContents = env.getContents('test.d.ts');
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ngModuleDef: 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 ngInjectorDef: i0.ɵɵInjectorDef');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1180,7 +1180,7 @@ runInEachFileSystem(os => {
|
||||||
expect(jsContents).toContain('TestCmp.ɵcmp =');
|
expect(jsContents).toContain('TestCmp.ɵcmp =');
|
||||||
expect(jsContents).toContain('TestDir.ɵdir =');
|
expect(jsContents).toContain('TestDir.ɵdir =');
|
||||||
expect(jsContents).toContain('TestPipe.ɵpipe =');
|
expect(jsContents).toContain('TestPipe.ɵpipe =');
|
||||||
expect(jsContents).toContain('TestNgModule.ngModuleDef =');
|
expect(jsContents).toContain('TestNgModule.ɵmod =');
|
||||||
|
|
||||||
// Validate that each class also has an injectable definition.
|
// Validate that each class also has an injectable definition.
|
||||||
expect(jsContents).toContain('TestCmp.ngInjectableDef =');
|
expect(jsContents).toContain('TestCmp.ngInjectableDef =');
|
||||||
|
@ -1453,7 +1453,7 @@ runInEachFileSystem(os => {
|
||||||
|
|
||||||
declare class RouterModule {
|
declare class RouterModule {
|
||||||
static forRoot(): ModuleWithProviders<RouterModule>;
|
static forRoot(): ModuleWithProviders<RouterModule>;
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -1492,7 +1492,7 @@ runInEachFileSystem(os => {
|
||||||
env.write('node_modules/router/internal.d.ts', `
|
env.write('node_modules/router/internal.d.ts', `
|
||||||
import {ɵɵNgModuleDefWithMeta} from '@angular/core';
|
import {ɵɵNgModuleDefWithMeta} from '@angular/core';
|
||||||
export declare class InternalRouterModule {
|
export declare class InternalRouterModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<InternalRouterModule, never, never, never>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<InternalRouterModule, never, never, never>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -1508,14 +1508,14 @@ runInEachFileSystem(os => {
|
||||||
'i0.ɵɵNgModuleDefWithMeta<TestModule, never, [typeof i1.InternalRouterModule], never>');
|
'i0.ɵɵNgModuleDefWithMeta<TestModule, never, [typeof i1.InternalRouterModule], never>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not reference a constant with a ModuleWithProviders value in ngModuleDef imports',
|
it('should not reference a constant with a ModuleWithProviders value in module def imports',
|
||||||
() => {
|
() => {
|
||||||
env.write('dep.d.ts', `
|
env.write('dep.d.ts', `
|
||||||
import {ModuleWithProviders, ɵɵNgModuleDefWithMeta as ɵɵNgModuleDefWithMeta} from '@angular/core';
|
import {ModuleWithProviders, ɵɵNgModuleDefWithMeta as ɵɵNgModuleDefWithMeta} from '@angular/core';
|
||||||
|
|
||||||
export declare class DepModule {
|
export declare class DepModule {
|
||||||
static forRoot(arg1: any, arg2: any): ModuleWithProviders<DepModule>;
|
static forRoot(arg1: any, arg2: any): ModuleWithProviders<DepModule>;
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<DepModule, never, never, never>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<DepModule, never, never, never>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
env.write('test.ts', `
|
env.write('test.ts', `
|
||||||
|
@ -1555,7 +1555,7 @@ runInEachFileSystem(os => {
|
||||||
|
|
||||||
declare class RouterModule {
|
declare class RouterModule {
|
||||||
static forRoot(): (MyType)&{ngModule:RouterModule};
|
static forRoot(): (MyType)&{ngModule:RouterModule};
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -1587,7 +1587,7 @@ runInEachFileSystem(os => {
|
||||||
|
|
||||||
declare class RouterModule {
|
declare class RouterModule {
|
||||||
static forRoot(): core.ModuleWithProviders<RouterModule>;
|
static forRoot(): core.ModuleWithProviders<RouterModule>;
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -2947,7 +2947,7 @@ runInEachFileSystem(os => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ExternalModule {
|
export declare class ExternalModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof ExternalDir], never, [typeof ExternalDir]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof ExternalDir], never, [typeof ExternalDir]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
env.write('test.ts', `
|
env.write('test.ts', `
|
||||||
|
@ -2981,7 +2981,7 @@ runInEachFileSystem(os => {
|
||||||
export {InternalDir as ExternalDir} from './internal';
|
export {InternalDir as ExternalDir} from './internal';
|
||||||
|
|
||||||
export declare class ExternalModule {
|
export declare class ExternalModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof InternalDir], never, [typeof InternalDir]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof InternalDir], never, [typeof InternalDir]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
env.write('node_modules/external/internal.d.ts', `
|
env.write('node_modules/external/internal.d.ts', `
|
||||||
|
@ -3234,7 +3234,7 @@ runInEachFileSystem(os => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ExternalModule {
|
export declare class ExternalModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof ExternalDir], never, [typeof ExternalDir]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof ExternalDir], never, [typeof ExternalDir]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -3543,7 +3543,7 @@ runInEachFileSystem(os => {
|
||||||
export declare class RouterModule {
|
export declare class RouterModule {
|
||||||
static forRoot(arg1: any, arg2: any): ModuleWithProviders<RouterModule>;
|
static forRoot(arg1: any, arg2: any): ModuleWithProviders<RouterModule>;
|
||||||
static forChild(arg1: any): ModuleWithProviders<RouterModule>;
|
static forChild(arg1: any): ModuleWithProviders<RouterModule>;
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<RouterModule, never, never, never>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
@ -4180,7 +4180,7 @@ export const Foo = Foo__PRE_R3__;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class AlphaModule {
|
export declare class AlphaModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<AlphaModule, [typeof ExternalDir], never, [typeof ExternalDir]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<AlphaModule, [typeof ExternalDir], never, [typeof ExternalDir]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -4190,7 +4190,7 @@ export const Foo = Foo__PRE_R3__;
|
||||||
import {AlphaModule} from './alpha';
|
import {AlphaModule} from './alpha';
|
||||||
|
|
||||||
export declare class BetaModule {
|
export declare class BetaModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<AlphaModule, never, never, [typeof AlphaModule]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<AlphaModule, never, never, [typeof AlphaModule]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -4231,7 +4231,7 @@ export const Foo = Foo__PRE_R3__;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ExternalModule {
|
export declare class ExternalModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof ExternalDir], never, [typeof ExternalDir, typeof LibModule]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<ExternalModule, [typeof ExternalDir], never, [typeof ExternalDir, typeof LibModule]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
env.write('lib.d.ts', `
|
env.write('lib.d.ts', `
|
||||||
|
@ -4242,7 +4242,7 @@ export const Foo = Foo__PRE_R3__;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class LibModule {
|
export declare class LibModule {
|
||||||
static ngModuleDef: ɵɵNgModuleDefWithMeta<LibModule, [typeof LibDir], never, [typeof LibDir]>;
|
static ɵmod: ɵɵNgModuleDefWithMeta<LibModule, [typeof LibDir], never, [typeof LibDir]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
env.write('foo.ts', `
|
env.write('foo.ts', `
|
||||||
|
|
|
@ -51,7 +51,7 @@ runInEachFileSystem(() => {
|
||||||
const dtsContents = env.getContents('test.d.ts');
|
const dtsContents = env.getContents('test.d.ts');
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ngModuleDef: i0.ɵɵNgModuleDefWithMeta<TestModule, never, [typeof OtherModule], never>');
|
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, never, [typeof OtherModule], never>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should produce an error when an invalid class is imported', () => {
|
it('should produce an error when an invalid class is imported', () => {
|
||||||
|
@ -112,7 +112,7 @@ runInEachFileSystem(() => {
|
||||||
const dtsContents = env.getContents('test.d.ts');
|
const dtsContents = env.getContents('test.d.ts');
|
||||||
expect(dtsContents)
|
expect(dtsContents)
|
||||||
.toContain(
|
.toContain(
|
||||||
'static ngModuleDef: i0.ɵɵNgModuleDefWithMeta<TestModule, never, never, [typeof OtherModule]>');
|
'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, never, never, [typeof OtherModule]>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should produce an error when a non-NgModule class is exported', () => {
|
it('should produce an error when a non-NgModule class is exported', () => {
|
||||||
|
|
|
@ -56,7 +56,7 @@ export declare class NgIf {
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class CommonModule {
|
export declare class CommonModule {
|
||||||
static ngModuleDef: i0.ɵɵNgModuleDefWithMeta<CommonModule, [typeof NgIf, typeof NgForOf, typeof IndexPipe], never, [typeof NgIf, typeof NgForOf, typeof IndexPipe]>;
|
static ɵmod: i0.ɵɵNgModuleDefWithMeta<CommonModule, [typeof NgIf, typeof NgForOf, typeof IndexPipe], never, [typeof NgIf, typeof NgForOf, typeof IndexPipe]>;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ export interface R3NgModuleDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata required by the module compiler to generate a `ngModuleDef` for a type.
|
* Metadata required by the module compiler to generate a module def (`ɵmod`) for a type.
|
||||||
*/
|
*/
|
||||||
export interface R3NgModuleMetadata {
|
export interface R3NgModuleMetadata {
|
||||||
/**
|
/**
|
||||||
|
@ -261,7 +261,7 @@ export function compileNgModuleFromRender2(
|
||||||
}
|
}
|
||||||
|
|
||||||
function accessExportScope(module: o.Expression): o.Expression {
|
function accessExportScope(module: o.Expression): o.Expression {
|
||||||
const selectorScope = new o.ReadPropExpr(module, 'ngModuleDef');
|
const selectorScope = new o.ReadPropExpr(module, 'ɵmod');
|
||||||
return new o.ReadPropExpr(selectorScope, 'exported');
|
return new o.ReadPropExpr(selectorScope, 'exported');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ export {
|
||||||
NG_COMP_DEF as ɵNG_COMP_DEF,
|
NG_COMP_DEF as ɵNG_COMP_DEF,
|
||||||
NG_DIR_DEF as ɵNG_DIR_DEF,
|
NG_DIR_DEF as ɵNG_DIR_DEF,
|
||||||
NG_PIPE_DEF as ɵNG_PIPE_DEF,
|
NG_PIPE_DEF as ɵNG_PIPE_DEF,
|
||||||
NG_MODULE_DEF as ɵNG_MODULE_DEF,
|
NG_MOD_DEF as ɵNG_MOD_DEF,
|
||||||
NG_BASE_DEF as ɵNG_BASE_DEF
|
NG_BASE_DEF as ɵNG_BASE_DEF
|
||||||
} from './render3/fields';
|
} from './render3/fields';
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,14 @@ function assertSameOrNotExisting(id: string, type: Type<any>| null, incoming: Ty
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerNgModuleType(ngModuleType: NgModuleType) {
|
export function registerNgModuleType(ngModuleType: NgModuleType) {
|
||||||
if (ngModuleType.ngModuleDef.id !== null) {
|
if (ngModuleType.ɵmod.id !== null) {
|
||||||
const id = ngModuleType.ngModuleDef.id;
|
const id = ngModuleType.ɵmod.id;
|
||||||
const existing = modules.get(id) as NgModuleType | null;
|
const existing = modules.get(id) as NgModuleType | null;
|
||||||
assertSameOrNotExisting(id, existing, ngModuleType);
|
assertSameOrNotExisting(id, existing, ngModuleType);
|
||||||
modules.set(id, ngModuleType);
|
modules.set(id, ngModuleType);
|
||||||
}
|
}
|
||||||
|
|
||||||
let imports = ngModuleType.ngModuleDef.imports;
|
let imports = ngModuleType.ɵmod.imports;
|
||||||
if (imports instanceof Function) {
|
if (imports instanceof Function) {
|
||||||
imports = imports();
|
imports = imports();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,7 @@ export function assertComponentType(
|
||||||
|
|
||||||
export function assertNgModuleType(
|
export function assertNgModuleType(
|
||||||
actual: any,
|
actual: any,
|
||||||
msg: string =
|
msg: string = 'Type passed in is not NgModuleType, it does not have \'ɵmod\' property.') {
|
||||||
'Type passed in is not NgModuleType, it does not have \'ngModuleDef\' property.') {
|
|
||||||
if (!getNgModuleDef(actual)) {
|
if (!getNgModuleDef(actual)) {
|
||||||
throwError(msg);
|
throwError(msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {initNgDevMode} from '../util/ng_dev_mode';
|
||||||
import {stringify} from '../util/stringify';
|
import {stringify} from '../util/stringify';
|
||||||
|
|
||||||
import {EMPTY_ARRAY, EMPTY_OBJ} from './empty';
|
import {EMPTY_ARRAY, EMPTY_OBJ} from './empty';
|
||||||
import {NG_BASE_DEF, NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF, NG_LOCALE_ID_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from './fields';
|
import {NG_BASE_DEF, NG_COMP_DEF, NG_DIR_DEF, NG_FACTORY_DEF, NG_LOCALE_ID_DEF, NG_MOD_DEF, NG_PIPE_DEF} from './fields';
|
||||||
import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, DirectiveType, DirectiveTypesOrFactory, FactoryFn, HostBindingsFunction, PipeDef, PipeType, PipeTypesOrFactory, ViewQueriesFunction, ɵɵBaseDef} from './interfaces/definition';
|
import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, ContentQueriesFunction, DirectiveDef, DirectiveDefFeature, DirectiveType, DirectiveTypesOrFactory, FactoryFn, HostBindingsFunction, PipeDef, PipeType, PipeTypesOrFactory, ViewQueriesFunction, ɵɵBaseDef} from './interfaces/definition';
|
||||||
import {TAttributes} from './interfaces/node';
|
import {TAttributes} from './interfaces/node';
|
||||||
// while SelectorFlags is unused here, it's required so that types don't get resolved lazily
|
// while SelectorFlags is unused here, it's required so that types don't get resolved lazily
|
||||||
|
@ -768,9 +768,9 @@ export function getFactoryDef<T>(type: any, throwNotFound?: boolean): FactoryFn<
|
||||||
export function getNgModuleDef<T>(type: any, throwNotFound: true): NgModuleDef<T>;
|
export function getNgModuleDef<T>(type: any, throwNotFound: true): NgModuleDef<T>;
|
||||||
export function getNgModuleDef<T>(type: any): NgModuleDef<T>|null;
|
export function getNgModuleDef<T>(type: any): NgModuleDef<T>|null;
|
||||||
export function getNgModuleDef<T>(type: any, throwNotFound?: boolean): NgModuleDef<T>|null {
|
export function getNgModuleDef<T>(type: any, throwNotFound?: boolean): NgModuleDef<T>|null {
|
||||||
const ngModuleDef = type[NG_MODULE_DEF] || null;
|
const ngModuleDef = type[NG_MOD_DEF] || null;
|
||||||
if (!ngModuleDef && throwNotFound === true) {
|
if (!ngModuleDef && throwNotFound === true) {
|
||||||
throw new Error(`Type ${stringify(type)} does not have 'ngModuleDef' property.`);
|
throw new Error(`Type ${stringify(type)} does not have 'ɵmod' property.`);
|
||||||
}
|
}
|
||||||
return ngModuleDef;
|
return ngModuleDef;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {getClosureSafeProperty} from '../util/property';
|
||||||
export const NG_COMP_DEF = getClosureSafeProperty({ɵcmp: getClosureSafeProperty});
|
export const NG_COMP_DEF = getClosureSafeProperty({ɵcmp: getClosureSafeProperty});
|
||||||
export const NG_DIR_DEF = getClosureSafeProperty({ɵdir: getClosureSafeProperty});
|
export const NG_DIR_DEF = getClosureSafeProperty({ɵdir: getClosureSafeProperty});
|
||||||
export const NG_PIPE_DEF = getClosureSafeProperty({ɵpipe: getClosureSafeProperty});
|
export const NG_PIPE_DEF = getClosureSafeProperty({ɵpipe: getClosureSafeProperty});
|
||||||
export const NG_MODULE_DEF = getClosureSafeProperty({ngModuleDef: getClosureSafeProperty});
|
export const NG_MOD_DEF = getClosureSafeProperty({ɵmod: getClosureSafeProperty});
|
||||||
export const NG_LOCALE_ID_DEF = getClosureSafeProperty({ngLocaleIdDef: getClosureSafeProperty});
|
export const NG_LOCALE_ID_DEF = getClosureSafeProperty({ngLocaleIdDef: getClosureSafeProperty});
|
||||||
export const NG_BASE_DEF = getClosureSafeProperty({ngBaseDef: getClosureSafeProperty});
|
export const NG_BASE_DEF = getClosureSafeProperty({ngBaseDef: getClosureSafeProperty});
|
||||||
export const NG_FACTORY_DEF = getClosureSafeProperty({ɵfac: getClosureSafeProperty});
|
export const NG_FACTORY_DEF = getClosureSafeProperty({ɵfac: getClosureSafeProperty});
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {ModuleWithProviders, NgModule, NgModuleDef, NgModuleTransitiveScopes} fr
|
||||||
import {deepForEach, flatten} from '../../util/array_utils';
|
import {deepForEach, flatten} from '../../util/array_utils';
|
||||||
import {assertDefined} from '../../util/assert';
|
import {assertDefined} from '../../util/assert';
|
||||||
import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition';
|
import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../definition';
|
||||||
import {NG_COMP_DEF, NG_DIR_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from '../fields';
|
import {NG_COMP_DEF, NG_DIR_DEF, NG_MOD_DEF, NG_PIPE_DEF} from '../fields';
|
||||||
import {ComponentDef} from '../interfaces/definition';
|
import {ComponentDef} from '../interfaces/definition';
|
||||||
import {NgModuleType} from '../ng_module_ref';
|
import {NgModuleType} from '../ng_module_ref';
|
||||||
import {maybeUnwrapFn, stringifyForError} from '../util/misc_utils';
|
import {maybeUnwrapFn, stringifyForError} from '../util/misc_utils';
|
||||||
|
@ -93,7 +93,7 @@ export function compileNgModule(moduleType: Type<any>, ngModule: NgModule = {}):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles and adds the `ngModuleDef` and `ngInjectorDef` properties to the module class.
|
* Compiles and adds the `ɵmod` and `ngInjectorDef` 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.
|
||||||
|
@ -105,7 +105,7 @@ export function compileNgModuleDefs(
|
||||||
ngDevMode && assertDefined(ngModule, 'Required value ngModule');
|
ngDevMode && assertDefined(ngModule, 'Required value ngModule');
|
||||||
const declarations: Type<any>[] = flatten(ngModule.declarations || EMPTY_ARRAY);
|
const declarations: Type<any>[] = flatten(ngModule.declarations || EMPTY_ARRAY);
|
||||||
let ngModuleDef: any = null;
|
let ngModuleDef: any = null;
|
||||||
Object.defineProperty(moduleType, NG_MODULE_DEF, {
|
Object.defineProperty(moduleType, NG_MOD_DEF, {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
get: () => {
|
get: () => {
|
||||||
if (ngModuleDef === null) {
|
if (ngModuleDef === null) {
|
||||||
|
@ -115,7 +115,7 @@ export function compileNgModuleDefs(
|
||||||
throw new Error(`'${stringifyForError(moduleType)}' module can't import itself`);
|
throw new Error(`'${stringifyForError(moduleType)}' module can't import itself`);
|
||||||
}
|
}
|
||||||
ngModuleDef = getCompilerFacade().compileNgModule(
|
ngModuleDef = getCompilerFacade().compileNgModule(
|
||||||
angularCoreEnv, `ng:///${moduleType.name}/ngModuleDef.js`, {
|
angularCoreEnv, `ng:///${moduleType.name}/ɵmod.js`, {
|
||||||
type: moduleType,
|
type: moduleType,
|
||||||
bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY).map(resolveForwardRef),
|
bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY).map(resolveForwardRef),
|
||||||
declarations: declarations.map(resolveForwardRef),
|
declarations: declarations.map(resolveForwardRef),
|
||||||
|
@ -429,7 +429,7 @@ export function transitiveScopesFor<T>(
|
||||||
moduleType: Type<T>,
|
moduleType: Type<T>,
|
||||||
processNgModuleFn?: (ngModule: NgModuleType) => void): NgModuleTransitiveScopes {
|
processNgModuleFn?: (ngModule: NgModuleType) => void): NgModuleTransitiveScopes {
|
||||||
if (!isNgModule(moduleType)) {
|
if (!isNgModule(moduleType)) {
|
||||||
throw new Error(`${moduleType.name} does not have an ngModuleDef`);
|
throw new Error(`${moduleType.name} does not have a module def (ɵmod property)`);
|
||||||
}
|
}
|
||||||
const def = getNgModuleDef(moduleType) !;
|
const def = getNgModuleDef(moduleType) !;
|
||||||
|
|
||||||
|
@ -465,11 +465,11 @@ export function transitiveScopesFor<T>(
|
||||||
maybeUnwrapFn(def.imports).forEach(<I>(imported: Type<I>) => {
|
maybeUnwrapFn(def.imports).forEach(<I>(imported: Type<I>) => {
|
||||||
const importedType = imported as Type<I>& {
|
const importedType = imported as Type<I>& {
|
||||||
// If imported is an @NgModule:
|
// If imported is an @NgModule:
|
||||||
ngModuleDef?: NgModuleDef<I>;
|
ɵmod?: NgModuleDef<I>;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isNgModule<I>(importedType)) {
|
if (!isNgModule<I>(importedType)) {
|
||||||
throw new Error(`Importing ${importedType.name} which does not have an ngModuleDef`);
|
throw new Error(`Importing ${importedType.name} which does not have a ɵmod property`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processNgModuleFn) {
|
if (processNgModuleFn) {
|
||||||
|
@ -488,7 +488,7 @@ export function transitiveScopesFor<T>(
|
||||||
// Components, Directives, NgModules, and Pipes can all be exported.
|
// Components, Directives, NgModules, and Pipes can all be exported.
|
||||||
ɵcmp?: any;
|
ɵcmp?: any;
|
||||||
ɵdir?: any;
|
ɵdir?: any;
|
||||||
ngModuleDef?: NgModuleDef<E>;
|
ɵmod?: NgModuleDef<E>;
|
||||||
ɵpipe?: any;
|
ɵpipe?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -528,6 +528,6 @@ function isModuleWithProviders(value: any): value is ModuleWithProviders<{}> {
|
||||||
return (value as{ngModule?: any}).ngModule !== undefined;
|
return (value as{ngModule?: any}).ngModule !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNgModule<T>(value: Type<T>): value is Type<T>&{ngModuleDef: NgModuleDef<T>} {
|
function isNgModule<T>(value: Type<T>): value is Type<T>&{ɵmod: NgModuleDef<T>} {
|
||||||
return !!getNgModuleDef(value);
|
return !!getNgModuleDef(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import {getNgLocaleIdDef, getNgModuleDef} from './definition';
|
||||||
import {setLocaleId} from './i18n';
|
import {setLocaleId} from './i18n';
|
||||||
import {maybeUnwrapFn} from './util/misc_utils';
|
import {maybeUnwrapFn} from './util/misc_utils';
|
||||||
|
|
||||||
export interface NgModuleType<T = any> extends Type<T> { ngModuleDef: NgModuleDef<T>; }
|
export interface NgModuleType<T = any> extends Type<T> { ɵmod: NgModuleDef<T>; }
|
||||||
|
|
||||||
const COMPONENT_FACTORY_RESOLVER: StaticProvider = {
|
const COMPONENT_FACTORY_RESOLVER: StaticProvider = {
|
||||||
provide: viewEngine_ComponentFactoryResolver,
|
provide: viewEngine_ComponentFactoryResolver,
|
||||||
|
|
|
@ -335,14 +335,14 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
.it('should register a module even if not importing the .ngfactory file or calling create()',
|
.it('should register a module even if not importing the .ngfactory file or calling create()',
|
||||||
() => {
|
() => {
|
||||||
class ChildModule {
|
class ChildModule {
|
||||||
static ngModuleDef = defineNgModule({
|
static ɵmod = defineNgModule({
|
||||||
type: ChildModule,
|
type: ChildModule,
|
||||||
id: 'child',
|
id: 'child',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class Module {
|
class Module {
|
||||||
static ngModuleDef = defineNgModule({
|
static ɵmod = defineNgModule({
|
||||||
type: Module,
|
type: Module,
|
||||||
id: 'test',
|
id: 'test',
|
||||||
imports: [ChildModule],
|
imports: [ChildModule],
|
||||||
|
|
|
@ -156,7 +156,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
class Module {
|
class Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
const moduleDef: NgModuleDef<Module> = (Module as any).ngModuleDef;
|
const moduleDef: NgModuleDef<Module> = (Module as any).ɵmod;
|
||||||
expect(moduleDef).toBeDefined();
|
expect(moduleDef).toBeDefined();
|
||||||
if (!Array.isArray(moduleDef.declarations)) {
|
if (!Array.isArray(moduleDef.declarations)) {
|
||||||
return fail('Expected an array');
|
return fail('Expected an array');
|
||||||
|
@ -208,7 +208,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
class Module {
|
class Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
const moduleDef: NgModuleDef<Module> = (Module as any).ngModuleDef;
|
const moduleDef: NgModuleDef<Module> = (Module as any).ɵmod;
|
||||||
// directive defs are still null, since no directives were in that component
|
// directive defs are still null, since no directives were in that component
|
||||||
expect(cmpDef.directiveDefs).toBeNull();
|
expect(cmpDef.directiveDefs).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1134,7 +1134,7 @@ describe('providers', () => {
|
||||||
{provide: String, useValue: 'From module injector'}
|
{provide: String, useValue: 'From module injector'}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
static ngModuleDef: NgModuleDef<any> = { bootstrap: [] } as any;
|
static ɵmod: NgModuleDef<any> = { bootstrap: [] } as any;
|
||||||
}
|
}
|
||||||
const myAppModuleFactory = new NgModuleFactory(MyAppModule);
|
const myAppModuleFactory = new NgModuleFactory(MyAppModule);
|
||||||
const ngModuleRef = myAppModuleFactory.create(null);
|
const ngModuleRef = myAppModuleFactory.create(null);
|
||||||
|
|
|
@ -553,7 +553,7 @@ describe('TestBed', () => {
|
||||||
|
|
||||||
// This is an AOT compiled module which declares (but does not export) SomeComponent.
|
// This is an AOT compiled module which declares (but does not export) SomeComponent.
|
||||||
class ModuleClass {
|
class ModuleClass {
|
||||||
static ngModuleDef = defineNgModule({
|
static ɵmod = defineNgModule({
|
||||||
type: ModuleClass,
|
type: ModuleClass,
|
||||||
declarations: [SomeComponent],
|
declarations: [SomeComponent],
|
||||||
});
|
});
|
||||||
|
|
|
@ -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_MODULE_DEF as NG_MODULE_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_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 {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';
|
||||||
|
@ -130,7 +130,7 @@ export class R3TestBedCompiler {
|
||||||
|
|
||||||
this.recompileNgModule(ngModule);
|
this.recompileNgModule(ngModule);
|
||||||
|
|
||||||
// At this point, the module has a valid .ngModuleDef, but the override may have introduced
|
// At this point, the module has a valid module def (ɵmod), but the override may have introduced
|
||||||
// new declarations or imported modules. Ingest any possible new types and add them to the
|
// new declarations or imported modules. Ingest any possible new types and add them to the
|
||||||
// current queue.
|
// current queue.
|
||||||
this.queueTypesFromModulesArray([ngModule]);
|
this.queueTypesFromModulesArray([ngModule]);
|
||||||
|
@ -285,7 +285,7 @@ export class R3TestBedCompiler {
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
_getComponentFactories(moduleType: NgModuleType): ComponentFactory<any>[] {
|
_getComponentFactories(moduleType: NgModuleType): ComponentFactory<any>[] {
|
||||||
return maybeUnwrapFn(moduleType.ngModuleDef.declarations).reduce((factories, declaration) => {
|
return maybeUnwrapFn(moduleType.ɵmod.declarations).reduce((factories, declaration) => {
|
||||||
const componentDef = (declaration as any).ɵcmp;
|
const componentDef = (declaration as any).ɵcmp;
|
||||||
componentDef && factories.push(new ComponentFactory(componentDef, this.testModuleRef !));
|
componentDef && factories.push(new ComponentFactory(componentDef, this.testModuleRef !));
|
||||||
return factories;
|
return factories;
|
||||||
|
@ -380,7 +380,7 @@ export class R3TestBedCompiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply provider overrides to imported modules recursively
|
// Apply provider overrides to imported modules recursively
|
||||||
const moduleDef: any = (moduleType as any)[NG_MODULE_DEF];
|
const moduleDef: any = (moduleType as any)[NG_MOD_DEF];
|
||||||
for (const importType of moduleDef.imports) {
|
for (const importType of moduleDef.imports) {
|
||||||
this.applyProviderOverridesToModule(importType);
|
this.applyProviderOverridesToModule(importType);
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,7 @@ export class R3TestBedCompiler {
|
||||||
throw new Error(`Unable to resolve metadata for NgModule: ${ngModule.name}`);
|
throw new Error(`Unable to resolve metadata for NgModule: ${ngModule.name}`);
|
||||||
}
|
}
|
||||||
// Cache the initial ngModuleDef as it will be overwritten.
|
// Cache the initial ngModuleDef as it will be overwritten.
|
||||||
this.maybeStoreNgDef(NG_MODULE_DEF, ngModule);
|
this.maybeStoreNgDef(NG_MOD_DEF, ngModule);
|
||||||
this.maybeStoreNgDef(NG_INJECTOR_DEF, ngModule);
|
this.maybeStoreNgDef(NG_INJECTOR_DEF, ngModule);
|
||||||
|
|
||||||
compileNgModuleDefs(ngModule as NgModuleType<any>, metadata);
|
compileNgModuleDefs(ngModule as NgModuleType<any>, metadata);
|
||||||
|
@ -469,7 +469,7 @@ export class R3TestBedCompiler {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
this.queueTypesFromModulesArray(value);
|
this.queueTypesFromModulesArray(value);
|
||||||
} else if (hasNgModuleDef(value)) {
|
} else if (hasNgModuleDef(value)) {
|
||||||
const def = value.ngModuleDef;
|
const def = value.ɵmod;
|
||||||
// Look through declarations, imports, and exports, and queue everything found there.
|
// Look through declarations, imports, and exports, and queue everything found there.
|
||||||
this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
|
this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
|
||||||
this.queueTypesFromModulesArray(maybeUnwrapFn(def.imports));
|
this.queueTypesFromModulesArray(maybeUnwrapFn(def.imports));
|
||||||
|
@ -682,7 +682,7 @@ function initResolvers(): Resolvers {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasNgModuleDef<T>(value: Type<T>): value is NgModuleType<T> {
|
function hasNgModuleDef<T>(value: Type<T>): value is NgModuleType<T> {
|
||||||
return value.hasOwnProperty('ngModuleDef');
|
return value.hasOwnProperty('ɵmod');
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeUnwrapFn<T>(maybeFn: (() => T) | T): T {
|
function maybeUnwrapFn<T>(maybeFn: (() => T) | T): T {
|
||||||
|
|
Loading…
Reference in New Issue