File tree Expand file tree Collapse file tree 4 files changed +22
-9
lines changed
Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -193,8 +193,13 @@ export class Evaluator {
193193 }
194194
195195 if ( node . type === "getSingleVar" ) {
196+ const name = ( node as GetSingleVarNode ) . name ;
197+
196198 const value = blockContext . blockScope . get ( ( node as GetSingleVarNode ) . name ) ;
197- return value === undefined ? null : value ;
199+ if ( value === undefined ) {
200+ throw new Error ( `Variable ${ name } is not defined.` ) ;
201+ }
202+ return value ;
198203 }
199204
200205 if ( node . type === "binOp" ) {
Original file line number Diff line number Diff line change @@ -200,8 +200,12 @@ export class EvaluatorAsync {
200200 }
201201
202202 if ( node . type === "getSingleVar" ) {
203- const value = blockContext . blockScope . get ( ( node as GetSingleVarNode ) . name ) ;
204- return value === undefined ? null : value ;
203+ const name = ( node as GetSingleVarNode ) . name ;
204+ const value = blockContext . blockScope . get ( name ) ;
205+ if ( value === undefined ) {
206+ throw new Error ( `Variable ${ name } is not defined.` ) ;
207+ }
208+ return value ;
205209 }
206210
207211 if ( node . type === "binOp" ) {
Original file line number Diff line number Diff line change @@ -290,8 +290,8 @@ describe('Interpreter', () => {
290290 } ) ;
291291
292292 it ( 'chaining funcCall with null coelsing' , ( ) => {
293- expect ( e . eval ( "p?.f()?.sdsd" ) ) . toBe ( null ) ;
294- expect ( e . eval ( "p?.f()?.sdsd or 5" ) ) . toBe ( 5 ) ;
293+ expect ( e . eval ( "p={f: ()=>null}\np ?.f()?.sdsd" ) ) . toBe ( null ) ;
294+ expect ( e . eval ( "p={f: ()=>null}\np ?.f()?.sdsd or 5" ) ) . toBe ( 5 ) ;
295295 } ) ;
296296
297297 it ( 'comparison operations' , ( ) => {
@@ -323,10 +323,10 @@ describe('Interpreter', () => {
323323 } ) ;
324324
325325 it ( 'conditionals' , async ( ) => {
326- expect ( await e . evaluate ( 'x == null' ) ) . toBe ( true )
327- expect ( await e . evaluate ( 'x?.p1?.p == null' ) ) . toBe ( true )
328- expect ( await e . evaluate ( 'x != null and x.length >0' ) ) . toBe ( false )
329- expect ( await e . evaluate ( 'x?.p1?.p != null and x.length >0' ) ) . toBe ( false )
326+ expect ( await e . evaluate ( 'x = null\nx = = null' ) ) . toBe ( true )
327+ expect ( await e . evaluate ( 'x = null\nx ?.p1?.p == null' ) ) . toBe ( true )
328+ expect ( await e . evaluate ( 'x = null\nx != null and x.length >0' ) ) . toBe ( false )
329+ expect ( await e . evaluate ( 'x = null\nx ?.p1?.p != null and x.length >0' ) ) . toBe ( false )
330330 } ) ;
331331
332332 it ( 'arithmetic + comparison' , async ( ) => {
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ export class Interpreter {
2626 return new Interpreter ( ) ;
2727 }
2828
29+ jsPythonInfo ( ) {
30+ return this . initialScope . jsPython ( ) ;
31+ }
32+
2933 tokenize ( script : string ) : Token [ ] {
3034 const tokenizer = new Tokenizer ( ) ;
3135 return tokenizer . tokenize ( script ) ;
You can’t perform that action at this time.
0 commit comments