Skip to content

Commit

Permalink
Use buildUndefinedNode from types in types (#16493)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 16, 2024
1 parent 1f010df commit 5a7c827
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions packages/babel-types/src/converters/gatherSequenceExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
assignmentExpression,
conditionalExpression,
} from "../builders/generated/index.ts";
import { buildUndefinedNode } from "../builders/productions.ts";
import cloneNode from "../clone/cloneNode.ts";
import type * as t from "../index.ts";
import type { Scope } from "@babel/traverse";

export type DeclarationInfo = {
kind: t.VariableDeclaration["kind"];
Expand All @@ -30,7 +30,6 @@ export type DeclarationInfo = {

export default function gatherSequenceExpressions(
nodes: ReadonlyArray<t.Node>,
scope: Scope,
declars: Array<DeclarationInfo>,
) {
const exprs: t.Expression[] = [];
Expand Down Expand Up @@ -67,16 +66,16 @@ export default function gatherSequenceExpressions(
ensureLastUndefined = true;
} else if (isIfStatement(node)) {
const consequent = node.consequent
? gatherSequenceExpressions([node.consequent], scope, declars)
: scope.buildUndefinedNode();
? gatherSequenceExpressions([node.consequent], declars)
: buildUndefinedNode();
const alternate = node.alternate
? gatherSequenceExpressions([node.alternate], scope, declars)
: scope.buildUndefinedNode();
? gatherSequenceExpressions([node.alternate], declars)
: buildUndefinedNode();
if (!consequent || !alternate) return; // bailed

exprs.push(conditionalExpression(node.test, consequent, alternate));
} else if (isBlockStatement(node)) {
const body = gatherSequenceExpressions(node.body, scope, declars);
const body = gatherSequenceExpressions(node.body, declars);
if (!body) return; // bailed

exprs.push(body);
Expand All @@ -93,7 +92,7 @@ export default function gatherSequenceExpressions(
}

if (ensureLastUndefined) {
exprs.push(scope.buildUndefinedNode());
exprs.push(buildUndefinedNode());
}

if (exprs.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function toSequenceExpression(
if (!nodes?.length) return;

const declars: DeclarationInfo[] = [];
const result = gatherSequenceExpressions(nodes, scope, declars);
const result = gatherSequenceExpressions(nodes, declars);
if (!result) return;

for (const declar of declars) {
Expand Down

0 comments on commit 5a7c827

Please sign in to comment.