Skip to content

Enable warnings for unsafe transformations #570

Open

Description

@szimek

Having this option enabled by default in babili preset can cause a lot of issues, especially when using Babili on the server side with express.js, which relies on arguments.length, because it will convert an error handler to a normal middleware by removing the last parameter:

app.use((err, req, res, next) => {
  if (err) { res.status(500).send('¯\_(ツ)_/¯') }
});

gets converted to:

app.use((a,b,c)=>{a&&c.status(500).send('\xAF_(\u30C4)_/\xAF')});

It's also causing issues with ioredis library (and probably many more), which unfortunately also relies on arguments.length in a few places.

If enabling this by default is not an option, maybe a warning about it could be added to the README for Babili or babili-preset package? Currently it's only mentioned in the README for dead code elimination plugin itself, but I doubt people usually go through every plugin in the preset to see what options they have and if they are potentially dangerous. Or maybe there could be a babel-babili-preset-safe with all these keep* options turned on?

Activity

  1. boopathi commented on Jun 7, 2017

    @boopathi
    Member

    Thanks for bringing this up. I'd better have warnings rather than not doing the unsafe transformations - as it's tedious to specify the option to do the transformation instead of specifying it for NOT doing the transformation for a common case. A lot of transformations that a minifier does is unsafe. So, it would be nice to add warnings at all those places which are unsafe transformations.

    As you mentioned, the warnings could be added to the babili JS API, console.warn during the transformation for Node/CLI and also a mention in the README.

  2. added this to the 1.0 milestone on Dec 9, 2017
  3. changed the title [-]Enable keepFnArgs in dead code elimination plugin by default[/-] [+]Enable warnings for unsafe transformations[/+] on Dec 9, 2017
  4. jogibear9988 commented on Dec 17, 2017

    @jogibear9988
    Contributor

    Is is not also wrong, that the unicode characters get converted to a escape sequence?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions