0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

Fix performance regression with JSON Modules

This commit is contained in:
Kitson Kelly 2018-11-02 11:30:30 +11:00 committed by Ryan Dahl
parent 6345b60ed8
commit 7f8284addf

View file

@ -441,27 +441,27 @@ export class DenoCompiler
}
const { fileName, sourceCode, mediaType, moduleId } = moduleMetaData;
console.warn("Compiling", moduleId);
const service = this._service;
// Instead of using TypeScript to transpile JSON modules, we will just do
// it directly.
if (mediaType === MediaType.Json) {
moduleMetaData.outputCode = jsonAmdTemplate(sourceCode, fileName);
} else {
const service = this._service;
assert(
mediaType === MediaType.TypeScript || mediaType === MediaType.JavaScript
);
// TypeScript is overly opinionated that only CommonJS modules kinds can
// support JSON imports. Allegedly this was fixed in
// Microsoft/TypeScript#26825 but that doesn't seem to be working here,
// so we will trick the TypeScript compiler.
this._options.module = ts.ModuleKind.AMD;
const output = service.getEmitOutput(fileName);
this._options.module = ts.ModuleKind.CommonJS;
// Get the relevant diagnostics - this is 3x faster than
// `getPreEmitDiagnostics`.
const diagnostics = [
...service.getCompilerOptionsDiagnostics(),
// TypeScript is overly opinionated that only CommonJS modules kinds can
// support JSON imports. Allegedly this was fixed in
// Microsoft/TypeScript#26825 but that doesn't seem to be working here,
// so we will ignore complaints about this compiler setting.
...service
.getCompilerOptionsDiagnostics()
.filter(diagnostic => diagnostic.code !== 5070),
...service.getSyntacticDiagnostics(fileName),
...service.getSemanticDiagnostics(fileName)
];