mirror of
https://github.com/react/react-native.git
synced 2026-09-28 13:23:09 +08:00
Summary: Fixes https://github.com/react/react-native/issues/57956. A spec containing a type alias whose name matches the aliased `CodegenTypes` member hangs codegen forever: ```js import type {CodegenTypes} from 'react-native'; type Double = CodegenTypes.Double; ``` `getResolvedTypeAnnotation` resolves `Double` to the alias's RHS (`CodegenTypes.Double`), but `getTypeAnnotationName` strips the namespace qualifier before the local-alias lookup — so the RHS resolves straight back to the same alias, forever. This hangs the Node process of anything driving the parser, most visibly ESLint via `react-native/eslint-plugin-specs`. Contrary to the issue's initial isolation, **both** the Flow and the TypeScript parsers hang (verified with a subprocess-timeout harness against both). Two guards in each parser's resolution loop: 1. A qualified name (`CodegenTypes.Double` / `TSQualifiedName`) names a namespace member, never a local alias — stop local resolution there. Downstream translation already handles qualified names, so the alias now resolves to the correct primitive (`DoubleTypeAnnotation`). 2. Track resolved alias names, so genuinely cyclic aliases (`type A = B; type B = A;`) stop resolving and fail through the existing `UnsupportedGenericParserError` (`Unrecognized generic type 'A'`) instead of hanging. ## Changelog: [GENERAL] [FIXED] - Codegen no longer hangs on type aliases that shadow CodegenTypes member names Pull Request resolved: https://github.com/react/react-native/pull/57986 Test Plan: - New `NAMESPACED_NATIVE_MODULE_WITH_LOCAL_TYPE_ALIASES` fixture in both the Flow and TypeScript module snapshot suites — before the fix these hang the test runner; after it they produce the correct schema (aliased `Double`/`Float` resolve to `DoubleTypeAnnotation`/`FloatTypeAnnotation`, snapshots included, cross-parser consistency suite passes). - `jest packages/react-native-codegen/src/parsers`: 13 suites, 1965 tests, 186 snapshots — all passing. - `jest packages/eslint-plugin-specs`: passing. - Verified `type A = B; type B = A;` now throws `UnsupportedGenericParserError` instead of hanging. Reviewed By: javache Differential Revision: D116386584 Pulled By: christophpurrer fbshipit-source-id: edbf04c8531d4dc35655318d6245918080ae55b7