123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- export default function getMembers(path, includeRoot = false) {
- const result = [];
- let argumentPaths = [];
- let resultPath = path;
-
- while (true) {
- if (resultPath.isMemberExpression()) {
- const property = resultPath.get('property');
- result.push({
- path: property,
- computed: resultPath.node.computed,
- argumentPaths,
- });
- argumentPaths = [];
- resultPath = resultPath.get('object');
- }
- else if (resultPath.isCallExpression()) {
- const callee = resultPath.get('callee');
- if (callee.isExpression()) {
- argumentPaths = resultPath.get('arguments');
- resultPath = callee;
- }
- else {
- break;
- }
- }
- else {
- break;
- }
- }
- if (includeRoot && result.length > 0) {
- result.push({
- path: resultPath,
- computed: false,
- argumentPaths,
- });
- }
- return result.reverse();
- }
|