fix(parser-native): unblock stdlib expansion by avoiding bare case-decl pattern (#597)#603
Merged
fix(parser-native): unblock stdlib expansion by avoiding bare case-decl pattern (#597)#603
Conversation
…h case as single statement, avoids parser-native iteration dropping trailing return on bare [var_decl, if_no_else, return] pattern (#597)
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #597 — the regression that blocked stdlib additions past 8 count. Unblocks #585 (net TCP module) and future stdlib expansion.
User-facing effect
Root cause (narrow observation)
Parser-native's switch_case iteration was producing a case body missing the trailing `return` for `case "unary_expression":`. The source body was:
```ts
case "unary_expression":
const voidOpChild = getChild(node, 0);
if (voidOpChild && (voidOpChild as NodeBase).type === "void") {
return { type: "variable", name: "undefined" };
}
return transformUnaryExpression(node);
```
Tree-sitter reports `namedChildCount=3` for this case clause (value + const + if), so parser-native iterates 3 children and the final `return` is never added to `caseStatements`. Downstream `checkMissingReturns` correctly flagged the resulting `[var_decl, if_no_else]` sequence as "does not return on all paths".
Why tree-sitter reports 3 instead of 4 is not yet root-caused — could be grammar greed in `if_statement`'s consequence production, or a named/anonymous node classification quirk. That is a separate investigation tracked as a followup in #597.
Fix (not a workaround, but avoids the trigger)
Extract the case body into a helper function `transformUnaryExpressionOrVoid`. The switch case becomes a single-statement body that can't trip the bare-case-decl pattern:
```ts
case "unary_expression":
return transformUnaryExpressionOrVoid(node);
```
Why this approach over the rejected alternatives:
The helper extraction is one-line-shift in behavior (same logic, different call site), preserves all existing parser paths, and the full self-host suite passes.
Test plan