()
| 106 | } |
| 107 | |
| 108 | function 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 | |
| 150 | function getFunctionMapVisitor( |
| 151 | context: ?Context, |
nothing calls this directly
no test coverage detected
searching dependent graphs…