mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 17:27:54 -05:00
Fix emit for json file
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ if (x) {
|
||||
"b": "hello"
|
||||
}
|
||||
|
||||
//// [b.js]
|
||||
//// [b.json]
|
||||
{
|
||||
"a": true,
|
||||
"b": "hello"
|
||||
};
|
||||
}
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// @module: commonjs
|
||||
// @outdir: out/
|
||||
|
||||
// @Filename: file1.ts
|
||||
import b1 = require('./b');
|
||||
|
||||
Reference in New Issue
Block a user