Skip to content

Simplify AST validators - #18103

Merged
nicolo-ribaudo merged 5 commits into
babel:mainfrom
fisker:validators-simply
Jul 24, 2026
Merged

nicolo-ribaudo merged 5 commits into
babel:mainfrom
fisker:validators-simply

Conversation

@fisker

@fisker fisker commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
Q 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

@fisker
fisker force-pushed the validators-simply branch from db0da4a to 1b5c198 Compare June 25, 2026 15:54
return opts == null || shallowEqual(node, opts);
return (
node?.type === "ArrayExpression" &&
(opts == null || shallowEqual(node, opts))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we could have a shallowEqualN function that returns true is opts is null, to avoid repeating the check every time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If so, should we move the node.type compare to it too? 馃槃

@babel-bot

babel-bot commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61960

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: fb150ab

@JLHwung

JLHwung commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@fisker It seems to me that this PR is ready for review. Are there any pending action items?

@fisker

fisker commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Are there any pending action items?

#18103 (comment)

I mean, do we want change

export function isBlockStatement<Opts extends Options<t.BlockStatement>>(
  node: t.Node | null | undefined,
  opts?: Opts | null,
): boolean {
-  return node?.type === "BlockStatement" && shallowEqualN(node, opts);
+  return shallowEqualN(node, "BlockStatement", opts);
}

@fisker
fisker marked this pull request as ready for review July 22, 2026 02:16
@JLHwung

JLHwung commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Are there any pending action items?

#18103 (comment)

I mean, do we want change

export function isBlockStatement<Opts extends Options<t.BlockStatement>>(
  node: t.Node | null | undefined,
  opts?: Opts | null,
): boolean {
-  return node?.type === "BlockStatement" && shallowEqualN(node, opts);
+  return shallowEqualN(node, "BlockStatement", opts);
}

This change looks good to me, in this case we can also consider rename shallowEqualN to something like isType(type: string, node, opts)

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't seem to affect performance. Thank you!

@liuxingbaoyu liuxingbaoyu added PR: Polish 馃拝 A type of pull request used for our changelog categories pkg: types labels Jul 24, 2026
@nicolo-ribaudo nicolo-ribaudo added PR: Internal 馃彔 A type of pull request used for our changelog categories and removed PR: Polish 馃拝 A type of pull request used for our changelog categories labels Jul 24, 2026
@nicolo-ribaudo nicolo-ribaudo changed the title Simplify validators Simplify AST validators Jul 24, 2026
@nicolo-ribaudo
nicolo-ribaudo merged commit e74e391 into babel:main Jul 24, 2026
57 checks passed
@fisker
fisker deleted the validators-simply branch July 24, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: types PR: Internal 馃彔 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants