Spaces:
Sleeping
Sleeping
File size: 1,279 Bytes
cc651f6 |
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 |
"use strict";
const babel = require("./babel-core.cjs");
const convert = require("../convert/index.cjs");
const astInfo = require("./ast-info.cjs");
const extractParserOptionsPlugin = require("./extract-parser-options-plugin.cjs");
const {
getVisitorKeys,
getTokLabels
} = astInfo;
const ref = {};
let extractParserOptionsConfigItem;
const MULTIPLE_OVERRIDES = /More than one plugin attempted to override parsing/;
module.exports = function maybeParse(code, options) {
if (!extractParserOptionsConfigItem) {
extractParserOptionsConfigItem = babel.createConfigItemSync([extractParserOptionsPlugin, ref], {
dirname: __dirname,
type: "plugin"
});
}
const {
plugins
} = options;
options.plugins = plugins.concat(extractParserOptionsConfigItem);
let ast;
try {
return {
parserOptions: babel.parseSync(code, options),
ast: null
};
} catch (err) {
if (!MULTIPLE_OVERRIDES.test(err.message)) {
throw err;
}
}
options.plugins = plugins;
try {
ast = babel.parseSync(code, options);
} catch (err) {
throw convert.convertError(err);
}
return {
ast: convert.convertFile(ast, code, getTokLabels(), getVisitorKeys()),
parserOptions: null
};
};
//# sourceMappingURL=maybeParse.cjs.map
|