Blame view

node_modules/@babel/generator/lib/index.js 2.85 KB
ce4c83ff   wxy   初始提交
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  "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 }; }
  
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  
  var Generator = function (_Printer) {
    _inheritsLoose(Generator, _Printer);
  
    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;
    }
  
    var _proto = Generator.prototype;
  
    _proto.generate = function generate() {
      return _Printer.prototype.generate.call(this, this.ast);
    };
  
    return Generator;
  }(_printer.default);
  
  function normalizeOptions(code, opts) {
    var format = {
      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
      }
    };
  
    if (format.minified) {
      format.compact = true;
  
      format.shouldPrintComment = format.shouldPrintComment || function () {
        return format.comments;
      };
    } else {
      format.shouldPrintComment = format.shouldPrintComment || function (value) {
        return format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0;
      };
    }
  
    if (format.compact === "auto") {
      format.compact = code.length > 500000;
  
      if (format.compact) {
        console.error("[BABEL] Note: The code generator has deoptimised the styling of " + (opts.filename + " as it exceeds the max of " + "500KB" + "."));
      }
    }
  
    if (format.compact) {
      format.indent.adjustMultilineComment = false;
    }
  
    return format;
  }
  
  var CodeGenerator = function () {
    function CodeGenerator(ast, opts, code) {
      this._generator = new Generator(ast, opts, code);
    }
  
    var _proto2 = CodeGenerator.prototype;
  
    _proto2.generate = function generate() {
      return this._generator.generate();
    };
  
    return CodeGenerator;
  }();
  
  exports.CodeGenerator = CodeGenerator;
  
  function _default(ast, opts, code) {
    var gen = new Generator(ast, opts, code);
    return gen.generate();
  }