refactor(core): rename ngDirectiveDef to ɵdir (#33110)
Directive 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 ngDirectiveDef to dir. 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" (ngFactoryDef, 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 #33110
This commit is contained in:

committed by
Miško Hevery

parent
d8249d1230
commit
1a67d70bf8
@ -28,8 +28,8 @@ import {createDirectiveDecorator, hasConstructor, hasDirectiveDecorator, isClass
|
||||
* ```
|
||||
*
|
||||
* When compiling `DerivedDir` which extends the undecorated `BasePlain` class, the compiler needs
|
||||
* to generate an `ngDirectiveDef` for `DerivedDir`. In particular, it needs to generate a factory
|
||||
* function that creates instances of `DerivedDir`.
|
||||
* to generate a directive def (`ɵdir`) for `DerivedDir`. In particular, it needs to generate a
|
||||
* factory function that creates instances of `DerivedDir`.
|
||||
*
|
||||
* As `DerivedDir` has no constructor, the factory function for `DerivedDir` must delegate to the
|
||||
* factory function for `BasePlain`. But for this to work, `BasePlain` must have a factory function,
|
||||
|
@ -119,7 +119,7 @@ runInEachFileSystem(() => {
|
||||
const typingsFile = result.find(f => f.path === _('/typings/file.d.ts')) !;
|
||||
expect(typingsFile.contents)
|
||||
.toContain(
|
||||
'foo(x: number): number;\n static ngFactoryDef: ɵngcc0.ɵɵFactoryDef<A>;\n static ngDirectiveDef: ɵngcc0.ɵɵDirectiveDefWithMeta');
|
||||
'foo(x: number): number;\n static ngFactoryDef: ɵngcc0.ɵɵFactoryDef<A>;\n static ɵdir: ɵngcc0.ɵɵDirectiveDefWithMeta');
|
||||
});
|
||||
|
||||
it('should render imports into typings files', () => {
|
||||
|
@ -230,7 +230,7 @@ A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, v
|
||||
|
||||
expect(addDefinitionsSpy.calls.first().args[2])
|
||||
.toEqual(`A.ngFactoryDef = function A_Factory(t) { return new (t || A)(); };
|
||||
A.ngDirectiveDef = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
|
||||
A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
|
||||
/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(A, [{
|
||||
type: Directive,
|
||||
args: [{ selector: '[a]' }]
|
||||
|
Reference in New Issue
Block a user