| 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 |
nothing calls this directly
no test coverage detected