quicktype-core 7.0.26 → 7.0.27

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.
@@ -731,9 +731,7 @@ class MinMaxValueTransformer extends ProducerTransformer {
731
731
  equals(other) {
732
732
  if (!super.equals(other))
733
733
  return false;
734
- return (other instanceof MinMaxValueTransformer &&
735
- this.minimum === other.minimum &&
736
- this.maximum === other.maximum);
734
+ return (other instanceof MinMaxValueTransformer && this.minimum === other.minimum && this.maximum === other.maximum);
737
735
  }
738
736
  }
739
737
  exports.MinMaxValueTransformer = MinMaxValueTransformer;
@@ -80,10 +80,7 @@ function normalizeURI(uri) {
80
80
  if (typeof uri === "string") {
81
81
  uri = new URI(uri);
82
82
  }
83
- return new URI(URI.decode(uri
84
- .clone()
85
- .normalize()
86
- .toString()));
83
+ return new URI(URI.decode(uri.clone().normalize().toString()));
87
84
  }
88
85
  class Ref {
89
86
  constructor(addressURI, path) {
@@ -1020,10 +1017,7 @@ class JSONSchemaInput {
1020
1017
  else {
1021
1018
  normalizedURIs = uris.map(uri => {
1022
1019
  const normalizedURI = normalizeURI(uri);
1023
- if (normalizedURI
1024
- .clone()
1025
- .hash("")
1026
- .toString() === "") {
1020
+ if (normalizedURI.clone().hash("").toString() === "") {
1027
1021
  normalizedURI.path(name);
1028
1022
  }
1029
1023
  return normalizedURI;
@@ -40,7 +40,7 @@ exports.all = [
40
40
  new Dart_1.DartTargetLanguage(),
41
41
  new Python_1.PythonTargetLanguage("Python", ["python", "py"], "py"),
42
42
  new Pike_1.PikeTargetLanguage(),
43
- new Haskell_1.HaskellTargetLanguage(),
43
+ new Haskell_1.HaskellTargetLanguage()
44
44
  ];
45
45
  function languageNamed(name, targetLanguages) {
46
46
  if (targetLanguages === undefined) {
@@ -22,12 +22,30 @@ const upperUnderscoreValue = ["upper-underscore-case", "upper-underscore"];
22
22
  const pascalUpperAcronymsValue = ["pascal-case-upper-acronyms", "pascal-upper-acronyms"];
23
23
  const camelUpperAcronymsValue = ["camel-case-upper-acronyms", "camel-upper-acronyms"];
24
24
  exports.cPlusPlusOptions = {
25
- typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [["single-source", true], ["multi-source", false]], "single-source", "secondary"),
26
- includeLocation: new RendererOptions_1.EnumOption("include-location", "Whether json.hpp is to be located globally or locally", [["local-include", true], ["global-include", false]], "local-include", "secondary"),
27
- codeFormat: new RendererOptions_1.EnumOption("code-format", "Generate classes with getters/setters, instead of structs", [["with-struct", false], ["with-getter-setter", true]], "with-getter-setter"),
28
- wstring: new RendererOptions_1.EnumOption("wstring", "Store strings using Utf-16 std::wstring, rather than Utf-8 std::string", [["use-string", false], ["use-wstring", true]], "use-string"),
29
- msbuildPermissive: new RendererOptions_1.EnumOption("msbuildPermissive", "Moves to_json and from_json types into the nlohmann::details namespace, so that msbuild can build it with conformance mode disabled", [["not-permissive", false], ["use-permissive", true]], "not-permissive", "secondary"),
30
- westConst: new RendererOptions_1.EnumOption("const-style", "Put const to the left/west (const T) or right/east (T const)", [["west-const", true], ["east-const", false]], "west-const"),
25
+ typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [
26
+ ["single-source", true],
27
+ ["multi-source", false]
28
+ ], "single-source", "secondary"),
29
+ includeLocation: new RendererOptions_1.EnumOption("include-location", "Whether json.hpp is to be located globally or locally", [
30
+ ["local-include", true],
31
+ ["global-include", false]
32
+ ], "local-include", "secondary"),
33
+ codeFormat: new RendererOptions_1.EnumOption("code-format", "Generate classes with getters/setters, instead of structs", [
34
+ ["with-struct", false],
35
+ ["with-getter-setter", true]
36
+ ], "with-getter-setter"),
37
+ wstring: new RendererOptions_1.EnumOption("wstring", "Store strings using Utf-16 std::wstring, rather than Utf-8 std::string", [
38
+ ["use-string", false],
39
+ ["use-wstring", true]
40
+ ], "use-string"),
41
+ msbuildPermissive: new RendererOptions_1.EnumOption("msbuildPermissive", "Moves to_json and from_json types into the nlohmann::details namespace, so that msbuild can build it with conformance mode disabled", [
42
+ ["not-permissive", false],
43
+ ["use-permissive", true]
44
+ ], "not-permissive", "secondary"),
45
+ westConst: new RendererOptions_1.EnumOption("const-style", "Put const to the left/west (const T) or right/east (T const)", [
46
+ ["west-const", true],
47
+ ["east-const", false]
48
+ ], "west-const"),
31
49
  justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
32
50
  namespace: new RendererOptions_1.StringOption("namespace", "Name of the generated namespace(s)", "NAME", "quicktype"),
33
51
  enumType: new RendererOptions_1.StringOption("enum-type", "Type of enum class", "NAME", "int", "secondary"),
@@ -56,7 +74,7 @@ exports.cPlusPlusOptions = {
56
74
  camelUpperAcronymsValue
57
75
  ]),
58
76
  boost: new RendererOptions_1.BooleanOption("boost", "Require a dependency on boost. Without boost, C++17 is required", true),
59
- hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false),
77
+ hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false)
60
78
  };
61
79
  class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
62
80
  constructor(displayName = "C++", names = ["c++", "cpp", "cplusplus"], extension = "cpp") {
@@ -77,7 +95,7 @@ class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
77
95
  exports.cPlusPlusOptions.enumeratorNamingStyle,
78
96
  exports.cPlusPlusOptions.enumType,
79
97
  exports.cPlusPlusOptions.boost,
80
- exports.cPlusPlusOptions.hideNullOptional,
98
+ exports.cPlusPlusOptions.hideNullOptional
81
99
  ];
82
100
  }
83
101
  get supportsUnionsWithBothNumberTypes() {
@@ -304,7 +322,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
304
322
  super(targetLanguage, renderContext);
305
323
  this._options = _options;
306
324
  this._gettersAndSettersForPropertyName = new Map();
307
- this.NarrowString = new class extends BaseString {
325
+ this.NarrowString = new (class extends BaseString {
308
326
  constructor() {
309
327
  super("std::string", "const std::string & ", "std::smatch", "std::regex", "", new WrappingCode(["std::to_string("], [")"]), "", "");
310
328
  }
@@ -314,8 +332,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
314
332
  emitHelperFunctions() {
315
333
  return;
316
334
  }
317
- }();
318
- this.WideString = new class extends BaseString {
335
+ })();
336
+ this.WideString = new (class extends BaseString {
319
337
  constructor(superThis) {
320
338
  super("std::wstring", "const std::wstring & ", "std::wsmatch", "std::wregex", "L", new WrappingCode(["std::to_wstring("], [")"]), "Utf16_Utf8", "convert");
321
339
  this.superThis = superThis;
@@ -398,7 +416,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
398
416
  });
399
417
  this.superThis.ensureBlankLine();
400
418
  }
401
- }(this);
419
+ })(this);
402
420
  this._enumType = _options.enumType;
403
421
  this._namespaceNames = _options.namespace.split("::");
404
422
  this.typeNamingStyle = _options.typeNamingStyle;
@@ -541,10 +559,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
541
559
  this.emitCommentLines(this.leadingComments);
542
560
  }
543
561
  else if (!this._options.justTypes) {
544
- this.emitCommentLines([
545
- " To parse this JSON data, first install",
546
- "",
547
- ]);
562
+ this.emitCommentLines([" To parse this JSON data, first install", ""]);
548
563
  if (this._options.boost) {
549
564
  this.emitCommentLines([" Boost http://www.boost.org"]);
550
565
  }
@@ -664,10 +679,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
664
679
  return [optionalType, "<", variant, ">"];
665
680
  }
666
681
  ourQualifier(inJsonNamespace) {
667
- return (inJsonNamespace || this._options.msbuildPermissive) ? [collection_utils_1.arrayIntercalate("::", this._namespaceNames), "::"] : [];
682
+ return inJsonNamespace || this._options.msbuildPermissive
683
+ ? [collection_utils_1.arrayIntercalate("::", this._namespaceNames), "::"]
684
+ : [];
668
685
  }
669
686
  jsonQualifier(inJsonNamespace) {
670
- return (inJsonNamespace || this._options.msbuildPermissive) ? [] : "nlohmann::";
687
+ return inJsonNamespace || this._options.msbuildPermissive ? [] : "nlohmann::";
671
688
  }
672
689
  variantIndirection(needIndirection, typeSrc) {
673
690
  if (!needIndirection)
@@ -676,7 +693,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
676
693
  }
677
694
  cppType(t, ctx, withIssues, forceNarrowString, isOptional) {
678
695
  const inJsonNamespace = ctx.inJsonNamespace;
679
- if (isOptional && t instanceof Type_1.UnionType) { // avoid have optionalType<optionalType<Type>>
696
+ if (isOptional && t instanceof Type_1.UnionType) {
697
+ // avoid have optionalType<optionalType<Type>>
680
698
  for (const tChild of t.getChildren()) {
681
699
  if (tChild.isNullable) {
682
700
  isOptional = false;
@@ -686,10 +704,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
686
704
  }
687
705
  let typeSource = TypeUtils_1.matchType(t, _anyType => {
688
706
  isOptional = false;
689
- return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [this.jsonQualifier(inJsonNamespace), "json"]);
707
+ return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [
708
+ this.jsonQualifier(inJsonNamespace),
709
+ "json"
710
+ ]);
690
711
  }, _nullType => {
691
712
  isOptional = false;
692
- return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [this.jsonQualifier(inJsonNamespace), "json"]);
713
+ return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [
714
+ this.jsonQualifier(inJsonNamespace),
715
+ "json"
716
+ ]);
693
717
  }, _boolType => "bool", _integerType => "int64_t", _doubleType => "double", _stringType => {
694
718
  if (forceNarrowString) {
695
719
  return "std::string";
@@ -701,10 +725,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
701
725
  "std::vector<",
702
726
  this.cppType(arrayType.items, { needsForwardIndirection: false, needsOptionalIndirection: true, inJsonNamespace }, withIssues, forceNarrowString, false),
703
727
  ">"
704
- ], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [
705
- this.ourQualifier(inJsonNamespace),
706
- this.nameForNamedType(classType)
707
- ]), mapType => {
728
+ ], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [this.ourQualifier(inJsonNamespace), this.nameForNamedType(classType)]), mapType => {
708
729
  let keyType = this._stringType.getType();
709
730
  if (forceNarrowString) {
710
731
  keyType = "std::string";
@@ -725,12 +746,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
725
746
  });
726
747
  if (!isOptional)
727
748
  return typeSource;
728
- return [
729
- optionalType,
730
- "<",
731
- typeSource,
732
- ">"
733
- ];
749
+ return [optionalType, "<", typeSource, ">"];
734
750
  }
