question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

return outside of functions

See original GitHub issue

Given:

// https://github.com/observing/pre-commit/blob/master/install.js#27
if (!exists(git) || !fs.lstatSync(git).isDirectory()) return;

I got a parse error:

SyntaxError: 'return' outside of function (1:54)
> 1 | if (!exists(git) || !fs.lstatSync(git).isDirectory()) return;
    |                                                       ^

This is because return is allowed within node modules but the parser does not like it.

https://prettier.github.io/prettier/#{"content"%3A"return"%2C"options"%3A{"printWidth"%3A80%2C"tabWidth"%3A2%2C"singleQuote"%3Afalse%2C"trailingComma"%3A"none"%2C"bracketSpacing"%3Atrue%2C"jsxBracketSameLine"%3Afalse%2C"parser"%3A"babylon"%2C"doc"%3Afalse}}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
jlongstercommented, Feb 28, 2017

It seems like we shouldn’t allow then. We want to encourage only spec-compliant code and this is a very strange node feature.

0reactions
escatoncommented, Mar 1, 2017

this is another question, why need to support two parsers that give different output?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python SyntaxError: 'return' outside function Solution
The “SyntaxError: 'return' outside function” error is raised when you specify a return statement outside of a function. To solve this error, ...
Read more >
Return Outside Function error in Python
Often, when one is confronted with a return outside function Python SyntaxError, it's due to improper indentation. Indentation tells Python that ...
Read more >
Return outside function Python: How to Resolve SyntaxError
The SyntaxError: return outside function in Python occurs when you are using return. The SyntaxError suggests that you are not using the ...
Read more >
Python return statement error " 'return' outside function"
The return statement only makes sense inside functions: def foo(): while True: return False.
Read more >
SyntaxError: return not in function - JavaScript - MDN Web Docs
A return or yield statement is called outside of a function. Maybe there are missing curly brackets somewhere? The return and yield statements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found