babel-schmooze-sprockets 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +14 -0
- data/bin/export-external-helpers +3 -0
- data/bin/setup +6 -0
- data/bin/update-npm-deps +8 -0
- data/examples/myapp/Gemfile +4 -5
- data/examples/myapp/Gemfile.lock +69 -93
- data/examples/myapp/app/assets/javascripts/code/hello.es6 +5 -1
- data/examples/myapp/app/views/layouts/application.html.erb +1 -0
- data/examples/myapp/app/views/site/home.html.erb +0 -1
- data/lib/babel-schmooze-sprockets/babel_processor.rb +6 -4
- data/lib/babel-schmooze-sprockets/engine.rb +1 -4
- data/lib/babel-schmooze-sprockets/version.rb +1 -1
- data/node_modules/amdefine/package.json +8 -1
- data/node_modules/babel-core/node_modules/babel-runtime/package.json +9 -5
- data/node_modules/babel-core/node_modules/babel-traverse/.npmignore +3 -0
- data/node_modules/babel-core/node_modules/babel-traverse/README.md +1 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/cache.js +20 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/context.js +219 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/hub.js +19 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/index.js +250 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/ancestry.js +317 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/comments.js +55 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js +297 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/conversion.js +48 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/evaluation.js +406 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/family.js +168 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js +245 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/inference/index.js +151 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/inference/inferer-reference.js +225 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/inference/inferers.js +198 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/introspection.js +518 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/lib/hoister.js +166 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/lib/removal-hooks.js +64 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/lib/virtual-types.js +141 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/modification.js +293 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/removal.js +72 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/path/replacement.js +302 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/scope/binding.js +105 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/scope/index.js +1222 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/scope/lib/renamer.js +154 -0
- data/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js +360 -0
- data/node_modules/babel-core/node_modules/babel-traverse/package.json +107 -0
- data/node_modules/babel-core/node_modules/core-js/package.json +20 -2
- data/node_modules/babel-core/package.json +31 -24
- data/node_modules/babel-generator/lib/buffer.js +69 -70
- data/node_modules/babel-generator/lib/generators/base.js +16 -12
- data/node_modules/babel-generator/lib/generators/classes.js +28 -19
- data/node_modules/babel-generator/lib/generators/expressions.js +76 -99
- data/node_modules/babel-generator/lib/generators/flow.js +178 -119
- data/node_modules/babel-generator/lib/generators/jsx.js +38 -29
- data/node_modules/babel-generator/lib/generators/methods.js +34 -25
- data/node_modules/babel-generator/lib/generators/modules.js +67 -40
- data/node_modules/babel-generator/lib/generators/statements.js +93 -76
- data/node_modules/babel-generator/lib/generators/template-literals.js +12 -11
- data/node_modules/babel-generator/lib/generators/types.js +56 -49
- data/node_modules/babel-generator/lib/index.js +52 -39
- data/node_modules/babel-generator/lib/node/index.js +12 -18
- data/node_modules/babel-generator/lib/node/parentheses.js +23 -27
- data/node_modules/babel-generator/lib/node/whitespace.js +20 -26
- data/node_modules/babel-generator/lib/position.js +5 -5
- data/node_modules/babel-generator/lib/printer.js +52 -81
- data/node_modules/babel-generator/lib/source-map.js +9 -11
- data/node_modules/babel-generator/lib/whitespace.js +13 -13
- data/node_modules/babel-generator/node_modules/babel-runtime/package.json +19 -6
- data/node_modules/babel-generator/node_modules/babel-types/.npmignore +3 -0
- data/node_modules/babel-generator/node_modules/babel-types/README.md +1141 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/constants.js +40 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/converters.js +378 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/core.js +704 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/es2015.js +354 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/experimental.js +85 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/flow.js +319 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/index.js +247 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/init.js +15 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/jsx.js +137 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/definitions/misc.js +21 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/flow.js +129 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/index.js +848 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/react.js +83 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/retrievers.js +123 -0
- data/node_modules/babel-generator/node_modules/babel-types/lib/validators.js +276 -0
- data/node_modules/babel-generator/node_modules/babel-types/package.json +103 -0
- data/node_modules/babel-generator/node_modules/core-js/package.json +10 -5
- data/node_modules/babel-generator/package.json +19 -16
- data/node_modules/babel-helpers/node_modules/babel-runtime/package.json +19 -3
- data/node_modules/babel-helpers/node_modules/core-js/package.json +20 -4
- data/node_modules/babel-helpers/package.json +8 -1
- data/node_modules/babel-register/node_modules/babel-runtime/package.json +19 -3
- data/node_modules/babel-register/node_modules/core-js/package.json +20 -4
- data/node_modules/babel-register/package.json +8 -1
- data/node_modules/balanced-match/package.json +8 -1
- data/node_modules/brace-expansion/package.json +19 -12
- data/node_modules/concat-map/package.json +9 -2
- data/node_modules/convert-source-map/package.json +8 -1
- data/node_modules/detect-indent/package.json +8 -1
- data/node_modules/get-stdin/package.json +8 -1
- data/node_modules/home-or-tmp/package.json +9 -2
- data/node_modules/is-finite/package.json +8 -2
- data/node_modules/json5/package.json +8 -1
- data/node_modules/minimatch/README.md +2 -9
- data/node_modules/minimatch/minimatch.js +15 -3
- data/node_modules/minimatch/package.json +29 -21
- data/node_modules/minimist/package.json +8 -1
- data/node_modules/mkdirp/node_modules/minimist/package.json +8 -1
- data/node_modules/mkdirp/package.json +8 -1
- data/node_modules/number-is-nan/package.json +8 -1
- data/node_modules/os-tmpdir/package.json +8 -1
- data/node_modules/path-exists/package.json +8 -1
- data/node_modules/path-is-absolute/package.json +8 -1
- data/node_modules/repeating/package.json +15 -11
- data/node_modules/shebang-regex/package.json +8 -1
- data/node_modules/slash/package.json +8 -1
- data/node_modules/source-map-support/node_modules/source-map/package.json +8 -1
- data/node_modules/source-map-support/package.json +8 -1
- data/node_modules/source-map/package.json +8 -1
- data/node_modules/user-home/package.json +8 -1
- data/package.json +1 -1
- metadata +54 -6
- data/node_modules/brace-expansion/.npmignore +0 -3
- data/node_modules/brace-expansion/example.js +0 -8
- data/node_modules/minimatch/browser.js +0 -1159
@@ -0,0 +1,166 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
|
5
|
+
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
|
6
|
+
|
7
|
+
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
8
|
+
|
9
|
+
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
|
10
|
+
|
11
|
+
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
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 referenceVisitor = {
|
22
|
+
ReferencedIdentifier: function ReferencedIdentifier(path, state) {
|
23
|
+
if (path.isJSXIdentifier() && _babelTypes.react.isCompatTag(path.node.name)) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
|
27
|
+
// direct references that we need to track to hoist this to the highest scope we can
|
28
|
+
var binding = path.scope.getBinding(path.node.name);
|
29
|
+
if (!binding) return;
|
30
|
+
|
31
|
+
// this binding isn't accessible from the parent scope so we can safely ignore it
|
32
|
+
// eg. it's in a closure etc
|
33
|
+
if (binding !== state.scope.getBinding(path.node.name)) return;
|
34
|
+
|
35
|
+
if (binding.constant) {
|
36
|
+
state.bindings[path.node.name] = binding;
|
37
|
+
} else {
|
38
|
+
for (var _iterator = binding.constantViolations, _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 violationPath = _ref;
|
51
|
+
|
52
|
+
state.breakOnScopePaths = state.breakOnScopePaths.concat(violationPath.getAncestry());
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
var PathHoister = function () {
|
59
|
+
function PathHoister(path, scope) {
|
60
|
+
(0, _classCallCheck3.default)(this, PathHoister);
|
61
|
+
|
62
|
+
this.breakOnScopePaths = [];
|
63
|
+
this.bindings = {};
|
64
|
+
this.scopes = [];
|
65
|
+
this.scope = scope;
|
66
|
+
this.path = path;
|
67
|
+
}
|
68
|
+
|
69
|
+
PathHoister.prototype.isCompatibleScope = function isCompatibleScope(scope) {
|
70
|
+
for (var key in this.bindings) {
|
71
|
+
var binding = this.bindings[key];
|
72
|
+
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
return true;
|
78
|
+
};
|
79
|
+
|
80
|
+
PathHoister.prototype.getCompatibleScopes = function getCompatibleScopes() {
|
81
|
+
var scope = this.path.scope;
|
82
|
+
do {
|
83
|
+
if (this.isCompatibleScope(scope)) {
|
84
|
+
this.scopes.push(scope);
|
85
|
+
} else {
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
} while (scope = scope.parent);
|
93
|
+
};
|
94
|
+
|
95
|
+
PathHoister.prototype.getAttachmentPath = function getAttachmentPath() {
|
96
|
+
var scopes = this.scopes;
|
97
|
+
|
98
|
+
var scope = scopes.pop();
|
99
|
+
if (!scope) return;
|
100
|
+
|
101
|
+
if (scope.path.isFunction()) {
|
102
|
+
if (this.hasOwnParamBindings(scope)) {
|
103
|
+
// should ignore this scope since it's ourselves
|
104
|
+
if (this.scope === scope) return;
|
105
|
+
|
106
|
+
// needs to be attached to the body
|
107
|
+
return scope.path.get("body").get("body")[0];
|
108
|
+
} else {
|
109
|
+
// doesn't need to be be attached to this scope
|
110
|
+
return this.getNextScopeStatementParent();
|
111
|
+
}
|
112
|
+
} else if (scope.path.isProgram()) {
|
113
|
+
return this.getNextScopeStatementParent();
|
114
|
+
}
|
115
|
+
};
|
116
|
+
|
117
|
+
PathHoister.prototype.getNextScopeStatementParent = function getNextScopeStatementParent() {
|
118
|
+
var scope = this.scopes.pop();
|
119
|
+
if (scope) return scope.path.getStatementParent();
|
120
|
+
};
|
121
|
+
|
122
|
+
PathHoister.prototype.hasOwnParamBindings = function hasOwnParamBindings(scope) {
|
123
|
+
for (var name in this.bindings) {
|
124
|
+
if (!scope.hasOwnBinding(name)) continue;
|
125
|
+
|
126
|
+
var binding = this.bindings[name];
|
127
|
+
if (binding.kind === "param") return true;
|
128
|
+
}
|
129
|
+
return false;
|
130
|
+
};
|
131
|
+
|
132
|
+
PathHoister.prototype.run = function run() {
|
133
|
+
var node = this.path.node;
|
134
|
+
if (node._hoisted) return;
|
135
|
+
node._hoisted = true;
|
136
|
+
|
137
|
+
this.path.traverse(referenceVisitor, this);
|
138
|
+
|
139
|
+
this.getCompatibleScopes();
|
140
|
+
|
141
|
+
var attachTo = this.getAttachmentPath();
|
142
|
+
if (!attachTo) return;
|
143
|
+
|
144
|
+
// don't bother hoisting to the same function as this will cause multiple branches to be evaluated more than once leading to a bad optimisation
|
145
|
+
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
146
|
+
|
147
|
+
var uid = attachTo.scope.generateUidIdentifier("ref");
|
148
|
+
|
149
|
+
attachTo.insertBefore([t.variableDeclaration("var", [t.variableDeclarator(uid, this.path.node)])]);
|
150
|
+
|
151
|
+
var parent = this.path.parentPath;
|
152
|
+
|
153
|
+
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
154
|
+
// turning the `span` in `<div><span /></div>` to an expression so we need to wrap it with
|
155
|
+
// an expression container
|
156
|
+
uid = t.JSXExpressionContainer(uid);
|
157
|
+
}
|
158
|
+
|
159
|
+
this.path.replaceWith(uid);
|
160
|
+
};
|
161
|
+
|
162
|
+
return PathHoister;
|
163
|
+
}();
|
164
|
+
|
165
|
+
exports.default = PathHoister;
|
166
|
+
module.exports = exports["default"];
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
// this file contains hooks that handle ancestry cleanup of parent nodes when removing children
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Pre hooks should be used for either rejecting removal or delegating removal
|
8
|
+
*/
|
9
|
+
|
10
|
+
var hooks = exports.hooks = [function (self, parent) {
|
11
|
+
if (self.key === "body" && parent.isArrowFunctionExpression()) {
|
12
|
+
self.replaceWith(self.scope.buildUndefinedNode());
|
13
|
+
return true;
|
14
|
+
}
|
15
|
+
}, function (self, parent) {
|
16
|
+
var removeParent = false;
|
17
|
+
|
18
|
+
// while (NODE);
|
19
|
+
// removing the test of a while/switch, we can either just remove it entirely *or* turn the `test` into `true`
|
20
|
+
// unlikely that the latter will ever be what's wanted so we just remove the loop to avoid infinite recursion
|
21
|
+
removeParent = removeParent || self.key === "test" && (parent.isWhile() || parent.isSwitchCase());
|
22
|
+
|
23
|
+
// export NODE;
|
24
|
+
// just remove a declaration for an export as this is no longer valid
|
25
|
+
removeParent = removeParent || self.key === "declaration" && parent.isExportDeclaration();
|
26
|
+
|
27
|
+
// label: NODE
|
28
|
+
// stray labeled statement with no body
|
29
|
+
removeParent = removeParent || self.key === "body" && parent.isLabeledStatement();
|
30
|
+
|
31
|
+
// let NODE;
|
32
|
+
// remove an entire declaration if there are no declarators left
|
33
|
+
removeParent = removeParent || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1;
|
34
|
+
|
35
|
+
// NODE;
|
36
|
+
// remove the entire expression statement if there's no expression
|
37
|
+
removeParent = removeParent || self.key === "expression" && parent.isExpressionStatement();
|
38
|
+
|
39
|
+
if (removeParent) {
|
40
|
+
parent.remove();
|
41
|
+
return true;
|
42
|
+
}
|
43
|
+
}, function (self, parent) {
|
44
|
+
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
45
|
+
// (node, NODE);
|
46
|
+
// we've just removed the second element of a sequence expression so let's turn that sequence
|
47
|
+
// expression into a regular expression
|
48
|
+
parent.replaceWith(parent.node.expressions[0]);
|
49
|
+
return true;
|
50
|
+
}
|
51
|
+
}, function (self, parent) {
|
52
|
+
if (parent.isBinary()) {
|
53
|
+
// left + NODE;
|
54
|
+
// NODE + right;
|
55
|
+
// we're in a binary expression, better remove it and replace it with the last expression
|
56
|
+
if (self.key === "left") {
|
57
|
+
parent.replaceWith(parent.node.right);
|
58
|
+
} else {
|
59
|
+
// key === "right"
|
60
|
+
parent.replaceWith(parent.node.left);
|
61
|
+
}
|
62
|
+
return true;
|
63
|
+
}
|
64
|
+
}];
|
@@ -0,0 +1,141 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = undefined;
|
5
|
+
|
6
|
+
var _babelTypes = require("babel-types");
|
7
|
+
|
8
|
+
var t = _interopRequireWildcard(_babelTypes);
|
9
|
+
|
10
|
+
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; } }
|
11
|
+
|
12
|
+
var ReferencedIdentifier = exports.ReferencedIdentifier = {
|
13
|
+
types: ["Identifier", "JSXIdentifier"],
|
14
|
+
checkPath: function checkPath(_ref, opts) {
|
15
|
+
var node = _ref.node;
|
16
|
+
var parent = _ref.parent;
|
17
|
+
|
18
|
+
if (!t.isIdentifier(node, opts)) {
|
19
|
+
if (t.isJSXIdentifier(node, opts)) {
|
20
|
+
if (_babelTypes.react.isCompatTag(node.name)) return false;
|
21
|
+
} else {
|
22
|
+
// not a JSXIdentifier or an Identifier
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
// check if node is referenced
|
28
|
+
return t.isReferenced(node, parent);
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
var ReferencedMemberExpression = exports.ReferencedMemberExpression = {
|
33
|
+
types: ["MemberExpression"],
|
34
|
+
checkPath: function checkPath(_ref2) {
|
35
|
+
var node = _ref2.node;
|
36
|
+
var parent = _ref2.parent;
|
37
|
+
|
38
|
+
return t.isMemberExpression(node) && t.isReferenced(node, parent);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
var BindingIdentifier = exports.BindingIdentifier = {
|
43
|
+
types: ["Identifier"],
|
44
|
+
checkPath: function checkPath(_ref3) {
|
45
|
+
var node = _ref3.node;
|
46
|
+
var parent = _ref3.parent;
|
47
|
+
|
48
|
+
return t.isIdentifier(node) && t.isBinding(node, parent);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
var Statement = exports.Statement = {
|
53
|
+
types: ["Statement"],
|
54
|
+
checkPath: function checkPath(_ref4) {
|
55
|
+
var node = _ref4.node;
|
56
|
+
var parent = _ref4.parent;
|
57
|
+
|
58
|
+
if (t.isStatement(node)) {
|
59
|
+
if (t.isVariableDeclaration(node)) {
|
60
|
+
if (t.isForXStatement(parent, { left: node })) return false;
|
61
|
+
if (t.isForStatement(parent, { init: node })) return false;
|
62
|
+
}
|
63
|
+
|
64
|
+
return true;
|
65
|
+
} else {
|
66
|
+
return false;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
var Expression = exports.Expression = {
|
72
|
+
types: ["Expression"],
|
73
|
+
checkPath: function checkPath(path) {
|
74
|
+
if (path.isIdentifier()) {
|
75
|
+
return path.isReferencedIdentifier();
|
76
|
+
} else {
|
77
|
+
return t.isExpression(path.node);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
};
|
81
|
+
|
82
|
+
var Scope = exports.Scope = {
|
83
|
+
types: ["Scopable"],
|
84
|
+
checkPath: function checkPath(path) {
|
85
|
+
return t.isScope(path.node, path.parent);
|
86
|
+
}
|
87
|
+
};
|
88
|
+
|
89
|
+
var Referenced = exports.Referenced = {
|
90
|
+
checkPath: function checkPath(path) {
|
91
|
+
return t.isReferenced(path.node, path.parent);
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
var BlockScoped = exports.BlockScoped = {
|
96
|
+
checkPath: function checkPath(path) {
|
97
|
+
return t.isBlockScoped(path.node);
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
var Var = exports.Var = {
|
102
|
+
types: ["VariableDeclaration"],
|
103
|
+
checkPath: function checkPath(path) {
|
104
|
+
return t.isVar(path.node);
|
105
|
+
}
|
106
|
+
};
|
107
|
+
|
108
|
+
var User = exports.User = {
|
109
|
+
checkPath: function checkPath(path) {
|
110
|
+
return path.node && !!path.node.loc;
|
111
|
+
}
|
112
|
+
};
|
113
|
+
|
114
|
+
var Generated = exports.Generated = {
|
115
|
+
checkPath: function checkPath(path) {
|
116
|
+
return !path.isUser();
|
117
|
+
}
|
118
|
+
};
|
119
|
+
|
120
|
+
var Pure = exports.Pure = {
|
121
|
+
checkPath: function checkPath(path, opts) {
|
122
|
+
return path.scope.isPure(path.node, opts);
|
123
|
+
}
|
124
|
+
};
|
125
|
+
|
126
|
+
var Flow = exports.Flow = {
|
127
|
+
types: ["Flow", "ImportDeclaration", "ExportDeclaration"],
|
128
|
+
checkPath: function checkPath(_ref5) {
|
129
|
+
var node = _ref5.node;
|
130
|
+
|
131
|
+
if (t.isFlow(node)) {
|
132
|
+
return true;
|
133
|
+
} else if (t.isImportDeclaration(node)) {
|
134
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
135
|
+
} else if (t.isExportDeclaration(node)) {
|
136
|
+
return node.exportKind === "type";
|
137
|
+
} else {
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
};
|
@@ -0,0 +1,293 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
|
5
|
+
var _typeof2 = require("babel-runtime/helpers/typeof");
|
6
|
+
|
7
|
+
var _typeof3 = _interopRequireDefault(_typeof2);
|
8
|
+
|
9
|
+
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
|
10
|
+
|
11
|
+
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
12
|
+
|
13
|
+
exports.insertBefore = insertBefore;
|
14
|
+
exports._containerInsert = _containerInsert;
|
15
|
+
exports._containerInsertBefore = _containerInsertBefore;
|
16
|
+
exports._containerInsertAfter = _containerInsertAfter;
|
17
|
+
exports._maybePopFromStatements = _maybePopFromStatements;
|
18
|
+
exports.insertAfter = insertAfter;
|
19
|
+
exports.updateSiblingKeys = updateSiblingKeys;
|
20
|
+
exports._verifyNodeList = _verifyNodeList;
|
21
|
+
exports.unshiftContainer = unshiftContainer;
|
22
|
+
exports.pushContainer = pushContainer;
|
23
|
+
exports.hoist = hoist;
|
24
|
+
|
25
|
+
var _cache = require("../cache");
|
26
|
+
|
27
|
+
var _hoister = require("./lib/hoister");
|
28
|
+
|
29
|
+
var _hoister2 = _interopRequireDefault(_hoister);
|
30
|
+
|
31
|
+
var _index = require("./index");
|
32
|
+
|
33
|
+
var _index2 = _interopRequireDefault(_index);
|
34
|
+
|
35
|
+
var _babelTypes = require("babel-types");
|
36
|
+
|
37
|
+
var t = _interopRequireWildcard(_babelTypes);
|
38
|
+
|
39
|
+
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; } }
|
40
|
+
|
41
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Insert the provided nodes before the current one.
|
45
|
+
*/
|
46
|
+
|
47
|
+
/* eslint max-len: 0 */
|
48
|
+
// This file contains methods that modify the path/node in some ways.
|
49
|
+
|
50
|
+
function insertBefore(nodes) {
|
51
|
+
this._assertUnremoved();
|
52
|
+
|
53
|
+
nodes = this._verifyNodeList(nodes);
|
54
|
+
|
55
|
+
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
56
|
+
return this.parentPath.insertBefore(nodes);
|
57
|
+
} else if (this.isNodeType("Expression") || this.parentPath.isForStatement() && this.key === "init") {
|
58
|
+
if (this.node) nodes.push(this.node);
|
59
|
+
this.replaceExpressionWithStatements(nodes);
|
60
|
+
} else {
|
61
|
+
this._maybePopFromStatements(nodes);
|
62
|
+
if (Array.isArray(this.container)) {
|
63
|
+
return this._containerInsertBefore(nodes);
|
64
|
+
} else if (this.isStatementOrBlock()) {
|
65
|
+
if (this.node) nodes.push(this.node);
|
66
|
+
this._replaceWith(t.blockStatement(nodes));
|
67
|
+
} else {
|
68
|
+
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
return [this];
|
73
|
+
}
|
74
|
+
|
75
|
+
function _containerInsert(from, nodes) {
|
76
|
+
this.updateSiblingKeys(from, nodes.length);
|
77
|
+
|
78
|
+
var paths = [];
|
79
|
+
|
80
|
+
for (var i = 0; i < nodes.length; i++) {
|
81
|
+
var to = from + i;
|
82
|
+
var node = nodes[i];
|
83
|
+
this.container.splice(to, 0, node);
|
84
|
+
|
85
|
+
if (this.context) {
|
86
|
+
var path = this.context.create(this.parent, this.container, to, this.listKey);
|
87
|
+
|
88
|
+
// While this path may have a context, there is currently no guarantee that the context
|
89
|
+
// will be the active context, because `popContext` may leave a final context in place.
|
90
|
+
// We should remove this `if` and always push once T7171 has been resolved.
|
91
|
+
if (this.context.queue) path.pushContext(this.context);
|
92
|
+
paths.push(path);
|
93
|
+
} else {
|
94
|
+
paths.push(_index2.default.get({
|
95
|
+
parentPath: this.parentPath,
|
96
|
+
parent: this.parent,
|
97
|
+
container: this.container,
|
98
|
+
listKey: this.listKey,
|
99
|
+
key: to
|
100
|
+
}));
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
var contexts = this._getQueueContexts();
|
105
|
+
|
106
|
+
for (var _iterator = paths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
|
107
|
+
var _ref;
|
108
|
+
|
109
|
+
if (_isArray) {
|
110
|
+
if (_i >= _iterator.length) break;
|
111
|
+
_ref = _iterator[_i++];
|
112
|
+
} else {
|
113
|
+
_i = _iterator.next();
|
114
|
+
if (_i.done) break;
|
115
|
+
_ref = _i.value;
|
116
|
+
}
|
117
|
+
|
118
|
+
var _path = _ref;
|
119
|
+
|
120
|
+
_path.setScope();
|
121
|
+
_path.debug(function () {
|
122
|
+
return "Inserted.";
|
123
|
+
});
|
124
|
+
|
125
|
+
for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
|
126
|
+
var _ref2;
|
127
|
+
|
128
|
+
if (_isArray2) {
|
129
|
+
if (_i2 >= _iterator2.length) break;
|
130
|
+
_ref2 = _iterator2[_i2++];
|
131
|
+
} else {
|
132
|
+
_i2 = _iterator2.next();
|
133
|
+
if (_i2.done) break;
|
134
|
+
_ref2 = _i2.value;
|
135
|
+
}
|
136
|
+
|
137
|
+
var context = _ref2;
|
138
|
+
|
139
|
+
context.maybeQueue(_path, true);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
return paths;
|
144
|
+
}
|
145
|
+
|
146
|
+
function _containerInsertBefore(nodes) {
|
147
|
+
return this._containerInsert(this.key, nodes);
|
148
|
+
}
|
149
|
+
|
150
|
+
function _containerInsertAfter(nodes) {
|
151
|
+
return this._containerInsert(this.key + 1, nodes);
|
152
|
+
}
|
153
|
+
|
154
|
+
function _maybePopFromStatements(nodes) {
|
155
|
+
var last = nodes[nodes.length - 1];
|
156
|
+
var isIdentifier = t.isIdentifier(last) || t.isExpressionStatement(last) && t.isIdentifier(last.expression);
|
157
|
+
|
158
|
+
if (isIdentifier && !this.isCompletionRecord()) {
|
159
|
+
nodes.pop();
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Insert the provided nodes after the current one. When inserting nodes after an
|
165
|
+
* expression, ensure that the completion record is correct by pushing the current node.
|
166
|
+
*/
|
167
|
+
|
168
|
+
function insertAfter(nodes) {
|
169
|
+
this._assertUnremoved();
|
170
|
+
|
171
|
+
nodes = this._verifyNodeList(nodes);
|
172
|
+
|
173
|
+
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
174
|
+
return this.parentPath.insertAfter(nodes);
|
175
|
+
} else if (this.isNodeType("Expression") || this.parentPath.isForStatement() && this.key === "init") {
|
176
|
+
if (this.node) {
|
177
|
+
var temp = this.scope.generateDeclaredUidIdentifier();
|
178
|
+
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
179
|
+
nodes.push(t.expressionStatement(temp));
|
180
|
+
}
|
181
|
+
this.replaceExpressionWithStatements(nodes);
|
182
|
+
} else {
|
183
|
+
this._maybePopFromStatements(nodes);
|
184
|
+
if (Array.isArray(this.container)) {
|
185
|
+
return this._containerInsertAfter(nodes);
|
186
|
+
} else if (this.isStatementOrBlock()) {
|
187
|
+
if (this.node) nodes.unshift(this.node);
|
188
|
+
this._replaceWith(t.blockStatement(nodes));
|
189
|
+
} else {
|
190
|
+
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
return [this];
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Update all sibling node paths after `fromIndex` by `incrementBy`.
|
199
|
+
*/
|
200
|
+
|
201
|
+
function updateSiblingKeys(fromIndex, incrementBy) {
|
202
|
+
if (!this.parent) return;
|
203
|
+
|
204
|
+
var paths = _cache.path.get(this.parent);
|
205
|
+
for (var i = 0; i < paths.length; i++) {
|
206
|
+
var path = paths[i];
|
207
|
+
if (path.key >= fromIndex) {
|
208
|
+
path.key += incrementBy;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
function _verifyNodeList(nodes) {
|
214
|
+
if (!nodes) {
|
215
|
+
return [];
|
216
|
+
}
|
217
|
+
|
218
|
+
if (nodes.constructor !== Array) {
|
219
|
+
nodes = [nodes];
|
220
|
+
}
|
221
|
+
|
222
|
+
for (var i = 0; i < nodes.length; i++) {
|
223
|
+
var node = nodes[i];
|
224
|
+
var msg = void 0;
|
225
|
+
|
226
|
+
if (!node) {
|
227
|
+
msg = "has falsy node";
|
228
|
+
} else if ((typeof node === "undefined" ? "undefined" : (0, _typeof3.default)(node)) !== "object") {
|
229
|
+
msg = "contains a non-object node";
|
230
|
+
} else if (!node.type) {
|
231
|
+
msg = "without a type";
|
232
|
+
} else if (node instanceof _index2.default) {
|
233
|
+
msg = "has a NodePath when it expected a raw object";
|
234
|
+
}
|
235
|
+
|
236
|
+
if (msg) {
|
237
|
+
var type = Array.isArray(node) ? "array" : typeof node === "undefined" ? "undefined" : (0, _typeof3.default)(node);
|
238
|
+
throw new Error("Node list " + msg + " with the index of " + i + " and type of " + type);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
return nodes;
|
243
|
+
}
|
244
|
+
|
245
|
+
function unshiftContainer(listKey, nodes) {
|
246
|
+
this._assertUnremoved();
|
247
|
+
|
248
|
+
nodes = this._verifyNodeList(nodes);
|
249
|
+
|
250
|
+
// get the first path and insert our nodes before it, if it doesn't exist then it
|
251
|
+
// doesn't matter, our nodes will be inserted anyway
|
252
|
+
var path = _index2.default.get({
|
253
|
+
parentPath: this,
|
254
|
+
parent: this.node,
|
255
|
+
container: this.node[listKey],
|
256
|
+
listKey: listKey,
|
257
|
+
key: 0
|
258
|
+
});
|
259
|
+
|
260
|
+
return path.insertBefore(nodes);
|
261
|
+
}
|
262
|
+
|
263
|
+
function pushContainer(listKey, nodes) {
|
264
|
+
this._assertUnremoved();
|
265
|
+
|
266
|
+
nodes = this._verifyNodeList(nodes);
|
267
|
+
|
268
|
+
// get an invisible path that represents the last node + 1 and replace it with our
|
269
|
+
// nodes, effectively inlining it
|
270
|
+
|
271
|
+
var container = this.node[listKey];
|
272
|
+
var path = _index2.default.get({
|
273
|
+
parentPath: this,
|
274
|
+
parent: this.node,
|
275
|
+
container: container,
|
276
|
+
listKey: listKey,
|
277
|
+
key: container.length
|
278
|
+
});
|
279
|
+
|
280
|
+
return path.replaceWithMultiple(nodes);
|
281
|
+
}
|
282
|
+
|
283
|
+
/**
|
284
|
+
* Hoist the current node to the highest scope possible and return a UID
|
285
|
+
* referencing it.
|
286
|
+
*/
|
287
|
+
|
288
|
+
function hoist() {
|
289
|
+
var scope = arguments.length <= 0 || arguments[0] === undefined ? this.scope : arguments[0];
|
290
|
+
|
291
|
+
var hoister = new _hoister2.default(this, scope);
|
292
|
+
return hoister.run();
|
293
|
+
}
|