From eae7a0186f8168155a8e8ee8302e6cc1b42d73c9 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Tue, 5 Jan 2016 20:49:54 -0800 Subject: [PATCH] Update to use latest version of typescript This updates the jest preprocessor to work with the new typescript compiler, allowing us to support the newer typescript features like "this' return types. The new typescript version found a legitimate error in a test file, which is also fixed in this rev --- __tests__/zip.ts | 2 +- package.json | 2 +- resources/jestPreprocessor.js | 37 ++++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/__tests__/zip.ts b/__tests__/zip.ts index 5fd63135b2..60e4fdeb68 100644 --- a/__tests__/zip.ts +++ b/__tests__/zip.ts @@ -58,7 +58,7 @@ describe('zip', () => { it('can zip to create immutable collections', () => { expect( I.Seq.of(1,2,3).zipWith( - () => I.List(arguments), + function () { return I.List(arguments); }, I.Seq.of(4,5,6), I.Seq.of(7,8,9) ).toJS() diff --git a/package.json b/package.json index 58a2da188f..c8ab0b8115 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "rollup": "0.24.0", "run-sequence": "1.1.5", "through2": "2.0.0", - "typescript": "~1.4.1", + "typescript": "1.7.5", "uglify-js": "2.6.1", "vinyl-buffer": "1.0.0", "vinyl-source-stream": "1.1.0" diff --git a/resources/jestPreprocessor.js b/resources/jestPreprocessor.js index ed12979150..6167492445 100644 --- a/resources/jestPreprocessor.js +++ b/resources/jestPreprocessor.js @@ -34,22 +34,31 @@ function compileTypeScript(filePath) { var host = typescript.createCompilerHost(options); var program = typescript.createProgram([filePath], options, host); - var checker = typescript.createTypeChecker(program, /*fullTypeCheck*/ true); - var result = checker.emitFiles(); - - program.getDiagnostics() - .concat(checker.getDiagnostics()) - .concat(result.diagnostics) - .forEach(function(diagnostic) { - var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); - console.error('%s %d:%d %s', diagnostic.file.filename, lineChar.line, lineChar.character, diagnostic.messageText); - }); - - if (result.emitResultStatus !== typescript.EmitReturnStatus.Succeeded) { - throw new Error('Compiling ' + filePath + ' failed'); + + var diagnostics = program.getSyntacticDiagnostics(); + + if (diagnostics.length === 0) { + diagnostics = program.getGlobalDiagnostics(); + } + + if (diagnostics.length === 0) { + diagnostics = program.getSemanticDiagnostics(); + } + + if (diagnostics.length === 0) { + var emitOutput = program.emit(); + diagnostics = emitOutput.diagnostics; + } + + if (diagnostics.length === 0) { + return fs.readFileSync(outputPath, {encoding: 'utf8'}); } - return fs.readFileSync(outputPath, {encoding: 'utf8'}); + diagnostics.forEach(function(diagnostic) { + var loc = typescript.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + console.error('%s %d:%d %s', diagnostic.file.fileName, loc.line, loc.character, diagnostic.messageText); + }); + throw new Error('Compiling ' + filePath + ' failed'); } function withLocalImmutable(filePath, jsSrc) {