Skip to content

Webpack 5.85.0 fails to correctly strip out parenthesis with barrel imports #17305

Closed

Description

@edusperoni

Bug report

What is the current behavior?

With the following code:


import * as barrel from './barrel';

console.log((barrel.something).nested);

Webpack will generate (notice the extra )):

(() => {
/*!*********************!*\
  !*** ./src/main.js ***!
  \*********************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _barrel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./barrel */ "./src/barrel.js");



console.log(_barrel__WEBPACK_IMPORTED_MODULE_0__.something).nested);


})();

Under webpack 5.84.0, the code is correctly generated:

(() => {
/*!*********************!*\
  !*** ./src/main.js ***!
  \*********************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _barrel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./barrel */ "./src/barrel.js");



console.log(_barrel__WEBPACK_IMPORTED_MODULE_0__.something.nested);


})();

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

https://github.com/edusperoni/webpack-import-paren-issue

Just run npm start

What is the expected behavior?

The parenthesis should be correctly stripped.

Other relevant information:
webpack version: 5.85.0

Reverting the change inlib/dependencies/HarmonyImportSpecifierDependency.js from @bworline fixes the issue:

https://github.com/webpack/webpack/pull/17203/files#diff-96335405b47eef62b17ba6fe88f6b35a1e37c9cf98fd762fe74599aca1c65d94R318-R353

Activity

  1. bworline commented on Jun 2, 2023

    @bworline
    Contributor

    I have a fix for this.

  2. added a commit that references this issue on Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions