MCPcopy
hub / github.com/BuilderIO/mitosis / replaceRefsInString

Function replaceRefsInString

packages/core/src/helpers/map-refs.ts:20–38  ·  view source on GitHub ↗
(code: string, refs: string[], mapper: RefMapper, type?: CodeType)

Source from the content-addressed store, hash-verified

18) => string;
19
20const 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
40export const mapRefs = (component: MitosisComponent, mapper: RefMapper): void => {
41 const refSet = getRefs(component);

Callers 1

mapRefsFunction · 0.85

Calls 1

babelTransformExpressionFunction · 0.90

Tested by

no test coverage detected