Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/parser-native/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,7 @@ function transformExpression(node: TreeSitterNode): Expression {
return transformBinaryExpression(node);

case "unary_expression":
// void expressions evaluate to undefined (not a unary op in our AST)
const voidOpChild = getChild(node, 0);
if (voidOpChild && (voidOpChild as NodeBase).type === "void") {
return { type: "variable", name: "undefined" };
}
return transformUnaryExpression(node);
return transformUnaryExpressionOrVoid(node);

case "update_expression":
return transformUpdateExpression(node);
Expand Down Expand Up @@ -616,6 +611,18 @@ function transformExpression(node: TreeSitterNode): Expression {
}
}

// Extracted to a helper so the "unary_expression" switch case in
// transformExpression is a single-statement body — avoiding parser-native's
// tree-sitter iteration dropping the trailing return when a bare case body has
// [var_decl, if_no_else, return]. See #597 for diagnostic.
function transformUnaryExpressionOrVoid(node: TreeSitterNode): Expression {
const voidOpChild = getChild(node, 0);
if (voidOpChild && (voidOpChild as NodeBase).type === "void") {
return { type: "variable", name: "undefined" };
}
return transformUnaryExpression(node);
}

// ============================================
// JSX DESUGARING (native parser)
// Mirrors the TS-API parser's JSX desugaring.
Expand Down
Loading