MCPcopy Create free account
hub / github.com/dropbox/ts-transform-react-constant-elements / visitor

Function visitor

src/transform.ts:109–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107 hoistedVariables: ts.VariableStatement[]
108): ts.Visitor {
109 const visitor: ts.Visitor = node => {
110 if (isConstantElement(node)) {
111 const variable = ts.createUniqueName("hoisted_constant_element");
112 const statement = ts.createVariableStatement(
113 undefined,
114 ts.createVariableDeclarationList([
115 ts.createVariableDeclaration(variable, undefined, node)
116 ])
117 );
118 // Store the variable assignement to hoist later
119 hoistedVariables.push(statement);
120
121 // Replace <foo /> with {hoisted_constant_element_1}
122 // TODO: Figure out case like `return <foo />
123 return ts.createJsxExpression(undefined, variable);
124 }
125 return ts.visitEachChild(node, visitor, ctx);
126 };
127 return visitor;
128}
129

Callers

nothing calls this directly

Calls 1

isConstantElementFunction · 0.85

Tested by

no test coverage detected