@@ -43,7 +43,7 @@ module ts {
43
43
}
44
44
45
45
if ( canUseOldTranspile ) {
46
- let diagnostics : Diagnostic [ ] = [ ] ;
46
+ let diagnostics : Diagnostic [ ] = [ ] ;
47
47
let transpileResult = transpile ( input , transpileOptions . compilerOptions , transpileOptions . fileName , diagnostics , transpileOptions . moduleName ) ;
48
48
checkDiagnostics ( diagnostics , testSettings . expectedDiagnosticCodes ) ;
49
49
if ( testSettings . expectedOutput ) {
@@ -57,18 +57,18 @@ module ts {
57
57
}
58
58
59
59
if ( ! transpileOptions . fileName ) {
60
- transpileOptions . fileName = "file.ts" ;
60
+ transpileOptions . fileName = transpileOptions . compilerOptions . jsx ? "file.tsx" : "file.ts" ;
61
61
}
62
62
63
- transpileOptions . compilerOptions . sourceMap = true ;
63
+ transpileOptions . compilerOptions . sourceMap = true ;
64
64
let transpileModuleResultWithSourceMap = transpileModule ( input , transpileOptions ) ;
65
65
assert . isTrue ( transpileModuleResultWithSourceMap . sourceMapText !== undefined ) ;
66
66
67
67
let expectedSourceMapFileName = removeFileExtension ( getBaseFileName ( normalizeSlashes ( transpileOptions . fileName ) ) ) + ".js.map" ;
68
68
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${ expectedSourceMapFileName } ` ;
69
69
70
70
if ( testSettings . expectedOutput !== undefined ) {
71
- assert . equal ( transpileModuleResultWithSourceMap . outputText , testSettings . expectedOutput + expectedSourceMappingUrlLine ) ;
71
+ assert . equal ( transpileModuleResultWithSourceMap . outputText , testSettings . expectedOutput + expectedSourceMappingUrlLine ) ;
72
72
}
73
73
else {
74
74
// expected output is not set, just verify that output text has sourceMappingURL as a last line
@@ -78,7 +78,7 @@ module ts {
78
78
assert . equal ( output , expectedSourceMappingUrlLine ) ;
79
79
}
80
80
else {
81
- let suffix = getNewLineCharacter ( transpileOptions . compilerOptions ) + expectedSourceMappingUrlLine
81
+ let suffix = getNewLineCharacter ( transpileOptions . compilerOptions ) + expectedSourceMappingUrlLine
82
82
assert . isTrue ( output . indexOf ( suffix , output . length - suffix . length ) !== - 1 ) ;
83
83
}
84
84
}
@@ -274,5 +274,62 @@ var x = 0;`,
274
274
it ( "Supports backslashes in file name" , ( ) => {
275
275
test ( "var x" , { expectedOutput : "var x;\r\n" , options : { fileName : "a\\b.ts" } } ) ;
276
276
} ) ;
277
+
278
+ it ( "transpile file as 'tsx' if 'jsx' is specified" , ( ) => {
279
+ let input = `import * as React from 'react';\r\n` +
280
+ `export default class Test extends React.Component<any, any> {\r\n` +
281
+ ` constructor(props: any) {\r\n` +
282
+ ` this.state = {\r\n` +
283
+ ` text : undefined\r\n` +
284
+ ` };\r\n` +
285
+ ` super();\r\n` +
286
+ ` }\r\n` +
287
+ ` handleClick(e) {\r\n` +
288
+ ` e.preventDefault();\r\n` +
289
+ ` this.setState({\r\n` +
290
+ ` text : 'just testing'\r\n` +
291
+ ` });\r\n` +
292
+ ` }\r\n` +
293
+ ` render() {\r\n` +
294
+ ` return (\r\n` +
295
+ ` <div>\r\n` +
296
+ ` <a href="#" onClick={this.handleClick}>\r\n` +
297
+ ` {'test'}\r\n` +
298
+ ` </a>\r\n` +
299
+ ` </div>\r\n` +
300
+ ` );\r\n` +
301
+ ` }\r\n` +
302
+ `}` ;
303
+ let output = `var __extends = (this && this.__extends) || function (d, b) {\r\n` +
304
+ ` for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\r\n` +
305
+ ` function __() { this.constructor = d; }\r\n` +
306
+ ` d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n` +
307
+ `};\r\n` +
308
+ `var React = require('react');\r\n` +
309
+ `var Test = (function (_super) {\r\n` +
310
+ ` __extends(Test, _super);\r\n` +
311
+ ` function Test(props) {\r\n` +
312
+ ` this.state = {\r\n` +
313
+ ` text: undefined\r\n` +
314
+ ` };\r\n` +
315
+ ` _super.call(this);\r\n` +
316
+ ` }\r\n` +
317
+ ` Test.prototype.handleClick = function (e) {\r\n` +
318
+ ` e.preventDefault();\r\n` +
319
+ ` this.setState({\r\n` +
320
+ ` text: 'just testing'\r\n` +
321
+ ` });\r\n` +
322
+ ` };\r\n` +
323
+ ` Test.prototype.render = function () {\r\n` +
324
+ ` return (React.createElement("div", null, React.createElement("a", {"href": "#", "onClick": this.handleClick}, 'test')));\r\n` +
325
+ ` };\r\n` +
326
+ ` return Test;\r\n` +
327
+ `})(React.Component);\r\n` +
328
+ `exports["default"] = Test;\r\n` ;
329
+ test ( input , {
330
+ expectedOutput : output ,
331
+ options : { compilerOptions : { jsx : JsxEmit . React , newLine : NewLineKind . CarriageReturnLineFeed } }
332
+ } )
333
+ } ) ;
277
334
} ) ;
278
335
}
0 commit comments