History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: LPP-5129
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: P0 P0
Assignee: Unassigned
Reporter: Sarah Allen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenLaszlo

lzo's compile differently? for (var i = 0, len = childNodes.length; i < len; i++) { causes error

Created: 18/Nov/07 05:52 PM   Updated: 05/Feb/08 02:08 PM
Component/s: Compiler - JavaScript
Affects Version/s: Cranberry
Fix Version/s: RingDing (4.1)

Time Tracking:
Not Specified

Severity: Minor
Fixed in Change#: 7,402
Runtime: N/A
Fix in hand: False


 Description  « Hide
This problem happened with the following problem code in a binary library (lzo) which compiled fine, but the error appeared when compiling the app that included that library (including the lzx did not cause a compiler error)

The problem appears to be that the compiler doesn't like syntax like this:
    for (var i = 0, len = childNodes.length; i < len; i++) {
 
 Changing it to:
     var len = childNodes.length;
     for (var i = 0; i < len; i++) {
 
 fixed it. This is perfectly legal JS -- it's just like
     var a, b;

but obviously the compiler doesn't accept it. It's also odd
that this compiles in runtime mode, but not using lzc. This
definitely seems like a bug in the compiled libraries feature.


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
P T Withington - 19/Nov/07 02:28 PM
Ok, I see the problem.

This is because the parser parses the variable declaration as VarDeclList, but turns it into a StatementList in the AST. That works fine in most places, but not in a for expression (where it needs to be treated as an ExpressionList not a StatementList. The unparser is unparsing it with ;'s as the list separator, which is broken.



P T Withington - 28/Nov/07 08:12 AM
r7402 | ptw | 2007-11-28 11:10:45 -0500 (Wed, 28 Nov 2007) | 38 lines
Changed paths:
   M /openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
   M /openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ASTVisitor.java
   M /openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
   M /openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
   M /openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
   M /openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java

Change 20071127-ptw-C by ptw@dueling-banjos.local on 2007-11-27 16:41:07 EST
    in /Users/ptw/OpenLaszlo/ringding-2
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Correct handling of comma-separated var expressions

Bugs Fixed:
LPP-5129 ' lzo's compile differently? for (var i = 0, len = childNodes.length; i < len; i++) { causes error'

Technical Reviewer: dda@ddanderson.com (Message-Id: <6C1DA5CA-369A-4F4A-AE69-4428513AAACB@ddanderson.com>)
QA Reviewer: hminsky (pending)

Details:
    JavascriptGenerator: Handle variableStatement, consolidate
    isExpression

    CommonGenerator: Handle new AST type VariableDeclarationList, mov
    base isExpression here

    ASTVisitor: Add interfaces for VariableDeclaration and
    VariableDeclarationList

    Compiler: A VariableStatement cannot be handled as a Statement.
    Implement correct unparsing of VariableStatement,
    VariableDeclarationList, and VariableDeclaration.

    CodeGenerator: consolidate isExpression

    Parser: Parse comma-separated variable declarations into new AST
    VariableDeclarationList

Tests:
    smokecheck

    observed that test case in bug report is correctly passed through
    for dhtml


Mamye Kratt - 05/Feb/08 02:08 PM
(pagan-deities build r7956 - from legals -> trunk -> pagan-deities)
Successfully ran test/smoke/smokecheck.lzx in swf/dhtml in debug and non-debug as suggested in ptw's checkin comments.