Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0632913

Browse files
fix: in operator branch distance (#206)
The 'in' operator was wrongly calculated in the branch distance visitor.
1 parent a66647f commit 0632913

File tree

1 file changed

+18
-47
lines changed

1 file changed

+18
-47
lines changed

‎libraries/search-javascript/lib/criterion/BranchDistanceVisitor.ts

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
7171
// the value does not exist or is not a distance
7272
throw new IllegalArgumentError(
7373
"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+
}
7586
);
7687
}
7788

@@ -303,48 +314,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
303314
this._isDistanceMap.set(path.toString(), false);
304315
};
305316

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-
348317
public UpdateExpression: (path: NodePath<t.UpdateExpression>) => void = (
349318
path
350319
) => {
@@ -620,7 +589,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
620589

621590
// distance
622591
case "==":
623-
// TODO
624592
case "===": {
625593
if (typeof leftValue === "number" && typeof rightValue === "number") {
626594
value = Math.abs(leftValue - rightValue);
@@ -647,7 +615,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
647615
break;
648616
}
649617
case "!=":
650-
// TODO
651618
case "!==": {
652619
if (operator === "!==") {
653620
value = leftValue === rightValue ? 1 : 0;
@@ -657,8 +624,12 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
657624
break;
658625
}
659626
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;
662633
} else {
663634
if (this._inverted) {
664635
value = leftValue in rightValue ? Number.MAX_VALUE : 0;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /