fix(ivy): detect frozen flyweight objects in definitions and unfreeze (#25755)
defineComponent() and friends can return a flyweight EMPTY object for specific fields when they contain no data. InheritDefinitionFeature was attempting to write into these flyweight objects, which have been protected with Object.freeze(). This commit adds detection to InheritDefinitionFeature to identify the frozen objects. PR Close #25755
This commit is contained in:

committed by
Misko Hevery

parent
2c66523222
commit
a417b2b419
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import {EventEmitter, Output} from '../../src/core';
|
||||
import {EMPTY} from '../../src/render3/definition';
|
||||
import {InheritDefinitionFeature} from '../../src/render3/features/inherit_definition_feature';
|
||||
import {ComponentDefInternal, DirectiveDefInternal, RenderFlags, defineBase, defineComponent, defineDirective} from '../../src/render3/index';
|
||||
|
||||
@ -127,6 +128,40 @@ describe('InheritDefinitionFeature', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should detect EMPTY inputs and outputs', () => {
|
||||
class SuperDirective {
|
||||
static ngDirectiveDef = defineDirective({
|
||||
inputs: {
|
||||
testIn: 'testIn',
|
||||
},
|
||||
outputs: {
|
||||
testOut: 'testOut',
|
||||
},
|
||||
type: SuperDirective,
|
||||
selectors: [['', 'superDir', '']],
|
||||
factory: () => new SuperDirective(),
|
||||
});
|
||||
}
|
||||
|
||||
class SubDirective extends SuperDirective {
|
||||
static ngDirectiveDef = defineDirective({
|
||||
type: SubDirective,
|
||||
selectors: [['', 'subDir', '']],
|
||||
factory: () => new SubDirective(),
|
||||
features: [InheritDefinitionFeature]
|
||||
});
|
||||
}
|
||||
|
||||
const subDef = SubDirective.ngDirectiveDef as DirectiveDefInternal<any>;
|
||||
|
||||
expect(subDef.inputs).toEqual({
|
||||
testIn: 'testIn',
|
||||
});
|
||||
expect(subDef.outputs).toEqual({
|
||||
testOut: 'testOut',
|
||||
});
|
||||
});
|
||||
|
||||
it('should inherit inputs from ngBaseDefs along the way', () => {
|
||||
|
||||
class Class5 {
|
||||
|
Reference in New Issue
Block a user