| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|---|
| 4 | function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|---|
| 5 | const babel = require("./babel-core.cjs");
|
|---|
| 6 | const convert = require("../convert/index.cjs");
|
|---|
| 7 | const astInfo = require("./ast-info.cjs");
|
|---|
| 8 | const extractParserOptionsPlugin = require("./extract-parser-options-plugin.cjs");
|
|---|
| 9 | const {
|
|---|
| 10 | getVisitorKeys,
|
|---|
| 11 | getTokLabels
|
|---|
| 12 | } = astInfo;
|
|---|
| 13 | const ref = {};
|
|---|
| 14 | let extractParserOptionsConfigItem;
|
|---|
| 15 | const MULTIPLE_OVERRIDES = /More than one plugin attempted to override parsing/;
|
|---|
| 16 | module.exports = function () {
|
|---|
| 17 | var _asyncMaybeParse = _asyncToGenerator(function* (code, options) {
|
|---|
| 18 | if (!extractParserOptionsConfigItem) {
|
|---|
| 19 | extractParserOptionsConfigItem = yield babel.createConfigItemAsync([extractParserOptionsPlugin, ref], {
|
|---|
| 20 | dirname: __dirname,
|
|---|
| 21 | type: "plugin"
|
|---|
| 22 | });
|
|---|
| 23 | }
|
|---|
| 24 | const {
|
|---|
| 25 | plugins
|
|---|
| 26 | } = options;
|
|---|
| 27 | options.plugins = plugins.concat(extractParserOptionsConfigItem);
|
|---|
| 28 | let ast;
|
|---|
| 29 | try {
|
|---|
| 30 | return {
|
|---|
| 31 | parserOptions: yield babel.parseAsync(code, options),
|
|---|
| 32 | ast: null
|
|---|
| 33 | };
|
|---|
| 34 | } catch (err) {
|
|---|
| 35 | if (!MULTIPLE_OVERRIDES.test(err.message)) {
|
|---|
| 36 | throw err;
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | options.plugins = plugins;
|
|---|
| 40 | try {
|
|---|
| 41 | ast = yield babel.parseAsync(code, options);
|
|---|
| 42 | } catch (err) {
|
|---|
| 43 | throw convert.convertError(err);
|
|---|
| 44 | }
|
|---|
| 45 | return {
|
|---|
| 46 | ast: convert.convertFile(ast, code, getTokLabels(), getVisitorKeys()),
|
|---|
| 47 | parserOptions: null
|
|---|
| 48 | };
|
|---|
| 49 | });
|
|---|
| 50 | function asyncMaybeParse(_x, _x2) {
|
|---|
| 51 | return _asyncMaybeParse.apply(this, arguments);
|
|---|
| 52 | }
|
|---|
| 53 | return asyncMaybeParse;
|
|---|
| 54 | }();
|
|---|
| 55 |
|
|---|
| 56 | //# sourceMappingURL=maybeParse.cjs.map
|
|---|