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

repl returns the result 'use strict' unexpectedly #2299

Closed
mikedmcfarland opened this issue Sep 1, 2015 · 4 comments
Closed

repl returns the result 'use strict' unexpectedly #2299

mikedmcfarland opened this issue Sep 1, 2015 · 4 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@mikedmcfarland
Copy link

The result of some single undefined statements when using the repl via babel-node is 'use strict' when I'd expect it to be undefined.
For example, using node's repl produces:

> node
> var s = ""
undefined

While babel's repl produces:

> babel-node
> var s = ""
'use strict'

I'd expect the result of the expression to also be undefined.

in case it's relevant, my versions are:

> node --version
v0.12.7

> babel --version
5.8.23 (babel-core 5.8.23)
@bradencanderson
Copy link
Contributor

Repro with babel-node -e "var a = 2;" -p.

This feels like a bug in the strict transformer. Consistent output between node and babel-node seems like a reasonable thing to expect.

babel-node -p should print the result of the source program, regardless of what the source is transformed into.

@loganfsmyth
Copy link
Member

Consistent output between node and babel-node seems like a reasonable thing to expect.

This is actually the same as what node prints, if you include it all on one line.

> "use strict"; var a = 2;
'use strict'
> 

This doesn't have anything to do with the strict transformer specifically, what this essentially comes down to is some weirdness in the way eval works, e.g.

eval('"use strict"; var a = 2;') === 'use strict'; 

Seems like you'd want a plugin to automatically add an expressionStatement to the end of the code if there wasn't one (assuming that is the logic eval follows).

Program(node){
    if (!t.isExpressionStatement(node.body[node.body.length - 1)){
        node.body.push(t.expressionStatement(t.identifier('undefined')));
    }
}

@jamiebuilds
Copy link
Contributor

@loganfsmyth That seems to be okay, I would just be worried about an edge case where the actual result isn't being output because undefined was being pushed to the end.

@hzoo
Copy link
Member

hzoo commented Dec 14, 2016

I believe we did this in #4562

@hzoo hzoo closed this as completed Dec 14, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants