ITADN

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

#289Closedjedwards1211 创建于 2024-03-14
J
jedwards1211commented
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 ```js 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 ```json { "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' } ```
关闭于 2024-07-05 0 条评论