summaryrefslogtreecommitdiff
path: root/deno_typescript/compiler_main.js
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2019-09-13 07:30:04 +1000
committerRyan Dahl <ry@tinyclouds.org>2019-09-12 17:30:04 -0400
commitd231df17b071f74bbcf5b600ee1fbf5152144397 (patch)
tree8733f8e4b6f54fa620d9e6fde0d2d0ab8f3ee527 /deno_typescript/compiler_main.js
parentc03cdcc939f86c9865dc7a700782bdf558fa83f5 (diff)
deno_typescript cleanup/improvements (#2901)
Diffstat (limited to 'deno_typescript/compiler_main.js')
-rw-r--r--deno_typescript/compiler_main.js71
1 files changed, 40 insertions, 31 deletions
diff --git a/deno_typescript/compiler_main.js b/deno_typescript/compiler_main.js
index 85e004117..8288306f3 100644
--- a/deno_typescript/compiler_main.js
+++ b/deno_typescript/compiler_main.js
@@ -11,6 +11,7 @@ const ASSETS = "$asset$";
* @param {string} configText
* @param {Array<string>} rootNames
*/
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
function main(configText, rootNames) {
println(`>>> ts version ${ts.version}`);
println(`>>> rootNames ${rootNames}`);
@@ -19,22 +20,26 @@ function main(configText, rootNames) {
assert(rootNames.length > 0);
- let { options, diagnostics } = configure(configText);
+ const { options, diagnostics } = configure(configText);
handleDiagnostics(host, diagnostics);
println(`>>> TS config: ${JSON.stringify(options)}`);
const program = ts.createProgram(rootNames, options, host);
- diagnostics = ts.getPreEmitDiagnostics(program).filter(({ code }) => {
- // TS2691: An import path cannot end with a '.ts' extension. Consider
- // importing 'bad-module' instead.
- if (code === 2691) return false;
- // TS5009: Cannot find the common subdirectory path for the input files.
- if (code === 5009) return false;
- return true;
- });
- handleDiagnostics(host, diagnostics);
+ handleDiagnostics(
+ host,
+ ts.getPreEmitDiagnostics(program).filter(({ code }) => {
+ // TS1063: An export assignment cannot be used in a namespace.
+ if (code === 1063) return false;
+ // TS2691: An import path cannot end with a '.ts' extension. Consider
+ // importing 'bad-module' instead.
+ if (code === 2691) return false;
+ // TS5009: Cannot find the common subdirectory path for the input files.
+ if (code === 5009) return false;
+ return true;
+ })
+ );
const emitResult = program.emit();
handleDiagnostics(host, emitResult.diagnostics);
@@ -102,20 +107,25 @@ const ops = {
};
/**
+ * This is a minimal implementation of a compiler host to be able to allow the
+ * creation of runtime bundles. Some of the methods are implemented in a way
+ * to just appease the TypeScript compiler, not to necessarily be a general
+ * purpose implementation.
+ *
* @implements {ts.CompilerHost}
*/
class Host {
/**
- * @param {string} fileName
+ * @param {string} _fileName
*/
- fileExists(fileName) {
+ fileExists(_fileName) {
return true;
}
/**
- * @param {string} fileName
+ * @param {string} _fileName
*/
- readFile(fileName) {
+ readFile(_fileName) {
unreachable();
return undefined;
}
@@ -163,18 +173,17 @@ class Host {
.replace("/index.d.ts", "");
}
- let { sourceCode, moduleName } = dispatch("readFile", {
+ const { sourceCode, moduleName } = dispatch("readFile", {
fileName,
languageVersion,
shouldCreateNewSourceFile
});
- // TODO(ry) A terrible hack. Please remove ASAP.
- if (fileName.endsWith("typescript.d.ts")) {
- sourceCode = sourceCode.replace("export = ts;", "");
- }
-
- let sourceFile = ts.createSourceFile(fileName, sourceCode, languageVersion);
+ const sourceFile = ts.createSourceFile(
+ fileName,
+ sourceCode,
+ languageVersion
+ );
sourceFile.moduleName = moduleName;
return sourceFile;
}
@@ -201,18 +210,18 @@ class Host {
}
/**
- * @param {string} fileName
- * @param {ts.Path} path
- * @param {ts.ScriptTarget} languageVersion
- * @param {*} onError
- * @param {boolean} shouldCreateNewSourceFile
+ * @param {string} _fileName
+ * @param {ts.Path} _path
+ * @param {ts.ScriptTarget} _languageVersion
+ * @param {*} _onError
+ * @param {boolean} _shouldCreateNewSourceFile
*/
getSourceFileByPath(
- fileName,
- path,
- languageVersion,
- onError,
- shouldCreateNewSourceFile
+ _fileName,
+ _path,
+ _languageVersion,
+ _onError,
+ _shouldCreateNewSourceFile
) {
unreachable();
return undefined;