refactor(core): rename ngPipeDef to ɵpipe (#33142)

Pipe 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
ngPipeDef to pipe. 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:
Kara Erickson 2019-10-11 19:19:59 -07:00 committed by Miško Hevery
parent f433d6604b
commit d62eff7316
17 changed files with 50 additions and 52 deletions

View File

@ -119,7 +119,7 @@ export class PipeDecoratorHandler implements DecoratorHandler<PipeHandlerData, D
} }
return [ return [
factoryRes, { factoryRes, {
name: 'ngPipeDef', name: 'ɵpipe',
initializer: res.expression, initializer: res.expression,
statements: [], statements: [],
type: res.type, type: res.type,

View File

@ -102,7 +102,7 @@ export class DtsMetadataReader implements MetadataReader {
*/ */
getPipeMetadata(ref: Reference<ClassDeclaration>): PipeMeta|null { getPipeMetadata(ref: Reference<ClassDeclaration>): PipeMeta|null {
const def = this.reflector.getMembersOfClass(ref.node).find( const def = this.reflector.getMembersOfClass(ref.node).find(
field => field.isStatic && field.name === 'ngPipeDef'); field => field.isStatic && field.name === 'ɵpipe');
if (def === undefined) { if (def === undefined) {
// No definition could be found. // No definition could be found.
return null; return null;

View File

@ -25,7 +25,7 @@ const R3_DEF_NAME_PATTERN = [
'ngInjectableDef', 'ngInjectableDef',
'ngInjectorDef', 'ngInjectorDef',
'ngModuleDef', 'ngModuleDef',
'ngPipeDef', 'ɵpipe',
'ɵfac', 'ɵfac',
].join('|'); ].join('|');

View File

@ -2016,7 +2016,7 @@ describe('compiler compliance', () => {
}; };
const MyPipeDefinition = ` const MyPipeDefinition = `
MyPipe.ngPipeDef = $r3$.ɵɵdefinePipe({ MyPipe.ɵpipe = $r3$.ɵɵdefinePipe({
name: "myPipe", name: "myPipe",
type: MyPipe, type: MyPipe,
pure: false pure: false
@ -2028,7 +2028,7 @@ describe('compiler compliance', () => {
`; `;
const MyPurePipeDefinition = ` const MyPurePipeDefinition = `
MyPurePipe.ngPipeDef = $r3$.ɵɵdefinePipe({ MyPurePipe.ɵpipe = $r3$.ɵɵdefinePipe({
name: "myPurePipe", name: "myPurePipe",
type: MyPurePipe, type: MyPurePipe,
pure: true pure: true
@ -2182,7 +2182,7 @@ describe('compiler compliance', () => {
}; };
const MyPipeDefinition = ` const MyPipeDefinition = `
MyPipe.ngPipeDef = $r3$.ɵɵdefinePipe({ MyPipe.ɵpipe = $r3$.ɵɵdefinePipe({
name: "myPipe", name: "myPipe",
type: MyPipe, type: MyPipe,
pure: true pure: true
@ -2194,7 +2194,7 @@ describe('compiler compliance', () => {
`; `;
const MyOtherPipeDefinition = ` const MyOtherPipeDefinition = `
MyOtherPipe.ngPipeDef = $r3$.ɵɵdefinePipe({ MyOtherPipe.ɵpipe = $r3$.ɵɵdefinePipe({
name: "myOtherPipe", name: "myOtherPipe",
type: MyOtherPipe, type: MyOtherPipe,
pure: true pure: true

View File

@ -374,7 +374,7 @@ runInEachFileSystem(os => {
expect(jsContents).toContain('TestBase.ngBaseDef = i0.ɵɵdefineBase'); expect(jsContents).toContain('TestBase.ngBaseDef = i0.ɵɵdefineBase');
expect(jsContents).toContain('TestComponent.ɵcmp = i0.ɵɵdefineComponent'); expect(jsContents).toContain('TestComponent.ɵcmp = i0.ɵɵdefineComponent');
expect(jsContents).toContain('TestDirective.ɵdir = i0.ɵɵdefineDirective'); expect(jsContents).toContain('TestDirective.ɵdir = i0.ɵɵdefineDirective');
expect(jsContents).toContain('TestPipe.ngPipeDef = 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.ngModuleDef = i0.ɵɵdefineNgModule');
expect(jsContents).toContain('MyModule.ngInjectorDef = i0.ɵɵdefineInjector'); expect(jsContents).toContain('MyModule.ngInjectorDef = i0.ɵɵdefineInjector');
@ -896,12 +896,11 @@ runInEachFileSystem(os => {
expect(jsContents) expect(jsContents)
.toContain( .toContain(
'TestPipe.ngPipeDef = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, pure: false })'); 'TestPipe.ɵpipe = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, pure: false })');
expect(jsContents) expect(jsContents)
.toContain( .toContain(
'TestPipe.ɵfac = function TestPipe_Factory(t) { return new (t || TestPipe)(); }'); 'TestPipe.ɵfac = function TestPipe_Factory(t) { return new (t || TestPipe)(); }');
expect(dtsContents) expect(dtsContents).toContain('static ɵpipe: i0.ɵɵPipeDefWithMeta<TestPipe, "test-pipe">;');
.toContain('static ngPipeDef: i0.ɵɵPipeDefWithMeta<TestPipe, "test-pipe">;');
expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef<TestPipe>;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef<TestPipe>;');
}); });
@ -922,12 +921,11 @@ runInEachFileSystem(os => {
expect(jsContents) expect(jsContents)
.toContain( .toContain(
'TestPipe.ngPipeDef = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, pure: true })'); 'TestPipe.ɵpipe = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, pure: true })');
expect(jsContents) expect(jsContents)
.toContain( .toContain(
'TestPipe.ɵfac = function TestPipe_Factory(t) { return new (t || TestPipe)(); }'); 'TestPipe.ɵfac = function TestPipe_Factory(t) { return new (t || TestPipe)(); }');
expect(dtsContents) expect(dtsContents).toContain('static ɵpipe: i0.ɵɵPipeDefWithMeta<TestPipe, "test-pipe">;');
.toContain('static ngPipeDef: i0.ɵɵPipeDefWithMeta<TestPipe, "test-pipe">;');
expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef<TestPipe>;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef<TestPipe>;');
}); });
@ -965,10 +963,10 @@ runInEachFileSystem(os => {
env.driveMain(); env.driveMain();
const jsContents = env.getContents('test.js'); const jsContents = env.getContents('test.js');
expect(jsContents).toContain('TestPipe.ngPipeDef ='); expect(jsContents).toContain('TestPipe.ɵpipe =');
const dtsContents = env.getContents('test.d.ts'); const dtsContents = env.getContents('test.d.ts');
expect(dtsContents) expect(dtsContents)
.toContain('static ngPipeDef: i0.ɵɵPipeDefWithMeta<TestPipe<any>, "test-pipe">;'); .toContain('static ɵpipe: i0.ɵɵPipeDefWithMeta<TestPipe<any>, "test-pipe">;');
expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef<TestPipe<any>>;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef<TestPipe<any>>;');
}); });
@ -1181,7 +1179,7 @@ runInEachFileSystem(os => {
// Validate that each class has the primary definition. // Validate that each class has the primary definition.
expect(jsContents).toContain('TestCmp.ɵcmp ='); expect(jsContents).toContain('TestCmp.ɵcmp =');
expect(jsContents).toContain('TestDir.ɵdir ='); expect(jsContents).toContain('TestDir.ɵdir =');
expect(jsContents).toContain('TestPipe.ngPipeDef ='); expect(jsContents).toContain('TestPipe.ɵpipe =');
expect(jsContents).toContain('TestNgModule.ngModuleDef ='); expect(jsContents).toContain('TestNgModule.ngModuleDef =');
// Validate that each class also has an injectable definition. // Validate that each class also has an injectable definition.

View File

@ -40,7 +40,7 @@ export declare class NgForOfContext<T> {
export declare class IndexPipe { export declare class IndexPipe {
transform<T>(value: T[], index: number): T; transform<T>(value: T[], index: number): T;
static ngPipeDef: i0.ɵPipeDefWithMeta<IndexPipe, 'index'>; static ɵpipe: i0.ɵPipeDefWithMeta<IndexPipe, 'index'>;
} }
export declare class NgForOf<T> { export declare class NgForOf<T> {

View File

@ -40,7 +40,7 @@ the decorator can be thought of as parameters to a class transformer that
transforms the class by generating definitions based on the decorator transforms the class by generating definitions based on the decorator
parameters. An `@Component` decorator transforms the class by adding parameters. An `@Component` decorator transforms the class by adding
a `ɵcmp` static property, `@Directive` adds `ɵdir`, a `ɵcmp` static property, `@Directive` adds `ɵdir`,
`@Pipe` adds `ngPipeDef`, etc. In most cases values supplied to the `@Pipe` adds `ɵpipe`, etc. In most cases values supplied to the
decorator is sufficient to generate the definition. However, in the case of decorator is sufficient to generate the definition. However, in the case of
interpreting the template, the compiler needs to know the selector defined for interpreting the template, the compiler needs to know the selector defined for
each component, directive and pipe that are in scope of the template. The each component, directive and pipe that are in scope of the template. The
@ -65,22 +65,22 @@ class:
| field | destination | | field | destination |
|---------------------|-----------------------| |---------------------|-----------------------|
| `type` | implicit | | `type` | implicit |
| `isComponent` | `ɵcmp` | | `isComponent` | `ɵcmp` |
| `selector` | `ngModuleScope` | | `selector` | `ngModuleScope` |
| `exportAs` | `ɵdir` | | `exportAs` | `ɵdir` |
| `inputs` | `ɵdir` | | `inputs` | `ɵdir` |
| `outputs` | `ɵdir` | | `outputs` | `ɵdir` |
| `hostListeners` | `ɵdir` | | `hostListeners` | `ɵdir` |
| `hostProperties` | `ɵdir` | | `hostProperties` | `ɵdir` |
| `hostAttributes` | `ɵdir` | | `hostAttributes` | `ɵdir` |
| `providers` | `ngInjectorDef` | | `providers` | `ngInjectorDef` |
| `viewProviders` | `ɵcmp` | | `viewProviders` | `ɵcmp` |
| `queries` | `ɵdir` | | `queries` | `ɵdir` |
| `guards` | not used | | `guards` | not used |
| `viewQueries` | `ɵcmp` | | `viewQueries` | `ɵcmp` |
| `entryComponents` | not used | | `entryComponents` | not used |
| `changeDetection` | `ɵcmp` | | `changeDetection` | `ɵcmp` |
| `template` | `ɵcmp` | | `template` | `ɵcmp` |
| `componentViewType` | not used | | `componentViewType` | not used |
| `renderType` | not used | | `renderType` | not used |
| `componentFactory` | not used | | `componentFactory` | not used |
@ -98,7 +98,7 @@ For `CompilePipeSummary` the table looks like:
|---------------------|-----------------------| |---------------------|-----------------------|
| `type` | implicit | | `type` | implicit |
| `name` | `ngModuleScope` | | `name` | `ngModuleScope` |
| `pure` | `ngPipeDef` | | `pure` | `ɵpipe` |
The only pieces of information that are not generated into the definition are The only pieces of information that are not generated into the definition are
the directive selector and the pipe name as they go into the module scope. the directive selector and the pipe name as they go into the module scope.
@ -239,7 +239,7 @@ export class MyDirective {
The metadata for a pipe is transformed by: The metadata for a pipe is transformed by:
1. Removing the `@Pipe` directive. 1. Removing the `@Pipe` directive.
2. Add `"ngPipeDef": {}` static field. 2. Add `"ɵpipe": {}` static field.
3. Add `"ngSelector": <name-value>` static field. 3. Add `"ngSelector": <name-value>` static field.
##### example ##### example
@ -256,7 +256,7 @@ export class MyPipe implements PipeTransform {
```js ```js
export class MyPipe { export class MyPipe {
transform(...) ... transform(...) ...
static ngPipeDef = ɵɵdefinePipe({...}); static ɵpipe = ɵɵdefinePipe({...});
} }
``` ```
@ -269,7 +269,7 @@ export class MyPipe {
"MyPipe": { "MyPipe": {
"__symbolic": "class", "__symbolic": "class",
"statics": { "statics": {
"ngPipeDef": {}, "ɵpipe": {},
"ngSelector": "myPipe" "ngSelector": "myPipe"
} }
} }

View File

@ -206,7 +206,7 @@ export class ConstantPool {
case DefinitionKind.Injector: case DefinitionKind.Injector:
return 'ngInjectorDef'; return 'ngInjectorDef';
case DefinitionKind.Pipe: case DefinitionKind.Pipe:
return 'ngPipeDef'; return 'ɵpipe';
} }
error(`Unknown definition kind ${kind}`); error(`Unknown definition kind ${kind}`);
return '<unknown>'; return '<unknown>';

View File

@ -705,7 +705,7 @@ export const ɵɵdefineDirective = ɵɵdefineComponent as any as<T>(directiveDef
* ``` * ```
* class MyPipe implements PipeTransform { * class MyPipe implements PipeTransform {
* // Generated by Angular Template Compiler * // Generated by Angular Template Compiler
* static ngPipeDef = definePipe({ * static ɵpipe = definePipe({
* ... * ...
* }); * });
* } * }

View File

@ -10,7 +10,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({ngPipeDef: getClosureSafeProperty}); export const NG_PIPE_DEF = getClosureSafeProperty({ɵpipe: getClosureSafeProperty});
export const NG_MODULE_DEF = getClosureSafeProperty({ngModuleDef: getClosureSafeProperty}); export const NG_MODULE_DEF = getClosureSafeProperty({ngModuleDef: 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});

View File

@ -88,10 +88,10 @@ export enum DirectiveDefFlags {
} }
/** /**
* A subclass of `Type` which has a static `ngPipeDef`:`PipeDef` field making it * A subclass of `Type` which has a static `ɵpipe`:`PipeDef` field making it
* consumable for rendering. * consumable for rendering.
*/ */
export interface PipeType<T> extends Type<T> { ngPipeDef: never; } export interface PipeType<T> extends Type<T> { ɵpipe: never; }
/** /**
* @codeGenApi * @codeGenApi

View File

@ -450,7 +450,7 @@ export function transitiveScopesFor<T>(
}; };
maybeUnwrapFn(def.declarations).forEach(declared => { maybeUnwrapFn(def.declarations).forEach(declared => {
const declaredWithDefs = declared as Type<any>& { ngPipeDef?: any; }; const declaredWithDefs = declared as Type<any>& { ɵpipe?: any; };
if (getPipeDef(declaredWithDefs)) { if (getPipeDef(declaredWithDefs)) {
scopes.compilation.pipes.add(declared); scopes.compilation.pipes.add(declared);
@ -489,7 +489,7 @@ export function transitiveScopesFor<T>(
ɵcmp?: any; ɵcmp?: any;
ɵdir?: any; ɵdir?: any;
ngModuleDef?: NgModuleDef<E>; ngModuleDef?: NgModuleDef<E>;
ngPipeDef?: any; ɵpipe?: any;
}; };
// Either the type is a module, a pipe, or a component/directive (which may not have a // Either the type is a module, a pipe, or a component/directive (which may not have a

View File

@ -37,7 +37,7 @@ export function compilePipe(type: Type<any>, meta: Pipe): void {
if (ngPipeDef === null) { if (ngPipeDef === null) {
const metadata = getPipeMetadata(type, meta); const metadata = getPipeMetadata(type, meta);
ngPipeDef = getCompilerFacade().compilePipe( ngPipeDef = getCompilerFacade().compilePipe(
angularCoreEnv, `ng:///${metadata.name}/ngPipeDef.js`, metadata); angularCoreEnv, `ng:///${metadata.name}/ɵpipe.js`, metadata);
} }
return ngPipeDef; return ngPipeDef;
}, },

View File

@ -241,7 +241,7 @@ ivyEnabled && describe('render3 jit', () => {
class P { class P {
} }
const pipeDef = (P as any).ngPipeDef as PipeDef<P>; const pipeDef = (P as any).ɵpipe as PipeDef<P>;
const pipeFactory = (P as any).ɵfac as FactoryFn<P>; const pipeFactory = (P as any).ɵfac as FactoryFn<P>;
expect(pipeDef.name).toBe('test-pipe'); expect(pipeDef.name).toBe('test-pipe');
expect(pipeDef.pure).toBe(false, 'pipe should not be pure'); expect(pipeDef.pure).toBe(false, 'pipe should not be pure');
@ -254,7 +254,7 @@ ivyEnabled && describe('render3 jit', () => {
class P { class P {
} }
const pipeDef = (P as any).ngPipeDef as PipeDef<P>; const pipeDef = (P as any).ɵpipe as PipeDef<P>;
expect(pipeDef.pure).toBe(true, 'pipe should be pure'); expect(pipeDef.pure).toBe(true, 'pipe should be pure');
}); });

View File

@ -30,7 +30,7 @@ describe('pipe', () => {
transform(value: any) { return new WrappedValue('Bar'); } transform(value: any) { return new WrappedValue('Bar'); }
static ɵfac = function WrappingPipe_Factory() { return new WrappingPipe(); }; static ɵfac = function WrappingPipe_Factory() { return new WrappingPipe(); };
static ngPipeDef = ɵɵdefinePipe({name: 'wrappingPipe', type: WrappingPipe, pure: false}); static ɵpipe = ɵɵdefinePipe({name: 'wrappingPipe', type: WrappingPipe, pure: false});
} }
function createTemplate() { function createTemplate() {

View File

@ -21,12 +21,12 @@ declare class SubComponent extends SuperComponent {
static ɵcmp: ɵɵComponentDefWithMeta<SubComponent, '[sub]', never, {}, {}, never>; static ɵcmp: ɵɵComponentDefWithMeta<SubComponent, '[sub]', never, {}, {}, never>;
} }
declare class SuperPipe { static ngPipeDef: PipeDefWithMeta<SuperPipe, 'super'>; } declare class SuperPipe { static ɵpipe: PipeDefWithMeta<SuperPipe, 'super'>; }
declare class SubPipe extends SuperPipe { declare class SubPipe extends SuperPipe {
onlyInSubtype: string; onlyInSubtype: string;
static ngPipeDef: PipeDefWithMeta<SubPipe, 'sub'>; static ɵpipe: PipeDefWithMeta<SubPipe, 'sub'>;
} }
describe('inheritance strict type checking', () => { describe('inheritance strict type checking', () => {

View File

@ -660,20 +660,20 @@ describe('TestBed', () => {
expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeTruthy(); expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy(); expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy();
expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeTruthy(); expect(PipeWithNoAnnotations.hasOwnProperty('ɵpipe')).toBeTruthy();
expect(SomePipe.hasOwnProperty('ngPipeDef')).toBeTruthy(); expect(SomePipe.hasOwnProperty('ɵpipe')).toBeTruthy();
TestBed.resetTestingModule(); TestBed.resetTestingModule();
// ng defs should be removed from classes with no annotations // ng defs should be removed from classes with no annotations
expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeFalsy(); expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeFalsy();
expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeFalsy(); expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeFalsy();
expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeFalsy(); expect(PipeWithNoAnnotations.hasOwnProperty('ɵpipe')).toBeFalsy();
// ng defs should be preserved on super types // ng defs should be preserved on super types
expect(SomeComponent.hasOwnProperty('ɵcmp')).toBeTruthy(); expect(SomeComponent.hasOwnProperty('ɵcmp')).toBeTruthy();
expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy(); expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy();
expect(SomePipe.hasOwnProperty('ngPipeDef')).toBeTruthy(); expect(SomePipe.hasOwnProperty('ɵpipe')).toBeTruthy();
}); });
it('should clean up overridden providers for modules that are imported more than once', it('should clean up overridden providers for modules that are imported more than once',