fix(ivy): fix property names of ngOnChanges (#27714)
- #reslove FW-812 - #reslove FW-844 PR Close #27714
This commit is contained in:

committed by
Miško Hevery

parent
4774a1abff
commit
1c93afe956
@ -345,8 +345,8 @@ export function defineNgModule<T>(def: {type: T} & Partial<NgModuleDef<T>>): nev
|
||||
* @Input()
|
||||
* propName1: string;
|
||||
*
|
||||
* @Input('publicName')
|
||||
* propName2: number;
|
||||
* @Input('publicName2')
|
||||
* declaredPropName2: number;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
@ -354,26 +354,35 @@ export function defineNgModule<T>(def: {type: T} & Partial<NgModuleDef<T>>): nev
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* a0: 'propName1',
|
||||
* b1: ['publicName', 'propName2'],
|
||||
* propName1: 'propName1',
|
||||
* declaredPropName2: ['publicName2', 'declaredPropName2'],
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* becomes
|
||||
* which is than translated by the minifier as:
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* 'propName1': 'a0',
|
||||
* 'publicName': 'b1'
|
||||
* minifiedPropName1: 'propName1',
|
||||
* minifiedPropName2: ['publicName2', 'declaredPropName2'],
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Optionally the function can take `secondary` which will result in:
|
||||
* becomes: (public name => minifiedName)
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* 'propName1': 'a0',
|
||||
* 'propName2': 'b1'
|
||||
* 'propName1': 'minifiedPropName1',
|
||||
* 'publicName2': 'minifiedPropName2',
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Optionally the function can take `secondary` which will result in: (public name => declared name)
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* 'propName1': 'propName1',
|
||||
* 'publicName2': 'declaredPropName2',
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
@ -384,7 +393,7 @@ function invertObject(obj: any, secondary?: any): any {
|
||||
const newLookup: any = {};
|
||||
for (const minifiedKey in obj) {
|
||||
if (obj.hasOwnProperty(minifiedKey)) {
|
||||
let publicName = obj[minifiedKey];
|
||||
let publicName: string = obj[minifiedKey];
|
||||
let declaredName = publicName;
|
||||
if (Array.isArray(publicName)) {
|
||||
declaredName = publicName[1];
|
||||
@ -392,7 +401,7 @@ function invertObject(obj: any, secondary?: any): any {
|
||||
}
|
||||
newLookup[publicName] = minifiedKey;
|
||||
if (secondary) {
|
||||
(secondary[declaredName] = minifiedKey);
|
||||
(secondary[publicName] = declaredName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,13 @@ type OnChangesExpando = OnChanges & {
|
||||
* ```
|
||||
*/
|
||||
export function NgOnChangesFeature<T>(definition: DirectiveDef<T>): void {
|
||||
const declaredToMinifiedInputs = definition.declaredInputs;
|
||||
const publicToDeclaredInputs = definition.declaredInputs;
|
||||
const publicToMinifiedInputs = definition.inputs;
|
||||
const proto = definition.type.prototype;
|
||||
for (const declaredName in declaredToMinifiedInputs) {
|
||||
if (declaredToMinifiedInputs.hasOwnProperty(declaredName)) {
|
||||
const minifiedKey = declaredToMinifiedInputs[declaredName];
|
||||
for (const publicName in publicToDeclaredInputs) {
|
||||
if (publicToDeclaredInputs.hasOwnProperty(publicName)) {
|
||||
const minifiedKey = publicToMinifiedInputs[publicName];
|
||||
const declaredKey = publicToDeclaredInputs[publicName];
|
||||
const privateMinKey = PRIVATE_PREFIX + minifiedKey;
|
||||
|
||||
// Walk the prototype chain to see if we find a property descriptor
|
||||
@ -72,12 +74,12 @@ export function NgOnChangesFeature<T>(definition: DirectiveDef<T>): void {
|
||||
}
|
||||
|
||||
const isFirstChange = !this.hasOwnProperty(privateMinKey);
|
||||
const currentChange = simpleChanges[declaredName];
|
||||
const currentChange = simpleChanges[declaredKey];
|
||||
|
||||
if (currentChange) {
|
||||
currentChange.currentValue = value;
|
||||
} else {
|
||||
simpleChanges[declaredName] =
|
||||
simpleChanges[declaredKey] =
|
||||
new SimpleChange(this[privateMinKey], value, isFirstChange);
|
||||
}
|
||||
|
||||
|
@ -84,10 +84,10 @@ describe('InheritDefinitionFeature', () => {
|
||||
qux: 'subQux',
|
||||
});
|
||||
expect(subDef.declaredInputs).toEqual({
|
||||
declaredFoo: 'superFoo',
|
||||
bar: 'superBar',
|
||||
baz: 'subBaz',
|
||||
qux: 'subQux',
|
||||
foo: 'declaredFoo',
|
||||
bar: 'bar',
|
||||
baz: 'baz',
|
||||
qux: 'qux',
|
||||
});
|
||||
});
|
||||
|
||||
@ -228,7 +228,7 @@ describe('InheritDefinitionFeature', () => {
|
||||
expect(subDef.declaredInputs).toEqual({
|
||||
input1: 'input1',
|
||||
input2: 'input2',
|
||||
input3: 'input3',
|
||||
alias3: 'input3',
|
||||
input4: 'input4',
|
||||
input5: 'input5',
|
||||
});
|
||||
|
@ -264,7 +264,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||
|
||||
const InputCompAny = InputComp as any;
|
||||
expect(InputCompAny.ngComponentDef.inputs).toEqual({publicName: 'privateName'});
|
||||
expect(InputCompAny.ngComponentDef.declaredInputs).toEqual({privateName: 'privateName'});
|
||||
expect(InputCompAny.ngComponentDef.declaredInputs).toEqual({publicName: 'privateName'});
|
||||
});
|
||||
|
||||
it('should add @Input properties to a directive', () => {
|
||||
@ -277,7 +277,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||
|
||||
const InputDirAny = InputDir as any;
|
||||
expect(InputDirAny.ngDirectiveDef.inputs).toEqual({publicName: 'privateName'});
|
||||
expect(InputDirAny.ngDirectiveDef.declaredInputs).toEqual({privateName: 'privateName'});
|
||||
expect(InputDirAny.ngDirectiveDef.declaredInputs).toEqual({publicName: 'privateName'});
|
||||
});
|
||||
|
||||
it('should add ngBaseDef to types with @Input properties', () => {
|
||||
|
Reference in New Issue
Block a user