Skip to content

Commit

Permalink
fix(compiler): error when reading compiled input transforms metadata …
Browse files Browse the repository at this point in the history
…in JIT mode (#50600)

Fixes an error that surfaced in #50580 where the compiler was throwing an error in JIT mode when reading the result of `compileDirectiveDeclaration`. It is caused by the fact that input transform functions were being passed around directly, instead of being wrapped in an AST node.

PR Close #50600
  • Loading branch information
crisbeto authored and alxhub committed Jun 7, 2023
1 parent 3044822 commit 4e66329
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/compiler/src/jit_compiler_facade.ts
Expand Up @@ -662,7 +662,7 @@ function inputsMappingToInputMetadata(inputs: Record<string, string|[string, str
result[key] = {
bindingPropertyName: value[0],
classPropertyName: value[1],
transformFunction: value[2] || null,
transformFunction: value[2] ? new WrappedNodeExpr(value[2]) : null,
required: false,
};
}
Expand Down
32 changes: 30 additions & 2 deletions packages/core/test/render3/jit/declare_component_spec.ts
Expand Up @@ -8,7 +8,7 @@

import {ChangeDetectionStrategy, Component, Directive, ElementRef, forwardRef, Pipe, Type, ViewEncapsulation, ɵɵngDeclareComponent} from '@angular/core';

import {AttributeMarker, ComponentDef, ɵɵInheritDefinitionFeature, ɵɵNgOnChangesFeature} from '../../../src/render3';
import {AttributeMarker, ComponentDef, ɵɵInheritDefinitionFeature, ɵɵInputTransformsFeature, ɵɵNgOnChangesFeature} from '../../../src/render3';

import {functionContaining} from './matcher';

Expand Down Expand Up @@ -62,6 +62,30 @@ describe('component declaration jit compilation', () => {
});
});

it('should compile input with a transform function', () => {
const transformFn = () => 1;
const def = ɵɵngDeclareComponent({
type: TestClass,
template: '<div></div>',
inputs: {
minifiedClassProperty: ['bindingName', 'classProperty', transformFn],
}
}) as ComponentDef<TestClass>;

expectComponentDef(def, {
inputs: {
'bindingName': 'minifiedClassProperty',
},
inputTransforms: {
'minifiedClassProperty': transformFn,
},
declaredInputs: {
'bindingName': 'classProperty',
},
features: [ɵɵInputTransformsFeature],
});
});

it('should compile exportAs', () => {
const def = ɵɵngDeclareComponent({
type: TestClass,
Expand Down Expand Up @@ -486,7 +510,7 @@ type ComponentDefExpectations = jasmine.Expected<Pick<
ComponentDef<unknown>,
'selectors'|'template'|'inputs'|'declaredInputs'|'outputs'|'features'|'hostAttrs'|
'hostBindings'|'hostVars'|'contentQueries'|'viewQuery'|'exportAs'|'providersResolver'|
'encapsulation'|'onPush'|'styles'|'data'>>&{
'encapsulation'|'onPush'|'styles'|'data'|'inputTransforms'>>&{
directives: Type<unknown>[]|null;
pipes: Type<unknown>[]|null;
};
Expand All @@ -504,6 +528,7 @@ function expectComponentDef(
template: jasmine.any(Function),
inputs: {},
declaredInputs: {},
inputTransforms: null,
outputs: {},
features: null,
hostAttrs: null,
Expand All @@ -529,6 +554,9 @@ function expectComponentDef(
expect(actual.template).withContext('template').toEqual(expectation.template);
expect(actual.inputs).withContext('inputs').toEqual(expectation.inputs);
expect(actual.declaredInputs).withContext('declaredInputs').toEqual(expectation.declaredInputs);
expect(actual.inputTransforms)
.withContext('inputTransforms')
.toEqual(expectation.inputTransforms);
expect(actual.outputs).withContext('outputs').toEqual(expectation.outputs);
expect(actual.features).withContext('features').toEqual(expectation.features);
expect(actual.hostAttrs).withContext('hostAttrs').toEqual(expectation.hostAttrs);
Expand Down

0 comments on commit 4e66329

Please sign in to comment.