forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel-parser.js
More file actions
64 lines (57 loc) · 1.44 KB
/
babel-parser.js
File metadata and controls
64 lines (57 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// @flow
const DEFAULT_BABEL_CONFIG = {
presets: ['es2015', 'react', 'stage-0'],
plugins: [
'transform-async-to-generator',
'transform-object-rest-spread',
'transform-decorators-legacy',
'transform-class-properties',
// Polyfills the runtime needed for async/await and generators
[
'transform-runtime',
{
helpers: false,
polyfill: false,
regenerator: true,
},
],
[
'transform-regenerator',
{
// Async functions are converted to generators by babel-preset-env
async: false,
},
],
],
};
/**
* Parses the .babelrc if it exists, if it doesn't it will return a default config
*/
export default function getBabelConfig(
config: Object | undefined,
loaderOptions: Object,
path: string,
isV7: boolean = false
) {
const resolvedConfig = config || DEFAULT_BABEL_CONFIG;
if (loaderOptions.disableCodeSandboxPlugins) {
return resolvedConfig;
}
const finalConfig = {
...resolvedConfig,
sourceMaps: 'inline',
sourceFileName: path,
filename: path,
};
const commonjsPluginName = isV7
? 'transform-modules-commonjs'
: 'transform-es2015-modules-commonjs';
if (finalConfig.plugins) {
if (finalConfig.plugins.indexOf(commonjsPluginName) === -1) {
finalConfig.plugins = [...finalConfig.plugins, commonjsPluginName];
}
} else {
finalConfig.plugins = [commonjsPluginName];
}
return finalConfig;
}