hermesc AOT compiler miscompiles unrelated code once a 4th class's private fields are resolved (corruption, not a real syntax error)
Bug Description
hermesc -emit-binary (AOT bytecode compiler) miscompiles a bundle that contains 4 specific classes using ES2022 private instance fields (#field), producing unrelated error: invalid statement encountered. diagnostics on completely different, syntactically-valid code elsewhere in the same file. The bundle compiles cleanly if any 3 of those same 4 classes have their private fields resolved (removed/transformed), regardless of which 3, or which resolution method is used (Babel's @babel/plugin-transform-class-properties, a manual rename to a non-private field, or a hand-written WeakMap-based equivalent of what Babel itself generates). The moment all 4 are resolved simultaneously, compilation fails with dozens of invalid statement encountered errors on bytes that are otherwise identical to a successful compile (confirmed via direct diff of the two bundles — only the 4 target modules' text differs; the "corrupted" lines are 100% unchanged).
This reproduces identically on both the Windows (win64-bin) and Linux (linux64-bin) hermesc binaries shipped with the same hermes-2025-07-07-RNv0.81.0-e0fc67142ec0763c6b6153ca2bf96df815539782 snapshot (confirmed via a real EAS cloud build, which uses the Linux binary on a different machine entirely).
Context
React Native 0.81.5's own source (e.g. Libraries/Animated/**, src/private/webapis/**) and [email protected] both use real #privateField syntax in their own shipped source, which this hermesc build does not directly support (error: private properties are not supported) — a known/expected gap, worked around by lowering that syntax with @babel/plugin-transform-class-properties before hermesc ever sees it. react-native-reanimated specifically has 4 files using this syntax: WorkletEventHandler.ts, ReanimatedModule/js-reanimated/JSReanimated.ts, ReanimatedModule/NativeReanimated.ts, createAnimatedComponent/NativeEventsManager.ts.
Lowering any 3 of those 4 files (in any combination) — via Babel, or by hand-patching the source to not use # at all — produces a clean compile (only the 4th file's own, expected, localized "private properties are not supported" errors remain). Lowering all 4 simultaneously corrupts the compile with ~20+ (uncapped: 600+) invalid statement encountered errors, all pointing at unrelated react-native modules (e.g. a transformed DOMRect/DOMRectReadOnly class, Libraries/Animated/** code) that compile with zero errors in the "3 of 4" case.
I also tried physically merging 2 of the 4 files into 1 module (reducing the file count from 4 to 3 while keeping all 4 classes' private fields resolved) — this did not avoid the bug, producing the identical error signature. This suggests the trigger is tied to some global count (of private-field-bearing classes resolved, or similar) rather than file/module count specifically, though I was not able to pin down the exact mechanism.
Steps to Reproduce
This is hard to give as a minimal standalone repro without a real Expo/RN project, since it depends on interaction between many already-transformed classes across a large real bundle (react-native's own private fields + reanimated's). Available on request if useful — happy to share the exact bundle (unminified, ~3.4MB) that reproduces it deterministically, or a stripped-down project.
High-level:
- Expo SDK 54 project,
[email protected],[email protected],[email protected], New Architecture enabled. - Lower private-class-field syntax in
react-native,react-native-worklets, and reanimated's 3 "smaller" glue files via a Babeloverridesblock using@babel/plugin-transform-class-properties,@babel/plugin-transform-private-methods,@babel/plugin-transform-private-property-in-object. - Generate the release bundle (
npx expo export:embed --platform android --dev false ...or the realcreateBundleReleaseJsAndAssetsGradle task). - Run
hermesc -emit-binaryon the bundle → succeeds, with only the 4th (untouched) file's own private-field errors. - Now also lower the 4th file's 2 private fields (any method — Babel, manual rename, WeakMap) →
hermesc -emit-binaryon the resulting bundle fails with dozens ofinvalid statement encounterederrors in unrelated code.
Environment
- Hermes:
hermes-2025-07-07-RNv0.81.0-e0fc67142ec0763c6b6153ca2bf96df815539782(bothwin64-binandlinux64-bin, confirmed same behavior) - React Native: 0.81.5 (also checked 0.81.6 — identical
.hermesversion, not applicable as a fix) - Expo SDK: 54.0.35
- react-native-reanimated: 4.1.7
- react-native-worklets: 0.5.1
Additional flags tried (none changed the outcome)
-O, -eager (force eager compilation, ruling out a lazy-compilation pre-scan boundary issue), -w, -ferror-limit=0, -max-diagnostic-width=80, -output-source-map — all produce the identical corrupted output once all 4 classes are resolved.
Source: facebook/hermes