[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = getBindingIdentifiers;
|
---|
| 7 |
|
---|
| 8 | var _generated = require("../validators/generated");
|
---|
| 9 |
|
---|
| 10 | function getBindingIdentifiers(node, duplicates, outerOnly) {
|
---|
| 11 | let search = [].concat(node);
|
---|
| 12 | const ids = Object.create(null);
|
---|
| 13 |
|
---|
| 14 | while (search.length) {
|
---|
| 15 | const id = search.shift();
|
---|
| 16 | if (!id) continue;
|
---|
| 17 | const keys = getBindingIdentifiers.keys[id.type];
|
---|
| 18 |
|
---|
| 19 | if ((0, _generated.isIdentifier)(id)) {
|
---|
| 20 | if (duplicates) {
|
---|
| 21 | const _ids = ids[id.name] = ids[id.name] || [];
|
---|
| 22 |
|
---|
| 23 | _ids.push(id);
|
---|
| 24 | } else {
|
---|
| 25 | ids[id.name] = id;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | continue;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | if ((0, _generated.isExportDeclaration)(id) && !(0, _generated.isExportAllDeclaration)(id)) {
|
---|
| 32 | if ((0, _generated.isDeclaration)(id.declaration)) {
|
---|
| 33 | search.push(id.declaration);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | continue;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | if (outerOnly) {
|
---|
| 40 | if ((0, _generated.isFunctionDeclaration)(id)) {
|
---|
| 41 | search.push(id.id);
|
---|
| 42 | continue;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | if ((0, _generated.isFunctionExpression)(id)) {
|
---|
| 46 | continue;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | if (keys) {
|
---|
| 51 | for (let i = 0; i < keys.length; i++) {
|
---|
| 52 | const key = keys[i];
|
---|
| 53 |
|
---|
| 54 | if (id[key]) {
|
---|
| 55 | search = search.concat(id[key]);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | return ids;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | getBindingIdentifiers.keys = {
|
---|
| 65 | DeclareClass: ["id"],
|
---|
| 66 | DeclareFunction: ["id"],
|
---|
| 67 | DeclareModule: ["id"],
|
---|
| 68 | DeclareVariable: ["id"],
|
---|
| 69 | DeclareInterface: ["id"],
|
---|
| 70 | DeclareTypeAlias: ["id"],
|
---|
| 71 | DeclareOpaqueType: ["id"],
|
---|
| 72 | InterfaceDeclaration: ["id"],
|
---|
| 73 | TypeAlias: ["id"],
|
---|
| 74 | OpaqueType: ["id"],
|
---|
| 75 | CatchClause: ["param"],
|
---|
| 76 | LabeledStatement: ["label"],
|
---|
| 77 | UnaryExpression: ["argument"],
|
---|
| 78 | AssignmentExpression: ["left"],
|
---|
| 79 | ImportSpecifier: ["local"],
|
---|
| 80 | ImportNamespaceSpecifier: ["local"],
|
---|
| 81 | ImportDefaultSpecifier: ["local"],
|
---|
| 82 | ImportDeclaration: ["specifiers"],
|
---|
| 83 | ExportSpecifier: ["exported"],
|
---|
| 84 | ExportNamespaceSpecifier: ["exported"],
|
---|
| 85 | ExportDefaultSpecifier: ["exported"],
|
---|
| 86 | FunctionDeclaration: ["id", "params"],
|
---|
| 87 | FunctionExpression: ["id", "params"],
|
---|
| 88 | ArrowFunctionExpression: ["params"],
|
---|
| 89 | ObjectMethod: ["params"],
|
---|
| 90 | ClassMethod: ["params"],
|
---|
| 91 | ClassPrivateMethod: ["params"],
|
---|
| 92 | ForInStatement: ["left"],
|
---|
| 93 | ForOfStatement: ["left"],
|
---|
| 94 | ClassDeclaration: ["id"],
|
---|
| 95 | ClassExpression: ["id"],
|
---|
| 96 | RestElement: ["argument"],
|
---|
| 97 | UpdateExpression: ["argument"],
|
---|
| 98 | ObjectProperty: ["value"],
|
---|
| 99 | AssignmentPattern: ["left"],
|
---|
| 100 | ArrayPattern: ["elements"],
|
---|
| 101 | ObjectPattern: ["properties"],
|
---|
| 102 | VariableDeclaration: ["declarations"],
|
---|
| 103 | VariableDeclarator: ["id"]
|
---|
| 104 | }; |
---|