Skip to content
Permalink
Browse files

Update typescript package and jest preprocessor (#17839)

  • Loading branch information
necolas committed Jan 14, 2020
1 parent 50eafef commit 3bd6adceda6335adc5f5bbae148dd2ff290eeea6
Showing with 37 additions and 29 deletions.
  1. +1 −1 package.json
  2. +32 −24 scripts/jest/typescript/preprocessor.js
  3. +4 −4 yarn.lock
@@ -88,7 +88,7 @@
"targz": "^1.0.1",
"through2": "^2.0.0",
"tmp": "~0.0.28",
"typescript": "~1.8.10",
"typescript": "^3.7.4",
"webpack": "^4.41.2"
},
"devEngines": {
@@ -10,29 +10,46 @@ const tsOptions = {
};

function formatErrorMessage(error) {
return (
error.file.filename +
'(' +
error.file.getLineAndCharacterOfPosition(error.start).line +
'): ' +
error.messageText
);
if (error.file) {
const message = ts.flattenDiagnosticMessageText(error.messageText, '\n');
return (
error.file.fileName +
'(' +
error.file.getLineAndCharacterOfPosition(error.start).line +
'): ' +
message
);
} else {
return ts.flattenDiagnosticMessageText(error.messageText, '\n');
}
}

function compile(content, contentFilename) {
let output = null;
const compilerHost = {
fileExists(filename) {
return ts.sys.fileExists(filename);
},
getCanonicalFileName(filename) {
return filename;
},
getCurrentDirectory() {
return '';
},
getDefaultLibFileName: () => 'lib.d.ts',
getNewLine: () => ts.sys.newLine,
getSourceFile(filename, languageVersion) {
let source;
const libRegex = /lib\.(.+\.)?d\.ts$/;
const jestRegex = /jest\.d\.ts/;
const reactRegex = /(?:React|ReactDOM|PropTypes)(?:\.d)?\.ts$/;

// `path.normalize` is used to turn forward slashes in
// the file path into backslashes on Windows.
filename = path.normalize(filename);
if (filename === 'lib.d.ts') {
if (filename.match(libRegex)) {
source = fs
.readFileSync(require.resolve('typescript/lib/lib.d.ts'))
.readFileSync(require.resolve('typescript/lib/' + filename))
.toString();
} else if (filename.match(jestRegex)) {
source = fs.readFileSync(path.join(__dirname, 'jest.d.ts')).toString();
@@ -55,28 +72,19 @@ function compile(content, contentFilename) {
}
return ts.createSourceFile(filename, source, 'ES5', '0');
},
readFile(filename) {
return ts.sys.readFile(filename);
},
useCaseSensitiveFileNames() {
return ts.sys.useCaseSensitiveFileNames;
},
writeFile(name, text, writeByteOrderMark) {
if (output === null) {
output = text;
} else {
throw new Error('Expected only one dependency.');
}
},
getCanonicalFileName(filename) {
return filename;
},
getCurrentDirectory() {
return '';
},
getNewLine() {
return '\n';
},
fileExists(filename) {
return ts.sys.fileExists(filename);
},
useCaseSensitiveFileNames() {
return ts.sys.useCaseSensitiveFileNames;
},
};
const program = ts.createProgram(
['lib.d.ts', 'jest.d.ts', contentFilename],
@@ -12804,10 +12804,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@~1.8.10:
version "1.8.10"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-1.8.10.tgz#b475d6e0dff0bf50f296e5ca6ef9fbb5c7320f1e"
integrity sha1-tHXW4N/wv1DyluXKbvn7tccyDx4=
typescript@^3.7.4:
version "3.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==

ua-parser-js@^0.7.18, ua-parser-js@^0.7.9:
version "0.7.20"

0 comments on commit 3bd6adc

Please sign in to comment.
You can’t perform that action at this time.