1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.default = void 0;
|
---|
5 |
|
---|
6 | var _utils = require("../utils");
|
---|
7 |
|
---|
8 | var _default = callProvider => {
|
---|
9 | function property(object, key, placement, path) {
|
---|
10 | return callProvider({
|
---|
11 | kind: "property",
|
---|
12 | object,
|
---|
13 | key,
|
---|
14 | placement
|
---|
15 | }, path);
|
---|
16 | }
|
---|
17 |
|
---|
18 | return {
|
---|
19 | // Symbol(), new Promise
|
---|
20 | ReferencedIdentifier(path) {
|
---|
21 | const {
|
---|
22 | node: {
|
---|
23 | name
|
---|
24 | },
|
---|
25 | scope
|
---|
26 | } = path;
|
---|
27 | if (scope.getBindingIdentifier(name)) return;
|
---|
28 | callProvider({
|
---|
29 | kind: "global",
|
---|
30 | name
|
---|
31 | }, path);
|
---|
32 | },
|
---|
33 |
|
---|
34 | MemberExpression(path) {
|
---|
35 | const key = (0, _utils.resolveKey)(path.get("property"), path.node.computed);
|
---|
36 | if (!key || key === "prototype") return;
|
---|
37 | const object = path.get("object");
|
---|
38 | const binding = object.scope.getBinding(object.node.name);
|
---|
39 | if (binding && binding.path.isImportNamespaceSpecifier()) return;
|
---|
40 | const source = (0, _utils.resolveSource)(object);
|
---|
41 | return property(source.id, key, source.placement, path);
|
---|
42 | },
|
---|
43 |
|
---|
44 | ObjectPattern(path) {
|
---|
45 | const {
|
---|
46 | parentPath,
|
---|
47 | parent
|
---|
48 | } = path;
|
---|
49 | let obj; // const { keys, values } = Object
|
---|
50 |
|
---|
51 | if (parentPath.isVariableDeclarator()) {
|
---|
52 | obj = parentPath.get("init"); // ({ keys, values } = Object)
|
---|
53 | } else if (parentPath.isAssignmentExpression()) {
|
---|
54 | obj = parentPath.get("right"); // !function ({ keys, values }) {...} (Object)
|
---|
55 | // resolution does not work after properties transform :-(
|
---|
56 | } else if (parentPath.isFunction()) {
|
---|
57 | const grand = parentPath.parentPath;
|
---|
58 |
|
---|
59 | if (grand.isCallExpression() || grand.isNewExpression()) {
|
---|
60 | if (grand.node.callee === parent) {
|
---|
61 | obj = grand.get("arguments")[path.key];
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | let id = null;
|
---|
67 | let placement = null;
|
---|
68 | if (obj) ({
|
---|
69 | id,
|
---|
70 | placement
|
---|
71 | } = (0, _utils.resolveSource)(obj));
|
---|
72 |
|
---|
73 | for (const prop of path.get("properties")) {
|
---|
74 | if (prop.isObjectProperty()) {
|
---|
75 | const key = (0, _utils.resolveKey)(prop.get("key"));
|
---|
76 | if (key) property(id, key, placement, prop);
|
---|
77 | }
|
---|
78 | }
|
---|
79 | },
|
---|
80 |
|
---|
81 | BinaryExpression(path) {
|
---|
82 | if (path.node.operator !== "in") return;
|
---|
83 | const source = (0, _utils.resolveSource)(path.get("right"));
|
---|
84 | const key = (0, _utils.resolveKey)(path.get("left"), true);
|
---|
85 | if (!key) return;
|
---|
86 | callProvider({
|
---|
87 | kind: "in",
|
---|
88 | object: source.id,
|
---|
89 | key,
|
---|
90 | placement: source.placement
|
---|
91 | }, path);
|
---|
92 | }
|
---|
93 |
|
---|
94 | };
|
---|
95 | };
|
---|
96 |
|
---|
97 | exports.default = _default; |
---|