@@ -71,7 +71,18 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
71
71
// the value does not exist or is not a distance
72
72
throw new IllegalArgumentError (
73
73
"Cannot get distance from unknown condition" ,
74
- { context : { condition : condition } }
74
+ {
75
+ context : {
76
+ condition : condition ,
77
+ inValueMap : this . _valueMap . has ( condition ) ,
78
+ isDistance :
79
+ this . _isDistanceMap . has ( condition ) &&
80
+ this . _isDistanceMap . get ( condition ) ,
81
+ availableValues : [ ...this . _valueMap . entries ( ) ] . map (
82
+ ( value ) => `${ value [ 0 ] } -> ${ String ( value [ 1 ] ) } `
83
+ ) ,
84
+ } ,
85
+ }
75
86
) ;
76
87
}
77
88
@@ -303,48 +314,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
303
314
this . _isDistanceMap . set ( path . toString ( ) , false ) ;
304
315
} ;
305
316
306
- // public ObjectExpression: (path: NodePath<t.ObjectExpression>) => void = (path) => {
307
- // this._valueMap.set(this._getNodeId(path), )
308
- // this._isDistanceMap.set(this._getNodeId(path), false);
309
- // }
310
-
311
- // public Identifier: (path: NodePath<t.Identifier>) => void = (path) => {
312
- // if (this._variables[path.node.name] === undefined) {
313
- // // we dont know what this variable is...
314
- // this._valueMap.set(this._getNodeId(path), undefined);
315
- // } else {
316
- // this._valueMap.set(
317
- // this._getNodeId(path),
318
- // this._variables[path.node.name]
319
- // );
320
- // }
321
- // this._isDistanceMap.set(this._getNodeId(path), false);
322
- // };
323
-
324
- // public MemberExpression: (path: NodePath<t.MemberExpression>) => void = (
325
- // path
326
- // ) => {
327
- // const result = generate(path.node);
328
- // const value = this._variables[result.code];
329
- // // might be undefined
330
- // this._valueMap.set(this._getNodeId(path), value);
331
- // this._isDistanceMap.set(this._getNodeId(path), false);
332
- // };
333
- // public Identifier: (path: NodePath<t.Identifier>) => void = (path) => {
334
- // if (this._variables[path.node.name] === undefined) {
335
- // // we dont know what this variable is...
336
- // // should never happen??
337
- // this._valueMap.set(path.toString(), undefined);
338
- // throw new ImplementationError(shouldNeverHappen('BranchDistanceVisitor'))
339
- // } else {
340
- // this._valueMap.set(
341
- // path.toString(),
342
- // this._variables[path.node.name]
343
- // );
344
- // }
345
- // this._isDistanceMap.set(path.toString(), false);
346
- // };
347
-
348
317
public UpdateExpression : ( path : NodePath < t . UpdateExpression > ) => void = (
349
318
path
350
319
) => {
@@ -620,7 +589,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
620
589
621
590
// distance
622
591
case "==" :
623
- // TODO
624
592
case "===" : {
625
593
if ( typeof leftValue === "number" && typeof rightValue === "number" ) {
626
594
value = Math . abs ( leftValue - rightValue ) ;
@@ -647,7 +615,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
647
615
break ;
648
616
}
649
617
case "!=" :
650
- // TODO
651
618
case "!==" : {
652
619
if ( operator === "!==" ) {
653
620
value = leftValue === rightValue ? 1 : 0 ;
@@ -657,8 +624,12 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
657
624
break ;
658
625
}
659
626
case "in" : {
660
- if ( rightValue === undefined || rightValue === null ) {
661
- value = 1 ; // TODO should this one be inverted?
627
+ if (
628
+ rightValue === undefined ||
629
+ rightValue === null ||
630
+ typeof rightValue !== "object"
631
+ ) {
632
+ value = this . _inverted ? Number . MAX_VALUE : 0 ;
662
633
} else {
663
634
if ( this . _inverted ) {
664
635
value = leftValue in rightValue ? Number . MAX_VALUE : 0 ;
0 commit comments