This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 226515 - Javascript interpretation error
Summary: Javascript interpretation error
Status: RESOLVED INCOMPLETE
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords: REGRESSION
Depends on:
Blocks:
 
Reported: 2013-02-22 09:47 UTC by maxevron
Modified: 2013-07-23 13:04 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Smarty template making use of HighCharts to produce graph (2.82 KB, text/plain)
2013-07-23 12:53 UTC, RichardPilks
Details

Note You need to log in before you can comment on or make changes to this bug.
Description maxevron 2013-02-22 09:47:03 UTC
Product Version = NetBeans IDE 7.3 (Build 201302132200)
Operating System = Linux version 3.2.0-38-generic running on amd64
Java; VM; Vendor = 1.7.0_15
Runtime = OpenJDK 64-Bit Server VM 23.7-b01


The following code is considered bogus:

function createBasket() {
        if ($.trim($("#basket_label").val()) == '') {
            $("#basket_result").text('You must provide a label');
        } else if ($("#basket_currency").find('option:selected').val() == '') {
            $("#basket_result").text('You must select a currency');
        } else if (($.trim($("#basket_amount_max").val()) != '') && (isNaN(parseInt($("#basket_amount_max").val().replace(/ /g, ''))))) {
            $("#basket_result").text('Maximum amount must be a number');
        } else {
            $("#basket_result").text('');
            $("#basket_amount_max").val($("#basket_amount_max").val().replace(/ /g, ''));
            $.ajax({
                type: 'POST',
                async: true,
                url: '/basket/0/save',
                data: $('#basket_form').serialize(),
                dataType: 'json',
                success: function(data) {
                    if (typeof data.error != 'undefined') {
                        if (data.error = 1) {
                            $("#basket_result").text('This label already exists');
                        }
                    } else {
                        intBasketAmount = 0;
                        intBasketMaxAmount = parseInt($("#basket_amount_max").val().replace(/ /g, ''));
                        intBasketCurrency = parseInt($("#basket_currency").find('option:selected').val());
                        strBasketCurrency = $("#basket_currency").find('option:selected').attr('code');
                        $('#basket_new').dialog('close');
                        $('#basket_list').append('<option value="' + data.basket_id + '" selected="selected">' + $.trim($("#basket_label").val()) + '</option>').change();
                    }
                },
                error:  function(data) {
                    $("#basket_result").text('An error occured. The form may be expired. Please, refresh');
                }
            });
        }


An error is detected at "error: function(data) {". NetBeans indicates a comma is expected whereas this comma is present on previous line. This error is found in a Smarty compiled template (ie. a .tpl transformed and saved in Smarty "template_c" directory) but is not detected in the original .tpl file.

This is a regretion, Netbeans 7.2 does not point this error.
Comment 1 Vladimir Riha 2013-02-22 10:37:02 UTC
seems to be caused by spanning string over multiple lines, placing \ at the end helps (not sure about the regexp). Reassigning to JavaScript
Comment 2 maxevron 2013-02-22 10:42:49 UTC
(In reply to comment #1)
> seems to be caused by spanning string over multiple lines, placing \ at the end
> helps (not sure about the regexp). Reassigning to JavaScript

There is no string over multiple lines. The strings in this code are displayed with a carriage return in this ticket but there is no carriage return in the original source code. This is also true with:

replace(/
/g, ''));

which is in fact "replace(/ /g, ''));" in the source code.

However, Netbeans shows an error at line:

error:  function(data) {
Comment 3 Petr Pisl 2013-02-22 11:48:38 UTC
In NB 7.2 was used different parser - Rhino. In NB 7.3 we use Nashorn parser which is more strict than Rhino.
Comment 4 Petr Hejl 2013-04-16 12:57:29 UTC
If it is still present attach the file as attachment so we can properly evaluate.
Comment 5 RichardPilks 2013-07-23 12:53:20 UTC
Created attachment 137626 [details]
Smarty template making use of HighCharts to produce graph
Comment 6 RichardPilks 2013-07-23 12:53:36 UTC
I have a similar problem with javascript in a smarty template file where an error is reported that does not seem to be an error. The same file did not show an error in 7.2.

snippet:
 title: {
    text: 'Comparison of Sales And Costs'
 },
 xAxis: {
    categories: [
        {foreach from=$results key=market item=res}
            '{ucwords(strtolower($market))}',
        {/foreach}
    ]
 },
 yAxis: {
    min: 0,
    title: {
       text: 'Sales'
    },
    stackLabels: {
       enabled: true,
       style: {
          fontWeight: 'bold',
          color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
       }
    }
 },


The error is indicated on the second and fourth line under the "yAxis: {" line:
@err     title: {
            'Sales'
@err     },

Expected ; but found:

The project runs as expected. I include the code as an attachment

I am using:

Product Version: NetBeans IDE 7.3 (Build 201306052037)
Java: 1.6.0_30; Java HotSpot(TM) Client VM 20.5-b03
Runtime: Java(TM) SE Runtime Environment 1.6.0_30-b12
System: Windows 7 version 6.1 running on x86; Cp1252; en_ZA (nb)
Comment 7 Vladimir Riha 2013-07-23 13:04:51 UTC
RichardPilks: Please report it as a new issue( JavaScript/Editor, use [1]), your problem seems to be different than this one. Thank you

[1] https://netbeans.org/bugzilla/enter_bug.cgi?product=javascript