Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: babel7 plugins use user options #723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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