nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: vendure-ecommerce/ngx-translate-extract
Pull request #47 (2024-05-06 10:39:46)

feat: support finding translations pipe in KeyedRead nodes
seems like KeyedRead was always there, but not detected.

Finds keys in static object and array access, e.g.:

```
{
  foo: 'a' | translate,
  bar: 'b' | translate,
}[ key ];
```

```
[
  'a' | translate,
  'b' | translate,
}[ index ];
```


Patch:
diff --git a/src/parsers/pipe.parser.ts b/src/parsers/pipe.parser.ts
index 5449287..5959b22 100644
--- a/src/parsers/pipe.parser.ts
+++ b/src/parsers/pipe.parser.ts
@@ -15,7 +15,8 @@ import {
 	TmplAstSwitchBlock,
 	TmplAstDeferredBlock,
 	TmplAstForLoopBlock,
-	TmplAstElement
+	TmplAstElement,
+	KeyedRead
 } from '@angular/compiler';
 
 import { ParserInterface } from './parser.interface.js';
@@ -195,6 +196,19 @@ export class PipeParser implements ParserInterface {
 			return this.getTranslatablesFromAsts(ast.args);
 		}
 
+		// immediately accessed static object or array - the angular parser bundles this as "KeyedRead", where:
+		// { 'a': 1, 'b': 2 }[ 'a' ];
+		//                     ^^^ <- keyedRead.key
+		// ^^^^^^^^^^^^^^^^^^ <- keyedRead.receiver
+		//
+		// html examples:
+		// - { key1: 'value1' | translate, key2: 'value2' | translate }[key]
+		// - [ 'value1' | translate, 'value2' | translate ][key]
+		// - [ 'foo', 'bar' ][ 'key' | translate ]
+		if (ast instanceof KeyedRead) {
+			return this.getTranslatablesFromAsts([ast.receiver, ast.key]);
+		}
+
 		return [];
 	}
 


Test patch:
diff --git a/tests/parsers/pipe.parser.spec.ts b/tests/parsers/pipe.parser.spec.ts
index 9eca297..d126b26 100644
--- a/tests/parsers/pipe.parser.spec.ts
+++ b/tests/parsers/pipe.parser.spec.ts
@@ -73,6 +73,34 @@ describe('PipeParser', () => {
 				expect(keys).to.deep.equal(['Hello', 'World']);
 			});
 
