MCPcopy Index your code
hub / github.com/react/metro / functionMapBabelPlugin

Function functionMapBabelPlugin

packages/metro-source-map/src/generateFunctionMap.js:108–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106}
107
108function functionMapBabelPlugin(): PluginObj<> {
109 return {
110 // Eagerly traverse the tree on `pre`, before any visitors have run, so
111 // that regardless of plugin order we're dealing with the AST before any
112 // mutations.
113 visitor: {},
114 pre: ({path, metadata, opts}) => {
115 const {filename} = nullthrows(opts);
116 const encoder = new MappingEncoder();
117 const visitor = getFunctionMapVisitor({filename}, mapping =>
118 encoder.push(mapping),
119 );
120 invariant(
121 path && t.isProgram(path.node),
122 'path missing or not a program node',
123 );
124 // $FlowFixMe[prop-missing] checked above
125 // $FlowFixMe[incompatible-type-arg] checked above
126 const programPath: NodePath<BabelNodeProgram> = path as $FlowFixMe;
127
128 visitor.enter(programPath);
129 programPath.traverse({
130 Function: visitor,
131 Class: visitor,
132 });
133 visitor.exit(programPath);
134
135 // $FlowFixMe[incompatible-type] Babel `File` is not generically typed
136 const metroMetadata: MetroBabelFileMetadata = metadata;
137
138 const functionMap = encoder.getResult();
139
140 // Set the result on a metadata property
141 if (!metroMetadata.metro) {
142 metroMetadata.metro = {functionMap};
143 } else {
144 metroMetadata.metro.functionMap = functionMap;
145 }
146 },
147 };
148}
149
150function getFunctionMapVisitor(
151 context: ?Context,

Callers

nothing calls this directly

Calls 4

pushMethod · 0.95
getResultMethod · 0.95
nullthrowsFunction · 0.85
getFunctionMapVisitorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…