{"version":3,"file":"guards.mjs","sources":["../../../../src/utils/ast/guards.ts"],"sourcesContent":["// Imported from\n// https://github.com/testing-library/eslint-plugin-testing-library/blob/main/lib/node-utils/is-node-of-type.ts\n\nimport type { TSESTree } from \"@typescript-eslint/utils\";\nimport { AST_NODE_TYPES } from \"@typescript-eslint/utils\";\nimport { Scope } from \"@typescript-eslint/utils/ts-eslint\";\n\nconst isNodeOfType =\n  <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) =>\n  (\n    node: TSESTree.Node | null | undefined,\n  ): node is TSESTree.Node & { type: NodeType } =>\n    node?.type === nodeType;\n\nexport const isIdentifier = isNodeOfType(AST_NODE_TYPES.Identifier);\nexport const isTaggedTemplateExpression = isNodeOfType(\n  AST_NODE_TYPES.TaggedTemplateExpression,\n);\nexport const isExportNamedDeclaration = isNodeOfType(\n  AST_NODE_TYPES.ExportNamedDeclaration,\n);\nexport const isExportDefaultDeclaration = isNodeOfType(\n  AST_NODE_TYPES.ExportDefaultDeclaration,\n);\nexport const isExportAllDeclaration = isNodeOfType(\n  AST_NODE_TYPES.ExportAllDeclaration,\n);\nexport const isArrayExpression = isNodeOfType(AST_NODE_TYPES.ArrayExpression);\nexport const isArrowFunctionExpression = isNodeOfType(\n  AST_NODE_TYPES.ArrowFunctionExpression,\n);\nexport const isBlockStatement = isNodeOfType(AST_NODE_TYPES.BlockStatement);\nexport const isCallExpression = isNodeOfType(AST_NODE_TYPES.CallExpression);\nexport const isRestElement = isNodeOfType(AST_NODE_TYPES.RestElement);\nexport const isExpressionStatement = isNodeOfType(\n  AST_NODE_TYPES.ExpressionStatement,\n);\nexport const isVariableDeclaration = isNodeOfType(\n  AST_NODE_TYPES.VariableDeclaration,\n);\nexport const isVariableDeclarator = isNodeOfType(\n  AST_NODE_TYPES.VariableDeclarator,\n);\nexport const isAssignmentExpression = isNodeOfType(\n  AST_NODE_TYPES.AssignmentExpression,\n);\nexport const isSequenceExpression = isNodeOfType(\n  AST_NODE_TYPES.SequenceExpression,\n);\nexport const isImportDeclaration = isNodeOfType(\n  AST_NODE_TYPES.ImportDeclaration,\n);\nexport const isImportDefaultSpecifier = isNodeOfType(\n  AST_NODE_TYPES.ImportDefaultSpecifier,\n);\nexport const isImportNamespaceSpecifier = isNodeOfType(\n  AST_NODE_TYPES.ImportNamespaceSpecifier,\n);\nexport const isImportSpecifier = isNodeOfType(AST_NODE_TYPES.ImportSpecifier);\nexport const isExportSpecifier = isNodeOfType(AST_NODE_TYPES.ExportSpecifier);\nexport const isSpreadElement = isNodeOfType(AST_NODE_TYPES.SpreadElement);\nexport const isJSXAttribute = isNodeOfType(AST_NODE_TYPES.JSXAttribute);\nexport const isLiteral = isNodeOfType(AST_NODE_TYPES.Literal);\nexport const isMemberExpression = isNodeOfType(AST_NODE_TYPES.MemberExpression);\nexport const isNewExpression = isNodeOfType(AST_NODE_TYPES.NewExpression);\nexport const isObjectExpression = isNodeOfType(AST_NODE_TYPES.ObjectExpression);\nexport const isObjectPattern = isNodeOfType(AST_NODE_TYPES.ObjectPattern);\nexport const isProperty = isNodeOfType(AST_NODE_TYPES.Property);\nexport const isMethodDefinition = isNodeOfType(AST_NODE_TYPES.MethodDefinition);\nexport const isReturnStatement = isNodeOfType(AST_NODE_TYPES.ReturnStatement);\nexport const isYieldExpression = isNodeOfType(AST_NODE_TYPES.YieldExpression);\nexport const isFunctionExpression = isNodeOfType(\n  AST_NODE_TYPES.FunctionExpression,\n);\nexport const isFunctionDeclaration = isNodeOfType(\n  AST_NODE_TYPES.FunctionDeclaration,\n);\nexport const isClassDeclaration = isNodeOfType(AST_NODE_TYPES.ClassDeclaration);\nexport const isPropertyDefinition = isNodeOfType(\n  AST_NODE_TYPES.PropertyDefinition,\n);\nexport const isProgram = isNodeOfType(AST_NODE_TYPES.Program);\nexport const isTSTypeReference = isNodeOfType(AST_NODE_TYPES.TSTypeReference);\nexport const isTSTypeAnnotation = isNodeOfType(AST_NODE_TYPES.TSTypeAnnotation);\nexport const isJSXExpressionContainer = isNodeOfType(\n  AST_NODE_TYPES.JSXExpressionContainer,\n);\nexport const isJSXEmptyExpression = isNodeOfType(\n  AST_NODE_TYPES.JSXEmptyExpression,\n);\nexport const isJSXIdentifier = isNodeOfType(AST_NODE_TYPES.JSXIdentifier);\nexport const isJSXNamespacedName = isNodeOfType(\n  AST_NODE_TYPES.JSXNamespacedName,\n);\n\n// Custom guards\n\nexport const isArrayPattern = isNodeOfType(AST_NODE_TYPES.ArrayPattern);\n\nexport const isParameter = (\n  def?: Scope.Definition | null,\n): def is Scope.Definition & { type: typeof Scope.DefinitionType.Parameter } =>\n  def?.type === Scope.DefinitionType.Parameter;\n\nexport const isImportBinding = (\n  def?: Scope.Definition | null,\n): def is Scope.Definition & {\n  type: typeof Scope.DefinitionType.ImportBinding;\n} => def?.type === Scope.DefinitionType.ImportBinding;\n\nexport const isFunctionName = (\n  def?: Scope.Definition | null,\n): def is Scope.Definition & {\n  type: typeof Scope.DefinitionType.FunctionName;\n} => def?.type === Scope.DefinitionType.FunctionName;\n\nexport const isClassName = (\n  def?: Scope.Definition | null,\n): def is Scope.Definition & {\n  type: typeof Scope.DefinitionType.ClassName;\n} => def?.type === Scope.DefinitionType.ClassName;\n\n// Basic guards\n\nexport function isPrimitive(\n  value: unknown,\n): value is string | number | boolean | undefined | null {\n  return (\n    !value ||\n    typeof value === \"string\" ||\n    typeof value === \"number\" ||\n    typeof value === \"bigint\" ||\n    typeof value === \"boolean\"\n  );\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === \"object\" && value != null && !Array.isArray(value);\n}\n\nexport function isSymbol(value: unknown): value is symbol {\n  return typeof value === \"symbol\";\n}\n\n// Literals\n\nexport const isTemplateLiteral = isNodeOfType(AST_NODE_TYPES.TemplateLiteral);\nexport const isTemplateElement = isNodeOfType(AST_NODE_TYPES.TemplateElement);\n\nexport function isBigIntLiteral(\n  literal: TSESTree.Literal,\n): literal is TSESTree.BigIntLiteral {\n  return typeof literal.value === \"bigint\";\n}\n\nexport function isBooleanLiteral(\n  literal: TSESTree.Literal,\n): literal is TSESTree.BooleanLiteral {\n  return typeof literal.value === \"boolean\";\n}\n\nexport function isNullLiteral(\n  literal: TSESTree.Literal,\n): literal is TSESTree.NullLiteral {\n  return literal.value === null;\n}\n\nexport function isNumberLiteral(\n  literal: TSESTree.Literal,\n): literal is TSESTree.NumberLiteral {\n  return typeof literal.value === \"number\";\n}\n\n/* export function isRegExpLiteral(\n  literal: TSESTree.Literal\n): literal is TSESTree.RegExpLiteral {\n  return typeof\n}*/\n\nexport function isStringLiteral(\n  literal: TSESTree.Literal,\n): literal is TSESTree.StringLiteral {\n  return typeof literal.value === \"string\";\n}\n"],"names":[],"mappings":";;;AAOA,MAAM,eACJ,CAAkC,QAAA,KAClC,CACE,IAAA,KAEA,MAAM,IAAA,KAAS,QAAA;AAEZ,MAAM,YAAA,GAAe,YAAA,CAAa,cAAA,CAAe,UAAU;AACxB,YAAA;AAAA,EACxC,cAAA,CAAe;AACjB;AACwC,YAAA;AAAA,EACtC,cAAA,CAAe;AACjB;AAC0C,YAAA;AAAA,EACxC,cAAA,CAAe;AACjB;AACsC,YAAA;AAAA,EACpC,cAAA,CAAe;AACjB;AACiC,YAAA,CAAa,cAAA,CAAe,eAAe;AACnC,YAAA;AAAA,EACvC,cAAA,CAAe;AACjB;AACgC,YAAA,CAAa,cAAA,CAAe,cAAc;AAC1C,YAAA,CAAa,cAAA,CAAe,cAAc;AAC7C,YAAA,CAAa,cAAA,CAAe,WAAW;AAC/B,YAAA;AAAA,EACnC,cAAA,CAAe;AACjB;AACqC,YAAA;AAAA,EACnC,cAAA,CAAe;AACjB;AACoC,YAAA;AAAA,EAClC,cAAA,CAAe;AACjB;AACsC,YAAA;AAAA,EACpC,cAAA,CAAe;AACjB;AACoC,YAAA;AAAA,EAClC,cAAA,CAAe;AACjB;AACmC,YAAA;AAAA,EACjC,cAAA,CAAe;AACjB;AACwC,YAAA;AAAA,EACtC,cAAA,CAAe;AACjB;AAC0C,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