Comparing version 1.4.1 to 1.4.2
@@ -92,2 +92,8 @@ "use strict"; | ||
} | ||
function getExtension(fileName) { | ||
if (compilerOptions.jsx === 'preserve' && path_1.extname(fileName) === '.tsx') { | ||
return '.jsx'; | ||
} | ||
return '.js'; | ||
} | ||
var getOutput = function (code, fileName) { | ||
@@ -107,3 +113,3 @@ var result = ts.transpileModule(code, { | ||
}; | ||
var compile = readThrough(cachedir, shouldCache, getFile, fileExists, cache, getOutput); | ||
var compile = readThrough(cachedir, shouldCache, getFile, fileExists, cache, getOutput, getExtension); | ||
var getTypeInfo = function (fileName, position) { | ||
@@ -166,3 +172,3 @@ throw new TypeError("No type information available under \"--fast\" mode"); | ||
return getOutput(code, fileName); | ||
}); | ||
}, getExtension); | ||
getTypeInfo = function (fileName, position) { | ||
@@ -231,10 +237,11 @@ addVersion_1(fileName); | ||
} | ||
function readThrough(cachedir, shouldCache, getFile, fileExists, cache, compile) { | ||
function readThrough(cachedir, shouldCache, getFile, fileExists, cache, compile, getExtension) { | ||
if (shouldCache === false) { | ||
return function (code, fileName) { | ||
var cachePath = path_1.join(cachedir, getCacheName(code, fileName)); | ||
var sourceMapPath = cachePath + ".js.map"; | ||
var extension = getExtension(fileName); | ||
var sourceMapPath = "" + cachePath + extension + ".map"; | ||
var out = compile(code, fileName); | ||
cache.sourceMaps[fileName] = sourceMapPath; | ||
var output = updateOutput(out[0], fileName, sourceMapPath); | ||
var output = updateOutput(out[0], fileName, extension, sourceMapPath); | ||
var sourceMap = updateSourceMap(out[1], fileName); | ||
@@ -247,4 +254,5 @@ fs_1.writeFileSync(sourceMapPath, sourceMap); | ||
var cachePath = path_1.join(cachedir, getCacheName(code, fileName)); | ||
var outputPath = cachePath + ".js"; | ||
var sourceMapPath = cachePath + ".js.map"; | ||
var extension = getExtension(fileName); | ||
var outputPath = "" + cachePath + extension; | ||
var sourceMapPath = outputPath + ".map"; | ||
cache.sourceMaps[fileName] = sourceMapPath; | ||
@@ -255,3 +263,3 @@ if (fileExists(outputPath)) { | ||
var out = compile(code, fileName); | ||
var output = updateOutput(out[0], fileName, sourceMapPath); | ||
var output = updateOutput(out[0], fileName, extension, sourceMapPath); | ||
var sourceMap = updateSourceMap(out[1], fileName); | ||
@@ -263,5 +271,5 @@ fs_1.writeFileSync(outputPath, output); | ||
} | ||
function updateOutput(outputText, fileName, sourceMapPath) { | ||
function updateOutput(outputText, fileName, extension, sourceMapPath) { | ||
var ext = path_1.extname(fileName); | ||
var originalPath = path_1.basename(fileName).slice(0, -ext.length) + '.js.map'; | ||
var originalPath = path_1.basename(fileName).slice(0, -ext.length) + (extension + ".map"); | ||
return outputText.slice(0, -originalPath.length) + sourceMapPath.replace(/\\/g, '/'); | ||
@@ -268,0 +276,0 @@ } |
@@ -130,3 +130,8 @@ "use strict"; | ||
describe('register', function () { | ||
index_1.register({ project: testDir }); | ||
index_1.register({ | ||
project: testDir, | ||
compilerOptions: { | ||
jsx: 'preserve' | ||
} | ||
}); | ||
it('should be able to require typescript', function () { | ||
@@ -158,4 +163,33 @@ var m = require('../tests/module'); | ||
}); | ||
describe('JSX preserve', function () { | ||
var old = require.extensions['.tsx']; | ||
var compiled; | ||
before(function () { | ||
var _this = this; | ||
require.extensions['.tsx'] = function (m, fileName) { | ||
var _compile = m._compile; | ||
m._compile = function (code, fileName) { | ||
compiled = code; | ||
return _compile.call(_this, code, fileName); | ||
}; | ||
return old(m, fileName); | ||
}; | ||
}); | ||
after(function () { | ||
require.extensions['.tsx'] = old; | ||
}); | ||
it('should use source maps', function (done) { | ||
try { | ||
require('../tests/with-jsx.tsx'); | ||
} | ||
catch (error) { | ||
chai_1.expect(error.stack).to.contain('SyntaxError: Unexpected token <\n'); | ||
chai_1.expect(compiled).to.not.contain('//# sourceMappingURL=w'); | ||
chai_1.expect(compiled).to.match(/\/\/# sourceMappingURL=.*\.jsx.map$/); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.spec.js.map |
{ | ||
"name": "ts-node", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"preferGlobal": true, | ||
@@ -5,0 +5,0 @@ "description": "TypeScript execution environment and REPL for node", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113189
914