babel pipeline
Summary: adding babel transpile pipeline for TypeScript files Reviewed By: jknoxville Differential Revision: D16651124 fbshipit-source-id: e9215ba2da467f58005271916b65d6da4f6e36b7
This commit is contained in:
committed by
Facebook Github Bot
parent
262b1fd4a9
commit
80b2929992
@@ -12,6 +12,7 @@
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
|
||||
"@babel/plugin-transform-flow-strip-types": "^7.4.0",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.4.0",
|
||||
"@babel/plugin-transform-typescript": "^7.5.5",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"expand-tilde": "^2.0.2",
|
||||
"fix-path": "^2.1.0",
|
||||
|
||||
@@ -15,28 +15,40 @@ function transform({filename, options, src}) {
|
||||
const presets = [require('../node_modules/@babel/preset-react')];
|
||||
const isPlugin =
|
||||
options.projectRoot && !__dirname.startsWith(options.projectRoot);
|
||||
const isTypeScript = filename.endsWith('.tsx');
|
||||
|
||||
let ast = babylon.parse(src, {
|
||||
filename,
|
||||
plugins: [
|
||||
'jsx',
|
||||
['flow', {all: true}],
|
||||
'classProperties',
|
||||
'objectRestSpread',
|
||||
'optionalChaining',
|
||||
],
|
||||
plugins: isTypeScript
|
||||
? ['jsx', 'typescript', 'classProperties']
|
||||
: [
|
||||
'jsx',
|
||||
['flow', {all: true}],
|
||||
'classProperties',
|
||||
'objectRestSpread',
|
||||
'optionalChaining',
|
||||
],
|
||||
sourceType: 'module',
|
||||
});
|
||||
|
||||
// run babel
|
||||
const plugins = [
|
||||
require('../node_modules/@babel/plugin-transform-modules-commonjs'),
|
||||
require('../node_modules/@babel/plugin-proposal-object-rest-spread'),
|
||||
require('../node_modules/@babel/plugin-proposal-class-properties'),
|
||||
require('../node_modules/@babel/plugin-transform-flow-strip-types'),
|
||||
require('../node_modules/@babel/plugin-proposal-optional-chaining'),
|
||||
require('./dynamic-requires.js'),
|
||||
];
|
||||
const plugins = [];
|
||||
|
||||
if (!isTypeScript) {
|
||||
plugins.push(
|
||||
require('../node_modules/@babel/plugin-transform-modules-commonjs'),
|
||||
require('../node_modules/@babel/plugin-proposal-object-rest-spread'),
|
||||
require('../node_modules/@babel/plugin-proposal-class-properties'),
|
||||
require('../node_modules/@babel/plugin-transform-flow-strip-types'),
|
||||
require('../node_modules/@babel/plugin-proposal-optional-chaining'),
|
||||
require('./dynamic-requires.js'),
|
||||
);
|
||||
} else {
|
||||
plugins.push(
|
||||
require('../node_modules/@babel/plugin-transform-typescript'),
|
||||
require('../node_modules/@babel/plugin-transform-modules-commonjs'),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
fs.existsSync(
|
||||
|
||||
@@ -587,7 +587,7 @@
|
||||
"@babel/helper-annotate-as-pure" "^7.0.0"
|
||||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
|
||||
"@babel/plugin-transform-typescript@^7.0.0":
|
||||
"@babel/plugin-transform-typescript@^7.0.0", "@babel/plugin-transform-typescript@^7.5.5":
|
||||
version "7.5.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.5.5.tgz#6d862766f09b2da1cb1f7d505fe2aedab6b7d4b8"
|
||||
integrity sha512-pehKf4m640myZu5B2ZviLaiBlxMCjSZ1qTEO459AXKX5GnPueyulJeCqZFs1nz/Ya2dDzXQ1NxZ/kKNWyD4h6w==
|
||||
|
||||
Reference in New Issue
Block a user