Skip to content

Commit

Permalink
feat: babel7 plugins use user options
Browse files Browse the repository at this point in the history
  • Loading branch information
furina-lu committed Oct 17, 2024
1 parent 8888701 commit 7a86b31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
3 changes: 2 additions & 1 deletion website/src/parsers/js/babylon7.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const parserSettingsConfiguration = {
}
],
};

export let parserOptions = []
export default {
...defaultParserInterface,

Expand Down Expand Up @@ -140,6 +140,7 @@ export default {
return plugin;
}
});
parserOptions = options.plugins
return babylon.parse(code, options);
},

Expand Down
50 changes: 19 additions & 31 deletions website/src/parsers/js/transformers/babel7/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import compileModule from '../../../utils/compileModule';
import pkg from 'babel7/package.json';

const ID = 'babelv7';

function checkForTypescript(data) {
if (data.includes("typescript")) {
return true;
}
for (let item of data) {
if (Array.isArray(item)) {
if (checkForTypescript(item)) {
return true;
}
}
}
return false;
}
export default {
id: ID,
displayName: ID,
Expand All @@ -14,46 +26,22 @@ export default {
loadTransformer(callback) {
require([
'../../../transpilers/babel',
'../../../transpilers/typescript',
'babel7',
'recast',
], (transpile, babel, recast) => callback({ transpile: transpile.default, babel, recast }));
'../../babylon7.js',
], (transpile, transpileTs, babel, recast, babylon7) => callback({ transpile: transpile.default, transpileTs: transpileTs.default, babel, recast, babylon7 }));
},

transform({ transpile, babel, recast }, transformCode, code) {
transformCode = transpile(transformCode);
transform({ transpile, transpileTs, babel, recast, babylon7 }, transformCode, code) {
transformCode = checkForTypescript(babylon7.parserOptions) ? transpileTs(transformCode, babylon7.parserOptions) : transpile(transformCode, babylon7.parserOptions);
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: {
Expand Down

0 comments on commit 7a86b31

Please sign in to comment.