From 16e42af9f665b0888064f92df02cc20772219abb Mon Sep 17 00:00:00 2001 From: vagusX Date: Wed, 5 Feb 2020 17:08:53 +0800 Subject: [PATCH] feat: use custom bablyon parser config for tsx/jsx (#57) --- bin/babylon.config.json | 11 +++-------- bin/cli.js | 25 ++++++------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/bin/babylon.config.json b/bin/babylon.config.json index 05a4329..c375f01 100644 --- a/bin/babylon.config.json +++ b/bin/babylon.config.json @@ -5,13 +5,6 @@ "startLine": 1, "tokens": true, "plugins": [ - [ - "flow", - { - "all": true - } - ], - "flowComments", "jsx", "asyncGenerators", "bigInt", @@ -27,6 +20,7 @@ "doExpressions", "dynamicImport", "exportDefaultFrom", + "exportExtensions", "exportNamespaceFrom", "functionBind", "functionSent", @@ -43,6 +37,7 @@ "proposal": "minimal" } ], - "throwExpressions" + "throwExpressions", + "typescript" ] } diff --git a/bin/cli.js b/bin/cli.js index eeaf8d7..64080dc 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -77,12 +77,8 @@ function getRunnerArgs( args.push('--parser', parser); - if (parser === 'tsx') { - args.push('--extensions=tsx,ts,jsx,js'); - } else { - args.push('--parser-config', babylonConfig); - args.push('--extensions=jsx,js'); - } + args.push('--parser-config', babylonConfig); + args.push('--extensions=tsx,ts,jsx,js'); args.push('--transform', transformerPath); @@ -109,20 +105,11 @@ async function run(filePath, args = {}) { // eslint-disable-next-line no-restricted-syntax for (const transformer of transformers.concat(extraScripts)) { - if (jsPaths.length) { - console.log( - chalk.bgYellow.bold('JS/JSX files to convert'), - jsPaths.length, - ); - // eslint-disable-next-line no-await-in-loop - await transform(transformer, 'babylon', filePath, args); - } + console.log(chalk.bgYellow.bold('JS/JSX files to convert'), jsPaths.length); + console.log(chalk.bgBlue.bold('TS/TSX files to convert'), tsPaths.length); - if (tsPaths.length) { - console.log(chalk.bgBlue.bold('TS/TSX files to convert'), tsPaths.length); - // eslint-disable-next-line no-await-in-loop - await transform(transformer, 'tsx', filePath, args); - } + // eslint-disable-next-line no-await-in-loop + await transform(transformer, 'babylon', filePath, args); } }