Skip to content

Commit 0dee268

Browse files
crisbetoalxhub
authored andcommitted
fix(compiler-cli): consider pre-release versions when detecting feature support (#59061)
Fixes that the logic which checks whether a feature is supported didn't account for pre-releases. Fixes angular/vscode-ng-language-service#2123. PR Close #59061
1 parent 1b9492e commit 0dee268

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/compiler-cli/src/ngtsc/core/src/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export class NgCompiler {
469469
// version of the compiler against an older version of Angular.
470470
this.implicitStandaloneValue =
471471
this.angularCoreVersion === null ||
472-
coreVersionSupportsFeature(this.angularCoreVersion, '>= 19.0.0-0');
472+
coreVersionSupportsFeature(this.angularCoreVersion, '>= 19.0.0');
473473
this.enableHmr = !!options['_enableHmr'];
474474
this.constructionDiagnostics.push(
475475
...this.adapter.constructionDiagnostics,
@@ -1037,7 +1037,7 @@ export class NgCompiler {
10371037
let allowSignalsInTwoWayBindings =
10381038
coreHasSymbol(this.inputProgram, R3Identifiers.unwrapWritableSignal) ??
10391039
(this.angularCoreVersion === null ||
1040-
coreVersionSupportsFeature(this.angularCoreVersion, '>= 17.2.0-0'));
1040+
coreVersionSupportsFeature(this.angularCoreVersion, '>= 17.2.0'));
10411041

10421042
// First select a type-checking configuration, based on whether full template type-checking is
10431043
// requested.

packages/compiler-cli/src/ngtsc/core/src/feature_detection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export function coreVersionSupportsFeature(coreVersion: string, minVersion: stri
2323
return true;
2424
}
2525

26-
return semver.satisfies(coreVersion, minVersion);
26+
return semver.satisfies(coreVersion, minVersion, {includePrerelease: true});
2727
}

packages/compiler-cli/test/ngtsc/ngtsc_spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11002,6 +11002,45 @@ runInEachFileSystem((os: string) => {
1100211002
);
1100311003
});
1100411004

11005+
it('should consider declarations as standalone by default in v19 pre-release versions', () => {
11006+
env.tsconfig({
11007+
_angularCoreVersion: '19.1.0-next.0',
11008+
});
11009+
11010+
env.write(
11011+
'/test.ts',
11012+
`
11013+
import {Directive, Component, Pipe, NgModule} from '@angular/core';
11014+
11015+
@Directive()
11016+
export class TestDir {}
11017+
11018+
@Component({template: ''})
11019+
export class TestComp {}
11020+
11021+
@Pipe({name: 'test'})
11022+
export class TestPipe {}
11023+
11024+
@NgModule({
11025+
declarations: [TestDir, TestComp, TestPipe]
11026+
})
11027+
export class TestModule {}
11028+
`,
11029+
);
11030+
11031+
const diags = env.driveDiagnostics();
11032+
expect(diags.length).toBe(3);
11033+
expect(diags[0].messageText).toContain(
11034+
'Directive TestDir is standalone, and cannot be declared in an NgModule.',
11035+
);
11036+
expect(diags[1].messageText).toContain(
11037+
'Component TestComp is standalone, and cannot be declared in an NgModule.',
11038+
);
11039+
expect(diags[2].messageText).toContain(
11040+
'Pipe TestPipe is standalone, and cannot be declared in an NgModule.',
11041+
);
11042+
});
11043+
1100511044
it('should disable standalone by default on versions older than 19', () => {
1100611045
env.tsconfig({
1100711046
_angularCoreVersion: '18.2.10',

0 commit comments

Comments
 (0)