Skip to content

Commit

Permalink
feat: use custom bablyon parser config for tsx/jsx (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
vagusX authored Feb 5, 2020
1 parent a8b4b82 commit 16e42af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
11 changes: 3 additions & 8 deletions bin/babylon.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"startLine": 1,
"tokens": true,
"plugins": [
[
"flow",
{
"all": true
}
],
"flowComments",
"jsx",
"asyncGenerators",
"bigInt",
Expand All @@ -27,6 +20,7 @@
"doExpressions",
"dynamicImport",
"exportDefaultFrom",
"exportExtensions",
"exportNamespaceFrom",
"functionBind",
"functionSent",
Expand All @@ -43,6 +37,7 @@
"proposal": "minimal"
}
],
"throwExpressions"
"throwExpressions",
"typescript"
]
}
25 changes: 6 additions & 19 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 16e42af

Please sign in to comment.