diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c7599e9bd6b..d8c852c996b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2609,8 +2609,8 @@ namespace ts { } } - if (!options.noEmit && options.allowJs && options.declaration) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration"); + if (!options.noEmit && options.allowJs && getEmitDeclarations(options)) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", options.declaration ? "declaration" : "composite"); } if (options.checkJs && !options.allowJs) { diff --git a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.errors.txt b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.errors.txt new file mode 100644 index 00000000000..7133188adc0 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.errors.txt @@ -0,0 +1,12 @@ +error TS5053: Option 'allowJs' cannot be specified with option 'composite'. + + +!!! error TS5053: Option 'allowJs' cannot be specified with option 'composite'. +==== tests/cases/compiler/a.ts (0 errors) ==== + class c { + } + +==== tests/cases/compiler/b.js (0 errors) ==== + function foo() { + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js new file mode 100644 index 00000000000..e34edb10ff4 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/jsFileCompilationWithEnabledCompositeOption.ts] //// + +//// [a.ts] +class c { +} + +//// [b.js] +function foo() { +} + + +//// [out.js] +var c = /** @class */ (function () { + function c() { + } + return c; +}()); +function foo() { +} + + +//// [out.d.ts] +declare class c { +} diff --git a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.symbols b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.symbols new file mode 100644 index 00000000000..5260b8d6cf3 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/a.ts === +class c { +>c : Symbol(c, Decl(a.ts, 0, 0)) +} + +=== tests/cases/compiler/b.js === +function foo() { +>foo : Symbol(foo, Decl(b.js, 0, 0)) +} + diff --git a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.types b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.types new file mode 100644 index 00000000000..dce83eeb8eb --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/a.ts === +class c { +>c : c +} + +=== tests/cases/compiler/b.js === +function foo() { +>foo : () => void +} + diff --git a/tests/cases/compiler/jsFileCompilationWithEnabledCompositeOption.ts b/tests/cases/compiler/jsFileCompilationWithEnabledCompositeOption.ts new file mode 100644 index 00000000000..90340ef5d3a --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationWithEnabledCompositeOption.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @out: out.js +// @composite: true +// @filename: a.ts +class c { +} + +// @filename: b.js +function foo() { +}