Skip to content

Codegen flow and typescript parsers infinite loop caused by circular aliases #57956

Description

@leotm

Description

For libs using ESLint plugin @react-native/eslint-plugin-specs rule @react-native/specs/react-native-modules

when a type alias name matches the RHS, e.g.

import { TurboModule, TurboModuleRegistry } from 'react-native';
import type { CodegenTypes } from 'react-native';

type Double = CodegenTypes.Double; // 👀

ESLint never finishes (the Node process hangs)

a current workaround is to either use the namespace e.g. CodegenTypes.Double everywhere
or rename your type alias to e.g. type _Double = CodegenTypes.Double for now

e.g. appandflow/react-native-safe-area-context#744 (review)

seems like the AST is being parsed like
type Double = CodegenTypes.Double → resolves to Double (same GenericTypeAnnotation TypeAlias) → repeat

digging deeper

only: [/react-native-codegen\/src\//],

parser: new RNFlowParser.FlowParser(),

isolates this to codegen flow parser (not the ts one)

i.e. packages\react-native-codegen\src\parsers\flow\parser.js

it looks like getResolvedTypeAnnotation (called indirectly in RNFlowParser/RNModuleParser/RNParserCommons)
is looping infinitely in the for loop so we need to break on circular type aliases

by monkey patching node_modules\@react-native\codegen\lib\parsers\flow\parser.js
managed to get it working so can propose a fix for the flow parser

it looks like it also happens with the ts parser, so can follow-up with a similar (if not the same) fix there too

also tested latest stable

  "resolutions": {
    "@react-native/codegen": "0.87.0"
  },

Steps to reproduce

  1. fix: replace deep RN imports with public API appandflow/react-native-safe-area-context#744 (review)
  2. yarn validate:eslint

React Native Version

0.85.3, 0.87.0, main

Affected Platforms

Build - Linux, Build - Windows, Build - MacOS

Output of npx @react-native-community/cli info

N/A

Stacktrace or Logs

yarn validate:eslint --debug

MANDATORY Reproducer

appandflow/react-native-safe-area-context#744 (review)

Screenshots and Videos

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FlowNeeds: Author FeedbackNeeds: ReproThis issue could be improved with a clear list of steps to reproduce the issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions