Skip to content

Commit

Permalink
refactor(core): rename ngComponentDef to ɵcmp (angular#33088)
Browse files Browse the repository at this point in the history
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 angular#33088
  • Loading branch information
kara authored and mhevery committed Oct 11, 2019
1 parent d4d0723 commit 64fd0d6
Show file tree
Hide file tree
Showing 61 changed files with 306 additions and 312 deletions.
2 changes: 1 addition & 1 deletion modules/benchmarks/src/tree/render3_function/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TreeFunction {
static ngFactoryDef = () => new TreeFunction;

/** @nocollapse */
static ngComponentDef = ɵɵdefineComponent({
static ɵcmp = ɵɵdefineComponent({
type: TreeFunction,
selectors: [['tree']],
decls: 5,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ runInEachFileSystem(() => {
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
expect(addDefinitionsSpy.calls.first().args[2])
.toEqual(`A.ngFactoryDef = function A_Factory(t) { return new (t || A)(); };
A.ngComponentDef = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, vars: 1, template: function A_Template(rf, ctx) { if (rf & 1) {
A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, vars: 1, template: function A_Template(rf, ctx) { if (rf & 1) {
ɵngcc0.ɵɵtext(0);
} if (rf & 2) {
ɵngcc0.ɵɵtextInterpolate(ctx.person.name);
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-cli/src/ngtsc/annotations/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -493,7 +493,7 @@ export class ComponentDecoratorHandler implements
}
return [
factoryRes, {
name: 'ngComponentDef',
name: 'ɵcmp',
initializer: res.expression,
statements: [],
type: res.type,
Expand Down
5 changes: 2 additions & 3 deletions packages/compiler-cli/src/ngtsc/metadata/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]),
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/src/ngtsc/scope/src/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/src/transformers/nocollapse_hack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Pattern matching all Render3 property names.
const R3_DEF_NAME_PATTERN = [
'ngBaseDef',
'ngComponentDef',
'ɵcmp',
'ngDirectiveDef',
'ngInjectableDef',
'ngInjectorDef',
Expand Down

0 comments on commit 64fd0d6

Please sign in to comment.