Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing files suppress async generators are unsupported errors #1389

Closed
leotm opened this issue May 2, 2024 · 4 comments
Closed

Importing files suppress async generators are unsupported errors #1389

leotm opened this issue May 2, 2024 · 4 comments
Labels
need more info Awating additional info before proceeding

Comments

@leotm
Copy link

leotm commented May 2, 2024

Bug Description

Hermes suppresses async generators are unsupported errors in imported files

if (compile_ && ESTree::isAsync(node) && ESTree::isGenerator(node)) {
sm_.error(node->getSourceRange(), "async generators are unsupported");
}

OS: Android, iOS
Platform : arm64-v8a (macOS, M2)

Steps To Reproduce

npx react-native@latest init RN07119 --version 0.71.19

npx react-native@latest init RN07214 --version 0.72.14

// file.cjs
async function* foo() {
  yield await Promise.resolve('a');
  yield await Promise.resolve('b');
  yield await Promise.resolve('c'); // remove this yield to see error in sim/emu
};
function bar() {}; // remove this fn to see error in sim/emu

// Try this example wrapped in a new Function(String.raw``)() to see error

// Hot reload any change to see error in Metro
// [Error: Exception in HostFunction: Compiling JS failed: 2:3:async generators are unsupported Buffer size 665 starts with: 5f5f642866756e6374696f6e2028676c]
// babel.config.js
module.exports = {
  ignore: [/file\.cjs/],
  presets: ['module:metro-react-native-babel-preset'],
};
// e.g. index.js, App.tsx, node_modules/react-native/Libraries/Core/InitializeCore.js
require('./file.cjs');

The Expected Behavior

Error async generators are unsupported (Android, iOS)

@tmikov
Copy link
Contributor

tmikov commented May 3, 2024

I am not sure I understand the problem. What are "imported files"?

Hermes, in the way it is currently used by React Native, has no concept of modules or imported files. It sees a single source file that has been transformed by Babel and packaged by Metro. If that file contains async generators, Hermes will report an error.

@tmikov tmikov added need more info Awating additional info before proceeding and removed bug Something isn't working labels May 3, 2024
@leotm
Copy link
Author

leotm commented May 6, 2024

i see ^ i mean files ignored by Babel, required or imported like

  • index.js > require('./file.cjs')
  • index.js > App.tsx > require('./file.cjs')
  • node_modules/react-native/Libraries/Core/InitializeCore.js > require('./file.cjs')

simple cases (stripping part of the example) report the Hermes error correctly to sim/emu
but more complex usage (full example, or ses.cjs) doesn't
unless e.g. called in a new Function(String.raw``)() which is strange

@leotm
Copy link
Author

leotm commented May 6, 2024

good point i suppose it's not Hermes side, since Metro hot reload outputs correctly to console
[Error: Exception in HostFunction: Compiling JS failed: 2:3:async generators are unsupported Buffer size 665 starts with: 5f5f642866756e6374696f6e2028676c]
so Hermes reports the single source file error correctly to Metro each change
also 8239e82 hasn't changed in nearly a year

i'll close here to fix either RN side or Metro side
since the bug is failing to propagate the Hermes error to sim/emu
with beyond simple usage of async generators

@leotm leotm closed this as completed May 6, 2024
@leotm
Copy link
Author

leotm commented May 6, 2024

also Metro doesn't fail with the Hermes error during bundling when requiring our example file.cjs
./gradlew :app:installDebug or ./gradlew :app:installRelease both modes bundle ok

but e.g. adding var test = foo; to reference the unsupported async generator
causes the release bundling to fail, correctly outputting the Hermes error
async generators are unsupported

Hermes, in the way it is currently used by React Native, has no concept of modules or imported files. It sees a single source file that has been transformed by Babel and packaged by Metro. If that file contains async generators, Hermes will report an error.

since defining an async generator fn alone (no var to reference it) should be enough for Hermes to recognise it in the source file and report an error (despite being unused)

looks like another Metro bug? since both debug and release bundling should be failing with a defined async generator in the source file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Awating additional info before proceeding
Projects
None yet
Development

No branches or pull requests

2 participants