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 [
factoryRes, {
name: 'ngPipeDef',
name: 'ɵpipe',
initializer: res.expression,
statements: [],
type: res.type,

View File

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

View File

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

View File

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

View File

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

View File

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