1
|
"use strict";
|
2
|
|
3
|
exports.__esModule = true;
|
4
|
exports.ImportSpecifier = ImportSpecifier;
|
5
|
exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
|
6
|
exports.ExportDefaultSpecifier = ExportDefaultSpecifier;
|
7
|
exports.ExportSpecifier = ExportSpecifier;
|
8
|
exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier;
|
9
|
exports.ExportAllDeclaration = ExportAllDeclaration;
|
10
|
exports.ExportNamedDeclaration = ExportNamedDeclaration;
|
11
|
exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
|
12
|
exports.ImportDeclaration = ImportDeclaration;
|
13
|
exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
|
14
|
|
15
|
var _babelTypes = require("babel-types");
|
16
|
|
17
|
var t = _interopRequireWildcard(_babelTypes);
|
18
|
|
19
|
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; } }
|
20
|
|
21
|
function ImportSpecifier(node) {
|
22
|
if (node.importKind === "type" || node.importKind === "typeof") {
|
23
|
this.word(node.importKind);
|
24
|
this.space();
|
25
|
}
|
26
|
|
27
|
this.print(node.imported, node);
|
28
|
if (node.local && node.local.name !== node.imported.name) {
|
29
|
this.space();
|
30
|
this.word("as");
|
31
|
this.space();
|
32
|
this.print(node.local, node);
|
33
|
}
|
34
|
}
|
35
|
|
36
|
function ImportDefaultSpecifier(node) {
|
37
|
this.print(node.local, node);
|
38
|
}
|
39
|
|
40
|
function ExportDefaultSpecifier(node) {
|
41
|
this.print(node.exported, node);
|
42
|
}
|
43
|
|
44
|
function ExportSpecifier(node) {
|
45
|
this.print(node.local, node);
|
46
|
if (node.exported && node.local.name !== node.exported.name) {
|
47
|
this.space();
|
48
|
this.word("as");
|
49
|
this.space();
|
50
|
this.print(node.exported, node);
|
51
|
}
|
52
|
}
|
53
|
|
54
|
function ExportNamespaceSpecifier(node) {
|
55
|
this.token("*");
|
56
|
this.space();
|
57
|
this.word("as");
|
58
|
this.space();
|
59
|
this.print(node.exported, node);
|
60
|
}
|
61
|
|
62
|
function ExportAllDeclaration(node) {
|
63
|
this.word("export");
|
64
|
this.space();
|
65
|
this.token("*");
|
66
|
this.space();
|
67
|
this.word("from");
|
68
|
this.space();
|
69
|
this.print(node.source, node);
|
70
|
this.semicolon();
|
71
|
}
|
72
|
|
73
|
function ExportNamedDeclaration() {
|
74
|
this.word("export");
|
75
|
this.space();
|
76
|
ExportDeclaration.apply(this, arguments);
|
77
|
}
|
78
|
|
79
|
function ExportDefaultDeclaration() {
|
80
|
this.word("export");
|
81
|
this.space();
|
82
|
this.word("default");
|
83
|
this.space();
|
84
|
ExportDeclaration.apply(this, arguments);
|
85
|
}
|
86
|
|
87
|
function ExportDeclaration(node) {
|
88
|
if (node.declaration) {
|
89
|
var declar = node.declaration;
|
90
|
this.print(declar, node);
|
91
|
if (!t.isStatement(declar)) this.semicolon();
|
92
|
} else {
|
93
|
if (node.exportKind === "type") {
|
94
|
this.word("type");
|
95
|
this.space();
|
96
|
}
|
97
|
|
98
|
var specifiers = node.specifiers.slice(0);
|
99
|
|
100
|
var hasSpecial = false;
|
101
|
while (true) {
|
102
|
var first = specifiers[0];
|
103
|
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
104
|
hasSpecial = true;
|
105
|
this.print(specifiers.shift(), node);
|
106
|
if (specifiers.length) {
|
107
|
this.token(",");
|
108
|
this.space();
|
109
|
}
|
110
|
} else {
|
111
|
break;
|
112
|
}
|
113
|
}
|
114
|
|
115
|
if (specifiers.length || !specifiers.length && !hasSpecial) {
|
116
|
this.token("{");
|
117
|
if (specifiers.length) {
|
118
|
this.space();
|
119
|
this.printList(specifiers, node);
|
120
|
this.space();
|
121
|
}
|
122
|
this.token("}");
|
123
|
}
|
124
|
|
125
|
if (node.source) {
|
126
|
this.space();
|
127
|
this.word("from");
|
128
|
this.space();
|
129
|
this.print(node.source, node);
|
130
|
}
|
131
|
|
132
|
this.semicolon();
|
133
|
}
|
134
|
}
|
135
|
|
136
|
function ImportDeclaration(node) {
|
137
|
this.word("import");
|
138
|
this.space();
|
139
|
|
140
|
if (node.importKind === "type" || node.importKind === "typeof") {
|
141
|
this.word(node.importKind);
|
142
|
this.space();
|
143
|
}
|
144
|
|
145
|
var specifiers = node.specifiers.slice(0);
|
146
|
if (specifiers && specifiers.length) {
|
147
|
while (true) {
|
148
|
var first = specifiers[0];
|
149
|
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
150
|
this.print(specifiers.shift(), node);
|
151
|
if (specifiers.length) {
|
152
|
this.token(",");
|
153
|
this.space();
|
154
|
}
|
155
|
} else {
|
156
|
break;
|
157
|
}
|
158
|
}
|
159
|
|
160
|
if (specifiers.length) {
|
161
|
this.token("{");
|
162
|
this.space();
|
163
|
this.printList(specifiers, node);
|
164
|
this.space();
|
165
|
this.token("}");
|
166
|
}
|
167
|
|
168
|
this.space();
|
169
|
this.word("from");
|
170
|
this.space();
|
171
|
}
|
172
|
|
173
|
this.print(node.source, node);
|
174
|
this.semicolon();
|
175
|
}
|
176
|
|
177
|
function ImportNamespaceSpecifier(node) {
|
178
|
this.token("*");
|
179
|
this.space();
|
180
|
this.word("as");
|
181
|
this.space();
|
182
|
this.print(node.local, node);
|
183
|
}
|