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:

committed by
Miško Hevery

parent
d62eff7316
commit
fc93dafab1
@ -24,7 +24,7 @@ import {ReferencesRegistry} from './references_registry';
|
||||
import {combineResolvers, findAngularDecorator, forwardRefResolver, getValidConstructorDependencies, isExpressionForwardReference, toR3Reference, unwrapExpression} from './util';
|
||||
|
||||
export interface NgModuleAnalysis {
|
||||
ngModuleDef: R3NgModuleMetadata;
|
||||
ɵmod: R3NgModuleMetadata;
|
||||
ngInjectorDef: R3InjectorMetadata;
|
||||
metadataStmt: Statement|null;
|
||||
declarations: Reference<ClassDeclaration>[];
|
||||
@ -236,8 +236,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||
return {
|
||||
analysis: {
|
||||
id,
|
||||
ngModuleDef,
|
||||
ngInjectorDef,
|
||||
ɵmod: ngModuleDef, ngInjectorDef,
|
||||
declarations: declarationRefs,
|
||||
exports: exportRefs,
|
||||
metadataStmt: generateSetClassMetadataCall(
|
||||
@ -282,7 +281,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||
|
||||
compile(node: ClassDeclaration, analysis: NgModuleAnalysis): CompileResult[] {
|
||||
const ngInjectorDef = compileInjector(analysis.ngInjectorDef);
|
||||
const ngModuleDef = compileNgModule(analysis.ngModuleDef);
|
||||
const ngModuleDef = compileNgModule(analysis.ɵmod);
|
||||
const ngModuleStatements = ngModuleDef.additionalStatements;
|
||||
if (analysis.metadataStmt !== null) {
|
||||
ngModuleStatements.push(analysis.metadataStmt);
|
||||
@ -309,7 +308,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
|
||||
}
|
||||
const res: CompileResult[] = [
|
||||
{
|
||||
name: 'ngModuleDef',
|
||||
name: 'ɵmod',
|
||||
initializer: ngModuleDef.expression,
|
||||
statements: ngModuleStatements,
|
||||
type: ngModuleDef.type,
|
||||
|
@ -77,7 +77,7 @@ runInEachFileSystem(() => {
|
||||
if (detected === undefined) {
|
||||
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.exports)).toEqual(['TestComp']);
|
||||
|
@ -38,7 +38,7 @@ export class DtsMetadataReader implements MetadataReader {
|
||||
// This operation is explicitly not memoized, as it depends on `ref.ownedByModuleGuess`.
|
||||
// TODO(alxhub): investigate caching of .d.ts module metadata.
|
||||
const ngModuleDef = this.reflector.getMembersOfClass(clazz).find(
|
||||
member => member.name === 'ngModuleDef' && member.isStatic);
|
||||
member => member.name === 'ɵmod' && member.isStatic);
|
||||
if (ngModuleDef === undefined) {
|
||||
return null;
|
||||
} else if (
|
||||
|
@ -90,7 +90,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
|
||||
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 {
|
||||
static ngModuleDef: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
||||
static ɵmod: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
||||
}
|
||||
|
||||
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 {
|
||||
static ngModuleDef: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
||||
static ɵmod: ModuleMeta<ModuleA, [typeof Dir], never, [typeof Dir]>;
|
||||
}
|
||||
`,
|
||||
'exported': `
|
||||
import * as d from 'declaration';
|
||||
|
||||
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 {
|
||||
static ngModuleDef: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||
static ɵmod: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||
}
|
||||
`,
|
||||
'middle': `
|
||||
@ -167,7 +167,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
|
||||
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': `
|
||||
@ -178,7 +178,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
|
||||
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 {
|
||||
static ngModuleDef: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||
static ɵmod: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||
}
|
||||
`,
|
||||
'middle': `
|
||||
@ -217,7 +217,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
|
||||
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': `
|
||||
@ -228,7 +228,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
|
||||
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 {
|
||||
static ngModuleDef: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||
static ɵmod: ModuleMeta<DeepModule, [typeof DeepDir], never, [typeof DeepDir]>;
|
||||
}
|
||||
|
||||
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',
|
||||
'ngInjectableDef',
|
||||
'ngInjectorDef',
|
||||
'ngModuleDef',
|
||||
'ɵmod',
|
||||
'ɵpipe',
|
||||
'ɵfac',
|
||||
].join('|');
|
||||
|
Reference in New Issue
Block a user