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

[Bug]: Wrong prototype for functions using function.sent #15522

Open
1 task
dead-claudia opened this issue Mar 27, 2023 · 1 comment
Open
1 task

[Bug]: Wrong prototype for functions using function.sent #15522

dead-claudia opened this issue Mar 27, 2023 · 1 comment

Comments

@dead-claudia
Copy link

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

REPL: https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABAKigUwM5QBQEpEDeAUIogJ4xoA2AJoqJLAgHQZphQDcRAvkelmYAHAE5wo4skLTNgcOIgC8iAIxEAbgEMRiAObsliATlxEYwRNgCE-sLPn5ipKAAsxAd0Rg0ngKIixEWwAIgADW3s4UK9xejhwGmDTHiA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=false&targets=&version=7.21.3&externalPlugins=%40babel%2Fplugin-proposal-function-sent%407.18.6&assumptions=%7B%7D

function *test() {
  yield function.sent;
}
test.prototype.foo = 1
var gen = test()
if (!gen.foo) {
  throw new Error("`gen.foo` not found")
}

Configuration file name

No response

Configuration

No response

Current and expected behavior

Current behavior: throws an error with message `gen.foo` not found
Expected behavior: doesn't throw

Environment

  • Babel: v7.21.3
  • Whatever else is the case for the online REPL

Possible solution

Here's two possible solutions:

  1. Add in an extra test.prototype = _test.prototype after the function (easiest, but doesn't tree-shake)
  2. Keep test as a generator and instead of returning the iterator directly, returning yield* _test.apply(this, arguments) (tree shakes, but adds some extra overhead)

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @dead-claudia! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

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

No branches or pull requests

2 participants