nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: benyap/resolve-tspaths
Pull request #304 (2023-09-27 04:10:30)

fix import and export regex
The previous regex did not correctly match newlines, but the updated regex ensures accurate matching of whitespace, including newlines.
This modification enables matching of import statements like the following:

```
import {
  A,
  B
} from "test"
```


Patch:
diff --git a/src/steps/generateChanges.ts b/src/steps/generateChanges.ts
index 5f9dfcb..203a51e 100644
--- a/src/steps/generateChanges.ts
+++ b/src/steps/generateChanges.ts
@@ -7,10 +7,10 @@ import { normalizePath } from "~/utils/path";
 import type { Alias, Change, ProgramPaths, TextChange } from "~/types";
 
 export const IMPORT_EXPORT_REGEX =
-  /((?:require\(|require\.resolve\(|import\()|(?:import|export) (?:.*from )?)['"]([^'"]*)['"]\)?/g;
+  /((?:require\(|require\.resolve\(|import\()|(?:import|export)\s+(?:[\s\S]*?from\s+)?)['"]([^'"]*)['"]\)?/g;
 
 export const ESM_IMPORT_EXPORT_REGEX =
-  /(?:(?:import\()|(?:import|export)\s+(?:.*from\s+)?)['"]([^'"]*)['"]\)?/g;
+  /(?:(?:import\()|(?:import|export)\s+(?:[\s\S]*?from\s+)?)['"]([^'"]*)['"]\)?/g
 
 export const COMMONJS_IMPORT_EXPORT_REGEX =
   /(?:(?:require\(|require\.resolve\()\s+)['"]([^'"]*)['"]\)/g;


Test patch:
diff --git a/test/steps/generateChanges.test.ts b/test/steps/generateChanges.test.ts
index fe99fa4..6ac57d8 100644
--- a/test/steps/generateChanges.test.ts
+++ b/test/steps/generateChanges.test.ts
@@ -62,6 +62,26 @@ describe("steps/generateChanges", () => {
       `);
     });
 
+    it("matches import statements with multiple named imports", () => {
+      const result = regex.exec(`import {
+  package as myPackage,
+  otherPackage,
+} from '../package';`);
+      expect(result).toMatchInlineSnapshot(`
+        [
+          "import {
+          package as myPackage,
+          otherPackage,
+        } from '../package'",
+          "import {
+          package as myPackage,
+          otherPackage,
+        } from ",
+          "../package",
+        ]
+      `);
+    })
+
     it("matches export * statements", () => {
       const result = regex.exec(`export * from 'package';`);
       expect(result).toMatchInlineSnapshot(`
@@ -119,6 +139,26 @@ describe("steps/generateChanges", () => {
       `);
     });
 
+    it("matches import statements with multiple named imports", () => {
+      const result = regex.exec(`export {
+  package as myPackage,
+  otherPackage,
+} from '../package';`);
+      expect(result).toMatchInlineSnapshot(`
+        [
+          "export {
+          package as myPackage,
+          otherPackage,
+        } from '../package'",
+          "export {
+          package as myPackage,
+          otherPackage,
+        } from ",
+          "../package",
+        ]
+      `);
+    })
+
     it("matches require statements", () => {
       const result = regex.exec(`require('package');`);
       expect(result).toMatchInlineSnapshot(`
Repository: badgateway/oauth2-client
Pull request #78 (2022-10-02 19:02:36)

Support 'scope' on authorization_code flow


Patch:
diff --git a/src/client/authorization-code.ts b/src/client/authorization-code.ts
index 6dc9c98..bd38c87 100644
--- a/src/client/authorization-code.ts
+++ b/src/client/authorization-code.ts
@@ -76,6 +76,9 @@ export class OAuth2AuthorizationCodeClient {
     if (params.state) {
       query.state = params.state;
     }
+    if (params.scope) {
+      query.scope = params.scope.join(' ');
+    }
 
     return authorizationEndpoint + '?' + generateQueryString(query);
 
diff --git a/src/messages.ts b/src/messages.ts
index 93f49c1..1b2fdb8 100644
--- a/src/messages.ts
+++ b/src/messages.ts
@@ -43,6 +43,7 @@ export type AuthorizationQueryParams = {
   client_id: string;
   redirect_uri: string;
   state?: string;
+  scope?: string;
   code_challenge_method?: 'plain' | 'S256';
   code_challenge?: string;
 }


Test patch:
diff --git a/test/authorization-code.ts b/test/authorization-code.ts
index 399b90c..ddb7808 100644
--- a/test/authorization-code.ts
+++ b/test/authorization-code.ts
@@ -24,12 +24,14 @@ describe('authorization-code', () => {
       const params = new URLSearchParams({
         client_id: 'test-client-id',
         response_type: 'code',
-        redirect_uri: redirectUri
+        redirect_uri: redirectUri,
+        scope: 'a b',
       });
 
       expect(
         await client.authorizationCode.getAuthorizeUri({
           redirectUri,
+          scope: ['a', 'b'],
         })
       ).to.equal(server.url + '/authorize?' + params.toString());