Skip to content

Commit

Permalink
update typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
chicoxyzzy authored and aaronabramov committed May 20, 2016
1 parent eda08d9 commit 655ac0f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"run-sequence": "^1.1.4",
"through2": "^2.0.0",
"tmp": "~0.0.28",
"typescript": "~1.4.0",
"typescript": "~1.8.10",
"uglify-js": "^2.5.0",
"uglifyify": "^3.0.1"
},
Expand Down
33 changes: 19 additions & 14 deletions scripts/jest/ts-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ var fs = require('fs');
var path = require('path');
var ts = require('typescript');

var tsOptions = {module: 'commonjs'};
var tsOptions = {
module: ts.ModuleKind.CommonJS,
jsx: ts.JsxEmit.React,
};

function formatErrorMessage(error) {
return (
error.file.filename + '(' +
error.file.getLineAndCharacterFromPosition(error.start).line +
error.file.getLineAndCharacterOfPosition(error.start).line +
'): ' +
error.messageText
);
Expand All @@ -18,7 +21,7 @@ function formatErrorMessage(error) {
function compile(content, contentFilename) {
var output = null;
var compilerHost = {
getSourceFile: function(filename, languageVersion) {
getSourceFile(filename, languageVersion) {
var source;

// `path.normalize` and `path.join` are used to turn forward slashes in
Expand All @@ -30,7 +33,7 @@ function compile(content, contentFilename) {

if (filename === 'lib.d.ts') {
source = fs.readFileSync(
require.resolve('typescript/bin/lib.d.ts')
require.resolve('typescript/lib/lib.d.ts')
).toString();
} else if (filename === 'jest.d.ts') {
source = fs.readFileSync(
Expand All @@ -55,34 +58,36 @@ function compile(content, contentFilename) {
}
return ts.createSourceFile(filename, source, 'ES5', '0');
},
writeFile: function(name, text, writeByteOrderMark) {
writeFile(name, text, writeByteOrderMark) {
if (output === null) {
output = text;
} else {
throw new Error('Expected only one dependency.');
}
},
getCanonicalFileName: function(filename) {
getCanonicalFileName(filename) {
return filename;
},
getCurrentDirectory: function() {
getCurrentDirectory() {
return '';
},
getNewLine: function() {
getNewLine() {
return '\n';
},
fileExists(filename) {
return ts.sys.fileExists(filename);
},
useCaseSensitiveFileNames() {
return ts.sys.useCaseSensitiveFileNames;
},
};
var program = ts.createProgram([
'lib.d.ts',
'jest.d.ts',
contentFilename,
], tsOptions, compilerHost);
var errors = program.getDiagnostics();
if (!errors.length) {
var checker = program.getTypeChecker(true);
errors = checker.getDiagnostics();
checker.emitFiles();
}
var emitResult = program.emit();
var errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
if (errors.length) {
throw new Error(errors.map(formatErrorMessage).join('\n'));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// <reference path="../React.d.ts" />
/// <reference path="../ReactDOM.d.ts" />

/*!
* Copyright 2015-present, Facebook, Inc.
* All rights reserved.
Expand Down

0 comments on commit 655ac0f

Please sign in to comment.