Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 52fc6c7

Browse files
committedMar 7, 2016
Fix TSX compilation
Add unit test
1 parent a912618 commit 52fc6c7

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed
 

‎compile-service.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ CP.getSourceFile = function(filePath) {
5252
var options = this.serviceHost.getCompilationSettings();
5353
var script = this.serviceHost.getScriptSnapshot(filePath);
5454
var version = this.serviceHost.getScriptVersion(filePath);
55-
// TODO: add ts.ScriptKind?
5655
var sourceFile = this.registry.acquireDocument(
5756
filePath, options, script, version);
5857
return sourceFile;

‎index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ exports.compile = function compile(fileContent, options) {
148148
var optPath = options && options.filePath;
149149
var moduleName = options && options.moduleName;
150150

151-
var optPath = optPath ? optPath : deepHash(fileContent, options) + ".ts";
151+
if (! optPath) {
152+
optPath = deepHash(fileContent, options);
153+
var tsx = (options && options.compilerOptions &&
154+
options.compilerOptions.jsx);
155+
optPath += tsx ? ".tsx" : ".ts";
156+
}
157+
152158
var getFileContent = function(filePath) {
153159
if (filePath === optPath) {
154160
return fileContent;

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"url": "https://github.com/barbatus/meteor-typescript/issues"
2626
},
2727
"dependencies": {
28-
"typescript": "^1.7.5",
28+
"typescript": "^1.8.5",
2929
"lru-cache": "^2.6.4",
3030
"underscore": "^1.8.3",
3131
"random-js": "^1.0.3"

‎tests/ts.spec.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ describe("meteor-typescript -> ", function() {
5757
var test = function() {
5858
meteorTS.compile(testCodeLine, getOptions({
5959
compilerOptions: {
60-
module: "wrong"
61-
}
62-
}));
60+
module: "wrong"
61+
}
62+
}));
6363
};
6464
expect(test).toThrow();
6565
});
@@ -84,6 +84,18 @@ describe("meteor-typescript -> ", function() {
8484
var result = meteorTS.compile(codeLine, getOptions());
8585
expect(result.isExternal).toEqual(false);
8686
});
87+
88+
it("should compile React if jsx set", function() {
89+
var reactCodeLine = "class Component { render() { return <div />; } }";
90+
var result = meteorTS.compile(reactCodeLine, getOptions({
91+
compilerOptions: {
92+
jsx: "react"
93+
},
94+
typings: ["typings/lib.d.ts"]
95+
}));
96+
97+
expect(result.diagnostics.semanticErrors.length).toEqual(0);
98+
});
8799
});
88100

89101
describe("testing diagnostics and typings -> ", function() {

‎tests/typings/lib.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
declare module "lib" {
22
export let api = {};
33
}
4+
5+
declare var React: any;

0 commit comments

Comments
 (0)