in packages/metro/src/ModuleGraph/output/reverse-dependency-map-references.js [34:71]
CallExpression(path: NodePath<CallExpression>, state: State) {
const {node} = path;
if (node.callee.name === `${state.opts.globalPrefix}__d`) {
// $FlowFixMe Flow error uncovered by typing Babel more strictly
const lastArg = node.arguments[0].params.slice(-1)[0];
// $FlowFixMe Flow error uncovered by typing Babel more strictly
const depMapName: ?string = lastArg && lastArg.name;
if (depMapName == null) {
return;
}
const body = path.get('arguments.0.body');
invariant(
!Array.isArray(body),
'meetro: Expected `body` to be a single path.',
);
const scope = body.scope;
const binding = nullthrows(scope.getBinding(depMapName));
binding.referencePaths.forEach(({parentPath}) => {
const memberNode = parentPath?.node;
if (
memberNode != null &&
memberNode.type === 'MemberExpression' &&
memberNode.property.type === 'NumericLiteral'
) {
const numericLiteral = t.numericLiteral(
state.opts.dependencyIds[memberNode.property.value],
);
nullthrows(parentPath).replaceWith(numericLiteral);
}
});
}
},