(code: string, refs: string[], mapper: RefMapper, type?: CodeType)
| 18 | ) => string; |
| 19 | |
| 20 | const replaceRefsInString = (code: string, refs: string[], mapper: RefMapper, type?: CodeType) => { |
| 21 | return babelTransformExpression(code, { |
| 22 | Identifier(path: NodePath<types.Identifier>) { |
| 23 | const name = path.node.name; |
| 24 | const isRef = refs.includes(name); |
| 25 | if (isRef && !path.node.extra?.replaced) { |
| 26 | path.replaceWith( |
| 27 | types.identifier( |
| 28 | mapper(name, { |
| 29 | type, |
| 30 | path, |
| 31 | }), |
| 32 | ), |
| 33 | ); |
| 34 | path.node.extra = { replaced: true }; |
| 35 | } |
| 36 | }, |
| 37 | }); |
| 38 | }; |
| 39 | |
| 40 | export const mapRefs = (component: MitosisComponent, mapper: RefMapper): void => { |
| 41 | const refSet = getRefs(component); |
no test coverage detected