From d62eff7316fef38cc832acb2cba744876d9cfc09 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Fri, 11 Oct 2019 19:19:59 -0700 Subject: [PATCH] =?UTF-8?q?refactor(core):=20rename=20ngPipeDef=20to=20?= =?UTF-8?q?=C9=B5pipe=20(#33142)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../src/ngtsc/annotations/src/pipe.ts | 2 +- .../src/ngtsc/metadata/src/dts.ts | 2 +- .../src/transformers/nocollapse_hack.ts | 2 +- .../compliance/r3_compiler_compliance_spec.ts | 8 ++--- .../compiler-cli/test/ngtsc/ngtsc_spec.ts | 18 +++++----- .../test/ngtsc/template_typecheck_spec.ts | 2 +- .../compiler/design/separate_compilation.md | 34 +++++++++---------- packages/compiler/src/constant_pool.ts | 2 +- packages/core/src/render3/definition.ts | 2 +- packages/core/src/render3/fields.ts | 2 +- .../core/src/render3/interfaces/definition.ts | 4 +-- packages/core/src/render3/jit/module.ts | 4 +-- packages/core/src/render3/jit/pipe.ts | 2 +- packages/core/test/render3/ivy/jit_spec.ts | 4 +-- packages/core/test/render3/pipe_spec.ts | 2 +- .../test/strict_types/inheritance_spec.ts | 4 +-- packages/core/test/test_bed_spec.ts | 8 ++--- 17 files changed, 50 insertions(+), 52 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts b/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts index 4bbfbab24f..d8668b439a 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts @@ -119,7 +119,7 @@ export class PipeDecoratorHandler implements DecoratorHandler): 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; diff --git a/packages/compiler-cli/src/transformers/nocollapse_hack.ts b/packages/compiler-cli/src/transformers/nocollapse_hack.ts index 0ad9f70682..e4a7f0ea57 100644 --- a/packages/compiler-cli/src/transformers/nocollapse_hack.ts +++ b/packages/compiler-cli/src/transformers/nocollapse_hack.ts @@ -25,7 +25,7 @@ const R3_DEF_NAME_PATTERN = [ 'ngInjectableDef', 'ngInjectorDef', 'ngModuleDef', - 'ngPipeDef', + 'ɵpipe', 'ɵfac', ].join('|'); diff --git a/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts b/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts index 5edb82f98f..7d62d559ae 100644 --- a/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts @@ -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 diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 4e56eb7ccd..9ce36d8049 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -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;'); + expect(dtsContents).toContain('static ɵpipe: i0.ɵɵPipeDefWithMeta;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); }); @@ -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;'); + expect(dtsContents).toContain('static ɵpipe: i0.ɵɵPipeDefWithMeta;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef;'); }); @@ -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, "test-pipe">;'); + .toContain('static ɵpipe: i0.ɵɵPipeDefWithMeta, "test-pipe">;'); expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDef>;'); }); @@ -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. diff --git a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts index 035be9e2d1..d3857982f3 100644 --- a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts +++ b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts @@ -40,7 +40,7 @@ export declare class NgForOfContext { export declare class IndexPipe { transform(value: T[], index: number): T; - static ngPipeDef: i0.ɵPipeDefWithMeta; + static ɵpipe: i0.ɵPipeDefWithMeta; } export declare class NgForOf { diff --git a/packages/compiler/design/separate_compilation.md b/packages/compiler/design/separate_compilation.md index a7264bde26..3b4c98ebff 100644 --- a/packages/compiler/design/separate_compilation.md +++ b/packages/compiler/design/separate_compilation.md @@ -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 parameters. An `@Component` decorator transforms the class by adding 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 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 @@ -65,22 +65,22 @@ class: | field | destination | |---------------------|-----------------------| | `type` | implicit | -| `isComponent` | `ɵcmp` | +| `isComponent` | `ɵcmp` | | `selector` | `ngModuleScope` | -| `exportAs` | `ɵdir` | -| `inputs` | `ɵdir` | -| `outputs` | `ɵdir` | -| `hostListeners` | `ɵdir` | -| `hostProperties` | `ɵdir` | -| `hostAttributes` | `ɵdir` | +| `exportAs` | `ɵdir` | +| `inputs` | `ɵdir` | +| `outputs` | `ɵdir` | +| `hostListeners` | `ɵdir` | +| `hostProperties` | `ɵdir` | +| `hostAttributes` | `ɵdir` | | `providers` | `ngInjectorDef` | -| `viewProviders` | `ɵcmp` | -| `queries` | `ɵdir` | +| `viewProviders` | `ɵcmp` | +| `queries` | `ɵdir` | | `guards` | not used | -| `viewQueries` | `ɵcmp` | +| `viewQueries` | `ɵcmp` | | `entryComponents` | not used | -| `changeDetection` | `ɵcmp` | -| `template` | `ɵcmp` | +| `changeDetection` | `ɵcmp` | +| `template` | `ɵcmp` | | `componentViewType` | not used | | `renderType` | not used | | `componentFactory` | not used | @@ -98,7 +98,7 @@ For `CompilePipeSummary` the table looks like: |---------------------|-----------------------| | `type` | implicit | | `name` | `ngModuleScope` | -| `pure` | `ngPipeDef` | +| `pure` | `ɵpipe` | 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. @@ -239,7 +239,7 @@ export class MyDirective { The metadata for a pipe is transformed by: 1. Removing the `@Pipe` directive. -2. Add `"ngPipeDef": {}` static field. +2. Add `"ɵpipe": {}` static field. 3. Add `"ngSelector": ` static field. ##### example @@ -256,7 +256,7 @@ export class MyPipe implements PipeTransform { ```js export class MyPipe { transform(...) ... - static ngPipeDef = ɵɵdefinePipe({...}); + static ɵpipe = ɵɵdefinePipe({...}); } ``` @@ -269,7 +269,7 @@ export class MyPipe { "MyPipe": { "__symbolic": "class", "statics": { - "ngPipeDef": {}, + "ɵpipe": {}, "ngSelector": "myPipe" } } diff --git a/packages/compiler/src/constant_pool.ts b/packages/compiler/src/constant_pool.ts index 2af889bae5..9c665d2a35 100644 --- a/packages/compiler/src/constant_pool.ts +++ b/packages/compiler/src/constant_pool.ts @@ -206,7 +206,7 @@ export class ConstantPool { case DefinitionKind.Injector: return 'ngInjectorDef'; case DefinitionKind.Pipe: - return 'ngPipeDef'; + return 'ɵpipe'; } error(`Unknown definition kind ${kind}`); return ''; diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index 766351743b..507b109692 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -705,7 +705,7 @@ export const ɵɵdefineDirective = ɵɵdefineComponent as any as(directiveDef * ``` * class MyPipe implements PipeTransform { * // Generated by Angular Template Compiler - * static ngPipeDef = definePipe({ + * static ɵpipe = definePipe({ * ... * }); * } diff --git a/packages/core/src/render3/fields.ts b/packages/core/src/render3/fields.ts index 482ad6e42e..e2cc955f8d 100644 --- a/packages/core/src/render3/fields.ts +++ b/packages/core/src/render3/fields.ts @@ -10,7 +10,7 @@ import {getClosureSafeProperty} from '../util/property'; export const NG_COMP_DEF = getClosureSafeProperty({ɵcmp: 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_LOCALE_ID_DEF = getClosureSafeProperty({ngLocaleIdDef: getClosureSafeProperty}); export const NG_BASE_DEF = getClosureSafeProperty({ngBaseDef: getClosureSafeProperty}); diff --git a/packages/core/src/render3/interfaces/definition.ts b/packages/core/src/render3/interfaces/definition.ts index 60b400612a..3794697fea 100644 --- a/packages/core/src/render3/interfaces/definition.ts +++ b/packages/core/src/render3/interfaces/definition.ts @@ -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. */ -export interface PipeType extends Type { ngPipeDef: never; } +export interface PipeType extends Type { ɵpipe: never; } /** * @codeGenApi diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index 637e398e89..9e0393658e 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -450,7 +450,7 @@ export function transitiveScopesFor( }; maybeUnwrapFn(def.declarations).forEach(declared => { - const declaredWithDefs = declared as Type& { ngPipeDef?: any; }; + const declaredWithDefs = declared as Type& { ɵpipe?: any; }; if (getPipeDef(declaredWithDefs)) { scopes.compilation.pipes.add(declared); @@ -489,7 +489,7 @@ export function transitiveScopesFor( ɵcmp?: any; ɵdir?: any; ngModuleDef?: NgModuleDef; - ngPipeDef?: any; + ɵpipe?: any; }; // Either the type is a module, a pipe, or a component/directive (which may not have a diff --git a/packages/core/src/render3/jit/pipe.ts b/packages/core/src/render3/jit/pipe.ts index c59fd70cfc..4025cfbd71 100644 --- a/packages/core/src/render3/jit/pipe.ts +++ b/packages/core/src/render3/jit/pipe.ts @@ -37,7 +37,7 @@ export function compilePipe(type: Type, meta: Pipe): void { if (ngPipeDef === null) { const metadata = getPipeMetadata(type, meta); ngPipeDef = getCompilerFacade().compilePipe( - angularCoreEnv, `ng:///${metadata.name}/ngPipeDef.js`, metadata); + angularCoreEnv, `ng:///${metadata.name}/ɵpipe.js`, metadata); } return ngPipeDef; }, diff --git a/packages/core/test/render3/ivy/jit_spec.ts b/packages/core/test/render3/ivy/jit_spec.ts index da7e4a7c7d..af8fcad23c 100644 --- a/packages/core/test/render3/ivy/jit_spec.ts +++ b/packages/core/test/render3/ivy/jit_spec.ts @@ -241,7 +241,7 @@ ivyEnabled && describe('render3 jit', () => { class P { } - const pipeDef = (P as any).ngPipeDef as PipeDef

; + const pipeDef = (P as any).ɵpipe as PipeDef

; const pipeFactory = (P as any).ɵfac as FactoryFn

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

; + const pipeDef = (P as any).ɵpipe as PipeDef

; expect(pipeDef.pure).toBe(true, 'pipe should be pure'); }); diff --git a/packages/core/test/render3/pipe_spec.ts b/packages/core/test/render3/pipe_spec.ts index 185319ff47..ee8ff71724 100644 --- a/packages/core/test/render3/pipe_spec.ts +++ b/packages/core/test/render3/pipe_spec.ts @@ -30,7 +30,7 @@ describe('pipe', () => { transform(value: any) { return new WrappedValue('Bar'); } 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() { diff --git a/packages/core/test/strict_types/inheritance_spec.ts b/packages/core/test/strict_types/inheritance_spec.ts index 78a8a44e63..29edf02795 100644 --- a/packages/core/test/strict_types/inheritance_spec.ts +++ b/packages/core/test/strict_types/inheritance_spec.ts @@ -21,12 +21,12 @@ declare class SubComponent extends SuperComponent { static ɵcmp: ɵɵComponentDefWithMeta; } -declare class SuperPipe { static ngPipeDef: PipeDefWithMeta; } +declare class SuperPipe { static ɵpipe: PipeDefWithMeta; } declare class SubPipe extends SuperPipe { onlyInSubtype: string; - static ngPipeDef: PipeDefWithMeta; + static ɵpipe: PipeDefWithMeta; } describe('inheritance strict type checking', () => { diff --git a/packages/core/test/test_bed_spec.ts b/packages/core/test/test_bed_spec.ts index d7223fdddb..e000fb3720 100644 --- a/packages/core/test/test_bed_spec.ts +++ b/packages/core/test/test_bed_spec.ts @@ -660,20 +660,20 @@ describe('TestBed', () => { expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeTruthy(); expect(SomeDirective.hasOwnProperty('ɵdir')).toBeTruthy(); - expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeTruthy(); - expect(SomePipe.hasOwnProperty('ngPipeDef')).toBeTruthy(); + expect(PipeWithNoAnnotations.hasOwnProperty('ɵpipe')).toBeTruthy(); + expect(SomePipe.hasOwnProperty('ɵpipe')).toBeTruthy(); TestBed.resetTestingModule(); // ng defs should be removed from classes with no annotations expect(ComponentWithNoAnnotations.hasOwnProperty('ɵcmp')).toBeFalsy(); expect(DirectiveWithNoAnnotations.hasOwnProperty('ɵdir')).toBeFalsy(); - expect(PipeWithNoAnnotations.hasOwnProperty('ngPipeDef')).toBeFalsy(); + expect(PipeWithNoAnnotations.hasOwnProperty('ɵpipe')).toBeFalsy(); // ng defs should be preserved on super types expect(SomeComponent.hasOwnProperty('ɵcmp')).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',