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> {

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
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": <name-value>` 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"
}
}

View File

@ -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 '<unknown>';

View File

@ -705,7 +705,7 @@ export const ɵɵdefineDirective = ɵɵdefineComponent as any as<T>(directiveDef
* ```
* class MyPipe implements PipeTransform {
* // 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_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});

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.
*/
export interface PipeType<T> extends Type<T> { ngPipeDef: never; }
export interface PipeType<T> extends Type<T> { ɵpipe: never; }
/**
* @codeGenApi

View File

@ -450,7 +450,7 @@ export function transitiveScopesFor<T>(
};
maybeUnwrapFn(def.declarations).forEach(declared => {
const declaredWithDefs = declared as Type<any>& { ngPipeDef?: any; };
const declaredWithDefs = declared as Type<any>& { ɵpipe?: any; };
if (getPipeDef(declaredWithDefs)) {
scopes.compilation.pipes.add(declared);
@ -489,7 +489,7 @@ export function transitiveScopesFor<T>(
ɵcmp?: any;
ɵdir?: any;
ngModuleDef?: NgModuleDef<E>;
ngPipeDef?: any;
ɵpipe?: any;
};
// 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) {
const metadata = getPipeMetadata(type, meta);
ngPipeDef = getCompilerFacade().compilePipe(
angularCoreEnv, `ng:///${metadata.name}/ngPipeDef.js`, metadata);
angularCoreEnv, `ng:///${metadata.name}/ɵpipe.js`, metadata);
}
return ngPipeDef;
},

View File

@ -241,7 +241,7 @@ ivyEnabled && describe('render3 jit', () => {
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>;
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<P>;
const pipeDef = (P as any).ɵpipe as PipeDef<P>;
expect(pipeDef.pure).toBe(true, 'pipe should be pure');
});

View File

@ -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() {

View File

@ -21,12 +21,12 @@ declare class SubComponent extends SuperComponent {
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 {
onlyInSubtype: string;
static ngPipeDef: PipeDefWithMeta<SubPipe, 'sub'>;
static ɵpipe: PipeDefWithMeta<SubPipe, 'sub'>;
}
describe('inheritance strict type checking', () => {

View File

@ -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',