Blame view

node_modules/babel-generator/lib/generators/base.js 1.29 KB
aaac7fed   liuqimichale   add
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
  "use strict";
  
  exports.__esModule = true;
  exports.File = File;
  exports.Program = Program;
  exports.BlockStatement = BlockStatement;
  exports.Noop = Noop;
  exports.Directive = Directive;
  
  var _types = require("./types");
  
  Object.defineProperty(exports, "DirectiveLiteral", {
    enumerable: true,
    get: function get() {
      return _types.StringLiteral;
    }
  });
  function File(node) {
    this.print(node.program, node);
  }
  
  function Program(node) {
    this.printInnerComments(node, false);
  
    this.printSequence(node.directives, node);
    if (node.directives && node.directives.length) this.newline();
  
    this.printSequence(node.body, node);
  }
  
  function BlockStatement(node) {
    this.token("{");
    this.printInnerComments(node);
  
    var hasDirectives = node.directives && node.directives.length;
  
    if (node.body.length || hasDirectives) {
      this.newline();
  
      this.printSequence(node.directives, node, { indent: true });
      if (hasDirectives) this.newline();
  
      this.printSequence(node.body, node, { indent: true });
      this.removeTrailingNewline();
  
      this.source("end", node.loc);
  
      if (!this.endsWith("\n")) this.newline();
  
      this.rightBrace();
    } else {
      this.source("end", node.loc);
      this.token("}");
    }
  }
  
  function Noop() {}
  
  function Directive(node) {
    this.print(node.value, node);
    this.semicolon();
  }