The generated AS3 source code for the function:
function testMethod () {
var $0 = 999, $1 = false;
result == 999 ? (visible = true) : visible = false;
Debug.info("visible=", $1)
}
On Fri, Sep 23, 2011 at 5:05 PM, Raju Bitter
<[email protected]> wrote:
> Had a small typo in the source code: for the Debug.info output it should be
> Debug.info("visible=", visible);
>
> On Fri, Sep 23, 2011 at 5:03 PM, Raju Bitter
> <[email protected]> wrote:
>> I've run into a problem with the ternary operator within LZX. Take the
>> following JS snippet:
>>
>> var result = 10;
>> var visible = false;
>> (result == 10) ? visible = true : visible = false;
>>
>> I can run the code snippet in Rhino and Chrome JavaScript console
>> without any problems. I can use the same code within an AS3
>> application. But the OpenLaszlo compiler shows the following error
>> message for both DHTML and SWF10:
>>
>> org.openlaszlo.sc.CompilerError:
>> ../../app/lzx/test/ou-jira-bugs/ternary/ternary.lzx: 7: Error: Access
>> of undefined property result, in line: result == 10 ? (visible = true)
>> : visible = false;
>> ../../app/lzx/test/ou-jira-bugs/ternary/ternary.lzx: 7: Error: Access
>> of undefined property visible, in line: result == 10 ? (visible =
>> true) : visible = false;
>> ../../app/lzx/test/ou-jira-bugs/ternary/ternary.lzx: 7: Error: Access
>> of undefined property visible, in line: result == 10 ? (visible =
>> true) : visible = false;
>>
>> Here's the full LZX code I use for testing:
>> <canvas debug="true">
>>
>> <node id="theNode">
>> <method name="testMethod">
>> var result = 999,
>> visible = false;
>> (result == 999) ? visible = true : visible = false;
>> Debug.info("result=", result);
>> </method>
>> </node>
>>
>> <button text="testMethod" onclick="theNode.testMethod()" />
>>
>> </canvas>
>>
>> Looking into the generated JS code for the DHTML runtime, I can see
>> that the expression is not compiled correctly:
>> Original code:
>> Generated: result == 999 ? (visible = true) : visible = false;
>>
>>
>> Generated code:
>> var $lzsc$temp = function() { /* -*- file: -*- */
>> try { /* -*- file: ternary.lzx#5 -*- */
>> var result_$0 = 999,
>> visible_$1 = false;
>>
>> result == 999 ? (visible = true) : visible = false;
>> Debug.info("result=", result_$0)
>> } /* -*- file: -*- */
>> catch ($lzsc$e) {
>> if ((Error["$lzsc$isa"] ? Error.$lzsc$isa($lzsc$e) :
>> $lzsc$e instanceof Error) && $lzsc$e !== lz["$lzsc$thrownError"]) {
>> $reportException("ternary.lzx", 4, $lzsc$e)
>> } else {
>> throw $lzsc$e
>> }
>> }
>> };
>>
>> Ternary operator expressions work with the following synax:
>> visible = (result == 999) ? true: false;
>>
>> Looks like a bug to me.
>>
>> - Raju
>>
>