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 241146

Summary: JSTL within javascript can cause javascript parser to become confused
Product: javascript Reporter: brettryan <brettryan>
Component: EditorAssignee: Petr Pisl <ppisl>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: PC   
OS: Mac OS X   
Issue Type: DEFECT Exception Reporter:

Description brettryan 2014-01-30 04:44:01 UTC
Sometimes you may find JSTL expressions within a javascript block that may build a static array for example. When this occurs it can confuse the javascript parser which causes it to then not format or recognize variables correctly even in function scope.

Consider the following:

  <script type="text/javascript">
    var widgetLinks = {
      <c:forEach var="ent" items="${requestScope['widgetLinks']}" varStatus="vs1">
        "${ent.key}": [
          <c:forEach varStatus="vs2" var="c" items="${ent.value}">${c.widgetId}${vs2.last ? '' : ','}</c:forEach>
        ]${vs1.last ? '' : ','}
      </c:forEach>
    };
  </script>

Forget the fact this looks ugly, note however that it because of `vs1.last' it causes the parser to go haywire.

Now I don't propose that this be fixed, I'm fine that it do this as it's complicated. What I am suggesting however, is that if it breaks within one script scope, that it does not affect other scripts. i.e. consider the following:

  <script type="text/javascript">
    // Above ugly block.
  </script>
  <script type="text/javascript">
    var doSomething = function(x) {
      return x + x * 3;
    );
    doSomething();
  </script>

In the above case, you can not rename, navigate references, or anything, within the second block. What I'm proposing is that each script block be treated semi-independently.

i.e. if a block exposes a global variable that can be identified, then that's all it should do. As soon as the script end tag is found the parser should not try and format anything going forward.



Product Version: NetBeans IDE Dev (Build 201401260001)
Java: 1.7.0_40; Java HotSpot(TM) 64-Bit Server VM 24.0-b56
Runtime: Java(TM) SE Runtime Environment 1.7.0_40-b43
System: Mac OS X version 10.9.1 running on x86_64; UTF-8; en_AU (nb)
User directory: /Users/bryan/Library/Application Support/NetBeans/dev
Cache directory: /Users/bryan/Library/Caches/NetBeans/dev
Comment 1 Petr Hejl 2014-07-31 14:23:55 UTC
This would need a complex logic in the parser (nashorn) or better error recovery.
Comment 2 Petr Hejl 2014-08-01 08:50:54 UTC
I have improved formatting of completely unparsable embedded code in web-main 46a2a493cf31.
Comment 3 Quality Engineering 2014-08-02 05:07:10 UTC
Integrated into 'main-silver', will be available in build *201408020001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/46a2a493cf31
User: Petr Hejl <phejl@netbeans.org>
Log: #241146 - JSTL within javascript can cause javascript parser to become confused
Comment 4 Quality Engineering 2014-08-03 01:57:13 UTC
Integrated into 'main-silver', will be available in build *201408030001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/8bcda38fcc2f
User: Petr Hejl <phejl@netbeans.org>
Log: #241146 - JSTL within javascript can cause javascript parser to become confused