test: add tests for arrow function fallback behavior #1063
+80
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket: DX-2214
This PR attempts to validate this following fix, which resolved an issue introduced by this Regression Commit.
Original Problem
The system encountered an error when parsing certain Arrow Functions with parameters (e.g.,
(codec) => t.array(codec)), specifically:Error: Error when parsing AdminUpdateShardKeyApiSpec: Unknown identifier codec.Cause: The parser attempts to inline the function body for optimization. During this process, it failed because the parameters (like
codec) were not recognized in the symbol table, leading to the "Unknown identifier" error.Previous Behavior: The old code immediately returned the parsing error upon inlining failure, preventing it from checking for custom codec definitions as a necessary fallback.
Why the Fix Works (Utilizing
E.isRightCheck)The fix modifies the parser's logic to handle inlining failures gracefully, allowing it to proceed to the custom codec check:
parseFunctionBody(...), the code now stores the result in a variable (bodyResult).E.isRight(bodyResult)check.This ensures that even if the inlining optimization fails, the parser still attempts to find a valid definition using custom codecs. Predefined codecs are found in
const knownImport = project.resolveKnownImport(imp.from, imp.importedName);inside thecodecIdentifierfunction.Testing the Fix
The test validates that the type parser correctly falls back to using a pre-defined custom codec for a field utilizing an arrow function with parameters (
arrayFromArrayOrSingle(NonEmptyString)), ensuring it resolves to an array type without throwing anUnknown identifier codecerror.