Multi Line comments in javascript aore marked as error

Hallo,

 

since I have updated to PHPStorm 2016 all multi line comments (/* comment */) in a javascript block nested in a file ending with .php are marked as error.

 

Is there any suggestion?

 

Regards

Claus

 

 

4 comments
Comment actions Permalink

Hi there,

Please provide sample code (ideally not as copy-paste text but as a downloadable file).

Please also state your exact IDE version.

1
Comment actions Permalink

Hallo Andriy

 

I could find out a little more details. But it is very strange

 

When I create a new PHP file test.php and insert this code

<?php
/**
* Created by PhpStorm.
* User: xxx
* Date: 22.09.16
* Time: 08:17
*/

?>

<script type="javascript">

/* Test */

</script>

 


everything works finde. But if I create a new file named test.js.php (which I use to determine if JS is used in this php file) and use the same contents, it get the error. It is very easy to reproduce.

Regards

Claus

0
Comment actions Permalink

Thanks for clarification.

It's not a bug but expected behaviour. And the issue is not about comments .. but actual <script> tags -- you do not need them in such file (if you remove them your comments will be treated properly).

What is ".php" file (from IDE point of view)? It's a file where PHP code is allowed/supported and outside them is a HTML context.

In your case you have double extension -- ".js.php". Here IDE does what users have asked to do (see original WI-24237 ticket) -- to have JavaScript as outer language context instead of default HTML. Basically -- IDE treats this file as ".js" file (where you do not need any <script> tags and write JavaScript straight away) with PHP code support. Before (few versions back -- like v8 and earlier) to have that done, you had to go into "Template Data Languages" settings page, find such file and associate JavaScript language manually -- now it's done automatically based on the file extensions.

To sum it up:

  • Any file with .js.php extension is treated as JavaScript file with possible PHP code in it.
  • This means that you simply do not need any <script> tags in such files

If you want to have "original" behaviour -- where file is treated as HTML with possible PHP code in it (as any .php file would be) you have few options:

  1. Do not use double extension
  2. If you have to use double extension -- use different one . Don't know --  .js.html.php maybe
  3. Keep this double extension ... but go into "Settings/Preferences | Languages & Frameworks | Template Data Languages" settings page (you can use search box in top left corner to speed up search) -- find this file in the list there and assign "HTML" in the right column

 

0
Comment actions Permalink

Hallo Andriy,

 

thanks for the fast reply and explanation.

 

Claus

0

Please sign in to leave a comment.