@@ -23,21 +23,32 @@ import { expressionTypes } from './types';
2323const operators = {
2424 '=' : ( context , leftHandSideValue , leftValue , value ) => {
2525 leftHandSideValue . assignFrom ( context , value ) ;
26+ return value ;
2627 } ,
2728 '+=' : ( context , leftHandSideValue , leftValue , value ) => {
28- leftHandSideValue . assignFrom ( context , leftValue . add ( context , value ) ) ;
29+ const result = leftValue . add ( context , value ) ;
30+ leftHandSideValue . assignFrom ( context , result ) ;
31+ return result ;
2932 } ,
3033 '-=' : ( context , leftHandSideValue , leftValue , value ) => {
31- leftHandSideValue . assignFrom ( context , leftValue . subtract ( context , value ) ) ;
34+ const result = leftValue . subtract ( context , value ) ;
35+ leftHandSideValue . assignFrom ( context , result ) ;
36+ return result ;
3237 } ,
3338 '*=' : ( context , leftHandSideValue , leftValue , value ) => {
34- leftHandSideValue . assignFrom ( context , leftValue . multiplyBy ( context , value ) ) ;
39+ const result = leftValue . multiplyBy ( context , value ) ;
40+ leftHandSideValue . assignFrom ( context , result ) ;
41+ return result ;
3542 } ,
3643 '/=' : ( context , leftHandSideValue , leftValue , value ) => {
37- leftHandSideValue . assignFrom ( context , leftValue . divideBy ( context , value ) ) ;
44+ const result = leftValue . divideBy ( context , value ) ;
45+ leftHandSideValue . assignFrom ( context , result ) ;
46+ return result ;
3847 } ,
3948 '%=' : ( context , leftHandSideValue , leftValue , value ) => {
40- leftHandSideValue . assignFrom ( context , leftValue . modulo ( context , value ) ) ;
49+ const result = leftValue . modulo ( context , value ) ;
50+ leftHandSideValue . assignFrom ( context , result ) ;
51+ return result ;
4152 } ,
4253} ;
4354
@@ -50,11 +61,9 @@ const evaluate = (location, leftHandSideExpression, operator, valueExpression) =
5061 const value = await valueExpression . evaluate ( context ) ;
5162 if ( operators [ operator ] ) {
5263 const leftValue = ( operator === '=' ) ? undefined : await leftHandSideExpression . evaluate ( context ) ;
53- operators [ operator ] ( context , leftHandSideValue , leftValue , value ) ;
54- } else {
55- throwRuntimeError ( `Unknown operator ${ operator } ` , context ) ;
64+ return operators [ operator ] ( context , leftHandSideValue , leftValue , value ) ;
5665 }
57- return value ;
66+ throwRuntimeError ( `Unknown operator ${ operator } ` , context ) ;
5867} ;
5968
6069export const createAssignmentExpression = ( location , leftHandSideExpression , operator , valueExpression ) => {
0 commit comments