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

[html] A 'return' statement can only be used within a function body #143220

Closed
tjx666 opened this issue Feb 16, 2022 · 14 comments
Closed

[html] A 'return' statement can only be used within a function body #143220

tjx666 opened this issue Feb 16, 2022 · 14 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues insiders-released Patch has been released in VS Code Insiders verified Verification succeeded
Milestone

Comments

@tjx666
Copy link
Contributor

tjx666 commented Feb 16, 2022

Does this issue occur when all extensions are disabled?: Yes/No

Yes.

  • VS Code Version: 1.65.0-insider
  • OS Version: MacOs 12.2.1

Steps to Reproduce:

  1. create new HTML file
  2. paste following code
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Hammer Explorer</title>
    </head>
    <body oncontextmenu="return false;">
    </body>
</html>

image

@lramos15 lramos15 added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Feb 16, 2022
@lramos15
Copy link
Member

lramos15 commented Feb 16, 2022

That's not a valid javascript function to be used for the callback. You can see samples here https://www.w3schools.com/tags/ev_oncontextmenu.asp

@tjx666
Copy link
Contributor Author

tjx666 commented Feb 16, 2022

@lramos15 https://stackoverflow.com/a/16987533/11027903

I know it isn't a valid function. But It indeed works to forbidden event handler.

@lramos15
Copy link
Member

@tjx666 Ah yes this is a weird edge case of the spec https://www.w3.org/TR/2017/REC-html52-20171214/webappapis.html#the-event-handler-processing-algorithm.

Functions which return false don't work but just the string literal return false; seems to.

@lramos15 lramos15 reopened this Feb 16, 2022
@lramos15 lramos15 added bug Issue identified by VS Code Team member as probable bug html HTML support issues and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Feb 16, 2022
@crymic
Copy link

crymic commented Mar 13, 2022

Yeah I just noticed all of javascript now is erroring out in VS Code cause of the return.
Any temporary fixes to just have it ignore return on problems?

@aeschli aeschli added this to the March 2022 milestone Mar 14, 2022
@DanielTOsborne
Copy link

I just turned off the HTML setting to validate embedded scripts.

For those that don't want to wait for a fix, the setting to turn this off is html.validate.scripts.

I couldn't stand the errors in all my HTML files, and the 100+ in the project.
At least for me, actual embedded scripts are nearly non-existent in my project, aside from the element event handlers.

@aeschli aeschli changed the title A 'return' statement can only be used within a function body [html] A 'return' statement can only be used within a function body Mar 21, 2022
@rzhao271 rzhao271 added the verified Verification succeeded label Mar 22, 2022
@RyanHeid
Copy link

I just turned off the HTML setting to validate embedded scripts.

For those that don't want to wait for a fix, the setting to turn this off is html.validate.scripts.

I couldn't stand the errors in all my HTML files, and the 100+ in the project. At least for me, actual embedded scripts are nearly non-existent in my project, aside from the element event handlers.

I'm having the same problem right now. Sorry, I am a newb to coding. How do I turn this off? You said 'html.validate.scripts'. I'm using VS code, and don't know where to find that. Thanks!

@crymic
Copy link

crymic commented Mar 26, 2022 via email

@tjx666
Copy link
Contributor Author

tjx666 commented Mar 26, 2022

Verified in latest insider:

image

@tjx666
Copy link
Contributor Author

tjx666 commented Mar 26, 2022

Open settings by shortcut cmd + ,, and search that setting @RyanHeid .

image

Uncheck here:

image

But the stable version next week will fix this.

@RyanHeid
Copy link

I found it, and it solved my issue. Thank you so much! @tjx666

@crymic
Copy link

crymic commented Mar 28, 2022

I am working in javascript exclusively and this is still an issue.
html.validate.scripts on or off does nothing. It still shows it's an error.

@aeschli
Copy link
Contributor

aeschli commented Mar 28, 2022

@crymic Please file a new issue with

  • the vs code version you are using
  • a small code sample
  • information which language the editor is in (status bar, lower right)

@DanielTOsborne
Copy link

I am working in javascript exclusively and this is still an issue. html.validate.scripts on or off does nothing. It still shows it's an error.

The specific setting I mentioned is only for HTML pages. If you are editing .js files, then it won't work. There's a separate setting for that, but it will disable all javascript validation, and probably not what you want.
Wait for the official fix when it comes out.

aeschli added a commit that referenced this issue Apr 4, 2022
@aeschli aeschli modified the milestones: March 2022, April 2022 Apr 4, 2022
@aeschli aeschli reopened this Apr 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues insiders-released Patch has been released in VS Code Insiders verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

8 participants
@lramos15 @aeschli @rzhao271 @crymic @tjx666 @DanielTOsborne @RyanHeid and others