Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For both operators, the trick is that both the left-hand-side and right-hand-side expression are not evaluated too often. To achieve this, we introduce auxiliary variables like for for each. The code transformation examples are for &&= only, as ||= works analogously.

Simple Pattern

...

ActionScript:

Code Block
<identifier> &&= <rhs>

...

Code Block
<identifier> = <identifier> && <rhs>

Complex Pattern

...

If the left-hand-side can be split into two expressions, where the first evaluates to some object and the second to some property, do so and rewrite:

...

Code Block
<exp1>[<exp2>] &&= <rhs>

JavaScript:

Code Block
var $0, $1;
($0 = <exp1>, )[$1 = <exp2>;
$0[$1] = $0[$1] && <rhs>;

Wiki Markup
Note that {{foo().y}} is the same as {{foo()\['y'\]}} and thus also matches this pattern.

Examples

Simple lhs

ActionScript:

Code Block

x &&= foo()

JavaScript:

Code Block

x = x && foo()

Complex lhs

Complex object

ActionScript:

Code Block

foo().y &&= bar()

JavaScript:

Code Block

var $0, $1;
($0  = foo())[$1 = 'y'] = $0[$1] && bar();

which of course could be simplified to

Code Block

var $0;
($0 = foo()).y = $0.y && bar()
Complex property

ActionScript:

Code Block

x[foo()] &&= bar()

JavaScript:

Code Block

var $0, $1;
($0 = x)[$1 = foo()] = $0[$1] && bar()

which of course could be simplified to

Code Block

var $1;
x[$1 = foo()] = x[$1] && bar()
Complex object and property

ActionScript:

Code Block

baz()[foo()] &&= bar()

JavaScript:

Code Block

var $0, $1;
($0 = baz())[$1 = foo()] = $0[$1] && bar()

which cannot be simplified.