Skip to content

Commit 109a757

Browse files
authored
fix: branch distance calculation (#170)
1 parent 5799ba2 commit 109a757

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
126126

127127
if (property.isIdentifier()) {
128128
const objectValue = this._valueMap.get(object.toString());
129-
const argument = path.get("arguments")[0];
130-
argument.visit();
131-
const argumentValue = <string>this._valueMap.get(argument.toString());
132129

133130
// TODO should check if the value is actually a string
134131
if (typeof objectValue !== "string") {
@@ -137,6 +134,12 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
137134

138135
switch (property.node.name) {
139136
case "endsWith": {
137+
const argument = path.get("arguments")[0];
138+
argument.visit();
139+
const argumentValue = <string>(
140+
this._valueMap.get(argument.toString())
141+
);
142+
140143
const endOfObject =
141144
objectValue.length > argumentValue.length
142145
? objectValue.slice(-argumentValue.length)
@@ -166,6 +169,12 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
166169
break;
167170
}
168171
case "startsWith": {
172+
const argument = path.get("arguments")[0];
173+
argument.visit();
174+
const argumentValue = <string>(
175+
this._valueMap.get(argument.toString())
176+
);
177+
169178
const startOfObject =
170179
objectValue.length > argumentValue.length
171180
? objectValue.slice(0, argumentValue.length)
@@ -195,6 +204,12 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
195204
break;
196205
}
197206
case "includes": {
207+
const argument = path.get("arguments")[0];
208+
argument.visit();
209+
const argumentValue = <string>(
210+
this._valueMap.get(argument.toString())
211+
);
212+
198213
this._isDistanceMap.set(path.toString(), true);
199214

200215
if (this._inverted) {

0 commit comments

Comments
 (0)