summaryrefslogtreecommitdiff
path: root/cli/js/compiler/host.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/compiler/host.ts')
-rw-r--r--cli/js/compiler/host.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/cli/js/compiler/host.ts b/cli/js/compiler/host.ts
index 627c52970..457388bd9 100644
--- a/cli/js/compiler/host.ts
+++ b/cli/js/compiler/host.ts
@@ -242,8 +242,16 @@ export class Host implements ts.CompilerHost {
assert(sourceFile != null);
if (!sourceFile.tsSourceFile) {
assert(sourceFile.sourceCode != null);
+ // even though we assert the extension for JSON modules to the compiler
+ // is TypeScript, TypeScript internally analyses the filename for its
+ // extension and tries to parse it as JSON instead of TS. We have to
+ // change the filename to the TypeScript file.
sourceFile.tsSourceFile = ts.createSourceFile(
- fileName.startsWith(ASSETS) ? sourceFile.filename : fileName,
+ fileName.startsWith(ASSETS)
+ ? sourceFile.filename
+ : fileName.toLowerCase().endsWith(".json")
+ ? `${fileName}.ts`
+ : fileName,
sourceFile.sourceCode,
languageVersion
);