Home / File/ bug-ref-prefix-postfix-operator.js — react Source File

bug-ref-prefix-postfix-operator.js — react Source File

Architecture documentation for bug-ref-prefix-postfix-operator.js, a javascript file in the react codebase. 1 imports, 0 dependents.

File javascript TestingUtilities Fixtures 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  46784e53_c387_aa35_7c52_9f991fd888c2["bug-ref-prefix-postfix-operator.js"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  46784e53_c387_aa35_7c52_9f991fd888c2 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  style 46784e53_c387_aa35_7c52_9f991fd888c2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import {useRef, useEffect} from 'react';

/**
 * The postfix increment operator should return the value before incrementing.
 * ```js
 * const id = count.current; // 0
 * count.current = count.current + 1; // 1
 * return id;
 * ```
 * The bug is that we currently increment the value before the expression is evaluated.
 * This bug does not trigger when the incremented value is a plain primitive.
 *
 * Found differences in evaluator results
 * Non-forget (expected):
 * (kind: ok) {"count":{"current":0},"updateCountPostfix":"[[ function params=0 ]]","updateCountPrefix":"[[ function params=0 ]]"}
 * logs: ['id = 0','count = 1']
 * Forget:
 * (kind: ok) {"count":{"current":0},"updateCountPostfix":"[[ function params=0 ]]","updateCountPrefix":"[[ function params=0 ]]"}
 * logs: ['id = 1','count = 1']
 */
function useFoo() {
  const count = useRef(0);
  const updateCountPostfix = () => {
    const id = count.current++;
    return id;
  };
  const updateCountPrefix = () => {
    const id = ++count.current;
    return id;
  };
  useEffect(() => {
    const id = updateCountPostfix();
    console.log(`id = ${id}`);
    console.log(`count = ${count.current}`);
  }, []);
  return {count, updateCountPostfix, updateCountPrefix};
}

export const FIXTURE_ENTRYPOINT = {
  fn: useFoo,
  params: [],
};

Subdomains

Functions

Dependencies

  • react

Frequently Asked Questions

What does bug-ref-prefix-postfix-operator.js do?
bug-ref-prefix-postfix-operator.js is a source file in the react codebase, written in javascript. It belongs to the TestingUtilities domain, Fixtures subdomain.
What functions are defined in bug-ref-prefix-postfix-operator.js?
bug-ref-prefix-postfix-operator.js defines 1 function(s): useFoo.
What does bug-ref-prefix-postfix-operator.js depend on?
bug-ref-prefix-postfix-operator.js imports 1 module(s): react.
Where is bug-ref-prefix-postfix-operator.js in the architecture?
bug-ref-prefix-postfix-operator.js is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-ref-prefix-postfix-operator.js (domain: TestingUtilities, subdomain: Fixtures, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free