index.js
1.19 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
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = function (_ref) {
var Plugin = _ref.Plugin;
var immutabilityVisitor = {
enter: function enter(node, parent, scope, state) {
var _this = this;
var stop = function stop() {
state.isImmutable = false;
_this.stop();
};
if (this.isJSXClosingElement()) {
this.skip();
return;
}
if (this.isJSXIdentifier({ name: "ref" }) && this.parentPath.isJSXAttribute({ name: node })) {
return stop();
}
if (this.isJSXIdentifier() || this.isIdentifier() || this.isJSXMemberExpression()) {
return;
}
if (!this.isImmutable()) stop();
}
};
return new Plugin("react-constant-elements", {
metadata: {
group: "builtin-basic"
},
visitor: {
JSXElement: function JSXElement(node) {
if (node._hoisted) return;
var state = { isImmutable: true };
this.traverse(immutabilityVisitor, state);
if (state.isImmutable) {
this.hoist();
} else {
node._hoisted = true;
}
}
}
});
};
module.exports = exports["default"];