Skip to content

Commit 4009d16

Browse files
authored
Merge pull request #27176 from a-tarasyuk/bug/26786-no-error-when-using-allowjs-with-composite
#26786: deny using allowJs option with composite
2 parents 6adb9d1 + 5b5af23 commit 4009d16

6 files changed

+68
-2
lines changed

src/compiler/program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,8 +2609,8 @@ namespace ts {
26092609
}
26102610
}
26112611

2612-
if (!options.noEmit && options.allowJs && options.declaration) {
2613-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration");
2612+
if (!options.noEmit && options.allowJs && getEmitDeclarations(options)) {
2613+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", options.declaration ? "declaration" : "composite");
26142614
}
26152615

26162616
if (options.checkJs && !options.allowJs) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error TS5053: Option 'allowJs' cannot be specified with option 'composite'.
2+
3+
4+
!!! error TS5053: Option 'allowJs' cannot be specified with option 'composite'.
5+
==== tests/cases/compiler/a.ts (0 errors) ====
6+
class c {
7+
}
8+
9+
==== tests/cases/compiler/b.js (0 errors) ====
10+
function foo() {
11+
}
12+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/jsFileCompilationWithEnabledCompositeOption.ts] ////
2+
3+
//// [a.ts]
4+
class c {
5+
}
6+
7+
//// [b.js]
8+
function foo() {
9+
}
10+
11+
12+
//// [out.js]
13+
var c = /** @class */ (function () {
14+
function c() {
15+
}
16+
return c;
17+
}());
18+
function foo() {
19+
}
20+
21+
22+
//// [out.d.ts]
23+
declare class c {
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/a.ts ===
2+
class c {
3+
>c : Symbol(c, Decl(a.ts, 0, 0))
4+
}
5+
6+
=== tests/cases/compiler/b.js ===
7+
function foo() {
8+
>foo : Symbol(foo, Decl(b.js, 0, 0))
9+
}
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/a.ts ===
2+
class c {
3+
>c : c
4+
}
5+
6+
=== tests/cases/compiler/b.js ===
7+
function foo() {
8+
>foo : () => void
9+
}
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @allowJs: true
2+
// @out: out.js
3+
// @composite: true
4+
// @filename: a.ts
5+
class c {
6+
}
7+
8+
// @filename: b.js
9+
function foo() {
10+
}

0 commit comments

Comments
 (0)