nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sjbarag/brs
Pull request #286 (2019-08-11 03:16:34)

Fix lexer.isToken
`lexer.isToken` is supposed to return a boolean, but it actually returns the last nonfalsey value it finds. If statement that actually compared it to `true`|`false` would result in unexpected behavior.

TwitchBronBron: And no rush on getting this released...I'm not actually depending on it for anything. I was just writing some extra unit tests in my copy of `brs` in `brighterscript`, and when I went to test the method, that's how I found the issue. 

Patch:
diff --git a/src/lexer/Token.ts b/src/lexer/Token.ts
index d3d4a42..f9993f9 100644
--- a/src/lexer/Token.ts
+++ b/src/lexer/Token.ts
@@ -53,8 +53,8 @@ export interface Identifier extends Token {
 /**
  * Determines whether or not `obj` is a `Token`.
  * @param obj the object to check for `Token`-ness
- * @returns `true` is `obj` is a `Token`, otherwise `false`
+ * @returns `true` if `obj` is a `Token`, otherwise `false`
  */
 export function isToken(obj: Record<string, any>): obj is Token {
-    return obj.kind && obj.text && obj.location;
+    return !!(obj.kind && obj.text && obj.location);
 }


Test patch:
diff --git a/test/lexer/Lexer.test.js b/test/lexer/Lexer.test.js
index 0770043..6b80b8e 100644
--- a/test/lexer/Lexer.test.js
+++ b/test/lexer/Lexer.test.js
@@ -422,4 +422,23 @@ describe("lexer", () => {
             ]);
         });
     });
+
+    describe("isToken", () => {
+        it("returns booleans", () => {
+            let location = {
+                start: {
+                    line: 1,
+                    column: 1,
+                },
+                end: {
+                    line: 1,
+                    column: 2,
+                },
+                file: "SomeFile.brs",
+            };
+
+            expect(lexer.isToken({ kind: Lexeme.And, text: "and", location: location })).toBe(true);
+            expect(lexer.isToken({ text: "and", location: location })).toBe(false);
+        });
+    });
 }); // lexer