+			it('should extract strings from object map', () => {
+				const contents = `{{ {
+					choice1: 'Hello' | ${translatePipeName},
+					choice2: 'World' | ${translatePipeName},
+				}[choice] }}`;
+				const keys = parser.extract(contents, templateFilename).keys();
+				expect(keys).to.deep.equal(['Hello', 'World']);
+			});
+
+			it('should extract strings from object map inside attribute', () => {
+				const contents = `
+					<span [attr]="{
+						choice1: 'Hello' | ${translatePipeName},
+						choice2: 'World' | ${translatePipeName}
+					}[choice]"></span>`;
+				const keys = parser.extract(contents, templateFilename).keys();
+				expect(keys).to.deep.equal(['Hello', 'World']);
+			});
+
+			it('should extract strings from KeyedRead.key', () => {
+				const contents = `{{ {
+					choice1: 'Foo',
+					choice2: 'Bar',
+				}[ 'choice' | ${translatePipeName} ] }}`;
+				const keys = parser.extract(contents, templateFilename).keys();
+				expect(keys).to.deep.equal(['choice']);
+			});
+
 			it('should extract strings from object', () => {
 				const contents = `{{ { foo: 'Hello' | ${translatePipeName}, bar: ['World' | ${translatePipeName}], deep: { nested: { baz: 'Yes' | ${translatePipeName} } } } | json }}`;
 				const keys = parser.extract(contents, templateFilename).keys();
Repository: fabien0102/ts-to-zod
Pull request #190 (2023-12-05 16:49:32)

feat: add null handling for @default tag
# Why

Implementing a solution to https://github.com/fabien0102/ts-to-zod/issues/188
This adds `nullable` to the modifiers when the property if the `@default` is `null`


Patch:
diff --git a/src/core/jsDocTags.ts b/src/core/jsDocTags.ts
index 2643a9c..176461b 100644
--- a/src/core/jsDocTags.ts
+++ b/src/core/jsDocTags.ts
@@ -55,7 +55,7 @@ type TagWithError<T> = {
 export interface JSDocTagsBase {
   minimum?: TagWithError<number>;
   maximum?: TagWithError<number>;
-  default?: number | string | boolean;
+  default?: number | string | boolean | null;
   minLength?: TagWithError<number>;
   maxLength?: TagWithError<number>;
   format?: TagWithError<BuiltInJSDocFormatsType | CustomJSDocFormatType>;
@@ -175,7 +175,9 @@ export function getJSDocTags(nodeType: ts.Node, sourceFile: ts.SourceFile) {
             jsDocTags[tagName] = { value, errorMessage };
             break;
           case "default":
-            if (
+            if (tag.comment === "null") {
+              jsDocTags[tagName] = null;
+            } else if (
               tag.comment &&
               !tag.comment.includes('"') &&
               !Number.isNaN(parseInt(tag.comment))
@@ -289,7 +291,7 @@ export function jsDocTagToZodProperties(
       identifier: "optional",
     });
   }
-  if (isNullable) {
+  if (isNullable || jsDocTags.default === null) {
     zodProperties.push({
       identifier: "nullable",
     });
@@ -314,6 +316,8 @@ export function jsDocTagToZodProperties(
           ? [f.createFalse()]
           : typeof jsDocTags.default === "number"
           ? [f.createNumericLiteral(jsDocTags.default)]
+          : jsDocTags.default === null
+          ? [f.createNull()]
           : [f.createStringLiteral(jsDocTags.default)],
     });
   }


Test patch:
diff --git a/src/core/generateZodSchema.test.ts b/src/core/generateZodSchema.test.ts
index 7b40a25..9860701 100644
--- a/src/core/generateZodSchema.test.ts
+++ b/src/core/generateZodSchema.test.ts
@@ -1300,6 +1300,39 @@ describe("generateZodSchema", () => {
     `);
   });
 
+  it("should deal with @default null value", () => {
+    const source = `export interface WithDefaults {
+      /**
+       * @default null
+       */
+      nonNullableString: string;
+      /**
+       * @default null
+       */
+      nullableString: string | null;
+      /**
+       * @default "null"
+       */
+      nonNullableStringWithStringAsDefault: string;
+   }`;
+    expect(generate(source)).toMatchInlineSnapshot(`
+      "export const withDefaultsSchema = z.object({
+          /**
+           * @default null
+           */
+          nonNullableString: z.string().nullable().default(null),
+          /**
+           * @default null
+           */
+          nullableString: z.string().nullable().default(null),
+          /**
+           * @default "null"
+           */
+          nonNullableStringWithStringAsDefault: z.string().default("null")
+      });"
+    `);
+  });
+
   it("should ignore unknown/broken jsdoc format", () => {
     const source = `export interface Hero {
      /**
Repository: fabien0102/ts-to-zod
Pull request #237 (2024-05-09 10:26:18)

fix: .partial() must be applied before .nullable() or .optional()
# Why

Zod API requires that `.partial()` be applied to an object type _before_ `.nullable()` or `.optional()`.



Patch:
diff --git a/src/core/jsDocTags.ts b/src/core/jsDocTags.ts
index cbc8070..882672c 100644
--- a/src/core/jsDocTags.ts
+++ b/src/core/jsDocTags.ts
@@ -301,6 +301,12 @@ export function jsDocTagToZodProperties(
   if (jsDocTags.strict) {
     zodProperties.push({ identifier: "strict" });
   }
+  // partial() must be before optional() and nullable()
+  if (isPartial) {
+    zodProperties.push({
+      identifier: "partial",
+    });
+  }
   if (isOptional) {
     zodProperties.push({
       identifier: "optional",
@@ -311,11 +317,6 @@ export function jsDocTagToZodProperties(
       identifier: "nullable",
     });
   }
-  if (isPartial) {
-    zodProperties.push({
-      identifier: "partial",
-    });
-  }
   if (isRequired) {
     zodProperties.push({
       identifier: "required",


Test patch:
diff --git a/src/core/generateZodSchema.test.ts b/src/core/generateZodSchema.test.ts
index bc4f96f..567da49 100644
--- a/src/core/generateZodSchema.test.ts
+++ b/src/core/generateZodSchema.test.ts
@@ -1263,7 +1263,21 @@ describe("generateZodSchema", () => {
       "export const exampleSchema = z.object({
           field: z.object({
               foo: z.string()
-          }).nullable().partial()
+          }).partial().nullable()
+      });"
+    `);
+  });
+
+  it("should deal with optional partial", () => {
+    const source = `export type Example = {
+        field?: Partial<{foo: string}>
+    }`;
+
+    expect(generate(source)).toMatchInlineSnapshot(`
+      "export const exampleSchema = z.object({
+          field: z.object({
+              foo: z.string()
+          }).partial().optional()
       });"
     `);
   });
Repository: fabien0102/ts-to-zod
Pull request #246 (2024-06-24 14:43:55)

fix(#244): handle IndexedAccessType of imported schemas
# Why

See #244 

We were missing one case in the traversal algorithm to extract the dependency


Patch:
diff --git a/src/utils/traverseTypes.ts b/src/utils/traverseTypes.ts
index 74ff4a5..c0fd8cd 100644
--- a/src/utils/traverseTypes.ts
+++ b/src/utils/traverseTypes.ts
@@ -66,6 +66,8 @@ export function getReferencedTypeNames(
       ts.isUnionTypeNode(typeNode)
     ) {
       typeNode.types.forEach(handleTypeNode);
+    } else if (ts.isIndexedAccessTypeNode(typeNode)) {
+      handleTypeNode(typeNode.objectType);
     }
   };
 


Test patch:
diff --git a/src/core/generate.test.ts b/src/core/generate.test.ts
index 0c6a811..bf17938 100644
--- a/src/core/generate.test.ts
+++ b/src/core/generate.test.ts
@@ -1229,6 +1229,41 @@ describe("generate", () => {
       });
     });
 
+    describe("reference to an imported type withing an IndexedAccessType node", () => {
+      const input = "./hero";
+      const output = "./hero.zod";
+      const inputOutputMappings: InputOutputMapping[] = [{ input, output }];
+
+      const sourceText = `
+        import { Hero } from "${input}"
+        
+        export interface Person {
+          id: number
+          hero: Hero["name"]
+        }
+        `;
+
+      const { getZodSchemasFile } = generate({
+        sourceText,
+        inputOutputMappings,
+      });
+
+      it("should generate the zod schemas with right import", () => {
+        expect(getZodSchemasFile(input)).toMatchInlineSnapshot(`
+          "// Generated by ts-to-zod
+          import { z } from "zod";
+          
+          import { heroSchema } from "${output}";
+          
+          export const personSchema = z.object({
+              id: z.number(),
+              hero: heroSchema.shape.name
+          });
+          "
+        `);
+      });
+    });
+
     describe("with useless imports", () => {
       const input = "./hero";
       const output = "./hero.zod";
diff --git a/src/utils/traverseTypes.test.ts b/src/utils/traverseTypes.test.ts
index 4048964..d082f08 100644
--- a/src/utils/traverseTypes.test.ts
+++ b/src/utils/traverseTypes.test.ts
@@ -452,6 +452,19 @@ describe("traverseTypes", () => {
         { name: "Person", partOfQualifiedName: true },
       ]);
     });
+
+    it("should extract type when leading an IndexedAccessType", () => {
+      const source = `
+        export type Hero = {
+          super: Person["super"]
+        }`;
+
+      const result = extractNames(source);
+      expect(result).toEqual([
+        { name: "Hero", partOfQualifiedName: false },
+        { name: "Person", partOfQualifiedName: false },
+      ]);
+    });
   });
 });
Repository: kiwicom/mobile
Pull request #705 (2018-06-05 10:39:20)

Localization: Handle changing translation id


Patch:
diff --git a/packages/localization/src/Translation.js b/packages/localization/src/Translation.js
index 6e4961cd..0ae96253 100644
--- a/packages/localization/src/Translation.js
+++ b/packages/localization/src/Translation.js
@@ -65,6 +65,13 @@ export default class Translation extends React.Component<Props, State> {
     this.setTranslatedString();
   };
 
+  componentDidUpdate = (prevProps: Props) => {
+    if (prevProps.id && this.props.id && prevProps.id !== this.props.id) {
+      //translationId changed
+      this.setTranslatedString();
+    }
+  };
+
   componentWillUnmount = () => {
     if (this.translatePromise !== null) {
       this.translatePromise.cancel();


Test patch:
diff --git a/packages/localization/src/__tests__/Translation.test.js b/packages/localization/src/__tests__/Translation.test.js
index a951ad76..ca48ab34 100644
--- a/packages/localization/src/__tests__/Translation.test.js
+++ b/packages/localization/src/__tests__/Translation.test.js
@@ -102,3 +102,17 @@ it('does not call set state if promise is rejected', async () => {
   // $FlowExpectedError: Intentionally resetting function
   CancellableTranslation.cancellableTranslation = originalFunction;
 });
+
+it('asks for new translation if id changes', () => {
+  jest.spyOn(Component, 'setTranslatedString');
+  Component.componentDidUpdate({ id: 'new.id' });
+
+  expect(Component.setTranslatedString).toHaveBeenCalled();
+});
+
+it('does not ask for new translation if id does not change', () => {
+  jest.spyOn(Component, 'setTranslatedString');
+  Component.componentDidUpdate({ id: 'test.key' });
+
+  expect(Component.setTranslatedString).not.toHaveBeenCalled();
+});
Repository: kiwicom/mobile
Pull request #837 (2018-07-10 07:35:44)

MMB: Fix bug where missing information was not shown


Patch:
diff --git a/app/MMB/src/components/MissingInformation.js b/app/MMB/src/components/MissingInformation.js
index de43bf8d..fd8c52a1 100644
--- a/app/MMB/src/components/MissingInformation.js
+++ b/app/MMB/src/components/MissingInformation.js
@@ -23,7 +23,7 @@ type Props = {|
   +navigation: NavigationType,
 |};
 
-class MissingInformation extends React.Component<Props> {
+export class MissingInformation extends React.Component<Props> {
   fillInPassengerInfo = () => {
     this.props.navigation.navigate({
       routeName: 'TravelDocumentScreen',
@@ -33,11 +33,11 @@ class MissingInformation extends React.Component<Props> {
 
   render = () => {
     const passengers = idx(this.props.data, _ => _.passengers) || [];
-    const passengerWithMissingId = passengers.find(passenger =>
-      Boolean(idx(passenger, _ => _.travelDocument.idNumber)),
+    const isPassengerMissingId = passengers.some(
+      passenger => idx(passenger, _ => _.travelDocument.idNumber) == null,
     );
 
-    if (passengerWithMissingId != null) {
+    if (!isPassengerMissingId) {
       return null;
     }
 


Test patch:
diff --git a/app/MMB/src/components/__tests__/MissingInformation.test.js b/app/MMB/src/components/__tests__/MissingInformation.test.js
new file mode 100644
index 00000000..ce62ceb0
--- /dev/null
+++ b/app/MMB/src/components/__tests__/MissingInformation.test.js
@@ -0,0 +1,54 @@
+// @flow strict
+
+import * as React from 'react';
+import ShallowRenderer from 'react-test-renderer/shallow';
+
+import { MissingInformation } from '../MissingInformation';
+
+const renderer = new ShallowRenderer();
+
+const getWrapper = data =>
+  // $FlowExpectedError: Intentionally passing just what is needed to test functionality
+  renderer.render(<MissingInformation data={data} navigation={null} />);
+
+describe('MissingInformation', () => {
+  it('renders correctly when a passenger is missing id', () => {
+    const data = {
+      passengers: [
+        {
+          travelDocument: {
+            idNumber: '123321',
+          },
+        },
+        {
+          travelDocument: {
+            idNumber: null,
+          },
+        },
+      ],
+    };
+    const wrapper = getWrapper(data);
+
+    expect(wrapper.props.children).not.toBeNull();
+  });
+
+  it('renders null when all passengers have id', () => {
+    const data = {
+      passengers: [
+        {
+          travelDocument: {
+            idNumber: '123321',
+          },
+        },
+        {
+          travelDocument: {
+            idNumber: '123456',
+          },
+        },
+      ],
+    };
+    const wrapper = getWrapper(data);
+
+    expect(wrapper).toBeNull();
+  });
+});
Repository: kiwicom/mobile
Pull request #911 (2018-07-24 12:29:00)

Hotels: Fix guests input border radius


Patch:
diff --git a/app/hotels/src/allHotels/searchForm/guests/Guests.js b/app/hotels/src/allHotels/searchForm/guests/Guests.js
index 204c5132..d7fc2d1c 100644
--- a/app/hotels/src/allHotels/searchForm/guests/Guests.js
+++ b/app/hotels/src/allHotels/searchForm/guests/Guests.js
@@ -40,7 +40,7 @@ export const ButtonTitle = ({
 
 export default function Guests({ guests, openGuestsModal }: Props) {
   return (
-    <Touchable onPress={openGuestsModal}>
+    <Touchable onPress={openGuestsModal} style={buttonStyles.button}>
       <View style={buttonStyles.buttonWrapper}>
         <Icon name="people" size={20} style={buttonStyles.icon} />
         <ButtonTitle
@@ -53,13 +53,17 @@ export default function Guests({ guests, openGuestsModal }: Props) {
 }
 
 const buttonStyles = StyleSheet.create({
+  button: {
+    android: {
+      borderRadius: 2,
+    },
+  },
   buttonWrapper: {
     flexDirection: 'row',
     alignItems: 'center',
     padding: 12,
     backgroundColor: Color.inputBackground,
     android: {
-      elevation: 1,
       height: 48,
       borderRadius: 2,
     },


Test patch:
diff --git a/app/hotels/src/allHotels/searchForm/guests/__tests__/__snapshots__/Guests.test.js.snap b/app/hotels/src/allHotels/searchForm/guests/__tests__/__snapshots__/Guests.test.js.snap
index 4f44e724..a4716f09 100644
--- a/app/hotels/src/allHotels/searchForm/guests/__tests__/__snapshots__/Guests.test.js.snap
+++ b/app/hotels/src/allHotels/searchForm/guests/__tests__/__snapshots__/Guests.test.js.snap
@@ -6,6 +6,7 @@ exports[`Guests Render all inputs 1`] = `
   disabled={false}
   onPress={[MockFunction]}
   rippleColor="rgba(0, 0, 0, .32)"
+  style={Object {}}
 >
   <Component
     style={