735
751
  /**
736
752
  * similar to cppType, it practically gathers all the generated types within
@@ -834,7 +850,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
834
850
  * a member called 'value' value = value will screw up the compiler
835
851
  */
836
852
  const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
837
- if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) || (property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")) {
853
+ if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) ||
854
+ (property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")) {
838
855
  this.emitLine(rendered, " ", getterName, "() const { return ", name, "; }");
839
856
  if (constraints !== undefined && constraints.has(jsonName)) {
840
857
  this.emitLine("void ", setterName, "(", rendered, " value) { if (value) ", checkConst, "(", this._stringType.createStringLiteral([name]), ", ", this.constraintMember(jsonName), ", *value); this->", name, " = value; }");
@@ -867,15 +884,26 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
867
884
  res.set(jsonName, [
868
885
  this.constraintMember(jsonName),
869
886
  "(",
870
- (minMax !== undefined && minMax[0] !== undefined) ? String(minMax[0]) : this._nulloptType,
887
+ minMax !== undefined && minMax[0] !== undefined ? String(minMax[0]) : this._nulloptType,
871
888
  ", ",
872
- (minMax !== undefined && minMax[1] !== undefined) ? String(minMax[1]) : this._nulloptType,
889
+ minMax !== undefined && minMax[1] !== undefined ? String(minMax[1]) : this._nulloptType,
873
890
  ", ",
874
- (minMaxLength !== undefined && minMaxLength[0] !== undefined) ? String(minMaxLength[0]) : this._nulloptType,
891
+ minMaxLength !== undefined && minMaxLength[0] !== undefined
892
+ ? String(minMaxLength[0])
893
+ : this._nulloptType,
875
894
  ", ",
876
- (minMaxLength !== undefined && minMaxLength[1] !== undefined) ? String(minMaxLength[1]) : this._nulloptType,
895
+ minMaxLength !== undefined && minMaxLength[1] !== undefined
896
+ ? String(minMaxLength[1])
897
+ : this._nulloptType,
877
898
  ", ",
878
- (pattern === undefined) ? this._nulloptType : [this._stringType.getType(), "(", this._stringType.createStringLiteral([Strings_1.stringEscape(pattern)]), ")"],
899
+ pattern === undefined
900
+ ? this._nulloptType
901
+ : [
902
+ this._stringType.getType(),
903
+ "(",
904
+ this._stringType.createStringLiteral([Strings_1.stringEscape(pattern)]),
905
+ ")"
906
+ ],
879
907
  ")"
880
908
  ]);
881
909
  });
