quicktype-core 23.3.18 → 23.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -350,7 +350,13 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
350
350
  if (converter !== undefined) {
351
351
  const typeSource = this.csType(targetType);
352
352
  this.emitLine("var converter = ", this.converterObject(converter), ";");
353
- this.emitLine("var ", variableName, " = (", typeSource, ")converter.ReadJson(reader, typeof(", typeSource, "), null, serializer);");
353
+ // The converter is for the non-null type, so if the target
354
+ // type is nullable we have to handle null ourselves.
355
+ const isNullable = targetType instanceof Type_1.UnionType &&
356
+ (0, TypeUtils_1.nullableFromUnion)(targetType) !== null;
357
+ this.emitLine("var ", variableName, " = ", isNullable
358
+ ? "reader.TokenType == JsonTokenType.Null ? null : "
359
+ : "", "(", typeSource, ")converter.Read(ref reader, typeof(", typeSource, "), options);");
354
360
  }
355
361
  else if (source.kind !== "null") {
356
362
  const output = targetType.kind === "double" ? targetType : source;
@@ -366,7 +372,7 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
366
372
  // FIXME: handle EOF
367
373
  this.emitLine("reader.Read();");
368
374
  this.emitLine("var ", variableName, " = new List<", this.csType(targetType.items), ">();");
369
- this.emitLine("while (reader.TokenType != JsonToken.EndArray)");
375
+ this.emitLine("while (reader.TokenType != JsonTokenType.EndArray)");
370
376
  this.emitBlock(() => {
371
377
  this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, (v) => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem", varGen);
372
378
  // FIXME: handle EOF
@@ -525,7 +531,24 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
525
531
  const converter = this.converterForType(xfer.sourceType);
526
532
  if (converter !== undefined) {
527
533
  this.emitLine("var converter = ", this.converterObject(converter), ";");
528
- this.emitLine("converter.WriteJson(writer, ", variable, ", serializer);");
534
+ // The converter is for the non-null type, so if the source
535
+ // type is nullable we have to handle null ourselves.
536
+ const maybeNullable = xfer.sourceType instanceof Type_1.UnionType
537
+ ? (0, TypeUtils_1.nullableFromUnion)(xfer.sourceType)
538
+ : null;
539
+ if (maybeNullable !== null) {
540
+ let member = variable;
541
+ if ((0, utils_1.isValueType)((0, Transformers_1.followTargetType)(maybeNullable))) {
542
+ member = [member, ".Value"];
543
+ }
544
+ this.emitLine("if (", variable, " == null)");
545
+ this.emitBlock(() => this.emitLine("writer.WriteNullValue();"));
546
+ this.emitLine("else");
547
+ this.emitBlock(() => this.emitLine("converter.Write(writer, ", member, ", options);"));
548
+ }
549
+ else {
550
+ this.emitLine("converter.Write(writer, ", variable, ", options);");
551
+ }
529
552
  }
530
553
  else {
531
554
  this.emitLine(this.serializeValueCode(variable), ";");
@@ -1 +1 @@
1
- export declare const keywords: readonly ["Serialize", "Deserialize", "{{root}}", "$crate", "as", "async", "box", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", "while", "abstract", "alignof", "become", "do", "final", "macro", "offsetof", "override", "priv", "proc", "pure", "sizeof", "typeof", "unsized", "virtual", "yield", "catch", "default", "dyn", "'static", "union", "option"];
1
+ export declare const keywords: readonly ["Serialize", "Deserialize", "{{root}}", "$crate", "as", "async", "box", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", "while", "abstract", "alignof", "become", "do", "final", "macro", "offsetof", "override", "priv", "proc", "pure", "sizeof", "typeof", "unsized", "virtual", "yield", "catch", "default", "dyn", "'static", "union", "option", "Option", "Some", "None", "Result", "Ok", "Err", "String", "Vec", "Box", "HashMap"];
@@ -71,4 +71,19 @@ exports.keywords = [
71
71
  "union",
72
72
  // Conflict between `std::Option` and potentially generated Option
73
73
  "option",
74
+ // Prelude and standard-library names that generated code refers to
75
+ // unqualified; a generated type with one of these names would shadow
76
+ // them and break compilation (e.g. a struct named `Option`).
77
+ "Option",
78
+ "Some",
79
+ "None",
80
+ "Result",
81
+ "Ok",
82
+ "Err",
83
+ "String",
84
+ "Vec",
85
+ "Box",
86
+ // Generated code contains `use std::collections::HashMap;`, which a
87
+ // type of the same name would conflict with.
88
+ "HashMap",
74
89
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.3.18",
3
+ "version": "23.3.20",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",