Skip to content

Commit 39ace86

Browse files
JoostKAndrewKushnir
authored andcommitted
fix(compiler-cli): enforce a minimum version to be used when a library uses input transform (#51413)
Angular 16.1 introduced the input transform feature, requiring the partial compilation output to be extended with a reference to the input transform function. This has resulted in a subtle breaking change, where older versions of the Angular linker can no longer consume libraries that have started to use this feature. We do try to support using a 16.1 library from an Angular 16.0 application, but if a library actually adopts a new feature then this is no longer possible. In such cases, it is desirable to report a message telling the user that their version of the Angular compiler is too old, as determined by the `"minVersion"` property that is present in each partial declaration. This version would still indicate that the declaration required at least Angular 14.0 to be compiled, but this is not accurate once input transforms are being used. Consequently, this error would not be reported, causing a less informative error once the input transform was being observed. Fixes #51411 PR Close #51413
1 parent 2c65ea9 commit 39ace86

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_input_outputs/GOLDEN_PARTIAL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function toNumber(value) {
111111
export class MyDirective {
112112
}
113113
MyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
114-
MyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyDirective, selector: "[my-directive]", inputs: { functionDeclarationInput: ["functionDeclarationInput", "functionDeclarationInput", toNumber], inlineFunctionInput: ["inlineFunctionInput", "inlineFunctionInput", (value, _) => value ? 1 : 0] }, ngImport: i0 });
114+
MyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "0.0.0-PLACEHOLDER", type: MyDirective, selector: "[my-directive]", inputs: { functionDeclarationInput: ["functionDeclarationInput", "functionDeclarationInput", toNumber], inlineFunctionInput: ["inlineFunctionInput", "inlineFunctionInput", (value, _) => value ? 1 : 0] }, ngImport: i0 });
115115
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyDirective, decorators: [{
116116
type: Directive,
117117
args: [{ selector: '[my-directive]' }]

packages/compiler/src/render3/partial/directive.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {toOptionalLiteralMap} from './util';
2222
*
2323
* Do not include any prerelease in these versions as they are ignored.
2424
*/
25-
const MINIMUM_PARTIAL_LINKER_VERSION = '14.0.0';
25+
const MINIMUM_PARTIAL_LINKER_VERSION = '16.1.0';
2626

2727
/**
2828
* Compile a directive declaration defined by the `R3DirectiveMetadata`.
@@ -45,7 +45,14 @@ export function createDirectiveDefinitionMap(meta: R3DirectiveMetadata):
4545
DefinitionMap<R3DeclareDirectiveMetadata> {
4646
const definitionMap = new DefinitionMap<R3DeclareDirectiveMetadata>();
4747

48-
definitionMap.set('minVersion', o.literal(MINIMUM_PARTIAL_LINKER_VERSION));
48+
const hasTransformFunctions =
49+
Object.values(meta.inputs).some(input => input.transformFunction !== null);
50+
// Note: in order to allow consuming Angular libraries that have been compiled with 16.1+ in
51+
// Angular 16.0, we only force a minimum version of 16.1 if input transform feature as introduced
52+
// in 16.1 is actually used.
53+
const minVersion = hasTransformFunctions ? MINIMUM_PARTIAL_LINKER_VERSION : '14.0.0';
54+
55+
definitionMap.set('minVersion', o.literal(minVersion));
4956
definitionMap.set('version', o.literal('0.0.0-PLACEHOLDER'));
5057

5158
// e.g. `type: MyDirective`

0 commit comments

Comments
 (0)