Projekt

Obecné

Profil

Stáhnout (2.4 KB) Statistiky
| Větev: | Revize:
1
"use strict";
2

    
3
exports.__esModule = true;
4
exports.FunctionDeclaration = undefined;
5
exports._params = _params;
6
exports._method = _method;
7
exports.FunctionExpression = FunctionExpression;
8
exports.ArrowFunctionExpression = ArrowFunctionExpression;
9

    
10
var _babelTypes = require("babel-types");
11

    
12
var t = _interopRequireWildcard(_babelTypes);
13

    
14
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
15

    
16
function _params(node) {
17
  var _this = this;
18

    
19
  this.print(node.typeParameters, node);
20
  this.token("(");
21
  this.printList(node.params, node, {
22
    iterator: function iterator(node) {
23
      if (node.optional) _this.token("?");
24
      _this.print(node.typeAnnotation, node);
25
    }
26
  });
27
  this.token(")");
28

    
29
  if (node.returnType) {
30
    this.print(node.returnType, node);
31
  }
32
}
33

    
34
function _method(node) {
35
  var kind = node.kind;
36
  var key = node.key;
37

    
38
  if (kind === "method" || kind === "init") {
39
    if (node.generator) {
40
      this.token("*");
41
    }
42
  }
43

    
44
  if (kind === "get" || kind === "set") {
45
    this.word(kind);
46
    this.space();
47
  }
48

    
49
  if (node.async) {
50
    this.word("async");
51
    this.space();
52
  }
53

    
54
  if (node.computed) {
55
    this.token("[");
56
    this.print(key, node);
57
    this.token("]");
58
  } else {
59
    this.print(key, node);
60
  }
61

    
62
  this._params(node);
63
  this.space();
64
  this.print(node.body, node);
65
}
66

    
67
function FunctionExpression(node) {
68
  if (node.async) {
69
    this.word("async");
70
    this.space();
71
  }
72
  this.word("function");
73
  if (node.generator) this.token("*");
74

    
75
  if (node.id) {
76
    this.space();
77
    this.print(node.id, node);
78
  } else {
79
    this.space();
80
  }
81

    
82
  this._params(node);
83
  this.space();
84
  this.print(node.body, node);
85
}
86

    
87
exports.FunctionDeclaration = FunctionExpression;
88
function ArrowFunctionExpression(node) {
89
  if (node.async) {
90
    this.word("async");
91
    this.space();
92
  }
93

    
94
  var firstParam = node.params[0];
95

    
96
  if (node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypes(node, firstParam)) {
97
    this.print(firstParam, node);
98
  } else {
99
    this._params(node);
100
  }
101

    
102
  this.space();
103
  this.token("=>");
104
  this.space();
105

    
106
  this.print(node.body, node);
107
}
108

    
109
function hasTypes(node, param) {
110
  return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments;
111
}
(6-6/10)