source: trip-planner-front/node_modules/@babel/helper-explode-assignable-expression/lib/index.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = _default;
7
8var _t = require("@babel/types");
9
10const {
11 assignmentExpression,
12 cloneNode,
13 isIdentifier,
14 isLiteral,
15 isMemberExpression,
16 isPrivateName,
17 isPureish,
18 isSuper,
19 memberExpression,
20 toComputedKey
21} = _t;
22
23function getObjRef(node, nodes, scope) {
24 let ref;
25
26 if (isIdentifier(node)) {
27 if (scope.hasBinding(node.name)) {
28 return node;
29 } else {
30 ref = node;
31 }
32 } else if (isMemberExpression(node)) {
33 ref = node.object;
34
35 if (isSuper(ref) || isIdentifier(ref) && scope.hasBinding(ref.name)) {
36 return ref;
37 }
38 } else {
39 throw new Error(`We can't explode this node type ${node["type"]}`);
40 }
41
42 const temp = scope.generateUidIdentifierBasedOnNode(ref);
43 scope.push({
44 id: temp
45 });
46 nodes.push(assignmentExpression("=", cloneNode(temp), cloneNode(ref)));
47 return temp;
48}
49
50function getPropRef(node, nodes, scope) {
51 const prop = node.property;
52
53 if (isPrivateName(prop)) {
54 throw new Error("We can't generate property ref for private name, please install `@babel/plugin-proposal-class-properties`");
55 }
56
57 const key = toComputedKey(node, prop);
58 if (isLiteral(key) && isPureish(key)) return key;
59 const temp = scope.generateUidIdentifierBasedOnNode(prop);
60 scope.push({
61 id: temp
62 });
63 nodes.push(assignmentExpression("=", cloneNode(temp), cloneNode(prop)));
64 return temp;
65}
66
67function _default(node, nodes, file, scope, allowedSingleIdent) {
68 let obj;
69
70 if (isIdentifier(node) && allowedSingleIdent) {
71 obj = node;
72 } else {
73 obj = getObjRef(node, nodes, scope);
74 }
75
76 let ref, uid;
77
78 if (isIdentifier(node)) {
79 ref = cloneNode(node);
80 uid = obj;
81 } else {
82 const prop = getPropRef(node, nodes, scope);
83 const computed = node.computed || isLiteral(prop);
84 uid = memberExpression(cloneNode(obj), cloneNode(prop), computed);
85 ref = memberExpression(cloneNode(obj), cloneNode(prop), computed);
86 }
87
88 return {
89 uid: uid,
90 ref: ref
91 };
92}
Note: See TracBrowser for help on using the repository browser.