Home / File/ astUtils.js — react Source File

astUtils.js — react Source File

Architecture documentation for astUtils.js, a javascript file in the react codebase. 3 imports, 4 dependents.

File javascript BabelCompiler Validation 3 imports 4 dependents 16 functions

Entity Profile

Dependency Diagram

graph LR
  22acaf1d_d624_cc04_9046_5e8603f3a58d["astUtils.js"]
  7e1e25cd_0db6_762f_27ad_866e33149c52["PerformanceLoggingUtils"]
  22acaf1d_d624_cc04_9046_5e8603f3a58d --> 7e1e25cd_0db6_762f_27ad_866e33149c52
  ceff537f_04b5_ea96_fed3_19a0a7315bc6["traverse"]
  22acaf1d_d624_cc04_9046_5e8603f3a58d --> ceff537f_04b5_ea96_fed3_19a0a7315bc6
  741f125f_8d71_2134_c016_a18fb8f60d66["ReactDebugHooks"]
  22acaf1d_d624_cc04_9046_5e8603f3a58d --> 741f125f_8d71_2134_c016_a18fb8f60d66
  5751162b_425a_76d9_4373_4cf5cde09b49["SourceMapMetadataConsumer.js"]
  5751162b_425a_76d9_4373_4cf5cde09b49 --> 22acaf1d_d624_cc04_9046_5e8603f3a58d
  d816dd9a_2650_2f50_e9eb_2cdf900b512f["generateHookMap.js"]
  d816dd9a_2650_2f50_e9eb_2cdf900b512f --> 22acaf1d_d624_cc04_9046_5e8603f3a58d
  5ab6cc34_8610_de9f_93dc_9e7a8742ce9b["getHookNameForLocation.js"]
  5ab6cc34_8610_de9f_93dc_9e7a8742ce9b --> 22acaf1d_d624_cc04_9046_5e8603f3a58d
  76da1f28_5fe1_2c37_5657_67756acc6f55["parseSourceAndMetadata.js"]
  76da1f28_5fe1_2c37_5657_67756acc6f55 --> 22acaf1d_d624_cc04_9046_5e8603f3a58d
  style 22acaf1d_d624_cc04_9046_5e8603f3a58d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import {withSyncPerfMeasurements} from 'react-devtools-shared/src/PerformanceLoggingUtils';
import traverse from '@babel/traverse';

import type {HooksNode} from 'react-debug-tools/src/ReactDebugHooks';

// Missing types in @babel/traverse
type NodePath = any;
type Node = any;
// Missing types in @babel/types
type File = any;

export type Position = {
  line: number,
  column: number,
};

export type SourceFileASTWithHookDetails = {
  sourceFileAST: File,
  line: number,
  source: string,
};

export const NO_HOOK_NAME = '<no-hook>';

const AST_NODE_TYPES = Object.freeze({
  PROGRAM: 'Program',
  CALL_EXPRESSION: 'CallExpression',
  MEMBER_EXPRESSION: 'MemberExpression',
  ARRAY_PATTERN: 'ArrayPattern',
  IDENTIFIER: 'Identifier',
  NUMERIC_LITERAL: 'NumericLiteral',
  VARIABLE_DECLARATOR: 'VariableDeclarator',
});

// Check if line number obtained from source map and the line number in hook node match
function checkNodeLocation(
  path: NodePath,
  line: number,
  column?: number | null = null,
): boolean {
  const {start, end} = path.node.loc;

  if (line !== start.line) {
    return false;
  }

  if (column !== null) {
    // Column numbers are represented differently between tools/engines.
    // Error.prototype.stack columns are 1-based (like most IDEs) but ASTs are 0-based.
    //
    // In practice this will probably never matter,
// ... (578 more lines)

Domain

Subdomains

Dependencies

  • PerformanceLoggingUtils
  • ReactDebugHooks
  • traverse

Frequently Asked Questions

What does astUtils.js do?
astUtils.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in astUtils.js?
astUtils.js defines 16 function(s): assertCallExpression, checkNodeLocation, getFilteredHookASTNodes, getHookName, getHookNameFromNode, getHookVariableName, getPotentialHookDeclarationsFromAST, isBuiltInHookThatReturnsTuple, isConfirmedHookDeclaration, isHook, and 6 more.
What does astUtils.js depend on?
astUtils.js imports 3 module(s): PerformanceLoggingUtils, ReactDebugHooks, traverse.
What files import astUtils.js?
astUtils.js is imported by 4 file(s): SourceMapMetadataConsumer.js, generateHookMap.js, getHookNameForLocation.js, parseSourceAndMetadata.js.
Where is astUtils.js in the architecture?
astUtils.js is located at packages/react-devtools-shared/src/hooks/astUtils.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/hooks).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free