UNPKG

1.27 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = babel6;
7
8var _astConverter = require("./astConverter");
9
10async function babel6(asset, options, babelOptions) {
11 let babel = await options.packageManager.require('babel-core', asset.filePath);
12 let config = babelOptions.config;
13 config.code = false;
14 config.ast = true;
15 config.filename = asset.filePath;
16 config.babelrc = false;
17 config.parserOpts = Object.assign({}, config.parserOpts, {
18 allowReturnOutsideFunction: true,
19 allowHashBang: true,
20 ecmaVersion: Infinity,
21 strictMode: false,
22 sourceType: 'module',
23 locations: true
24 }); // Passing a list of plugins as part of parserOpts seems to override any custom
25 // syntax plugins a user might have added (e.g. decorators). We add dynamicImport
26 // using a plugin instead.
27
28 config.plugins = (config.plugins || []).concat(dynamicImport);
29 let res = babel.transform((await asset.getCode()), config);
30
31 if (res.ast) {
32 return {
33 type: 'babel',
34 version: '7.0.0',
35 program: (0, _astConverter.babel6toBabel7)(res.ast)
36 };
37 }
38}
39
40function dynamicImport() {
41 return {
42 manipulateOptions(opts, parserOpts) {
43 parserOpts.plugins.push('dynamicImport');
44 }
45
46 };
47}
\No newline at end of file