@@ -936,7 +964,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
936
964
  toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
937
965
  this.emitLine([
938
966
  "x = ",
939
- this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["j.get<", cppType, ">()"]),
967
+ this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
968
+ "j.get<",
969
+ cppType,
970
+ ">()"
971
+ ]),
940
972
  ";"
941
973
  ]);
942
974
  });
@@ -976,7 +1008,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
976
1008
  return;
977
1009
  }
978
1010
  if (p.isOptional || t instanceof Type_1.UnionType) {
979
- const [nullOrOptional, typeSet] = function () {
1011
+ const [nullOrOptional, typeSet] = (function () {
980
1012
  if (t instanceof Type_1.UnionType) {
981
1013
  const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(t, true);
982
1014
  return [maybeNull !== null || p.isOptional, nonNulls];
@@ -986,7 +1018,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
986
1018
  set.add(t);
987
1019
  return [true, set];
988
1020
  }
989
- }();
1021
+ })();
990
1022
  if (nullOrOptional) {
991
1023
  cppType = this.cppTypeInOptional(typeSet, {
992
1024
  needsForwardIndirection: false,
@@ -1045,7 +1077,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1045
1077
  ";"
1046
1078
  ];
1047
1079
  if (p.isOptional && this._options.hideNullOptional) {
1048
- this.emitBlock(["if (", this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]), ")"], false, () => {
1080
+ this.emitBlock([
1081
+ "if (",
1082
+ this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]),
1083
+ ")"
1084
+ ], false, () => {
1049
1085
  this.emitLine(assignment);
1050
1086
  });
1051
1087
  }
@@ -1159,7 +1195,14 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1159
1195
  const ourQualifier = this.ourQualifier(true);
1160
1196
  this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, enumName, " & x)"], false, () => {
1161
1197
  if (this.isLargeEnum(e)) {
1162
- this.emitBlock(["static std::unordered_map<", this._stringType.getType(), ", ", ourQualifier, enumName, "> enumValues"], true, () => {
1198
+ this.emitBlock([
1199
+ "static std::unordered_map<",
1200
+ this._stringType.getType(),
1201
+ ", ",
1202
+ ourQualifier,
1203
+ enumName,
1204
+ "> enumValues"
1205
+ ], true, () => {
1163
1206
  this.forEachEnumCase(e, "none", (name, jsonName) => {
1164
1207
  this.emitLine("{", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(jsonName)])]), ", ", ourQualifier, enumName, "::", name, "},");
1165
1208
  });
@@ -1306,7 +1349,15 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1306
1349
  this.ensureBlankLine();
1307
1350
  }
1308
1351
  const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
1309
- this.emitBlock(["inline void ", checkConst, "(", this._stringType.getConstType(), " name, ", this.withConst(classConstraint), " & c, int64_t value)"], false, () => {
1352
+ this.emitBlock([
1353
+ "inline void ",
1354
+ checkConst,
1355
+ "(",
1356
+ this._stringType.getConstType(),
1357
+ " name, ",
1358
+ this.withConst(classConstraint),
1359
+ " & c, int64_t value)"
1360
+ ], false, () => {
1310
1361
  this.emitBlock(["if (c.", getterMinValue, "() != ", this._nulloptType, " && value < *c.", getterMinValue, "())"], false, () => {
1311
1362
  this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooLowException), " (", this._stringType.createStringLiteral(["Value too low for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value"]), " + ", this._stringType.createStringLiteral(["<"]), " + ", this._stringType.wrapToString(["*c.", getterMinValue, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1312
1363
  });
@@ -1317,12 +1368,38 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1317
1368
  this.ensureBlankLine();
1318
1369
  });
1319
1370
  this.ensureBlankLine();
1320
- this.emitBlock(["inline void ", checkConst, "(", this._stringType.getConstType(), " name, ", this.withConst(classConstraint), " & c, ", this._stringType.getConstType(), " value)"], false, () => {
1321
- this.emitBlock(["if (c.", getterMinLength, "() != ", this._nulloptType, " && value.length() < *c.", getterMinLength, "())"], false, () => {
1371
+ this.emitBlock([
1372
+ "inline void ",
1373
+ checkConst,
1374
+ "(",
1375
+ this._stringType.getConstType(),
1376
+ " name, ",
1377
+ this.withConst(classConstraint),
1378
+ " & c, ",
1379
+ this._stringType.getConstType(),
1380
+ " value)"
1381
+ ], false, () => {
1382
+ this.emitBlock([
1383
+ "if (c.",
1384
+ getterMinLength,
1385
+ "() != ",
1386
+ this._nulloptType,
1387
+ " && value.length() < *c.",
1388
+ getterMinLength,
1389
+ "())"
1390
+ ], false, () => {
1322
1391
  this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooShortException), " (", this._stringType.createStringLiteral(["Value too short for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value.length()"]), " + ", this._stringType.createStringLiteral(["<"]), " + ", this._stringType.wrapToString(["*c.", getterMinLength, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1323
1392
  });
1324
1393
  this.ensureBlankLine();
1325
- this.emitBlock(["if (c.", getterMaxLength, "() != ", this._nulloptType, " && value.length() > *c.", getterMaxLength, "())"], false, () => {
1394
+ this.emitBlock([
1395
+ "if (c.",
1396
+ getterMaxLength,
1397
+ "() != ",
1398
+ this._nulloptType,
1399
+ " && value.length() > *c.",
1400
+ getterMaxLength,
1401
+ "())"
1402
+ ], false, () => {
1326
1403
  this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooLongException), " (", this._stringType.createStringLiteral(["Value too long for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value.length()"]), " + ", this._stringType.createStringLiteral([">"]), " + ", this._stringType.wrapToString(["*c.", getterMaxLength, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1327
1404
  });
1328
1405
  this.ensureBlankLine();
@@ -1357,18 +1434,14 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1357
1434
  untypedMacroName += "HELPER";
1358
1435
  this.emitLine("#ifndef " + untypedMacroName);
1359
1436
  this.emitLine("#define " + untypedMacroName);
1360
- this.emitBlock([
1361
- "inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"
1362
- ], false, () => {
1437
+ this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
1363
1438
  this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
1364
1439
  this.emitLine("return j.at(property).get<json>();");
1365
1440
  });
1366
1441
  this.emitLine("return json();");
1367
1442
  });
1368
1443
  this.ensureBlankLine();
1369
- this.emitBlock([
1370
- "inline json get_untyped(", this.withConst("json"), " & j, std::string property)"
1371
- ], false, () => {
1444
+ this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, std::string property)"], false, () => {
1372
1445
  this.emitLine("return get_untyped(j, property.data());");
1373
1446
  });
1374
1447
  this.emitLine("#endif");
@@ -1378,7 +1451,15 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
1378
1451
  this.emitLine("#ifndef " + optionalMacroName);
1379
1452
  this.emitLine("#define " + optionalMacroName);
1380
1453
  this.emitLine("template <typename T>");
1381
- this.emitBlock(["inline ", optionalType, "<T> get_optional(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
1454
+ this.emitBlock([
1455
+ "inline ",
1456
+ optionalType,
1457
+ "<T> get_optional(",
1458
+ this.withConst("json"),
1459
+ " & j, ",
1460
+ this.withConst("char"),
1461
+ " * property)"
1462
+ ], false, () => {
1382
1463
  this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
1383
1464
  this.emitLine("return j.at(property).get<", optionalType, "<T>>();");
1384
1465
  });
@@ -78,30 +78,33 @@ function csTypeForTransformedStringType(t) {
78
78
  }
79
79
  }
80
80
  exports.cSharpOptions = {
81
- framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [["NewtonSoft", Framework.Newtonsoft], ["SystemTextJson", Framework.SystemTextJson]], "NewtonSoft"),
81
+ framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
82
+ ["NewtonSoft", Framework.Newtonsoft],
83
+ ["SystemTextJson", Framework.SystemTextJson]
84
+ ], "NewtonSoft"),
82
85
  useList: new RendererOptions_1.EnumOption("array-type", "Use T[] or List<T>", [
83
86
  ["array", false],
84
- ["list", true],
87
+ ["list", true]
85
88
  ]),
86
89
  dense: new RendererOptions_1.EnumOption("density", "Property density", [
87
90
  ["normal", false],
88
- ["dense", true],
91
+ ["dense", true]
89
92
  ], "normal", "secondary"),
90
93
  // FIXME: Do this via a configurable named eventually.
91
94
  namespace: new RendererOptions_1.StringOption("namespace", "Generated namespace", "NAME", "QuickType"),
92
95
  version: new RendererOptions_1.EnumOption("csharp-version", "C# version", [
93
96
  ["5", 5],
94
- ["6", 6],
97
+ ["6", 6]
95
98
  ], "6", "secondary"),
96
99
  virtual: new RendererOptions_1.BooleanOption("virtual", "Generate virtual properties", false),
97
100
  typeForAny: new RendererOptions_1.EnumOption("any-type", 'Type to use for "any"', [
98
101
  ["object", "object"],
99
- ["dynamic", "dynamic"],
102
+ ["dynamic", "dynamic"]
100
103
  ], "object", "secondary"),
101
104
  useDecimal: new RendererOptions_1.EnumOption("number-type", "Type to use for numbers", [
102
105
  ["double", false],
103
- ["decimal", true],
104
- ], "double", "secondary"),
106
+ ["decimal", true]
107
+ ], "double", "secondary")
105
108
  };
106
109
  class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
107
110
  constructor() {
@@ -116,7 +119,7 @@ class CSharpTargetLanguage extends TargetLanguage_1.TargetLanguage {
116
119
  exports.cSharpOptions.useList,
117
120
  exports.cSharpOptions.useDecimal,
118
121
  exports.cSharpOptions.typeForAny,
119
- exports.cSharpOptions.virtual,
122
+ exports.cSharpOptions.virtual
120
123
  ];
121
124
  }
122
125
  get stringTypeMapping() {
@@ -200,9 +203,9 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
200
203
  "Equals",
201
204
  "GetType",
202
205
  "MemberwiseClone",
203
- "ReferenceEquals",
206
+ "ReferenceEquals"
204
207
  ],
205
- includeGlobalForbidden: false,
208
+ includeGlobalForbidden: false
206
209
  };
207
210
  }
208
211
  forbiddenForUnionMembers(_, unionNamed) {
@@ -239,7 +242,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
239
242
  }
240
243
  csType(t, follow = Transformers_1.followTargetType, withIssues = false) {
241
244
  const actualType = follow(t);
242
- return TypeUtils_1.matchType(actualType, (_anyType) => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, this._csOptions.typeForAny), (_nullType) => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, this._csOptions.typeForAny), (_boolType) => "bool", (_integerType) => "long", (_doubleType) => this.doubleType, (_stringType) => "string", (arrayType) => {
245
+ return TypeUtils_1.matchType(actualType, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, this._csOptions.typeForAny), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, this._csOptions.typeForAny), _boolType => "bool", _integerType => "long", _doubleType => this.doubleType, _stringType => "string", arrayType => {
243
246
  const itemsType = this.csType(arrayType.items, follow, withIssues);
244
247
  if (this._csOptions.useList) {
245
248
  return ["System.Collections.Generic.List<", itemsType, ">"];
@@ -247,12 +250,16 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
247
250
  else {
248
251
  return [itemsType, "[]"];
249
252
  }
250
- }, (classType) => this.nameForNamedType(classType), (mapType) => ["System.Collections.Generic.Dictionary<string, ", this.csType(mapType.values, follow, withIssues), ">"], (enumType) => this.nameForNamedType(enumType), (unionType) => {
253
+ }, classType => this.nameForNamedType(classType), mapType => [
254
+ "System.Collections.Generic.Dictionary<string, ",
255
+ this.csType(mapType.values, follow, withIssues),
256
+ ">"
257
+ ], enumType => this.nameForNamedType(enumType), unionType => {
251
258
  const nullable = TypeUtils_1.nullableFromUnion(unionType);
252
259
  if (nullable !== null)
253
260
  return this.nullableCSType(nullable, noFollow);
254
261
  return this.nameForNamedType(unionType);
255
- }, (transformedStringType) => csTypeForTransformedStringType(transformedStringType));
262
+ }, transformedStringType => csTypeForTransformedStringType(transformedStringType));
256
263
  }
257
264
  nullableCSType(t, follow = Transformers_1.followTargetType, withIssues = false) {
258
265
  t = Transformers_1.followTargetType(t);
@@ -362,9 +369,9 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
362
369
  this.emitLine("public ", csType, " ", fieldName, ";");
363
370
  });
364
371
  this.ensureBlankLine();
365
- const nullTests = Array.from(nonNulls).map((t) => [
372
+ const nullTests = Array.from(nonNulls).map(t => [
366
373
  this.nameForUnionMember(u, t),
367
- " == null",
374
+ " == null"
368
375
  ]);
369
376
  this.ensureBlankLine();
370
377
  this.forEachUnionMember(u, nonNulls, "none", null, (fieldName, t) => {
@@ -378,7 +385,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
378
385
  }
379
386
  emitEnumDefinition(e, enumName) {
380
387
  const caseNames = [];
381
- this.forEachEnumCase(e, "none", (name) => {
388
+ this.forEachEnumCase(e, "none", name => {
382
389
  if (caseNames.length > 0)
383
390
  caseNames.push(", ");
384
391
  caseNames.push(name);
@@ -475,13 +482,13 @@ exports.newtonsoftCSharpOptions = Object.assign({}, exports.cSharpOptions, {
475
482
  ["complete", { namespaces: true, helpers: true, attributes: true }],
476
483
  ["attributes-only", { namespaces: true, helpers: false, attributes: true }],
477
484
  ["just-types-and-namespace", { namespaces: true, helpers: false, attributes: false }],
478
- ["just-types", { namespaces: true, helpers: false, attributes: false }],
485
+ ["just-types", { namespaces: true, helpers: false, attributes: false }]
479
486
  ]),
480
487
  baseclass: new RendererOptions_1.EnumOption("base-class", "Base class", [
481
488
  ["EntityData", "EntityData"],
482
- ["Object", undefined],
489
+ ["Object", undefined]
483
490
  ], "Object", "secondary"),
484
- checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false),
491
+ checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
485
492
  });
486
493
  class NewtonsoftCSharpRenderer extends CSharpRenderer {
487
494
  constructor(targetLanguage, renderContext, _options) {
@@ -504,7 +511,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
504
511
  "MetadataPropertyHandling",
505
512
  "DateParseHandling",
506
513
  "FromJson",
507
- "Required",
514
+ "Required"
508
515
  ];
509
516
  if (this._options.dense) {
510
517
  forbidden.push("J", "R", "N");
@@ -527,12 +534,12 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
527
534
  }
528
535
  return new Naming_1.SimpleName([`${xfer.kind}_converter`], namingFunction, ConvenienceRenderer_1.inferredNameOrder + 30);
529
536
  }
530
- return new Naming_1.DependencyName(namingFunction, typeName.order + 30, (lookup) => `${lookup(typeName)}_converter`);
537
+ return new Naming_1.DependencyName(namingFunction, typeName.order + 30, lookup => `${lookup(typeName)}_converter`);
531
538
  }
532
539
  makeNamedTypeDependencyNames(t, name) {
533
540
  if (!(t instanceof Type_1.EnumType))
534
541
  return [];
535
- const extensionsName = new Naming_1.DependencyName(namingFunction, name.order + 30, (lookup) => `${lookup(name)}_extensions`);
542
+ const extensionsName = new Naming_1.DependencyName(namingFunction, name.order + 30, lookup => `${lookup(name)}_extensions`);
536
543
  this._enumExtensionsNames.set(name, extensionsName);
537
544
  return [extensionsName];
538
545
  }
@@ -672,7 +679,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
672
679
  // Sometimes multiple top-levels will resolve to the same type, so we have to take care
673
680
  // not to emit more than one extension method for the same type.
674
681
  const seenTypes = new Set();
675
- this.forEachTopLevel("none", (t) => {
682
+ this.forEachTopLevel("none", t => {
676
683
  // FIXME: Make ToJson a Named
677
684
  if (!seenTypes.has(t)) {
678
685
  seenTypes.add(t);
@@ -765,7 +772,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
765
772
  this.emitLine("var ", variableName, " = new List<", this.csType(targetType.items), ">();");
766
773
  this.emitLine("while (reader.TokenType != JsonToken.EndArray)");
767
774
  this.emitBlock(() => {
768
- this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, (v) => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem");
775
+ this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, v => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem");
769
776
  // FIXME: handle EOF
770
777
  this.emitLine("reader.Read();");
771
778
  });
@@ -819,7 +826,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
819
826
  }
820
827
  if (xfer instanceof Transformers_1.ChoiceTransformer) {
821
828
  const caseXfers = xfer.transformers;
822
- if (caseXfers.length > 1 && caseXfers.every((caseXfer) => caseXfer instanceof Transformers_1.StringMatchTransformer)) {
829
+ if (caseXfers.length > 1 && caseXfers.every(caseXfer => caseXfer instanceof Transformers_1.StringMatchTransformer)) {
823
830
  this.emitLine("switch (", variable, ")");
824
831
  this.emitBlock(() => {
825
832
  for (const caseXfer of caseXfers) {
@@ -1037,7 +1044,7 @@ class NewtonsoftCSharpRenderer extends CSharpRenderer {
1037
1044
  if (haveNullable && !(targetType instanceof Type_1.UnionType)) {
1038
1045
  this.emitLine("if (reader.TokenType == JsonToken.Null) return null;");
1039
1046
  }
1040
- const allHandled = this.emitDecodeTransformer(xfer, targetType, (v) => this.emitLine("return ", v, ";"));
1047
+ const allHandled = this.emitDecodeTransformer(xfer, targetType, v => this.emitLine("return ", v, ";"));
1041
1048
  if (!allHandled) {
1042
1049
  this.emitThrow(['"Cannot unmarshal type ', csType, '"']);
1043
1050
  }
@@ -1084,13 +1091,13 @@ exports.systemTextJsonCSharpOptions = Object.assign({}, exports.cSharpOptions, {
1084
1091
  ["complete", { namespaces: true, helpers: true, attributes: true }],
1085
1092
  ["attributes-only", { namespaces: true, helpers: false, attributes: true }],
1086
1093
  ["just-types-and-namespace", { namespaces: true, helpers: false, attributes: false }],
1087
- ["just-types", { namespaces: true, helpers: false, attributes: false }],
1094
+ ["just-types", { namespaces: true, helpers: false, attributes: false }]
1088
1095
  ]),
1089
1096
  baseclass: new RendererOptions_1.EnumOption("base-class", "Base class", [
1090
1097
  ["EntityData", "EntityData"],
1091
- ["Object", undefined],
1098
+ ["Object", undefined]
1092
1099
  ], "Object", "secondary"),
1093
- checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false),
1100
+ checkRequired: new RendererOptions_1.BooleanOption("check-required", "Fail if required properties are missing", false)
1094
1101
  });
1095
1102
  class SystemTextJsonCSharpRenderer extends CSharpRenderer {
1096
1103
  constructor(targetLanguage, renderContext, _options) {
@@ -1567,7 +1574,7 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer {
1567
1574
  this.emitBlock(() => {
1568
1575
  // this.emitLine("var uri = new Uri(", variable, ");");
1569
1576
  // The default value about:blank should never happen, but this way we avoid a null reference warning.
1570
- this.emitLine("var uri = new Uri(\"about:blank\");");
1577
+ this.emitLine('var uri = new Uri("about:blank");');
1571
1578
  this.emitLine("if (!string.IsNullOrEmpty(stringValue))");
1572
1579
  this.emitBlock(() => {
1573
1580
  this.emitLine("uri = new Uri(", variable, ");");
@@ -13,7 +13,10 @@ const Source_1 = require("../Source");
13
13
  const Annotation_1 = require("../Annotation");
14
14
  exports.elmOptions = {
15
15
  justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
16
- useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [["array", false], ["list", true]]),
16
+ useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [
17
+ ["array", false],
18
+ ["list", true]
19
+ ]),
17
20
  // FIXME: Do this via a configurable named eventually.
18
21
  moduleName: new RendererOptions_1.StringOption("module", "Generated module name", "NAME", "QuickType")
19
22
  };