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.
This commit is contained in:
Bartek Iwańczuk 2020-06-10 16:02:41 +02:00 committed by GitHub
parent f364a4c2b6
commit 4b7d3b060e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 206 additions and 32 deletions

View file

@ -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;