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

Allow top-level return statements in JavaScript #1069

Closed
spahnke opened this issue Sep 19, 2018 · 2 comments · Fixed by microsoft/monaco-typescript#46
Closed

Allow top-level return statements in JavaScript #1069

spahnke opened this issue Sep 19, 2018 · 2 comments · Fixed by microsoft/monaco-typescript#46
Labels
feature-request Request for new features or functionality typescript
Milestone

Comments

@spahnke
Copy link
Contributor

spahnke commented Sep 19, 2018

Hi,

we would like to use the monaco-editor in a scripting environment where you only write the body of a function without having to specify/worry about the function signature itself. It is added on the server side before the code is executed. E.g.

let result = 0;
// compute result
return result;

However, top-level return statements are reported as a syntax error (because they normally are). Is there a way to suppress this specific diagnostic?

A 'return' statement can only be used within a function body.

Being able to do this would make a lot of sense in scripting environments that use the monaco-editor, IMHO.

Thanks!

P.S.: I found #45 as a possible workaround, though I haven't had the time to try that, yet. (And it uses non-API methods)

@spahnke
Copy link
Contributor Author

spahnke commented Sep 22, 2018

Since the methods mentioned in #45 seem to be gone, there is no obvious workaround for this. Is this the right place to ask, or is it rather a feature request for the TypeScript language server to have such an option?

@alexdima alexdima added feature-request Request for new features or functionality typescript labels Oct 16, 2018
spahnke added a commit to spahnke/monaco-playground that referenced this issue Nov 23, 2018
Since there is not option in TypeScript to allow top
level return statements we listen to changes to
decorations and filter the marker list.

microsoft/monaco-editor#1069
@khmylov
Copy link

khmylov commented Dec 6, 2018

👍, this would be extremely useful for various embedded scripting scenarios.
The only option I see for now is to listen to changes of editor's error markers and monkey-patch them to remove the ones we don't want to see :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants