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

Stops evaluating on return statement #20

Closed
sindresorhus opened this issue Jul 1, 2013 · 15 comments
Closed

Stops evaluating on return statement #20

sindresorhus opened this issue Jul 1, 2013 · 15 comments
Labels

Comments

@sindresorhus
Copy link

This JS code stop evaluating on the return statement.

function foo() {
    return 'bar';
// > Execution timed out.
}

console.log(foo());
@jcartledge
Copy link
Owner

Ouch. I haven't seen that in my own testing, and don't see it with your example:

function foo() {
    return 'bar';
}
// > undefined

console.log(foo());
// > bar
// > undefined

Can you tell me the output of node -v on your system?

(BTW thanks for reporting this!)

@sindresorhus
Copy link
Author

v0.10.11

@sindresorhus
Copy link
Author

Works fine in the Node REPL

@danharper
Copy link

Same here:

var doubleIt = function(num) {
    return num * 2;
// > Execution timed out.
}

doubleIt(2);

Node v0.10.2

@jcartledge
Copy link
Owner

Thanks. I really want to get to the bottom of this, but at present I can't reproduce it. Anything you can provide which will help me to get this result (OS, ST version, ???) would be greatly appreciated.

It looks like pexpect is hanging waiting for a prompt before it sends the next line to node. The relevant selection of the config is:

"JavaScript": {
    "cmd": "node -e \"require('repl').start('node> ')\"",
    "prompt": ["node> ", "\\.\\.+ "]
}

So we run node with a custom prompt then look for that prompt, or a run of dots (which is what is shown when inside a {} block.)

What prompt do you see in the node REPL when you are inside the body of the function?

@danharper
Copy link

Weirdly, @sindresorhus's example works for me, though:

function foo() {
    return 'bar';
}
// > undefined

console.log(foo());
// > bar
// > undefined

OSX 10.8.3
Sublime 2.0.1 build 2217

@danharper
Copy link

Wait. It's all working fine now? I didn't change anything. Same document, just re-pasted what I copied into here.

@jcartledge
Copy link
Owner

Thanks Dan. That's nuts. I'm glad to hear it's working now, but it sounds like there's definitely a bug here. Please post if you find anything else.

@danharper
Copy link

Idk, it's timed out again. In the node repl, it looks like this:

> var doubleIt = function(num) {
... return num * 2;
... }
undefined
> doubleIt(2);
4
>

@lpand
Copy link

lpand commented Jul 1, 2013

I don't know if this is related to this bug –if not i apologize– but, when i try to run any javascript code line i get this error inside the sublime interpreter:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./worksheet.py", line 101, in run
  File "./worksheet.py", line 19, in run
  File "./repl/repl.py", line 8, in get_repl
  File "./repl/repl.py", line 42, in __init__
  File "./repl/pexpect.py", line 429, in __init__
  File "./repl/pexpect.py", line 516, in _spawn
repl.pexpect.ExceptionPexpect: The command was not found or was not executable: node.

And obviously node works inside the terminal.

With Ruby it works.

I have OSX 10.8.4 and ST 2.0.1, build 2217.
Thanks,

Luca

@ghost
Copy link

ghost commented Jul 1, 2013

I have the same issue.

  • Node v0.8.19
  • OSX 10.8.4
  • ST 2.0.1, Build 2217

The NodeEval plugin works as expected, returning 7.

var x = 5;
// > undefined

function add_two(num) {
    return (num + 2);
// > Execution timed out.
}

add_two(x);

This issue aside, awesome plugin - thanks for your work!

@jcartledge
Copy link
Owner

@carettacaretta - that sounds like a different bug. Can you please open a new issue for it? Thanks very much.

@jcartledge
Copy link
Owner

OK I got it: it's tabs. The workaround is to indent with spaces but I know noone is going to be happy with that, so I guess I'll substitute them before sending to the REPL. Thanks to everyone who reported this; I had no idea.

@jcartledge
Copy link
Owner

There's a new tag - 0.7.2 - which should fix this. Not sure how long that will take to flow through to Package Control.

@danharper
Copy link

Bizarre. Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants