nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: salsita/node-pg-migrate
Pull request #696 (2020-09-22 06:42:26)

Handle string params in backward compatible way


Patch:
diff --git a/src/utils.ts b/src/utils.ts
index dc81e20..b845bf6 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -60,7 +60,11 @@ export const createTransformer = (literal: Literal) => (s: string, d?: { [key: s
       // eslint-disable-next-line security/detect-non-literal-regexp
       new RegExp(`{${p}}`, 'g'),
       // eslint-disable-next-line no-nested-ternary
-      v === undefined ? '' : typeof v === 'object' && v !== null && 'name' in v ? literal(v) : String(escapeValue(v)),
+      v === undefined
+        ? ''
+        : typeof v === 'string' || (typeof v === 'object' && v !== null && 'name' in v)
+        ? literal(v)
+        : String(escapeValue(v)),
     )
   }, s)
 


Test patch:
diff --git a/test/utils-test.ts b/test/utils-test.ts
index efbd2d8..b9e2677 100644
--- a/test/utils-test.ts
+++ b/test/utils-test.ts
@@ -103,6 +103,17 @@ describe('lib/utils', () => {
   })
 
   describe('.createTransformer', () => {
+    it('handle string and Name', () => {
+      const t = createTransformer(createSchemalize(true, true))
+
+      expect(
+        t('CREATE INDEX {string} ON {name} (id);', {
+          string: 'string',
+          name: { schema: 'schema', name: 'name' },
+        }),
+      ).to.equal('CREATE INDEX "string" ON "schema"."name" (id);')
+    })
+
     it('Do not escape PgLiteral', () => {
       const t = createTransformer(createSchemalize(true, true))