1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = parser;
|
---|
7 | function _parser() {
|
---|
8 | const data = require("@babel/parser");
|
---|
9 | _parser = function () {
|
---|
10 | return data;
|
---|
11 | };
|
---|
12 | return data;
|
---|
13 | }
|
---|
14 | function _codeFrame() {
|
---|
15 | const data = require("@babel/code-frame");
|
---|
16 | _codeFrame = function () {
|
---|
17 | return data;
|
---|
18 | };
|
---|
19 | return data;
|
---|
20 | }
|
---|
21 | var _missingPluginHelper = require("./util/missing-plugin-helper.js");
|
---|
22 | function* parser(pluginPasses, {
|
---|
23 | parserOpts,
|
---|
24 | highlightCode = true,
|
---|
25 | filename = "unknown"
|
---|
26 | }, code) {
|
---|
27 | try {
|
---|
28 | const results = [];
|
---|
29 | for (const plugins of pluginPasses) {
|
---|
30 | for (const plugin of plugins) {
|
---|
31 | const {
|
---|
32 | parserOverride
|
---|
33 | } = plugin;
|
---|
34 | if (parserOverride) {
|
---|
35 | const ast = parserOverride(code, parserOpts, _parser().parse);
|
---|
36 | if (ast !== undefined) results.push(ast);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 | if (results.length === 0) {
|
---|
41 | return (0, _parser().parse)(code, parserOpts);
|
---|
42 | } else if (results.length === 1) {
|
---|
43 | yield* [];
|
---|
44 | if (typeof results[0].then === "function") {
|
---|
45 | throw new Error(`You appear to be using an async parser plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
|
---|
46 | }
|
---|
47 | return results[0];
|
---|
48 | }
|
---|
49 | throw new Error("More than one plugin attempted to override parsing.");
|
---|
50 | } catch (err) {
|
---|
51 | if (err.code === "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED") {
|
---|
52 | err.message += "\nConsider renaming the file to '.mjs', or setting sourceType:module " + "or sourceType:unambiguous in your Babel config for this file.";
|
---|
53 | }
|
---|
54 | const {
|
---|
55 | loc,
|
---|
56 | missingPlugin
|
---|
57 | } = err;
|
---|
58 | if (loc) {
|
---|
59 | const codeFrame = (0, _codeFrame().codeFrameColumns)(code, {
|
---|
60 | start: {
|
---|
61 | line: loc.line,
|
---|
62 | column: loc.column + 1
|
---|
63 | }
|
---|
64 | }, {
|
---|
65 | highlightCode
|
---|
66 | });
|
---|
67 | if (missingPlugin) {
|
---|
68 | err.message = `${filename}: ` + (0, _missingPluginHelper.default)(missingPlugin[0], loc, codeFrame, filename);
|
---|
69 | } else {
|
---|
70 | err.message = `${filename}: ${err.message}\n\n` + codeFrame;
|
---|
71 | }
|
---|
72 | err.code = "BABEL_PARSE_ERROR";
|
---|
73 | }
|
---|
74 | throw err;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | 0 && 0;
|
---|
78 |
|
---|
79 | //# sourceMappingURL=index.js.map
|
---|