From bccb41e3db7a10be5c267d67403c1d381b81a234 Mon Sep 17 00:00:00 2001 From: furina-lu Date: Thu, 10 Oct 2024 12:31:00 +0800 Subject: [PATCH] feat: babel7 plugins use user options --- website/src/parsers/js/babylon7.js | 3 +- .../parsers/js/transformers/babel7/index.js | 34 +++---------------- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/website/src/parsers/js/babylon7.js b/website/src/parsers/js/babylon7.js index 6648a1e4..3d62316e 100644 --- a/website/src/parsers/js/babylon7.js +++ b/website/src/parsers/js/babylon7.js @@ -106,7 +106,7 @@ export const parserSettingsConfiguration = { } ], }; - +export let parserOptions = [] export default { ...defaultParserInterface, @@ -140,6 +140,7 @@ export default { return plugin; } }); + parserOptions = options.plugins return babylon.parse(code, options); }, diff --git a/website/src/parsers/js/transformers/babel7/index.js b/website/src/parsers/js/transformers/babel7/index.js index 8e68f1d2..84ff4a08 100644 --- a/website/src/parsers/js/transformers/babel7/index.js +++ b/website/src/parsers/js/transformers/babel7/index.js @@ -1,6 +1,5 @@ import compileModule from '../../../utils/compileModule'; import pkg from 'babel7/package.json'; - const ID = 'babelv7'; export default { @@ -16,44 +15,19 @@ export default { '../../../transpilers/babel', 'babel7', 'recast', - ], (transpile, babel, recast) => callback({ transpile: transpile.default, babel, recast })); + '../../babylon7.js', + ], (transpile, babel, recast, babylon7) => callback({ transpile: transpile.default, babel, recast, babylon7 })); }, - transform({ transpile, babel, recast }, transformCode, code) { + transform({ transpile, babel, recast, babylon7 }, transformCode, code) { transformCode = transpile(transformCode); let transform = compileModule( // eslint-disable-line no-shadow transformCode, ); - return babel.transformAsync(code, { parserOpts: { parser: recast.parse, - plugins: [ - 'asyncGenerators', - 'bigInt', - 'classPrivateMethods', - 'classPrivateProperties', - 'classProperties', - ['decorators', {decoratorsBeforeExport: false}], - 'doExpressions', - 'dynamicImport', - 'exportDefaultFrom', - 'exportNamespaceFrom', - 'flow', - 'flowComments', - 'functionBind', - 'functionSent', - 'importMeta', - 'jsx', - 'logicalAssignment', - 'nullishCoalescingOperator', - 'numericSeparator', - 'objectRestSpread', - 'optionalCatchBinding', - 'optionalChaining', - ['pipelineOperator', {proposal: 'minimal'}], - 'throwExpressions', - ], + plugins: babylon7.parserOptions, }, retainLines: false, generatorOpts: {