Skip to content

[webpack 5] Identifier of ?. is not correctly parsed #11186

@SunriseFox

Description

@SunriseFox

Bug report

What is the current behavior?

acorn's ChainExpression is not correctly parsed. Variables are not correctly resolved to imports when optional chaining is used.

import test from './test';

console.log(test.a)
console.log(test?.a)

compiles to

/* harmony import */ var _test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./test */ "./src/test.js");


console.log(_test__WEBPACK_IMPORTED_MODULE_0__.default.a)
console.log(test?.a)

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

https://github.com/SunriseFox/webpack-bug-optional-chaining

yarn && yarn start

What is the expected behavior?

should be

/* harmony import */ var _test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./test */ "./src/test.js");


console.log(_test__WEBPACK_IMPORTED_MODULE_0__.default.a)
console.log(_test__WEBPACK_IMPORTED_MODULE_0__.default?.a)

Other relevant information:
webpack version: 5.0.0-beta.22
Node.js version: v12.16.3
Operating System: MacOS 10.15.5
Additional tools: none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions