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

"Container is falsy" error with recent versions of babel plugins and reassignment of loop-scoped variable #289

Open
jedwards1211 opened this issue Mar 14, 2024 · 0 comments · May be fixed by #291

Comments

@jedwards1211
Copy link

jedwards1211 commented Mar 14, 2024

I can't say for sure if the fault lies with the babel core packages or babel-plugin-istanbul...@babel/preset-env with forceAllTransforms: true by itself doesn't choke on the code below, and neither does babel-plugin-istanbul by itself. But when they're run together, an error gets thrown.

Issue repository

https://github.com/jedwards1211/babel-plugin-istanbul-issue

Code

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

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 config

{
  "presets": [["@babel/preset-env", { "forceAllTransforms": true }]],
  "plugins": ["babel-plugin-istanbul"]
}

Package versions

    "@babel/cli": "^7.23.9",
    "@babel/preset-env": "^7.24.0",
    "babel-plugin-istanbul": "^6.1.1"

Error message

$ npm test

> babel-plugin-istanbul-issue@1.0.0 test
> babel index.js

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:135:11)
    at NodePath.replaceWith (/Users/andy/gh/babel-plugin-istanbul-issue/node_modules/@babel/traverse/lib/path/replacement.js:126: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'
}
@jedwards1211 jedwards1211 changed the title Container is falsy error on recent versions of babel plugins and unusual for loop variables Container is falsy error with recent versions of babel plugins and unusual for loop variables Mar 14, 2024
@jedwards1211 jedwards1211 changed the title Container is falsy error with recent versions of babel plugins and unusual for loop variables Container is falsy error with recent versions of babel plugins and uninitialized for loop variable Mar 14, 2024
@jedwards1211 jedwards1211 changed the title Container is falsy error with recent versions of babel plugins and uninitialized for loop variable Container is falsy error with recent versions of babel plugins and reassignment of loop-scoped variable Mar 14, 2024
@jedwards1211 jedwards1211 changed the title Container is falsy error with recent versions of babel plugins and reassignment of loop-scoped variable "Container is falsy" error with recent versions of babel plugins and reassignment of loop-scoped variable Mar 14, 2024
jedwards1211 added a commit to jedwards1211/babel-plugin-istanbul that referenced this issue Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant