BUG - RAPID - JS Syntax Error Error

Post your questions and problem reports here

Moderator: kfury77

Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.

  • Check the Support section of the corresponding product first. Chances are you will find your answer there;
  • Do not create new topics for already reported problems. Add your comments to the existing topics instead;
  • Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
  • Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
  • Include the version number of the software you are using;
  • This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;

BUG - RAPID - JS Syntax Error Error

Postby Will Fastie » Wed Jun 20, 2018 11:07 am

The following snippet of code trips an error in a PHP file when the cursor is placed somewhere inside the <script> tag:

Image

The error is obviously tripped by what the editor sees as a JavaScript syntax error.

If a manual PHP syntax check is run, no syntax error is found. That is the correct result because this is perfectly valid PHP, not an error.

Once the error is marked with the pink highlight, it remains unless another syntax error is found elsewhere in the file. If another error is found, that error is highlighted by the PHP syntax checker. Once that error is resolved, the highlight in the JS code does not return unless the cursor is again placed in the <script> tag.

This use case is quite common for me because it allows server-side results to customize the JS code that will be sent to the browser. I do it all the time.

Because the code shown above is legal PHP syntax, I consider this a serious bug.
Will
WebDesignBuild.biz, Fastie.com
User avatar
Will Fastie
 
Posts: 156
Joined: Mon Jan 31, 2005 6:47 pm
Location: Timonium, MD USA

Re: BUG - RAPID - JS Syntax Error Error

Postby pmk65 » Sun Jun 24, 2018 2:42 pm

This is not caused by PHP parsing, but the JavaScript parsing. I experienced the same problem with a pure JavaScript function.
Code: Select all
<script type="text/javascript">
// Get the word of a string given the string and index
function getWordAt(str, pos) {
    // Perform type conversions.
    str = String(str);
    pos = Number(pos) >>> 0;

    // Search for the word's beginning and end.
    var left = str.slice(0, pos + 1).search(/\S+$/),
        right = str.slice(pos).search(/\s/);

    // The last word in the string is a special case.
    if (right < 0) {
        return str.slice(left);
    }

    // Return the word, using the located bounds to extract it from the string.
    return [str.slice(left, right + pos), left];
}
</script>

With the above code, the line "return [str.slice(left, right + pos), left];" is wrongly flagged as "Unrecoverable syntax error. (66% scanned)"
But if I add a blank line after the 1st comment line, the error goes away?!?! And the error doesn't show up again if I remove the blank line again!?!?

My example and yours both uses RegEx matching, so my guess is that WeBuilder/RapidPHP JavaScript parsing "chokes" on the slashes somehow.

Really annoying bug. I hope it will get fixed soon..
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 671
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: BUG - RAPID - JS Syntax Error Error

Postby Will Fastie » Sun Jun 24, 2018 4:06 pm

pmk65 wrote:This is not caused by PHP parsing, but the JavaScript parsing.

I understand your point but it is not quite accurate. Yes, the parser is handling JS when it is in the script block. But the parent file is a PHP file and my inclusion of PHP code in the JS block is legal syntax. The parser must detect the legal presence of PHP in the JS block and act accordingly.

My guess is that this is a deeper problem than RegEx comparisons. I'm sure there is a computer science name for it but I call it "parser hopping" or "parser nesting" and it is something exacerbated in Web development because multiple languages (HTML, CSS, JS, PHP, and more) can be present in the same file. Worse, finding PHP in a JS file is an error, while finding PHP in a script tag in a PHP file is not. I believe PhpStorm can even parse SQL statements inside a PHP string, which is quite the thing.

I should mention that Visual Studio Code handles this correctly. I took the snippet pictured in the original post and induced a syntax error in the PHP tag, which was caught. I removed the error and VSC found no problem. I induced a JS syntax error and VSC caught that. In short, it can be done.
Will
WebDesignBuild.biz, Fastie.com
User avatar
Will Fastie
 
Posts: 156
Joined: Mon Jan 31, 2005 6:47 pm
Location: Timonium, MD USA

Re: BUG - RAPID - JS Syntax Error Error

Postby Aivars » Tue Jun 26, 2018 1:07 pm

We'll try to fix it for the next update. It's quite possible that the fix will remove Javascript error checking for inlined JavaScript that contains PHP/ASP code altogether, otherwise it's quite annoying, I agree with pmk65 there.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2374
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: BUG - RAPID - JS Syntax Error Error

Postby Will Fastie » Tue Jun 26, 2018 1:27 pm

Aivars wrote:It's quite possible that the fix will remove Javascript error checking for inlined JavaScript that contains PHP/ASP code altogether...

At the very least, that would be a disappointment.
Will
WebDesignBuild.biz, Fastie.com
User avatar
Will Fastie
 
Posts: 156
Joined: Mon Jan 31, 2005 6:47 pm
Location: Timonium, MD USA

Re: BUG - RAPID - JS Syntax Error Error

Postby Will Fastie » Tue Jul 24, 2018 10:19 am

NetBeans and Visual Studio Code both handle this situation properly.

In particular, if a PHP syntax error is induced into the line of PHP code inside the JavaScript block, both NB and VSC throw an error and when the error is corrected they both show the code as good.
Will
WebDesignBuild.biz, Fastie.com
User avatar
Will Fastie
 
Posts: 156
Joined: Mon Jan 31, 2005 6:47 pm
Location: Timonium, MD USA

Re: BUG - RAPID - JS Syntax Error Error

Postby Aivars » Tue Jul 24, 2018 11:01 am

Yes, that would still be the case. PHP syntax checking won't be affected, just the JavaScript code blocks that are broken up by inlined server-side code blocks.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2374
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: BUG - RAPID - JS Syntax Error Error

Postby Will Fastie » Tue Jul 24, 2018 12:07 pm

What I'm saying is that NB and VSC do not trip an error like Rapid does.
Will
WebDesignBuild.biz, Fastie.com
User avatar
Will Fastie
 
Posts: 156
Joined: Mon Jan 31, 2005 6:47 pm
Location: Timonium, MD USA


Return to HTMLPad / Rapid CSS / Rapid PHP / WeBuilder Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron