1 |
3a515b92
|
cagy
|
"use strict";
|
2 |
|
|
|
3 |
|
|
exports.__esModule = true;
|
4 |
|
|
|
5 |
|
|
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
|
6 |
|
|
|
7 |
|
|
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
8 |
|
|
|
9 |
|
|
exports.default = function (path, emit) {
|
10 |
|
|
var kind = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "var";
|
11 |
|
|
|
12 |
|
|
path.traverse(visitor, { kind: kind, emit: emit });
|
13 |
|
|
};
|
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22 |
|
|
|
23 |
|
|
var visitor = {
|
24 |
|
|
Scope: function Scope(path, state) {
|
25 |
|
|
if (state.kind === "let") path.skip();
|
26 |
|
|
},
|
27 |
|
|
Function: function Function(path) {
|
28 |
|
|
path.skip();
|
29 |
|
|
},
|
30 |
|
|
VariableDeclaration: function VariableDeclaration(path, state) {
|
31 |
|
|
if (state.kind && path.node.kind !== state.kind) return;
|
32 |
|
|
|
33 |
|
|
var nodes = [];
|
34 |
|
|
|
35 |
|
|
var declarations = path.get("declarations");
|
36 |
|
|
var firstId = void 0;
|
37 |
|
|
|
38 |
|
|
for (var _iterator = declarations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
|
39 |
|
|
var _ref;
|
40 |
|
|
|
41 |
|
|
if (_isArray) {
|
42 |
|
|
if (_i >= _iterator.length) break;
|
43 |
|
|
_ref = _iterator[_i++];
|
44 |
|
|
} else {
|
45 |
|
|
_i = _iterator.next();
|
46 |
|
|
if (_i.done) break;
|
47 |
|
|
_ref = _i.value;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
var declar = _ref;
|
51 |
|
|
|
52 |
|
|
firstId = declar.node.id;
|
53 |
|
|
|
54 |
|
|
if (declar.node.init) {
|
55 |
|
|
nodes.push(t.expressionStatement(t.assignmentExpression("=", declar.node.id, declar.node.init)));
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
for (var name in declar.getBindingIdentifiers()) {
|
59 |
|
|
state.emit(t.identifier(name), name);
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
if (path.parentPath.isFor({ left: path.node })) {
|
64 |
|
|
path.replaceWith(firstId);
|
65 |
|
|
} else {
|
66 |
|
|
path.replaceWithMultiple(nodes);
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
};
|
70 |
|
|
|
71 |
|
|
module.exports = exports["default"];
|