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

[ConstPlugin] use RestElement in ObjectPattern will got error #17189

Closed
chenyulun opened this issue May 14, 2023 · 2 comments
Closed

[ConstPlugin] use RestElement in ObjectPattern will got error #17189

chenyulun opened this issue May 14, 2023 · 2 comments

Comments

@chenyulun
Copy link

Bug report

What is the current behavior?

Module parse failed: Cannot read properties of undefined (reading 'type')
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
TypeError: Cannot read properties of undefined (reading 'type')
    at collectDeclaration (/Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/ConstPlugin.js:26:16)
    at getHoistedDeclarations (/Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/ConstPlugin.js:110:7)
    at /Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/ConstPlugin.js:196:25
    at Hook.eval [as call] (eval at create (/Users/chenyulun390/learn/testwebpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
    at Hook.CALL_DELEGATE [as _call] (/Users/chenyulun390/learn/testwebpack/node_modules/tapable/lib/Hook.js:14:14)
    at JavascriptParser.walkIfStatement (/Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/javascript/JavascriptParser.js:1805:41)
    at JavascriptParser.walkStatement (/Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/javascript/JavascriptParser.js:1736:10)
    at JavascriptParser.walkStatements (/Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/javascript/JavascriptParser.js:1613:9)
    at JavascriptParser.parse (/Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/javascript/JavascriptParser.js:3593:9)
    at /Users/chenyulun390/learn/testwebpack/node_modules/webpack/lib/NormalModule.js:1092:26

webpack 5.82.0 compiled with 1 error in 98 ms

If the current behavior is a bug, please provide the steps to reproduce.

// index.js
var test = {
  a: 1,
  b: 2,
  c: 3
};
if (process.env.NODE_ENV === 'development') {
  var {
    a,
    ...other
  } = test;
  console.log('development:', other);
} else {
  var {
    b,
    ..._other, // error here
  } = test;
  console.log('production:', _other);
}

What is the expected behavior?
image

Do it need to add a non empty judgment here?

for (const property of node.properties) {
+ if(property.value) {
    stack.push(property.value);
+ }
}

Other relevant information:
webpack version: 5.82.0
Node.js version: v16.17.0
Operating System: macOS
Additional tools:

@chenyulun
Copy link
Author

const test = {a:1, b:2, c: 3}
if (process.env.NODE_ENV === 'development') {
// if (true) {
  const {
    a,
    ...other
  } = test;
  console.log('development:', other);
} else {
  const {
    b,
    ...other
  } = test;
  console.log('production:', other);
}

I added @babel/plugin-transform-block-scoping to the Babel plugin, but did not add @babel/plugin-transform-spread,

Because hermes@0.7.2 does not support the following code

 for (let i = 0; i < 5; i++) {
         setTimeout(() => console.log(i), 1); // All returns here are 4
    }

@alexander-akait
Copy link
Member

Close in favor of #14800

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

No branches or pull requests

2 participants