refactor(core): rename ngComponentDef to ɵcmp (#33088)
Component 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 `ngComponentDef` to `cmp`. 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. Note that the other "defs" (ngDirectiveDef, etc) will be prefixed and shortened in follow-up PRs, in an attempt to limit how large and conflict-y this change is. PR Close #33088
This commit is contained in:

committed by
Miško Hevery

parent
d4d07233dc
commit
64fd0d6db9
@ -400,7 +400,7 @@ export class ComponentDecoratorHandler implements
|
||||
// First it needs to be determined if actually importing the directives/pipes used in the
|
||||
// template would create a cycle. Currently ngtsc refuses to generate cycles, so an option
|
||||
// known as "remote scoping" is used if a cycle would be created. In remote scoping, the
|
||||
// module file sets the directives/pipes on the ngComponentDef of the component, without
|
||||
// module file sets the directives/pipes on the ɵcmp of the component, without
|
||||
// requiring new imports (but also in a way that breaks tree shaking).
|
||||
//
|
||||
// Determining this is challenging, because the TemplateDefinitionBuilder is responsible for
|
||||
@ -456,7 +456,7 @@ export class ComponentDecoratorHandler implements
|
||||
this._recordSyntheticImport(pipe, context);
|
||||
}
|
||||
|
||||
// Check whether the directive/pipe arrays in ngComponentDef need to be wrapped in closures.
|
||||
// Check whether the directive/pipe arrays in ɵcmp need to be wrapped in closures.
|
||||
// This is required if any directive/pipe reference is to a declaration in the same file but
|
||||
// declared after this component.
|
||||
const wrapDirectivesAndPipesInClosure =
|
||||
@ -493,7 +493,7 @@ export class ComponentDecoratorHandler implements
|
||||
}
|
||||
return [
|
||||
factoryRes, {
|
||||
name: 'ngComponentDef',
|
||||
name: 'ɵcmp',
|
||||
initializer: res.expression,
|
||||
statements: [],
|
||||
type: res.type,
|
||||
|
@ -69,8 +69,7 @@ export class DtsMetadataReader implements MetadataReader {
|
||||
getDirectiveMetadata(ref: Reference<ClassDeclaration>): DirectiveMeta|null {
|
||||
const clazz = ref.node;
|
||||
const def = this.reflector.getMembersOfClass(clazz).find(
|
||||
field =>
|
||||
field.isStatic && (field.name === 'ngComponentDef' || field.name === 'ngDirectiveDef'));
|
||||
field => field.isStatic && (field.name === 'ɵcmp' || field.name === 'ngDirectiveDef'));
|
||||
if (def === undefined) {
|
||||
// No definition could be found.
|
||||
return null;
|
||||
@ -88,7 +87,7 @@ export class DtsMetadataReader implements MetadataReader {
|
||||
return {
|
||||
ref,
|
||||
name: clazz.name.text,
|
||||
isComponent: def.name === 'ngComponentDef', selector,
|
||||
isComponent: def.name === 'ɵcmp', selector,
|
||||
exportAs: readStringArrayType(def.type.typeArguments[2]),
|
||||
inputs: readStringMapType(def.type.typeArguments[3]),
|
||||
outputs: readStringMapType(def.type.typeArguments[4]),
|
||||
|
@ -91,7 +91,7 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
|
||||
* Tracks whether a given component requires "remote scoping".
|
||||
*
|
||||
* Remote scoping is when the set of directives which apply to a given component is set in the
|
||||
* NgModule's file instead of directly on the ngComponentDef (which is sometimes needed to get
|
||||
* NgModule's file instead of directly on the component def (which is sometimes needed to get
|
||||
* around cyclic import issues). This is not used in calculation of `LocalModuleScope`s, but is
|
||||
* tracked here for convenience.
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@
|
||||
// Pattern matching all Render3 property names.
|
||||
const R3_DEF_NAME_PATTERN = [
|
||||
'ngBaseDef',
|
||||
'ngComponentDef',
|
||||
'ɵcmp',
|
||||
'ngDirectiveDef',
|
||||
'ngInjectableDef',
|
||||
'ngInjectorDef',
|
||||
|
Reference in New Issue
Block a user