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

Regression - JavaScript false positive errors ("Expression expected.") #86983

Closed
ghnp5 opened this issue Dec 14, 2019 · 7 comments
Closed

Regression - JavaScript false positive errors ("Expression expected.") #86983

ghnp5 opened this issue Dec 14, 2019 · 7 comments
Assignees

Comments

@ghnp5
Copy link

ghnp5 commented Dec 14, 2019

  • VSCode Version: 1.41.0
  • OS Version: Windows 10

Steps to Reproduce:

<script type="text/javascript">
intVar = <?php echo $someInt; ?>;
someFunction(someArray[<?php echo $someInt; ?>]);
</script>

The first JS line will show error "Expression expected.".
The second JS line will show "An element access expression should take an argument.".

I suppose the JavaScript lint is stripping out the PHP elements before parsing, but in fact, those PHP elements are putting contents where the lint expects them to be.

@vscodebot vscodebot bot removed the new release label Dec 16, 2019
@mjbvz mjbvz assigned aeschli and unassigned mjbvz Dec 16, 2019
@aeschli
Copy link
Contributor

aeschli commented Dec 17, 2019

Is this with the built-in HTML language support?
We don't support PHP in HTML documents. If it once happen to work, that was just a lucky coincidence.
Instead you have to open the file in PHP mode and have a PHP extension that adds richer language support.
Or you can disable JavaScript validation in HTML, if you want to continue with it like that.

@aeschli aeschli closed this as completed Dec 17, 2019
@ghnp5
Copy link
Author

ghnp5 commented Dec 17, 2019

Why is this closed?

The file extension is .php and the parsing language in VSCode is PHP.

Why wouldn't you support PHP tags in the middle of HTML? That's very common in many projects... not everyone uses templates like Twig.

@aeschli
Copy link
Contributor

aeschli commented Dec 17, 2019

Ah, ok, you are in PHP mode and you are using a PHP extension. You need to file this against the PHP extension you use. VSCode has no rich PHP language support out-of-the-box.

@ghnp5
Copy link
Author

ghnp5 commented Dec 17, 2019

The PHP extensions I use are not giving any errors.

It is the built-in JS validator of VSCode that is complaining about invalid JS, in the lines similar to the above.

Do you still think this is something that the PHP extensions need to fix?

@aeschli
Copy link
Contributor

aeschli commented Dec 17, 2019

The HTML and/or JS support are only enabled if the editor language mode is HTML or JS.

Can you run VSCode with all extensions disabled?

Here's what I see when I try your example with PHP:
DeepinScreenshot_select-area_20191217151157

With HTML (errors as expected, PHP code is not HTML):
image

@bmewburn
Copy link

This is probably bmewburn/vscode-intelephense#836

@ghnp5
Copy link
Author

ghnp5 commented Dec 18, 2019

Thank you very much.
I raised bmewburn/vscode-intelephense#903 after I saw this error went away when disabling PHP Intelephense.

Oh - I see now it's a duplicate. Thanks for pointing that out, @bmewburn

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants