From da8cb408c878aa6e90542e26173f1f14b5254d29 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 19 Mar 2020 03:39:53 +1100 Subject: Provide compiled JSON to TypeScript compiler. (#4404) Fixes #4101 Previously, we would just provide the raw JSON to the TypeScript compiler worker, but TypeScript does not transform JSON. This caused a problem when emitting a bundle, that the JSON would just be "inlined" into the output, instead of being transformed into a module. This fixes this problem by providing the compiled JSON to the TypeScript compiler, so TypeScript just sees JSON as a "normal" TypeScript module. --- cli/js/compiler/sourcefile.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cli/js/compiler/sourcefile.ts') diff --git a/cli/js/compiler/sourcefile.ts b/cli/js/compiler/sourcefile.ts index 159ccda85..e400acbf5 100644 --- a/cli/js/compiler/sourcefile.ts +++ b/cli/js/compiler/sourcefile.ts @@ -35,7 +35,10 @@ function getExtension(fileName: string, mediaType: MediaType): ts.Extension { case MediaType.TSX: return ts.Extension.Tsx; case MediaType.Json: - return ts.Extension.Json; + // we internally compile JSON, so what gets provided to the TypeScript + // compiler is an ES module, but in order to get TypeScript to handle it + // properly we have to pretend it is TS. + return ts.Extension.Ts; case MediaType.Wasm: // Custom marker for Wasm type. return ts.Extension.Js; -- cgit v1.2.3