Fix emit for json file

This commit is contained in:
Sheetal Nandi
2017-01-17 13:51:00 -08:00
parent 3572fad981
commit 00b6c32a10
4 changed files with 15 additions and 4 deletions

View File

@@ -56,6 +56,10 @@ namespace ts {
// So for JavaScript files, '.jsx' is only emitted if the input was '.jsx', and JsxEmit.Preserve.
// For TypeScript, the only time to emit with a '.jsx' extension, is on JSX input, and JsxEmit.Preserve
function getOutputExtension(sourceFile: SourceFile, options: CompilerOptions): Extension {
if (isJsonSourceFile(sourceFile)) {
return Extension.Json;
}
if (options.jsx === JsxEmit.Preserve) {
if (isSourceFileJavaScript(sourceFile)) {
if (fileExtensionIs(sourceFile.fileName, Extension.Jsx)) {
@@ -1615,7 +1619,9 @@ namespace ts {
function emitExpressionStatement(node: ExpressionStatement) {
emitExpression(node.expression);
writeSemicolon();
if (!isJsonSourceFile(currentSourceFile)) {
writeSemicolon();
}
}
function emitIfStatement(node: IfStatement) {

View File

@@ -1802,6 +1802,10 @@ namespace Harness {
return ts.endsWith(fileName, ts.Extension.Jsx);
}
export function isJSON(fileName: string) {
return ts.endsWith(fileName, ts.Extension.Json);
}
export function isJSMap(fileName: string) {
return ts.endsWith(fileName, ".js.map") || ts.endsWith(fileName, ".jsx.map");
}
@@ -1822,7 +1826,7 @@ namespace Harness {
// .d.ts file, add to declFiles emit
this.declFilesCode.push(emittedFile);
}
else if (isJS(emittedFile.fileName) || isJSX(emittedFile.fileName)) {
else if (isJS(emittedFile.fileName) || isJSX(emittedFile.fileName) || isJSON(emittedFile.fileName)) {
// .js file, add to files
this.files.push(emittedFile);
}

View File

@@ -15,11 +15,11 @@ if (x) {
"b": "hello"
}
//// [b.js]
//// [b.json]
{
"a": true,
"b": "hello"
};
}
//// [file1.js]
"use strict";
exports.__esModule = true;

View File

@@ -1,4 +1,5 @@
// @module: commonjs
// @outdir: out/
// @Filename: file1.ts
import b1 = require('./b');