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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: do-expressions plugin throws "Couldn't find a Program" in Babel 8 #16293

Closed
1 task
0f-0b opened this issue Feb 19, 2024 · 2 comments 路 Fixed by #16305
Closed
1 task

[Bug]: do-expressions plugin throws "Couldn't find a Program" in Babel 8 #16293

0f-0b opened this issue Feb 19, 2024 · 2 comments 路 Fixed by #16305

Comments

@0f-0b
Copy link

0f-0b commented Feb 19, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

async () => do {
  await 0
  while (0) {}
  0
}

Configuration file name

babel.config.json

Configuration

{
  "plugins": [
    [
      "@babel/plugin-proposal-do-expressions"
    ]
  ]
}

Current and expected behavior

transformAsync when called with the code above throws a "Couldn't find a Program" error.

Stack trace
.../node_modules/@babel/traverse/lib/index.js:1362
    throw new Error("Couldn't find a Program");
          ^

Error: unknown file: Couldn't find a Program
    at Scope.getProgramParent (.../node_modules/@babel/traverse/lib/index.js:1362:11)
    at Scope.crawl (.../node_modules/@babel/traverse/lib/index.js:1274:32)
    at Scope.init (.../node_modules/@babel/traverse/lib/index.js:1264:12)
    at NodePath.setScope (.../node_modules/@babel/traverse/lib/index.js:3652:15)
    at NodePath.setContext (.../node_modules/@babel/traverse/lib/index.js:3664:8)
    at NodePath.popContext (.../node_modules/@babel/traverse/lib/index.js:3716:10)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/index.js:4876:12)
    at TraversalContext.visitMultiple (.../node_modules/@babel/traverse/lib/index.js:4839:17)
    at TraversalContext.visit (.../node_modules/@babel/traverse/lib/index.js:4885:19)
    at traverseNode (.../node_modules/@babel/traverse/lib/index.js:4905:17)
    at traverse (.../node_modules/@babel/traverse/lib/index.js:4942:3)
    at traverse.hasType (.../node_modules/@babel/traverse/lib/index.js:4974:3)
    at NodePath.replaceExpressionWithStatements (.../node_modules/@babel/traverse/lib/index.js:2297:57)
    at PluginPass.exit (.../node_modules/@babel/plugin-proposal-do-expressions/lib/index.js:20:18)
    at newFn (.../node_modules/@babel/traverse/lib/index.js:354:14)
    at NodePath._call (.../node_modules/@babel/traverse/lib/index.js:3582:20)
    at NodePath.call (.../node_modules/@babel/traverse/lib/index.js:3572:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/index.js:3624:8)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/index.js:4864:16)
    at TraversalContext.visitSingle (.../node_modules/@babel/traverse/lib/index.js:4843:19)
    at TraversalContext.visit (.../node_modules/@babel/traverse/lib/index.js:4887:19)
    at traverseNode (.../node_modules/@babel/traverse/lib/index.js:4905:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/index.js:3622:21)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/index.js:4864:16)
    at TraversalContext.visitSingle (.../node_modules/@babel/traverse/lib/index.js:4843:19)
    at TraversalContext.visit (.../node_modules/@babel/traverse/lib/index.js:4887:19)
    at traverseNode (.../node_modules/@babel/traverse/lib/index.js:4905:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/index.js:3622:21)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/index.js:4864:16)
    at TraversalContext.visitMultiple (.../node_modules/@babel/traverse/lib/index.js:4839:17)
    at TraversalContext.visit (.../node_modules/@babel/traverse/lib/index.js:4885:19)
    at traverseNode (.../node_modules/@babel/traverse/lib/index.js:4905:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/index.js:3622:21)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/index.js:4864:16)
    at traverseNode (.../node_modules/@babel/traverse/lib/index.js:4901:20)
    at traverse (.../node_modules/@babel/traverse/lib/index.js:4942:3)
    at transformFile (.../node_modules/@babel/core/lib/transformation/index.js:68:7)
    at transformFile.next (<anonymous>)
    at run (.../node_modules/@babel/core/lib/transformation/index.js:12:12)
    at run.next (<anonymous>)
    at transform (.../node_modules/@babel/core/lib/transform.js:8:17)
    at transform.next (<anonymous>)
    at step (.../node_modules/gensync/index.js:261:32)
    at .../node_modules/gensync/index.js:273:13
    at async.call.result.err.err (.../node_modules/gensync/index.js:223:11)
    at .../node_modules/gensync/index.js:189:28
    at .../node_modules/@babel/core/lib/gensync-utils/async.js:42:7
    at .../node_modules/gensync/index.js:113:33
    at step (.../node_modules/gensync/index.js:287:14)
    at .../node_modules/gensync/index.js:273:13
    at async.call.result.err.err (.../node_modules/gensync/index.js:223:11) {
  code: 'BABEL_TRANSFORM_ERROR'
}

Node.js v21.6.2

The error does not occur in Babel 7.

Environment

System:
  OS: macOS 14.1.1
Binaries:
  Node: 21.6.2 - /opt/homebrew/bin/node
  npm: 10.4.0 - /opt/homebrew/bin/npm
npmPackages:
  @babel/core: 8.0.0-alpha.6 => 8.0.0-alpha.6 
  @babel/plugin-proposal-do-expressions: 8.0.0-alpha.6 => 8.0.0-alpha.6 

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @0f-0b! 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.

@nicolo-ribaudo
Copy link
Member

Thanks for testing Babel 8 :)

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

Successfully merging a pull request may close this issue.

4 participants