Skip to content

Commit 2a751ab

Browse files
committed
Merge pull request microsoft#4371 from Microsoft/emitOutputForTsx
Emit tsx files correctly in getEmitOutput calls
2 parents 8ad9138 + f95fcf9 commit 2a751ab

File tree

6 files changed

+113
-2
lines changed

6 files changed

+113
-2
lines changed

src/compiler/emitter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
8585
else {
8686
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
8787
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
88-
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, forEach(host.getSourceFiles(), shouldEmitJsx) ? ".jsx" : ".js");
88+
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js");
8989
emitFile(jsFilePath, targetSourceFile);
9090
}
9191
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {

src/harness/fourslash.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ module FourSlash {
128128
sourceRoot: "sourceRoot",
129129
allowNonTsExtensions: "allowNonTsExtensions",
130130
resolveReference: "ResolveReference", // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file
131+
jsx: "jsx",
131132
};
132133

133134
// List of allowed metadata names
134135
let fileMetadataNames = [metadataOptionNames.fileName, metadataOptionNames.emitThisFile, metadataOptionNames.resolveReference];
135136
let globalMetadataNames = [metadataOptionNames.allowNonTsExtensions, metadataOptionNames.baselineFile, metadataOptionNames.declaration,
136137
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out,
137-
metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot];
138+
metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot, metadataOptionNames.jsx];
138139

139140
function convertGlobalOptionsToCompilerOptions(globalOptions: { [idx: string]: string }): ts.CompilerOptions {
140141
let settings: ts.CompilerOptions = { target: ts.ScriptTarget.ES5 };
@@ -178,6 +179,20 @@ module FourSlash {
178179
case metadataOptionNames.sourceRoot:
179180
settings.sourceRoot = globalOptions[prop];
180181
break;
182+
case metadataOptionNames.jsx:
183+
switch (globalOptions[prop].toLowerCase()) {
184+
case "react":
185+
settings.jsx = ts.JsxEmit.React;
186+
break;
187+
case "preserve":
188+
settings.jsx = ts.JsxEmit.Preserve;
189+
break;
190+
default:
191+
ts.Debug.assert(globalOptions[prop] === undefined || globalOptions[prop] === "None");
192+
settings.jsx = ts.JsxEmit.None;
193+
break;
194+
}
195+
break;
181196
}
182197
}
183198
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
EmitSkipped: false
2+
FileName : tests/cases/fourslash/inputFile1.js.map
3+
{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":["Bar","Bar.constructor"],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAAA;IAGAC,CAACA;IAADD,UAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js
4+
// regular ts file
5+
var t = 5;
6+
var Bar = (function () {
7+
function Bar() {
8+
}
9+
return Bar;
10+
})();
11+
//# sourceMappingURL=inputFile1.js.mapFileName : tests/cases/fourslash/inputFile1.d.ts
12+
declare var t: number;
13+
declare class Bar {
14+
x: string;
15+
y: number;
16+
}
17+
18+
EmitSkipped: false
19+
FileName : tests/cases/fourslash/inputFile2.jsx.map
20+
{"version":3,"file":"inputFile2.jsx","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.jsx
21+
var y = "my div";
22+
var x = <div name={y}/>;
23+
//# sourceMappingURL=inputFile2.jsx.mapFileName : tests/cases/fourslash/inputFile2.d.ts
24+
declare var y: string;
25+
declare var x: any;
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
EmitSkipped: false
2+
FileName : tests/cases/fourslash/inputFile1.js.map
3+
{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":["Bar","Bar.constructor"],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAAA;IAGAC,CAACA;IAADD,UAACA;AAADA,CAACA,AAHD,IAGC"}FileName : tests/cases/fourslash/inputFile1.js
4+
// regular ts file
5+
var t = 5;
6+
var Bar = (function () {
7+
function Bar() {
8+
}
9+
return Bar;
10+
})();
11+
//# sourceMappingURL=inputFile1.js.mapFileName : tests/cases/fourslash/inputFile1.d.ts
12+
declare var t: number;
13+
declare class Bar {
14+
x: string;
15+
y: number;
16+
}
17+
18+
EmitSkipped: false
19+
FileName : tests/cases/fourslash/inputFile2.js.map
20+
{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,qBAAC,GAAG,KAAC,IAAI,GAAG,CAAE,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.js
21+
var y = "my div";
22+
var x = React.createElement("div", {"name": y});
23+
//# sourceMappingURL=inputFile2.js.mapFileName : tests/cases/fourslash/inputFile2.d.ts
24+
declare var y: string;
25+
declare var x: any;
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @BaselineFile: getEmitOutputTsxFile_Preserve.baseline
4+
// @declaration: true
5+
// @sourceMap: true
6+
// @jsx: preserve
7+
8+
// @Filename: inputFile1.ts
9+
// @emitThisFile: true
10+
////// regular ts file
11+
//// var t: number = 5;
12+
//// class Bar {
13+
//// x : string;
14+
//// y : number
15+
//// }
16+
17+
// @Filename: inputFile2.tsx
18+
// @emitThisFile: true
19+
//// var y = "my div";
20+
//// var x = <div name= {y} />
21+
22+
verify.baselineGetEmitOutput();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @BaselineFile: getEmitOutputTsxFile_React.baseline
4+
// @declaration: true
5+
// @sourceMap: true
6+
// @jsx: react
7+
8+
// @Filename: inputFile1.ts
9+
// @emitThisFile: true
10+
////// regular ts file
11+
//// var t: number = 5;
12+
//// class Bar {
13+
//// x : string;
14+
//// y : number
15+
//// }
16+
17+
// @Filename: inputFile2.tsx
18+
// @emitThisFile: true
19+
//// var y = "my div";
20+
//// var x = <div name= {y} />
21+
22+
verify.baselineGetEmitOutput();

0 commit comments

Comments
 (0)