I think this is fine.  It means that users can write compile-time conditionals 
that mix with runtime in a natural way.

  if (true && ...)

is something that should be optimized away by any decent back-end, so I would 
not worry about that extra bit.

On 2011-01-14, at 09:35, André Bargull wrote:

> Yes and no. The compile-time evaluator supports short-circuiting, but it 
> doesn't remove neutral elements from boolean expressions.
> 
> In your example:
>> if ((! $mobile) && this.quirks.ie_alpha_image_loader ) {
> 
> Compiling with $mobile = `true`:
> if ((! true) && this.quirks.ie_alpha_image_loader) { ... }
> => if (false && this.quirks.ie_alpha_image_loader) { ... }
> => if (false) { ... } /* short-circuiting applied */
> => /* statement removed */
> 
> Compiling with $mobile = `false`:
> if ((! false) && this.quirks.ie_alpha_image_loader) { ... }
> => if (true && this.quirks.ie_alpha_image_loader) { ... }
> => /* this.quirks.ie_alpha_image_loader can't be eval'ed at compile time */
> => /* the complete statement will be emitted */
> 
> 
> Therefore I've suggested to use the conditional operator:
>> if (! $mobile ? this.quirks.ie_alpha_image_loader : false) { ... }
> 
> The compile-time evaluator is applied two times for this statement:
> 1) for the if-clause
> 2) for the conditional operator
> 
> Compiling with $mobile = `true`:
> if (! $mobile ? this.quirks.ie_alpha_image_loader : false) { ... }
> => if (! true ? this.quirks.ie_alpha_image_loader : false) { ... }
> => if (false ? this.quirks.ie_alpha_image_loader : false) { ... }
> => if (false) { ... }
> => /* statement removed */
> 
> Compiling with $mobile = `false`:
> if (! $mobile ? this.quirks.ie_alpha_image_loader : false) { ... }
> => if (! false ? this.quirks.ie_alpha_image_loader : false) { ... }
> => if (true ? this.quirks.ie_alpha_image_loader : false) { ... }
> => /* this.quirks.ie_alpha_image_loader can't be eval'ed at compile time */
> => /* now the compiler visits the conditional expression */
> => /* this will return `this.quirks.ie_alpha_image_loader` */
> => /* if-statement is rewritten to: */
> if (this.quirks.ie_alpha_image_loader) { ... }
> 
> 
> 
> On 1/13/2011 7:43 PM, P T Withington wrote:
>> Is the compile-time evaluator smart enough to short-circuit boolean 
>> expressions even if not all the terms are compile-time constants?  E.g.,
>> 
>>   if ((! $mobile)&&  this.quirks.ie_alpha_image_loader ) {
>> 
>> should emit no code for $mobile, and be equivalent to:
>> 
>>   if (this.quirks.ie_alpha_image_loader) {
>> 
>> for non-mobile?  Then you would not need the more contorted:
>> 
>>   if (! $mobile ? this.quirks.ie_alpha_image_loader : false) {
>> 
>> On 2011-01-12, at 12:29, André Bargull wrote:
>> 
>>> The conditional operator is also handled by the compile-time evaluator, so 
>>> these two alternatives actually work and only emit the minimal javascript 
>>> code:
>>>> if (! $mobile ? this.quirks.ie_alpha_image_loader : false) {
>>>>  i._parent.style.display = '';
>>>> } else {
>>>>  i.style.display = '';
>>>> }
>>> and:
>>>> var target = $mobile ? e.target : (e.target || e.srcElement);
>>> 
>>> 
>>> On 1/12/2011 5:36 PM, Max Carlson wrote:
>>>> Change maxcarlson-20110112-6K9 by maxcarlson@friendly on 2011-01-12 
>>>> 08:29:25 PST
>>>>     in /Users/maxcarlson/openlaszlo/trunk2
>>>>     for http://svn.openlaszlo.org/openlaszlo/trunk
>>>> 
>>>> Summary: First pass at commenting out non-mobile code for $mobile runtime
>>>> 
>>>> Bugs Fixed: LPP-9645 - add if (! $mobile) {...} blocks to DHTML LFC 
>>>> (partial)
>>>> 
>>>> Technical Reviewer: hminsky
>>>> QA Reviewer: ptw
>>>> 
>>>> Details: Without trying too hard, I was able to reduce the total size of 
>>>> the mobile LFC by ~1.6K compressed, down to 94k from 95.7k!  I think this 
>>>> is moving in the right direction.
>>>> 
>>>> I could have been more aggressive, but I'm trying to not restructure the 
>>>> code.  This means I have to leave some bits in, e.g.:
>>>> 
>>>>         if (this.quirks.ie_alpha_image_loader) {
>>>> if (! $mobile) {
>>>>             i._parent.style.display = '';
>>>> }
>>>>         } else {
>>>>             i.style.display = '';
>>>>         }
>>>> 
>>>> I could restructure a bit and eliminate the test, but this is just a first 
>>>> pass...  Also, it would be nice if I could do things like:
>>>> 
>>>>     // IE calls `target` `srcElement`
>>>>     var target = e.target
>>>> if (! $mobile) {
>>>>     || e.srcElement;
>>>> }
>>>> 
>>>> but that freaks out the parser.
>>>> 
>>>> Files:
>>>> M       WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
>>>> 
>>>> Changeset: 
>>>> http://svn.openlaszlo.org/openlaszlo/patches/maxcarlson-20110112-6K9.tar
>>>> 
>>>> 
>> 
>> 


Reply via email to