Projekt

Obecné

Profil

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

    
3
exports.__esModule = true;
4
exports.ImportDeclaration = exports.ModuleDeclaration = undefined;
5

    
6
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
7

    
8
var _getIterator3 = _interopRequireDefault(_getIterator2);
9

    
10
exports.ExportDeclaration = ExportDeclaration;
11
exports.Scope = Scope;
12

    
13
var _babelTypes = require("babel-types");
14

    
15
var t = _interopRequireWildcard(_babelTypes);
16

    
17
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; } }
18

    
19
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20

    
21
var ModuleDeclaration = exports.ModuleDeclaration = {
22
  enter: function enter(path, file) {
23
    var node = path.node;
24

    
25
    if (node.source) {
26
      node.source.value = file.resolveModuleSource(node.source.value);
27
    }
28
  }
29
};
30

    
31
var ImportDeclaration = exports.ImportDeclaration = {
32
  exit: function exit(path, file) {
33
    var node = path.node;
34

    
35

    
36
    var specifiers = [];
37
    var imported = [];
38
    file.metadata.modules.imports.push({
39
      source: node.source.value,
40
      imported: imported,
41
      specifiers: specifiers
42
    });
43

    
44
    for (var _iterator = path.get("specifiers"), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
45
      var _ref;
46

    
47
      if (_isArray) {
48
        if (_i >= _iterator.length) break;
49
        _ref = _iterator[_i++];
50
      } else {
51
        _i = _iterator.next();
52
        if (_i.done) break;
53
        _ref = _i.value;
54
      }
55

    
56
      var specifier = _ref;
57

    
58
      var local = specifier.node.local.name;
59

    
60
      if (specifier.isImportDefaultSpecifier()) {
61
        imported.push("default");
62
        specifiers.push({
63
          kind: "named",
64
          imported: "default",
65
          local: local
66
        });
67
      }
68

    
69
      if (specifier.isImportSpecifier()) {
70
        var importedName = specifier.node.imported.name;
71
        imported.push(importedName);
72
        specifiers.push({
73
          kind: "named",
74
          imported: importedName,
75
          local: local
76
        });
77
      }
78

    
79
      if (specifier.isImportNamespaceSpecifier()) {
80
        imported.push("*");
81
        specifiers.push({
82
          kind: "namespace",
83
          local: local
84
        });
85
      }
86
    }
87
  }
88
};
89

    
90
function ExportDeclaration(path, file) {
91
  var node = path.node;
92

    
93

    
94
  var source = node.source ? node.source.value : null;
95
  var exports = file.metadata.modules.exports;
96

    
97
  var declar = path.get("declaration");
98
  if (declar.isStatement()) {
99
    var bindings = declar.getBindingIdentifiers();
100

    
101
    for (var name in bindings) {
102
      exports.exported.push(name);
103
      exports.specifiers.push({
104
        kind: "local",
105
        local: name,
106
        exported: path.isExportDefaultDeclaration() ? "default" : name
107
      });
108
    }
109
  }
110

    
111
  if (path.isExportNamedDeclaration() && node.specifiers) {
112
    for (var _iterator2 = node.specifiers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
113
      var _ref2;
114

    
115
      if (_isArray2) {
116
        if (_i2 >= _iterator2.length) break;
117
        _ref2 = _iterator2[_i2++];
118
      } else {
119
        _i2 = _iterator2.next();
120
        if (_i2.done) break;
121
        _ref2 = _i2.value;
122
      }
123

    
124
      var specifier = _ref2;
125

    
126
      var exported = specifier.exported.name;
127
      exports.exported.push(exported);
128

    
129
      if (t.isExportDefaultSpecifier(specifier)) {
130
        exports.specifiers.push({
131
          kind: "external",
132
          local: exported,
133
          exported: exported,
134
          source: source
135
        });
136
      }
137

    
138
      if (t.isExportNamespaceSpecifier(specifier)) {
139
        exports.specifiers.push({
140
          kind: "external-namespace",
141
          exported: exported,
142
          source: source
143
        });
144
      }
145

    
146
      var local = specifier.local;
147
      if (!local) continue;
148

    
149
      if (source) {
150
        exports.specifiers.push({
151
          kind: "external",
152
          local: local.name,
153
          exported: exported,
154
          source: source
155
        });
156
      }
157

    
158
      if (!source) {
159
        exports.specifiers.push({
160
          kind: "local",
161
          local: local.name,
162
          exported: exported
163
        });
164
      }
165
    }
166
  }
167

    
168
  if (path.isExportAllDeclaration()) {
169
    exports.specifiers.push({
170
      kind: "external-all",
171
      source: source
172
    });
173
  }
174
}
175

    
176
function Scope(path) {
177
  path.skip();
178
}
(4-4/4)