Invalid inspections & syntax highlighting in *.js.php files

I recently upgraded from PHPStorm 10 to 2018.1 and found that the new IDE is misinterpreting all my *.js.php files, adding strange syntax highlights and showing errors where there are none. Everything works fine when I rename the file to *.php, but adding *.js.php confuses it. Here's some sample code:

<?php
$u = new stdClass();
$u->id = 'id';
?>

function ViewModel()
{
var setUser = function(user) {
var userId = user.<?=$u->id?>;
var string = <?='TestString'?>;
}
}
0

Hi there,

".js.php" file extension means that JavaScript is set as main outer language instead of default HTML. It's the same as if you have just ".php" extension and then go to "Settings/Preferences | Languages & Frameworks | Template Data Languages" and manually assign JavaScript language to that file there. With such double extension IDE does it automatically for you.

With the above in mind -- your JS code gets validated accordingly and such dynamic usage of a property (user.<?=$u->id?>) is not something that IDE supports well right now.

 

Cannot suggest any related existing tickets right now -- could not find one that would match your situation (about highlighting the "user.<?=$u->id?>" part).

Other than that -- either change file double extension to something else .. or override outer language manually (see first paragraph).

0
Avatar
Permanently deleted user

Hi Andriy,

Thanks for your help. Yes, my use case has always been tricky for IDEs: using "name objects" to keep back-end models in sync with front-end code. However, PHPStorm 10 didn't have nearly so much trouble. (I used "Template Data Language" settings in both cases but as you say, it's automatic now.) Here's what I'm seeing:

 

Is there a reason the new version seems more confused by ".js.php" code than the old version?

0

I may only suggest to file a ticket to the Issue Tracker , especially since it was working better in the past.

ATM I have no idea what may have caused this.

Error highlighting (what places are highlighted) look particularly wrong in some places (e.g. "String"  in "TestString" part...)

1

请先登录再写评论。