Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected skip of emit in TS compiler and double compilation of dynamic imports #6177

Merged
merged 11 commits into from
Jun 10, 2020
19 changes: 17 additions & 2 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const DEFAULT_BUNDLER_OPTIONS: ts.CompilerOptions = {
};

const DEFAULT_COMPILE_OPTIONS: ts.CompilerOptions = {
allowJs: false,
allowJs: true,
allowNonTsExtensions: true,
checkJs: false,
esModuleInterop: true,
Expand Down Expand Up @@ -1167,7 +1167,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;
Expand Down
1 change: 1 addition & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,7 @@ itest!(cjs_imports {
itest!(ts_import_from_js {
args: "run --quiet --reload ts_import_from_js.js",
output: "ts_import_from_js.js.out",
http_server: true,
});

itest!(proto_exploit {
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/ts_import_from_js.deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./005_more_imports.ts";
export { printHello } from "http://localhost:4545/cli/tests/subdir/mod2.ts";
4 changes: 3 additions & 1 deletion cli/tests/ts_import_from_js.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import "./005_more_imports.ts";
import { printHello } from "./ts_import_from_js.deps.js";
printHello();
console.log("success");
2 changes: 2 additions & 0 deletions cli/tests/ts_import_from_js.js.out
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Hello
Hello
success