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

"Container is falsy" error with babel-plugin-istanbul and @babel/plugin-transform-block-scoping #16354

Closed
1 task
jedwards1211 opened this issue Mar 14, 2024 · 3 comments
Labels
i: third party The report is a problem of third party

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented Mar 14, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

for (let f; ; ) {
  f = "0";
  () => (0 ? 1 : parseInt(f));
}

Configuration file name

.babelrc

Configuration

{
  "plugins": ["babel-plugin-istanbul", "@babel/plugin-transform-block-scoping"]
}

Current and expected behavior

expected to transpile successfully, but I get:

ReferenceError: /Users/andy/gh/babel-plugin-istanbul-issue/index.js: Container is falsy
    at NodePath._replaceWith (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/path/replacement.js:139:11)
    at NodePath.replaceWith (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/path/replacement.js:127:8)
    at wrapLoopBody (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/plugin-transform-block-scoping/lib/loop.js:162:43)
    at PluginPass.Loop (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/plugin-transform-block-scoping/lib/index.js:82:50)
    at newFn (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/visitors.js:160:14)
    at NodePath._call (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/path/context.js:46:20)
    at NodePath.call (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/path/context.js:36:17)
    at NodePath.visit (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/path/context.js:82:31)
    at TraversalContext.visitQueue (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/context.js:89:16)
    at TraversalContext.visitMultiple (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/context.js:61:17) {
  code: 'BABEL_TRANSFORM_ERROR'
}

Environment

  • @babel/plugin-transform-block-scoping@7.23.4
  • @babel/cli@7.23.9
  • @babel/preset-env@7.24.0
  • babel-plugin-istanbul@6.1.1

Possible solution

No response

Additional context

I'm not sure if this is babel's fault or babel-plugin-istanbul's fault, but I'm linking istanbuljs/babel-plugin-istanbul#289 here in case the babel team has any ideas.

The parseInt(f) gets transformed into cov_1c743zp148().b[0][1]++, parseInt(f). But for some reason that expression is orphaned by the time @babel/plugin-transform-block-scoping tries to rename f to _f, causing an error to be thrown.

@babel-bot
Copy link
Collaborator

Hey @jedwards1211! 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.

@liuxingbaoyu
Copy link
Member

liuxingbaoyu commented Mar 15, 2024

I think the fix will be better in istanbul. Fortunately, istanbul only has one visitor Program, so it only need to add path.scope.crawl(); to synchronize the new binding information to completely fix this problem.
image

@liuxingbaoyu liuxingbaoyu added i: third party The report is a problem of third party and removed i: needs triage labels Mar 15, 2024
@jedwards1211
Copy link
Contributor Author

I see, thank you! I'll make a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i: third party The report is a problem of third party
Projects
None yet
Development

No branches or pull requests

3 participants