1- import { FIELD , toBool , autoConvertAdd , isBlank , FunctionWrapper , BaseException } from "facade/lang" ;
1+ import { FIELD , autoConvertAdd , isBlank , isPresent , FunctionWrapper , BaseException } from "facade/lang" ;
22import { List , Map , ListWrapper , MapWrapper } from "facade/collection" ;
33import { ClosureMap } from "./closure_map" ;
44
@@ -29,6 +29,9 @@ export class ImplicitReceiver extends AST {
2929 }
3030}
3131
32+ /**
33+ * Multiple expressions separated by a semicolon.
34+ */
3235export class Chain extends AST {
3336 @FIELD ( 'final expressions:List' )
3437 constructor ( expressions :List ) {
@@ -39,7 +42,7 @@ export class Chain extends AST {
3942 var result ;
4043 for ( var i = 0 ; i < this . expressions . length ; i ++ ) {
4144 var last = this . expressions [ i ] . eval ( context ) ;
42- if ( last != null ) result = last ;
45+ if ( isPresent ( last ) ) result = last ;
4346 }
4447 return result ;
4548 }
@@ -118,7 +121,7 @@ export class KeyedAccess extends AST {
118121 } else if ( obj instanceof List ) {
119122 return ListWrapper . get ( obj , key ) ;
120123 } else {
121- throw new BaseException ( `Cannot access ${ key } on ${ obj } ` ) ;
124+ return obj [ key ] ;
122125 }
123126 }
124127
@@ -135,7 +138,7 @@ export class KeyedAccess extends AST {
135138 } else if ( obj instanceof List ) {
136139 ListWrapper . set ( obj , key , value ) ;
137140 } else {
138- throw new BaseException ( `Cannot access ${ key } on ${ obj } ` ) ;
141+ obj [ key ] = value ;
139142 }
140143 return value ;
141144 }
@@ -225,14 +228,14 @@ export class Binary extends AST {
225228 eval ( context ) {
226229 var left = this . left . eval ( context ) ;
227230 switch ( this . operation ) {
228- case '&&' : return toBool ( left ) && toBool ( this . right . eval ( context ) ) ;
229- case '||' : return toBool ( left ) || toBool ( this . right . eval ( context ) ) ;
231+ case '&&' : return left && this . right . eval ( context ) ;
232+ case '||' : return left || this . right . eval ( context ) ;
230233 }
231234 var right = this . right . eval ( context ) ;
232235
233236 // Null check for the operations.
234- if ( left == null || right == null ) {
235- throw new BaseException ( "One of the operands is null " ) ;
237+ if ( isBlank ( left ) || isBlank ( right ) ) {
238+ throw new BaseException ( "One of the operands is not defined " ) ;
236239 }
237240
238241 switch ( this . operation ) {
@@ -266,7 +269,7 @@ export class PrefixNot extends AST {
266269 }
267270
268271 eval ( context ) {
269- return ! toBool ( this . expression . eval ( context ) ) ;
272+ return ! this . expression . eval ( context ) ;
270273 }
271274
272275 visit ( visitor ) {
0 commit comments