1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/generator/lib/index.js

108 lines
2.8 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
exports.CodeGenerator = void 0;
var _sourceMap = _interopRequireDefault(require("./source-map"));
var _printer = _interopRequireDefault(require("./printer"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2024-01-16 21:26:16 +08:00
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var Generator = function (_Printer) {
_inheritsLoose(Generator, _Printer);
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
function Generator(ast, opts, code) {
var _this;
if (opts === void 0) {
opts = {};
}
var format = normalizeOptions(code, opts);
var map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null;
_this = _Printer.call(this, format, map) || this;
_this.ast = ast;
return _this;
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
var _proto = Generator.prototype;
_proto.generate = function generate() {
return _Printer.prototype.generate.call(this, this.ast);
};
return Generator;
}(_printer.default);
2023-12-18 13:12:25 +08:00
function normalizeOptions(code, opts) {
2024-01-16 21:26:16 +08:00
var format = {
2023-12-18 13:12:25 +08:00
auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
shouldPrintComment: opts.shouldPrintComment,
retainLines: opts.retainLines,
retainFunctionParens: opts.retainFunctionParens,
comments: opts.comments == null || opts.comments,
compact: opts.compact,
minified: opts.minified,
concise: opts.concise,
jsonCompatibleStrings: opts.jsonCompatibleStrings,
indent: {
adjustMultilineComment: true,
style: " ",
base: 0
2024-01-16 21:26:16 +08:00
}
2023-12-18 13:12:25 +08:00
};
if (format.minified) {
format.compact = true;
2024-01-16 21:26:16 +08:00
format.shouldPrintComment = format.shouldPrintComment || function () {
return format.comments;
};
2023-12-18 13:12:25 +08:00
} else {
2024-01-16 21:26:16 +08:00
format.shouldPrintComment = format.shouldPrintComment || function (value) {
return format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0;
};
2023-12-18 13:12:25 +08:00
}
if (format.compact === "auto") {
format.compact = code.length > 500000;
if (format.compact) {
2024-01-16 21:26:16 +08:00
console.error("[BABEL] Note: The code generator has deoptimised the styling of " + (opts.filename + " as it exceeds the max of " + "500KB" + "."));
2023-12-18 13:12:25 +08:00
}
}
if (format.compact) {
format.indent.adjustMultilineComment = false;
}
return format;
}
2024-01-16 21:26:16 +08:00
var CodeGenerator = function () {
function CodeGenerator(ast, opts, code) {
2023-12-18 13:12:25 +08:00
this._generator = new Generator(ast, opts, code);
}
2024-01-16 21:26:16 +08:00
var _proto2 = CodeGenerator.prototype;
_proto2.generate = function generate() {
2023-12-18 13:12:25 +08:00
return this._generator.generate();
2024-01-16 21:26:16 +08:00
};
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
return CodeGenerator;
}();
2023-12-18 13:12:25 +08:00
exports.CodeGenerator = CodeGenerator;
function _default(ast, opts, code) {
2024-01-16 21:26:16 +08:00
var gen = new Generator(ast, opts, code);
2023-12-18 13:12:25 +08:00
return gen.generate();
}