From 4b7d3b060e88c02bc0ca12664f52111a4666b167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 10 Jun 2020 16:02:41 +0200 Subject: fix: several regressions in TS compiler (#6177) This commit fixes several regressions in TS compiler: * double compilation of same module during same process run * compilation of JavaScript entry point with non-JS imports * unexpected skip of emit during compilation Additional checks were added to ensure "allowJs" setting is used in TS compiler if JavaScript has non-JS dependencies. --- cli/js/compiler.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'cli/js/compiler.ts') diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 06117413a..abe145da2 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -1049,6 +1049,7 @@ interface SourceFileMapEntry { interface CompilerRequestCompile { type: CompilerRequestType.Compile; + allowJs: boolean; target: CompilerHostTarget; rootNames: string[]; configPath?: string; @@ -1099,6 +1100,7 @@ interface RuntimeBundleResult { function compile(request: CompilerRequestCompile): CompileResult { const { + allowJs, bundle, config, configPath, @@ -1138,6 +1140,10 @@ function compile(request: CompilerRequestCompile): CompileResult { })); let diagnostics: readonly ts.Diagnostic[] = []; + if (!bundle) { + host.mergeOptions({ allowJs }); + } + // if there is a configuration supplied, we need to parse that if (config && config.length && configPath) { const configResult = host.configure(cwd, configPath, config); @@ -1167,7 +1173,22 @@ function compile(request: CompilerRequestCompile): CompileResult { setRootExports(program, rootNames[0]); } const emitResult = program.emit(); - assert(emitResult.emitSkipped === false, "Unexpected skip of the emit."); + // If `checkJs` is off we still might be compiling entry point JavaScript file + // (if it has `.ts` imports), but it won't be emitted. In that case we skip + // assertion. + if (!bundle) { + if (options.checkJs) { + assert( + emitResult.emitSkipped === false, + "Unexpected skip of the emit." + ); + } + } else { + assert( + emitResult.emitSkipped === false, + "Unexpected skip of the emit." + ); + } // emitResult.diagnostics is `readonly` in TS3.5+ and can't be assigned // without casting. diagnostics = emitResult.diagnostics; -- cgit v1.2.3