@tachybase/module-cloud-component 0.23.22 → 0.23.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +7 -7
- package/dist/node_modules/@babel/core/lib/index.js +76 -76
- package/dist/node_modules/@babel/core/node_modules/.bin/parser +4 -4
- package/dist/node_modules/@babel/core/package.json +1 -1
- package/dist/node_modules/@babel/parser/LICENSE +19 -0
- package/dist/node_modules/@babel/parser/bin/babel-parser.js +15 -0
- package/dist/node_modules/@babel/parser/index.cjs +5 -0
- package/dist/node_modules/@babel/parser/lib/index.js +1 -0
- package/dist/node_modules/@babel/parser/package.json +1 -0
- package/dist/node_modules/@babel/parser/typings/babel-parser.d.ts +267 -0
- package/dist/node_modules/@babel/traverse/LICENSE +22 -0
- package/dist/node_modules/@babel/traverse/lib/cache.js +44 -0
- package/dist/node_modules/@babel/traverse/lib/context.js +119 -0
- package/dist/node_modules/@babel/traverse/lib/hub.js +19 -0
- package/dist/node_modules/@babel/traverse/lib/index.js +13 -0
- package/dist/node_modules/@babel/traverse/lib/path/ancestry.js +141 -0
- package/dist/node_modules/@babel/traverse/lib/path/comments.js +52 -0
- package/dist/node_modules/@babel/traverse/lib/path/context.js +242 -0
- package/dist/node_modules/@babel/traverse/lib/path/conversion.js +609 -0
- package/dist/node_modules/@babel/traverse/lib/path/evaluation.js +347 -0
- package/dist/node_modules/@babel/traverse/lib/path/family.js +340 -0
- package/dist/node_modules/@babel/traverse/lib/path/index.js +292 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/index.js +149 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js +151 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/inferers.js +207 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/util.js +30 -0
- package/dist/node_modules/@babel/traverse/lib/path/introspection.js +398 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/hoister.js +171 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js +37 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/virtual-types-validator.js +163 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/virtual-types.js +26 -0
- package/dist/node_modules/@babel/traverse/lib/path/modification.js +229 -0
- package/dist/node_modules/@babel/traverse/lib/path/removal.js +69 -0
- package/dist/node_modules/@babel/traverse/lib/path/replacement.js +263 -0
- package/dist/node_modules/@babel/traverse/lib/scope/binding.js +83 -0
- package/dist/node_modules/@babel/traverse/lib/scope/index.js +981 -0
- package/dist/node_modules/@babel/traverse/lib/scope/lib/renamer.js +131 -0
- package/dist/node_modules/@babel/traverse/lib/traverse-node.js +29 -0
- package/dist/node_modules/@babel/traverse/lib/types.js +3 -0
- package/dist/node_modules/@babel/traverse/lib/visitors.js +258 -0
- package/dist/node_modules/@babel/traverse/node_modules/.bin/parser +17 -0
- package/dist/node_modules/@babel/traverse/package.json +1 -0
- package/dist/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/@hapi/topo/lib/index.js +1 -0
- package/dist/node_modules/@hapi/topo/package.json +1 -0
- package/dist/server/services/cloud-libraries-service.js +36 -1
- package/package.json +13 -9
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _t = require("@babel/types");
|
|
8
|
+
var _t2 = _t;
|
|
9
|
+
const {
|
|
10
|
+
react
|
|
11
|
+
} = _t;
|
|
12
|
+
const {
|
|
13
|
+
cloneNode,
|
|
14
|
+
jsxExpressionContainer,
|
|
15
|
+
variableDeclaration,
|
|
16
|
+
variableDeclarator
|
|
17
|
+
} = _t2;
|
|
18
|
+
const referenceVisitor = {
|
|
19
|
+
ReferencedIdentifier(path, state) {
|
|
20
|
+
if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (path.node.name === "this") {
|
|
24
|
+
let scope = path.scope;
|
|
25
|
+
do {
|
|
26
|
+
if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
} while (scope = scope.parent);
|
|
30
|
+
if (scope) state.breakOnScopePaths.push(scope.path);
|
|
31
|
+
}
|
|
32
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
33
|
+
if (!binding) return;
|
|
34
|
+
for (const violation of binding.constantViolations) {
|
|
35
|
+
if (violation.scope !== binding.path.scope) {
|
|
36
|
+
state.mutableBinding = true;
|
|
37
|
+
path.stop();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (binding !== state.scope.getBinding(path.node.name)) return;
|
|
42
|
+
state.bindings[path.node.name] = binding;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
class PathHoister {
|
|
46
|
+
constructor(path, scope) {
|
|
47
|
+
this.breakOnScopePaths = void 0;
|
|
48
|
+
this.bindings = void 0;
|
|
49
|
+
this.mutableBinding = void 0;
|
|
50
|
+
this.scopes = void 0;
|
|
51
|
+
this.scope = void 0;
|
|
52
|
+
this.path = void 0;
|
|
53
|
+
this.attachAfter = void 0;
|
|
54
|
+
this.breakOnScopePaths = [];
|
|
55
|
+
this.bindings = {};
|
|
56
|
+
this.mutableBinding = false;
|
|
57
|
+
this.scopes = [];
|
|
58
|
+
this.scope = scope;
|
|
59
|
+
this.path = path;
|
|
60
|
+
this.attachAfter = false;
|
|
61
|
+
}
|
|
62
|
+
isCompatibleScope(scope) {
|
|
63
|
+
for (const key of Object.keys(this.bindings)) {
|
|
64
|
+
const binding = this.bindings[key];
|
|
65
|
+
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
getCompatibleScopes() {
|
|
72
|
+
let scope = this.path.scope;
|
|
73
|
+
do {
|
|
74
|
+
if (this.isCompatibleScope(scope)) {
|
|
75
|
+
this.scopes.push(scope);
|
|
76
|
+
} else {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (this.breakOnScopePaths.includes(scope.path)) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
} while (scope = scope.parent);
|
|
83
|
+
}
|
|
84
|
+
getAttachmentPath() {
|
|
85
|
+
let path = this._getAttachmentPath();
|
|
86
|
+
if (!path) return;
|
|
87
|
+
let targetScope = path.scope;
|
|
88
|
+
if (targetScope.path === path) {
|
|
89
|
+
targetScope = path.scope.parent;
|
|
90
|
+
}
|
|
91
|
+
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
|
92
|
+
for (const name of Object.keys(this.bindings)) {
|
|
93
|
+
if (!targetScope.hasOwnBinding(name)) continue;
|
|
94
|
+
const binding = this.bindings[name];
|
|
95
|
+
if (binding.kind === "param" || binding.path.parentKey === "params") {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const bindingParentPath = this.getAttachmentParentForPath(binding.path);
|
|
99
|
+
if (bindingParentPath.key >= path.key) {
|
|
100
|
+
this.attachAfter = true;
|
|
101
|
+
path = binding.path;
|
|
102
|
+
for (const violationPath of binding.constantViolations) {
|
|
103
|
+
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
|
104
|
+
path = violationPath;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return path;
|
|
111
|
+
}
|
|
112
|
+
_getAttachmentPath() {
|
|
113
|
+
const scopes = this.scopes;
|
|
114
|
+
const scope = scopes.pop();
|
|
115
|
+
if (!scope) return;
|
|
116
|
+
if (scope.path.isFunction()) {
|
|
117
|
+
if (this.hasOwnParamBindings(scope)) {
|
|
118
|
+
if (this.scope === scope) return;
|
|
119
|
+
const bodies = scope.path.get("body").get("body");
|
|
120
|
+
for (let i = 0; i < bodies.length; i++) {
|
|
121
|
+
if (bodies[i].node._blockHoist) continue;
|
|
122
|
+
return bodies[i];
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
return this.getNextScopeAttachmentParent();
|
|
126
|
+
}
|
|
127
|
+
} else if (scope.path.isProgram()) {
|
|
128
|
+
return this.getNextScopeAttachmentParent();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
getNextScopeAttachmentParent() {
|
|
132
|
+
const scope = this.scopes.pop();
|
|
133
|
+
if (scope) return this.getAttachmentParentForPath(scope.path);
|
|
134
|
+
}
|
|
135
|
+
getAttachmentParentForPath(path) {
|
|
136
|
+
do {
|
|
137
|
+
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
|
138
|
+
return path;
|
|
139
|
+
}
|
|
140
|
+
} while (path = path.parentPath);
|
|
141
|
+
}
|
|
142
|
+
hasOwnParamBindings(scope) {
|
|
143
|
+
for (const name of Object.keys(this.bindings)) {
|
|
144
|
+
if (!scope.hasOwnBinding(name)) continue;
|
|
145
|
+
const binding = this.bindings[name];
|
|
146
|
+
if (binding.kind === "param" && binding.constant) return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
run() {
|
|
151
|
+
this.path.traverse(referenceVisitor, this);
|
|
152
|
+
if (this.mutableBinding) return;
|
|
153
|
+
this.getCompatibleScopes();
|
|
154
|
+
const attachTo = this.getAttachmentPath();
|
|
155
|
+
if (!attachTo) return;
|
|
156
|
+
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
|
157
|
+
let uid = attachTo.scope.generateUidIdentifier("ref");
|
|
158
|
+
const declarator = variableDeclarator(uid, this.path.node);
|
|
159
|
+
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
|
160
|
+
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
|
|
161
|
+
const parent = this.path.parentPath;
|
|
162
|
+
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
|
163
|
+
uid = jsxExpressionContainer(uid);
|
|
164
|
+
}
|
|
165
|
+
this.path.replaceWith(cloneNode(uid));
|
|
166
|
+
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.default = PathHoister;
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=hoister.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hooks = void 0;
|
|
7
|
+
const hooks = exports.hooks = [function (self, parent) {
|
|
8
|
+
const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
|
|
9
|
+
if (removeParent) {
|
|
10
|
+
parent.remove();
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}, function (self, parent) {
|
|
14
|
+
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
|
15
|
+
parent.replaceWith(parent.node.expressions[0]);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}, function (self, parent) {
|
|
19
|
+
if (parent.isBinary()) {
|
|
20
|
+
if (self.key === "left") {
|
|
21
|
+
parent.replaceWith(parent.node.right);
|
|
22
|
+
} else {
|
|
23
|
+
parent.replaceWith(parent.node.left);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}, function (self, parent) {
|
|
28
|
+
if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
|
29
|
+
self.replaceWith({
|
|
30
|
+
type: "BlockStatement",
|
|
31
|
+
body: []
|
|
32
|
+
});
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}];
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=removal-hooks.js.map
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isBindingIdentifier = isBindingIdentifier;
|
|
7
|
+
exports.isBlockScoped = isBlockScoped;
|
|
8
|
+
exports.isExpression = isExpression;
|
|
9
|
+
exports.isFlow = isFlow;
|
|
10
|
+
exports.isForAwaitStatement = isForAwaitStatement;
|
|
11
|
+
exports.isGenerated = isGenerated;
|
|
12
|
+
exports.isPure = isPure;
|
|
13
|
+
exports.isReferenced = isReferenced;
|
|
14
|
+
exports.isReferencedIdentifier = isReferencedIdentifier;
|
|
15
|
+
exports.isReferencedMemberExpression = isReferencedMemberExpression;
|
|
16
|
+
exports.isRestProperty = isRestProperty;
|
|
17
|
+
exports.isScope = isScope;
|
|
18
|
+
exports.isSpreadProperty = isSpreadProperty;
|
|
19
|
+
exports.isStatement = isStatement;
|
|
20
|
+
exports.isUser = isUser;
|
|
21
|
+
exports.isVar = isVar;
|
|
22
|
+
var _t = require("@babel/types");
|
|
23
|
+
const {
|
|
24
|
+
isBinding,
|
|
25
|
+
isBlockScoped: nodeIsBlockScoped,
|
|
26
|
+
isExportDeclaration,
|
|
27
|
+
isExpression: nodeIsExpression,
|
|
28
|
+
isFlow: nodeIsFlow,
|
|
29
|
+
isForStatement,
|
|
30
|
+
isForXStatement,
|
|
31
|
+
isIdentifier,
|
|
32
|
+
isImportDeclaration,
|
|
33
|
+
isImportSpecifier,
|
|
34
|
+
isJSXIdentifier,
|
|
35
|
+
isJSXMemberExpression,
|
|
36
|
+
isMemberExpression,
|
|
37
|
+
isRestElement: nodeIsRestElement,
|
|
38
|
+
isReferenced: nodeIsReferenced,
|
|
39
|
+
isScope: nodeIsScope,
|
|
40
|
+
isStatement: nodeIsStatement,
|
|
41
|
+
isVar: nodeIsVar,
|
|
42
|
+
isVariableDeclaration,
|
|
43
|
+
react,
|
|
44
|
+
isForOfStatement
|
|
45
|
+
} = _t;
|
|
46
|
+
const {
|
|
47
|
+
isCompatTag
|
|
48
|
+
} = react;
|
|
49
|
+
function isReferencedIdentifier(opts) {
|
|
50
|
+
const {
|
|
51
|
+
node,
|
|
52
|
+
parent
|
|
53
|
+
} = this;
|
|
54
|
+
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
|
55
|
+
if (isJSXIdentifier(node, opts)) {
|
|
56
|
+
if (isCompatTag(node.name)) return false;
|
|
57
|
+
} else {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
|
62
|
+
}
|
|
63
|
+
function isReferencedMemberExpression() {
|
|
64
|
+
const {
|
|
65
|
+
node,
|
|
66
|
+
parent
|
|
67
|
+
} = this;
|
|
68
|
+
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
|
69
|
+
}
|
|
70
|
+
function isBindingIdentifier() {
|
|
71
|
+
const {
|
|
72
|
+
node,
|
|
73
|
+
parent
|
|
74
|
+
} = this;
|
|
75
|
+
const grandparent = this.parentPath.parent;
|
|
76
|
+
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
|
77
|
+
}
|
|
78
|
+
function isStatement() {
|
|
79
|
+
const {
|
|
80
|
+
node,
|
|
81
|
+
parent
|
|
82
|
+
} = this;
|
|
83
|
+
if (nodeIsStatement(node)) {
|
|
84
|
+
if (isVariableDeclaration(node)) {
|
|
85
|
+
if (isForXStatement(parent, {
|
|
86
|
+
left: node
|
|
87
|
+
})) return false;
|
|
88
|
+
if (isForStatement(parent, {
|
|
89
|
+
init: node
|
|
90
|
+
})) return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
} else {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isExpression() {
|
|
98
|
+
if (this.isIdentifier()) {
|
|
99
|
+
return this.isReferencedIdentifier();
|
|
100
|
+
} else {
|
|
101
|
+
return nodeIsExpression(this.node);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isScope() {
|
|
105
|
+
return nodeIsScope(this.node, this.parent);
|
|
106
|
+
}
|
|
107
|
+
function isReferenced() {
|
|
108
|
+
return nodeIsReferenced(this.node, this.parent);
|
|
109
|
+
}
|
|
110
|
+
function isBlockScoped() {
|
|
111
|
+
return nodeIsBlockScoped(this.node);
|
|
112
|
+
}
|
|
113
|
+
function isVar() {
|
|
114
|
+
return nodeIsVar(this.node);
|
|
115
|
+
}
|
|
116
|
+
function isUser() {
|
|
117
|
+
return this.node && !!this.node.loc;
|
|
118
|
+
}
|
|
119
|
+
function isGenerated() {
|
|
120
|
+
return !this.isUser();
|
|
121
|
+
}
|
|
122
|
+
function isPure(constantsOnly) {
|
|
123
|
+
return this.scope.isPure(this.node, constantsOnly);
|
|
124
|
+
}
|
|
125
|
+
function isFlow() {
|
|
126
|
+
const {
|
|
127
|
+
node
|
|
128
|
+
} = this;
|
|
129
|
+
if (nodeIsFlow(node)) {
|
|
130
|
+
return true;
|
|
131
|
+
} else if (isImportDeclaration(node)) {
|
|
132
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
|
133
|
+
} else if (isExportDeclaration(node)) {
|
|
134
|
+
return node.exportKind === "type";
|
|
135
|
+
} else if (isImportSpecifier(node)) {
|
|
136
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
|
137
|
+
} else {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function isRestProperty() {
|
|
142
|
+
var _this$parentPath;
|
|
143
|
+
return nodeIsRestElement(this.node) && ((_this$parentPath = this.parentPath) == null ? void 0 : _this$parentPath.isObjectPattern());
|
|
144
|
+
}
|
|
145
|
+
function isSpreadProperty() {
|
|
146
|
+
var _this$parentPath2;
|
|
147
|
+
return nodeIsRestElement(this.node) && ((_this$parentPath2 = this.parentPath) == null ? void 0 : _this$parentPath2.isObjectExpression());
|
|
148
|
+
}
|
|
149
|
+
function isForAwaitStatement() {
|
|
150
|
+
return isForOfStatement(this.node, {
|
|
151
|
+
await: true
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
{
|
|
155
|
+
exports.isExistentialTypeParam = function isExistentialTypeParam() {
|
|
156
|
+
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
|
|
157
|
+
};
|
|
158
|
+
exports.isNumericLiteralTypeAnnotation = function isNumericLiteralTypeAnnotation() {
|
|
159
|
+
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=virtual-types-validator.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
|
|
7
|
+
const ReferencedIdentifier = exports.ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
|
|
8
|
+
const ReferencedMemberExpression = exports.ReferencedMemberExpression = ["MemberExpression"];
|
|
9
|
+
const BindingIdentifier = exports.BindingIdentifier = ["Identifier"];
|
|
10
|
+
const Statement = exports.Statement = ["Statement"];
|
|
11
|
+
const Expression = exports.Expression = ["Expression"];
|
|
12
|
+
const Scope = exports.Scope = ["Scopable", "Pattern"];
|
|
13
|
+
const Referenced = exports.Referenced = null;
|
|
14
|
+
const BlockScoped = exports.BlockScoped = null;
|
|
15
|
+
const Var = exports.Var = ["VariableDeclaration"];
|
|
16
|
+
const User = exports.User = null;
|
|
17
|
+
const Generated = exports.Generated = null;
|
|
18
|
+
const Pure = exports.Pure = null;
|
|
19
|
+
const Flow = exports.Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
|
|
20
|
+
const RestProperty = exports.RestProperty = ["RestElement"];
|
|
21
|
+
const SpreadProperty = exports.SpreadProperty = ["RestElement"];
|
|
22
|
+
const ExistentialTypeParam = exports.ExistentialTypeParam = ["ExistsTypeAnnotation"];
|
|
23
|
+
const NumericLiteralTypeAnnotation = exports.NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
|
|
24
|
+
const ForAwaitStatement = exports.ForAwaitStatement = ["ForOfStatement"];
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=virtual-types.js.map
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports._containerInsert = _containerInsert;
|
|
7
|
+
exports._containerInsertAfter = _containerInsertAfter;
|
|
8
|
+
exports._containerInsertBefore = _containerInsertBefore;
|
|
9
|
+
exports._verifyNodeList = _verifyNodeList;
|
|
10
|
+
exports.insertAfter = insertAfter;
|
|
11
|
+
exports.insertBefore = insertBefore;
|
|
12
|
+
exports.pushContainer = pushContainer;
|
|
13
|
+
exports.unshiftContainer = unshiftContainer;
|
|
14
|
+
exports.updateSiblingKeys = updateSiblingKeys;
|
|
15
|
+
var _cache = require("../cache.js");
|
|
16
|
+
var _hoister = require("./lib/hoister.js");
|
|
17
|
+
var _index = require("./index.js");
|
|
18
|
+
var _context = require("./context.js");
|
|
19
|
+
var _removal = require("./removal.js");
|
|
20
|
+
var _t = require("@babel/types");
|
|
21
|
+
const {
|
|
22
|
+
arrowFunctionExpression,
|
|
23
|
+
assertExpression,
|
|
24
|
+
assignmentExpression,
|
|
25
|
+
blockStatement,
|
|
26
|
+
callExpression,
|
|
27
|
+
cloneNode,
|
|
28
|
+
expressionStatement,
|
|
29
|
+
isAssignmentExpression,
|
|
30
|
+
isCallExpression,
|
|
31
|
+
isExportNamedDeclaration,
|
|
32
|
+
isExpression,
|
|
33
|
+
isIdentifier,
|
|
34
|
+
isSequenceExpression,
|
|
35
|
+
isSuper,
|
|
36
|
+
thisExpression
|
|
37
|
+
} = _t;
|
|
38
|
+
function insertBefore(nodes_) {
|
|
39
|
+
_removal._assertUnremoved.call(this);
|
|
40
|
+
const nodes = _verifyNodeList.call(this, nodes_);
|
|
41
|
+
const {
|
|
42
|
+
parentPath,
|
|
43
|
+
parent
|
|
44
|
+
} = this;
|
|
45
|
+
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
|
46
|
+
return parentPath.insertBefore(nodes);
|
|
47
|
+
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
|
48
|
+
if (this.node) nodes.push(this.node);
|
|
49
|
+
return this.replaceExpressionWithStatements(nodes);
|
|
50
|
+
} else if (Array.isArray(this.container)) {
|
|
51
|
+
return _containerInsertBefore.call(this, nodes);
|
|
52
|
+
} else if (this.isStatementOrBlock()) {
|
|
53
|
+
const node = this.node;
|
|
54
|
+
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
|
55
|
+
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
|
|
56
|
+
return this.unshiftContainer("body", nodes);
|
|
57
|
+
} else {
|
|
58
|
+
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?");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function _containerInsert(from, nodes) {
|
|
62
|
+
updateSiblingKeys.call(this, from, nodes.length);
|
|
63
|
+
const paths = [];
|
|
64
|
+
this.container.splice(from, 0, ...nodes);
|
|
65
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
66
|
+
var _this$context;
|
|
67
|
+
const to = from + i;
|
|
68
|
+
const path = this.getSibling(to);
|
|
69
|
+
paths.push(path);
|
|
70
|
+
if ((_this$context = this.context) != null && _this$context.queue) {
|
|
71
|
+
_context.pushContext.call(path, this.context);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const contexts = _context._getQueueContexts.call(this);
|
|
75
|
+
for (const path of paths) {
|
|
76
|
+
_context.setScope.call(path);
|
|
77
|
+
path.debug("Inserted.");
|
|
78
|
+
for (const context of contexts) {
|
|
79
|
+
context.maybeQueue(path, true);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return paths;
|
|
83
|
+
}
|
|
84
|
+
function _containerInsertBefore(nodes) {
|
|
85
|
+
return _containerInsert.call(this, this.key, nodes);
|
|
86
|
+
}
|
|
87
|
+
function _containerInsertAfter(nodes) {
|
|
88
|
+
return _containerInsert.call(this, this.key + 1, nodes);
|
|
89
|
+
}
|
|
90
|
+
const last = arr => arr[arr.length - 1];
|
|
91
|
+
function isHiddenInSequenceExpression(path) {
|
|
92
|
+
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
|
|
93
|
+
}
|
|
94
|
+
function isAlmostConstantAssignment(node, scope) {
|
|
95
|
+
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const blockScope = scope.getBlockParent();
|
|
99
|
+
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
|
|
100
|
+
}
|
|
101
|
+
function insertAfter(nodes_) {
|
|
102
|
+
_removal._assertUnremoved.call(this);
|
|
103
|
+
if (this.isSequenceExpression()) {
|
|
104
|
+
return last(this.get("expressions")).insertAfter(nodes_);
|
|
105
|
+
}
|
|
106
|
+
const nodes = _verifyNodeList.call(this, nodes_);
|
|
107
|
+
const {
|
|
108
|
+
parentPath,
|
|
109
|
+
parent
|
|
110
|
+
} = this;
|
|
111
|
+
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
|
112
|
+
return parentPath.insertAfter(nodes.map(node => {
|
|
113
|
+
return isExpression(node) ? expressionStatement(node) : node;
|
|
114
|
+
}));
|
|
115
|
+
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
|
116
|
+
const self = this;
|
|
117
|
+
if (self.node) {
|
|
118
|
+
const node = self.node;
|
|
119
|
+
let {
|
|
120
|
+
scope
|
|
121
|
+
} = this;
|
|
122
|
+
if (scope.path.isPattern()) {
|
|
123
|
+
assertExpression(node);
|
|
124
|
+
self.replaceWith(callExpression(arrowFunctionExpression([], node), []));
|
|
125
|
+
self.get("callee.body").insertAfter(nodes);
|
|
126
|
+
return [self];
|
|
127
|
+
}
|
|
128
|
+
if (isHiddenInSequenceExpression(self)) {
|
|
129
|
+
nodes.unshift(node);
|
|
130
|
+
} else if (isCallExpression(node) && isSuper(node.callee)) {
|
|
131
|
+
nodes.unshift(node);
|
|
132
|
+
nodes.push(thisExpression());
|
|
133
|
+
} else if (isAlmostConstantAssignment(node, scope)) {
|
|
134
|
+
nodes.unshift(node);
|
|
135
|
+
nodes.push(cloneNode(node.left));
|
|
136
|
+
} else if (scope.isPure(node, true)) {
|
|
137
|
+
nodes.push(node);
|
|
138
|
+
} else {
|
|
139
|
+
if (parentPath.isMethod({
|
|
140
|
+
computed: true,
|
|
141
|
+
key: node
|
|
142
|
+
})) {
|
|
143
|
+
scope = scope.parent;
|
|
144
|
+
}
|
|
145
|
+
const temp = scope.generateDeclaredUidIdentifier();
|
|
146
|
+
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
|
|
147
|
+
nodes.push(expressionStatement(cloneNode(temp)));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return this.replaceExpressionWithStatements(nodes);
|
|
151
|
+
} else if (Array.isArray(this.container)) {
|
|
152
|
+
return _containerInsertAfter.call(this, nodes);
|
|
153
|
+
} else if (this.isStatementOrBlock()) {
|
|
154
|
+
const node = this.node;
|
|
155
|
+
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
|
156
|
+
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
|
|
157
|
+
return this.pushContainer("body", nodes);
|
|
158
|
+
} else {
|
|
159
|
+
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?");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function updateSiblingKeys(fromIndex, incrementBy) {
|
|
163
|
+
if (!this.parent) return;
|
|
164
|
+
const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || [];
|
|
165
|
+
for (const [, path] of paths) {
|
|
166
|
+
if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) {
|
|
167
|
+
path.key += incrementBy;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function _verifyNodeList(nodes) {
|
|
172
|
+
if (!nodes) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
if (!Array.isArray(nodes)) {
|
|
176
|
+
nodes = [nodes];
|
|
177
|
+
}
|
|
178
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
179
|
+
const node = nodes[i];
|
|
180
|
+
let msg;
|
|
181
|
+
if (!node) {
|
|
182
|
+
msg = "has falsy node";
|
|
183
|
+
} else if (typeof node !== "object") {
|
|
184
|
+
msg = "contains a non-object node";
|
|
185
|
+
} else if (!node.type) {
|
|
186
|
+
msg = "without a type";
|
|
187
|
+
} else if (node instanceof _index.default) {
|
|
188
|
+
msg = "has a NodePath when it expected a raw object";
|
|
189
|
+
}
|
|
190
|
+
if (msg) {
|
|
191
|
+
const type = Array.isArray(node) ? "array" : typeof node;
|
|
192
|
+
throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return nodes;
|
|
196
|
+
}
|
|
197
|
+
function unshiftContainer(listKey, nodes) {
|
|
198
|
+
_removal._assertUnremoved.call(this);
|
|
199
|
+
nodes = _verifyNodeList.call(this, nodes);
|
|
200
|
+
const path = _index.default.get({
|
|
201
|
+
parentPath: this,
|
|
202
|
+
parent: this.node,
|
|
203
|
+
container: this.node[listKey],
|
|
204
|
+
listKey,
|
|
205
|
+
key: 0
|
|
206
|
+
}).setContext(this.context);
|
|
207
|
+
return _containerInsertBefore.call(path, nodes);
|
|
208
|
+
}
|
|
209
|
+
function pushContainer(listKey, nodes) {
|
|
210
|
+
_removal._assertUnremoved.call(this);
|
|
211
|
+
const verifiedNodes = _verifyNodeList.call(this, nodes);
|
|
212
|
+
const container = this.node[listKey];
|
|
213
|
+
const path = _index.default.get({
|
|
214
|
+
parentPath: this,
|
|
215
|
+
parent: this.node,
|
|
216
|
+
container: container,
|
|
217
|
+
listKey,
|
|
218
|
+
key: container.length
|
|
219
|
+
}).setContext(this.context);
|
|
220
|
+
return path.replaceWithMultiple(verifiedNodes);
|
|
221
|
+
}
|
|
222
|
+
{
|
|
223
|
+
exports.hoist = function hoist(scope = this.scope) {
|
|
224
|
+
const hoister = new _hoister.default(this, scope);
|
|
225
|
+
return hoister.run();
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=modification.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports._assertUnremoved = _assertUnremoved;
|
|
7
|
+
exports._callRemovalHooks = _callRemovalHooks;
|
|
8
|
+
exports._markRemoved = _markRemoved;
|
|
9
|
+
exports._remove = _remove;
|
|
10
|
+
exports._removeFromScope = _removeFromScope;
|
|
11
|
+
exports.remove = remove;
|
|
12
|
+
var _removalHooks = require("./lib/removal-hooks.js");
|
|
13
|
+
var _cache = require("../cache.js");
|
|
14
|
+
var _replacement = require("./replacement.js");
|
|
15
|
+
var _index = require("./index.js");
|
|
16
|
+
var _t = require("@babel/types");
|
|
17
|
+
var _modification = require("./modification.js");
|
|
18
|
+
var _context = require("./context.js");
|
|
19
|
+
const {
|
|
20
|
+
getBindingIdentifiers
|
|
21
|
+
} = _t;
|
|
22
|
+
function remove() {
|
|
23
|
+
var _this$opts;
|
|
24
|
+
_assertUnremoved.call(this);
|
|
25
|
+
_context.resync.call(this);
|
|
26
|
+
if (_callRemovalHooks.call(this)) {
|
|
27
|
+
_markRemoved.call(this);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
|
|
31
|
+
_removeFromScope.call(this);
|
|
32
|
+
}
|
|
33
|
+
this.shareCommentsWithSiblings();
|
|
34
|
+
_remove.call(this);
|
|
35
|
+
_markRemoved.call(this);
|
|
36
|
+
}
|
|
37
|
+
function _removeFromScope() {
|
|
38
|
+
const bindings = getBindingIdentifiers(this.node, false, false, true);
|
|
39
|
+
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
|
40
|
+
}
|
|
41
|
+
function _callRemovalHooks() {
|
|
42
|
+
if (this.parentPath) {
|
|
43
|
+
for (const fn of _removalHooks.hooks) {
|
|
44
|
+
if (fn(this, this.parentPath)) return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _remove() {
|
|
49
|
+
if (Array.isArray(this.container)) {
|
|
50
|
+
this.container.splice(this.key, 1);
|
|
51
|
+
_modification.updateSiblingKeys.call(this, this.key, -1);
|
|
52
|
+
} else {
|
|
53
|
+
_replacement._replaceWith.call(this, null);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function _markRemoved() {
|
|
57
|
+
this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
|
|
58
|
+
if (this.parent) {
|
|
59
|
+
(0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node);
|
|
60
|
+
}
|
|
61
|
+
this.node = null;
|
|
62
|
+
}
|
|
63
|
+
function _assertUnremoved() {
|
|
64
|
+
if (this.removed) {
|
|
65
|
+
throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=removal.js.map
|