index.js
1.88 KB
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
"use strict";
exports.__esModule = true;
var _symbol = require("babel-runtime/core-js/symbol");
var _symbol2 = _interopRequireDefault(_symbol);
exports.default = function (_ref) {
var t = _ref.types;
var VISITED = (0, _symbol2.default)();
return {
visitor: {
ExportDefaultDeclaration: function ExportDefaultDeclaration(path) {
if (!path.get("declaration").isClassDeclaration()) return;
var node = path.node;
var ref = node.declaration.id || path.scope.generateUidIdentifier("class");
node.declaration.id = ref;
path.replaceWith(node.declaration);
path.insertAfter(t.exportDefaultDeclaration(ref));
},
ClassDeclaration: function ClassDeclaration(path) {
var node = path.node;
var ref = node.id || path.scope.generateUidIdentifier("class");
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(ref, t.toExpression(node))]));
},
ClassExpression: function ClassExpression(path, state) {
var node = path.node;
if (node[VISITED]) return;
var inferred = (0, _babelHelperFunctionName2.default)(path);
if (inferred && inferred !== node) return path.replaceWith(inferred);
node[VISITED] = true;
var Constructor = _vanilla2.default;
if (state.opts.loose) Constructor = _loose2.default;
path.replaceWith(new Constructor(path, state.file).run());
}
}
};
};
var _loose = require("./loose");
var _loose2 = _interopRequireDefault(_loose);
var _vanilla = require("./vanilla");
var _vanilla2 = _interopRequireDefault(_vanilla);
var _babelHelperFunctionName = require("babel-helper-function-name");
var _babelHelperFunctionName2 = _interopRequireDefault(_babelHelperFunctionName);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports["default"];