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

@babel/plugin-transform-optional-chaining, configuration does not take effect #1008

Closed
Lhhpw0204 opened this issue Nov 17, 2023 · 1 comment

Comments

@Lhhpw0204
Copy link

In the typescript file, optional chain syntax is used.
After being compiled by ts-loader, and then processed by babel-loader, the optional chain syntax still exists in the packaged js file.

You can view it via the link below:
https://codesandbox.io/p/sandbox/empty-cache-79clq2?file=%2Fwebpack.config.js%3A21%2C6-21%2C47

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Nov 17, 2023

If you build for development and not production (thus without a minifier) you'll see that optional chain is properly compiled.

I think the problem is that terser is undoing Babel's compilation to generate smaller code.

As an experiment, you can try replacing your input code with the following:

const obja = {
  foo: {
    bar: {
      baz: 42,
      _name: "FUTU COM",
    },
  },
};

const _baz = obja === null || obja === void 0 ? void 0 : obja.foo;

console.log(_baz, "_baz2223================");

const say = () => {
  console.log("hello world");
};
say();

export {};

it contains no optional chaining, but the output code still uses ?.. I suggest asking in https://github.com/webpack/webpack/discussions how to disable this specific minifier optimization.

@nicolo-ribaudo nicolo-ribaudo closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
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