Skip to content

Commit 7a86b31

Browse files
author
furina-lu
committed
feat: babel7 plugins use user options
1 parent 8888701 commit 7a86b31

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

website/src/parsers/js/babylon7.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const parserSettingsConfiguration = {
106106
}
107107
],
108108
};
109-
109+
export let parserOptions = []
110110
export default {
111111
...defaultParserInterface,
112112

@@ -140,6 +140,7 @@ export default {
140140
return plugin;
141141
}
142142
});
143+
parserOptions = options.plugins
143144
return babylon.parse(code, options);
144145
},
145146

website/src/parsers/js/transformers/babel7/index.js

+19-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import compileModule from '../../../utils/compileModule';
22
import pkg from 'babel7/package.json';
3-
43
const ID = 'babelv7';
54

5+
function checkForTypescript(data) {
6+
if (data.includes("typescript")) {
7+
return true;
8+
}
9+
for (let item of data) {
10+
if (Array.isArray(item)) {
11+
if (checkForTypescript(item)) {
12+
return true;
13+
}
14+
}
15+
}
16+
return false;
17+
}
618
export default {
719
id: ID,
820
displayName: ID,
@@ -14,46 +26,22 @@ export default {
1426
loadTransformer(callback) {
1527
require([
1628
'../../../transpilers/babel',
29+
'../../../transpilers/typescript',
1730
'babel7',
1831
'recast',
19-
], (transpile, babel, recast) => callback({ transpile: transpile.default, babel, recast }));
32+
'../../babylon7.js',
33+
], (transpile, transpileTs, babel, recast, babylon7) => callback({ transpile: transpile.default, transpileTs: transpileTs.default, babel, recast, babylon7 }));
2034
},
2135

22-
transform({ transpile, babel, recast }, transformCode, code) {
23-
transformCode = transpile(transformCode);
36+
transform({ transpile, transpileTs, babel, recast, babylon7 }, transformCode, code) {
37+
transformCode = checkForTypescript(babylon7.parserOptions) ? transpileTs(transformCode, babylon7.parserOptions) : transpile(transformCode, babylon7.parserOptions);
2438
let transform = compileModule( // eslint-disable-line no-shadow
2539
transformCode,
2640
);
27-
2841
return babel.transformAsync(code, {
2942
parserOpts: {
3043
parser: recast.parse,
31-
plugins: [
32-
'asyncGenerators',
33-
'bigInt',
34-
'classPrivateMethods',
35-
'classPrivateProperties',
36-
'classProperties',
37-
['decorators', {decoratorsBeforeExport: false}],
38-
'doExpressions',
39-
'dynamicImport',
40-
'exportDefaultFrom',
41-
'exportNamespaceFrom',
42-
'flow',
43-
'flowComments',
44-
'functionBind',
45-
'functionSent',
46-
'importMeta',
47-
'jsx',
48-
'logicalAssignment',
49-
'nullishCoalescingOperator',
50-
'numericSeparator',
51-
'objectRestSpread',
52-
'optionalCatchBinding',
53-
'optionalChaining',
54-
['pipelineOperator', {proposal: 'minimal'}],
55-
'throwExpressions',
56-
],
44+
plugins: babylon7.parserOptions,
5745
},
5846
retainLines: false,
5947
generatorOpts: {

0 commit comments

Comments
 (0)