lebab / lebab

Turn your ES5 code into readable ES6. Lebab does the opposite of what Babel does.

Home Page:https://lebab.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some template string conversions aren't safe

webbedspace opened this issue · comments

commented

Consider this code:

        var a = {
          toString: function() { return "foo"; },
          valueOf: function() { return "bar"; },
        };
        console.log(a+'')

This outputs "bar". But Lebab will convert it to this code:

        const a = {
          toString() { return "foo"; },
          valueOf() { return "bar"; },
        };
        console.log(`${a}`)

This outputs "foo" in conforming ES6 engines.
Of course, it isn't possible to statically confirm whether a given value has a valueOf that meaningfully differs from toString. At the least, consider including a warning about this.

That's indeed a tricky case. Pretty much impossible to ensure that it doesn't happen.

Did you actually encounter a code like this or is it a purely theoretical issue?

I think the best we can do about this is to document this shortcoming of the template transform. Not even feasible to display a warning, as that would mean printing a warning for pretty much every template string conversion.

I've linked this issue from the main page, but I don't think there's anything we can really do about that.

If somebody actually encounters this bug with real-world code, feel free to comment.

Closing this for now as won't fix.