summaryrefslogtreecommitdiff
path: root/cli/js/compiler.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-06-10 16:02:41 +0200
committerGitHub <noreply@github.com>2020-06-10 16:02:41 +0200
commit4b7d3b060e88c02bc0ca12664f52111a4666b167 (patch)
tree018968e67c8d34c5cffe73578643eb071fa103b0 /cli/js/compiler.ts
parentf364a4c2b6dcce65959af2da3663f0b4a7338229 (diff)
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.
Diffstat (limited to 'cli/js/compiler.ts')
-rw-r--r--cli/js/compiler.ts23
1 files changed, 22 insertions, 1 deletions
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;