Files
react/jest/preprocessor.js
T
Sebastian Markbage f6fd4a8506 Use TypeScript Compiler API Directly
In 1.4.0 we can use the TypeScript API directly to preprocess our files.
This lets us get rid of a dependency.

https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

We can also use this to provide our default libraries so that we don't
need to keep the references in the test file.
2015-02-01 22:41:00 -08:00

26 lines
611 B
JavaScript

"use strict";
var ReactTools = require('../main.js');
var coffee = require('coffee-script');
var tsPreprocessor = require('./ts-preprocessor');
var defaultLibraries = [
require.resolve('./jest.d.ts'),
require.resolve('../src/modern/class/React.d.ts')
];
var ts = tsPreprocessor(defaultLibraries);
module.exports = {
process: function(src, path) {
if (path.match(/\.coffee$/)) {
return coffee.compile(src, {'bare': true});
}
if (path.match(/\.ts$/) && !path.match(/\.d\.ts$/)) {
return ts.compile(src, path);
}
return ReactTools.transform(src, {harmony: true});
}
};