web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.5 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = generate;
  6. exports.CodeGenerator = void 0;
  7. var _sourceMap = _interopRequireDefault(require("./source-map"));
  8. var _printer = _interopRequireDefault(require("./printer"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. class Generator extends _printer.default {
  11. constructor(ast, opts = {}, code) {
  12. const format = normalizeOptions(code, opts);
  13. const map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null;
  14. super(format, map);
  15. this.ast = void 0;
  16. this.ast = ast;
  17. }
  18. generate() {
  19. return super.generate(this.ast);
  20. }
  21. }
  22. function normalizeOptions(code, opts) {
  23. const format = {
  24. auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
  25. auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
  26. shouldPrintComment: opts.shouldPrintComment,
  27. retainLines: opts.retainLines,
  28. retainFunctionParens: opts.retainFunctionParens,
  29. comments: opts.comments == null || opts.comments,
  30. compact: opts.compact,
  31. minified: opts.minified,
  32. concise: opts.concise,
  33. indent: {
  34. adjustMultilineComment: true,
  35. style: " ",
  36. base: 0
  37. },
  38. decoratorsBeforeExport: !!opts.decoratorsBeforeExport,
  39. jsescOption: Object.assign({
  40. quotes: "double",
  41. wrap: true,
  42. minimal: false
  43. }, opts.jsescOption),
  44. recordAndTupleSyntaxType: opts.recordAndTupleSyntaxType
  45. };
  46. {
  47. format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
  48. }
  49. if (format.minified) {
  50. format.compact = true;
  51. format.shouldPrintComment = format.shouldPrintComment || (() => format.comments);
  52. } else {
  53. format.shouldPrintComment = format.shouldPrintComment || (value => format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0);
  54. }
  55. if (format.compact === "auto") {
  56. format.compact = code.length > 500000;
  57. if (format.compact) {
  58. console.error("[BABEL] Note: The code generator has deoptimised the styling of " + `${opts.filename} as it exceeds the max of ${"500KB"}.`);
  59. }
  60. }
  61. if (format.compact) {
  62. format.indent.adjustMultilineComment = false;
  63. }
  64. return format;
  65. }
  66. class CodeGenerator {
  67. constructor(ast, opts, code) {
  68. this._generator = void 0;
  69. this._generator = new Generator(ast, opts, code);
  70. }
  71. generate() {
  72. return this._generator.generate();
  73. }
  74. }
  75. exports.CodeGenerator = CodeGenerator;
  76. function generate(ast, opts, code) {
  77. const gen = new Generator(ast, opts, code);
  78. return gen.generate();
  79. }