in src/utils/expressionTo.ts [12:79]
function toArray(path: NodePath, importer: Importer): string[] {
const parts = [path];
let result: string[] = [];
while (parts.length > 0) {
path = parts.shift() as NodePath;
const node = path.node;
if (t.CallExpression.check(node)) {
parts.push(path.get('callee'));
continue;
} else if (t.MemberExpression.check(node)) {
parts.push(path.get('object'));
if (node.computed) {
const resolvedPath = resolveToValue(path.get('property'), importer);
if (resolvedPath !== undefined) {
result = result.concat(toArray(resolvedPath, importer));
} else {
result.push('<computed>');
}
} else {
// @ts-ignore
result.push(node.property.name);
}
continue;
} else if (t.Identifier.check(node)) {
result.push(node.name);
continue;
} else if (t.Literal.check(node)) {
// @ts-ignore
result.push(node.raw);
continue;
} else if (t.FunctionExpression.check(node)) {
result.push('<function>');
continue;
} else if (t.ThisExpression.check(node)) {
result.push('this');
continue;
} else if (t.ObjectExpression.check(node)) {
const properties = path.get('properties').map(function (property) {
if (t.SpreadElement.check(property.node)) {
return `...${toString(property.get('argument'), importer)}`;
} else {
return (
toString(property.get('key'), importer) +
': ' +
toString(property.get('value'), importer)
);
}
});
result.push('{' + properties.join(', ') + '}');
continue;
} else if (t.ArrayExpression.check(node)) {
result.push(
'[' +
path
.get('elements')
.map(function (el) {
return toString(el, importer);
})
.join(', ') +
']',
);
continue;
}
}
return result.reverse();
}