Skip to content

Commit

Permalink
Skip the unnecessary isType check if nodeType is empty. (#15555)
Browse files Browse the repository at this point in the history
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Co-authored-by: Yvan Yang <ybyang@best-inc.com>
  • Loading branch information
3 people committed Jul 18, 2023
1 parent ee0c795 commit 11844c1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/babel-types/src/validators/isType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default function isType(
export default function isType(nodeType: string, targetType: string): boolean {
if (nodeType === targetType) return true;

// If nodeType is nullish, it can't be an alias of targetType.
if (nodeType == null) return false;

// This is a fast-path. If the test above failed, but an alias key is found, then the
// targetType was a primary node type, so there's no need to check the aliases.
// @ts-expect-error targetType may not index ALIAS_KEYS
Expand Down

0 comments on commit 11844c1

Please sign in to comment.