summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/compiler.ts12
-rw-r--r--js/compiler_test.ts17
-rw-r--r--js/main.ts3
3 files changed, 28 insertions, 4 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index 624aab201..f0f82ffb1 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -169,6 +169,8 @@ export class DenoCompiler
// A reference to the global scope so it can be monkey patched during
// testing
private _window = window;
+ // Flags forcing recompilation of TS code
+ public recompile = false;
/**
* Drain the run queue, retrieving the arguments for the module
@@ -412,11 +414,15 @@ export class DenoCompiler
/**
* Retrieve the output of the TypeScript compiler for a given module and
- * cache the result.
+ * cache the result. Re-compilation can be forced using '--recompile' flag.
*/
compile(moduleMetaData: ModuleMetaData): OutputCode {
- this._log("compiler.compile", moduleMetaData.fileName);
- if (moduleMetaData.outputCode) {
+ const recompile = !!this.recompile;
+ this._log(
+ "compiler.compile",
+ { filename: moduleMetaData.fileName, recompile }
+ );
+ if (!recompile && moduleMetaData.outputCode) {
return moduleMetaData.outputCode;
}
const { fileName, sourceCode } = moduleMetaData;
diff --git a/js/compiler_test.ts b/js/compiler_test.ts
index fdb5fe03b..fef18ec3d 100644
--- a/js/compiler_test.ts
+++ b/js/compiler_test.ts
@@ -458,6 +458,23 @@ test(function compilerGetScriptFileNames() {
teardown();
});
+test(function compilerRecompileFlag() {
+ setup();
+ compilerInstance.run("foo/bar.ts", "/root/project");
+ assertEqual(getEmitOutputStack.length, 1, "Expected only a single emitted file.");
+ // running compiler against same file should use cached code
+ compilerInstance.run("foo/bar.ts", "/root/project");
+ assertEqual(getEmitOutputStack.length, 1, "Expected only a single emitted file.");
+ compilerInstance.recompile = true;
+ compilerInstance.run("foo/bar.ts", "/root/project");
+ assertEqual(getEmitOutputStack.length, 2, "Expected two emitted file.");
+ assert(
+ getEmitOutputStack[0] === getEmitOutputStack[1],
+ "Expected same file to be emitted twice."
+ );
+ teardown();
+});
+
test(function compilerGetScriptKind() {
assertEqual(compilerInstance.getScriptKind("foo.ts"), ts.ScriptKind.TS);
assertEqual(compilerInstance.getScriptKind("foo.d.ts"), ts.ScriptKind.TS);
diff --git a/js/main.ts b/js/main.ts
index e927710a7..63d72e87f 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -37,7 +37,7 @@ export default function denoMain() {
libdeno.setGlobalErrorHandler(onGlobalError);
const compiler = DenoCompiler.instance();
- // First we send an empty "Start" message to let the privlaged side know we
+ // First we send an empty "Start" message to let the privileged side know we
// are ready. The response should be a "StartRes" message containing the CLI
// args and other info.
const startResMsg = sendStart();
@@ -68,5 +68,6 @@ export default function denoMain() {
os.exit(0);
}
+ compiler.recompile = startResMsg.recompileFlag();
compiler.run(inputFn, `${cwd}/`);
}