1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = bindifyDecorators;
|
7 |
|
8 | var t = _interopRequireWildcard(require("@babel/types"));
|
9 |
|
10 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
11 |
|
12 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
13 |
|
14 | function bindifyDecorators(decorators) {
|
15 | for (const decoratorPath of decorators) {
|
16 | const decorator = decoratorPath.node;
|
17 | const expression = decorator.expression;
|
18 | if (!t.isMemberExpression(expression)) continue;
|
19 | const temp = decoratorPath.scope.maybeGenerateMemoised(expression.object);
|
20 | let ref;
|
21 | const nodes = [];
|
22 |
|
23 | if (temp) {
|
24 | ref = temp;
|
25 | nodes.push(t.assignmentExpression("=", temp, expression.object));
|
26 | } else {
|
27 | ref = expression.object;
|
28 | }
|
29 |
|
30 | nodes.push(t.callExpression(t.memberExpression(t.memberExpression(ref, expression.property, expression.computed), t.identifier("bind")), [ref]));
|
31 |
|
32 | if (nodes.length === 1) {
|
33 | decorator.expression = nodes[0];
|
34 | } else {
|
35 | decorator.expression = t.sequenceExpression(nodes);
|
36 | }
|
37 | }
|
38 | } |
\ | No newline at end of file |