Skip to content

DefinePlugin process with object shorthand property incorrectly #16764

@lwr

Description

@lwr

Bug report

What is the current behavior?

  • config
module.exports = {
    plugins : [
        new webpack.DefinePlugin({foo : 'aFoo', bar : 'aBar', crash : 'other.prop'})
    ]
}
  • source code
console.log({foo : foo, bar : bar}); // correct
console.log({foo, bar}); // incorrect
console.log({crash}); // SyntaxError: Unexpected token '.'
  • translated code
console.log({foo : aFoo, bar : aBar}); // correct
console.log({aFoo, aBar}); // incorrect
console.log({other.prop}); // SyntaxError: Unexpected token '.'

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

What is the expected behavior?

the shorthand property should expand before translate with DefinePlugin,
and only property value can be translated

Other relevant information:
webpack version: 5.75.0
Node.js version: 19.6.1
Operating System: macOs 13.2.1 (22D68)
Additional tools:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions