MCPcopy Create free account
hub / github.com/Snapchat/Valdi / transformNodeGeneric

Method transformNodeGeneric

compiler/companion/src/JSXProcessor.ts:1338–1358  ·  view source on GitHub ↗
(
    parent: ts.Node,
    node: ts.Node,
    outputState: JSXOutputState,
    transformContext: ts.TransformationContext,
  )

Source from the content-addressed store, hash-verified

1336 // A version of transformNode which which will ensure that we transform statements into expressions
1337 // if our node was an expression
1338 private transformNodeGeneric(
1339 parent: ts.Node,
1340 node: ts.Node,
1341 outputState: JSXOutputState,
1342 transformContext: ts.TransformationContext,
1343 ): ts.Node {
1344 const result = this.transformNode(node, outputState, transformContext);
1345
1346 if (isExpressionNode(node) && !isExpressionNode(result)) {
1347 if (ts.isArrowFunction(parent) && parent.body === node) {
1348 // Special case for arrow functions, we don't need to convert them to expression since
1349 // the body can be a statement
1350 return result;
1351 }
1352
1353 // We were an expression but we are not anymore, convert to an expression
1354 return this.toExpression(result, transformContext);
1355 }
1356
1357 return result;
1358 }
1359
1360 private onError(node: ts.Node, message: string): never {
1361 const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(node.getStart());

Callers 1

transformNodeMethod · 0.95

Calls 3

transformNodeMethod · 0.95
toExpressionMethod · 0.95
isExpressionNodeFunction · 0.90

Tested by

no test coverage detected