github-pages-deploy-action/node_modules/@babel/core/lib/parse.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-31 20:42:07 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
2020-03-31 20:57:48 +08:00
exports.parseSync = parseSync;
exports.parseAsync = parseAsync;
exports.parse = void 0;
2020-03-31 20:42:07 +08:00
var _config = _interopRequireDefault(require("./config"));
2020-03-31 20:57:48 +08:00
var _normalizeFile = _interopRequireDefault(require("./transformation/normalize-file"));
2020-03-31 20:42:07 +08:00
var _normalizeOpts = _interopRequireDefault(require("./transformation/normalize-opts"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2020-03-31 20:57:48 +08:00
const parse = function parse(code, opts, callback) {
if (typeof opts === "function") {
callback = opts;
opts = undefined;
}
if (callback === undefined) return parseSync(code, opts);
const config = (0, _config.default)(opts);
2020-03-31 20:42:07 +08:00
if (config === null) {
return null;
}
2020-03-31 20:57:48 +08:00
const cb = callback;
process.nextTick(() => {
let ast = null;
2020-03-31 20:42:07 +08:00
2020-03-31 20:57:48 +08:00
try {
const cfg = (0, _config.default)(opts);
if (cfg === null) return cb(null, null);
ast = (0, _normalizeFile.default)(cfg.passes, (0, _normalizeOpts.default)(cfg), code).ast;
} catch (err) {
return cb(err);
}
2020-03-31 20:42:07 +08:00
2020-03-31 20:57:48 +08:00
cb(null, ast);
});
2020-03-31 20:42:07 +08:00
};
exports.parse = parse;
2020-03-31 20:57:48 +08:00
function parseSync(code, opts) {
const config = (0, _config.default)(opts);
if (config === null) {
return null;
}
return (0, _normalizeFile.default)(config.passes, (0, _normalizeOpts.default)(config), code).ast;
}
function parseAsync(code, opts) {
return new Promise((res, rej) => {
parse(code, opts, (err, result) => {
if (err == null) res(result);else rej(err);
});
});
}