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

Some template string conversions aren't safe #107

Closed
webbedspace opened this issue Mar 2, 2016 · 2 comments
Closed

Some template string conversions aren't safe #107

webbedspace opened this issue Mar 2, 2016 · 2 comments

Comments

@webbedspace
Copy link

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.

@nene
Copy link
Collaborator

nene commented Mar 2, 2016

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.

@nene
Copy link
Collaborator

nene commented Mar 3, 2016

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.

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