Skip to content

Conversation

@yanxue-22
Copy link
Contributor

@yanxue-22 yanxue-22 commented Oct 24, 2025

Problem

Previously, only implicit-return arrow functions were supported. However, BlockStatement arrow functions are not yet supported.


Example

// implicit-return arrow functions were supported
const factory = () => t.string;  // ✅ Works

// BlockStatement arrow functions with explicit returns would fail
const factory = () => {
  return t.string;  // ❌ Error: "BlockStatement arrow functions are not yet supported
};

Fix:

  • Searches BlockStatement.stmts for ReturnStatement nodes
  • Extracts the return value expression (returnStmt.argument)
  • Passes it to parseCodecInitializer() for recursive parsing
  • Validates that a return statement exists with a non-undefined argument

Both (block statement and non-block statement) styles now produce identical schemas since they converge on the same parseCodecInitializer() call with the return value expression.

Test case added using BooleanFromNullableWithFallback() with explicit block syntax to verify the parser handles both arrow function styles.

Previously, only implicit-return arrow functions were supported:

```typescript
const factory = () => t.string;  // ✅ Worked

BlockStatement arrow functions with explicit returns would fail:
  const factory = () => {
  return t.string;  // ❌ Error: "BlockStatement arrow functions are not yet supported"
};
```

This fix:
- Searches BlockStatement.stmts for ReturnStatement nodes
- Extracts the return value expression (returnStmt.argument)
- Passes it to parseCodecInitializer() for recursive parsing
- Validates that a return statement exists with a non-undefined argument

Both styles now produce identical schemas since they converge on the
same parseCodecInitializer() call with the return value expression.

Test case added using BooleanFromNullableWithFallback() with explicit
block syntax to verify the parser handles both arrow function styles.
@yanxue-22 yanxue-22 marked this pull request as ready for review October 24, 2025 19:29
@yanxue-22 yanxue-22 requested a review from a team as a code owner October 24, 2025 19:29
Copy link
Contributor

@shenbenson shenbenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@yanxue-22 yanxue-22 merged commit 269dada into master Oct 27, 2025
6 checks passed
@yanxue-22 yanxue-22 deleted the DX-2182-openapi-generator-failing-to-parse-utils branch October 27, 2025 19:01
@github-actions
Copy link

🎉 This PR is included in version @api-ts/[email protected] 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants