quicktype 17.0.1 → 17.0.3

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.
Files changed (139) hide show
  1. package/dist/cli/CompressedJSONFromStream.js +26 -38
  2. package/dist/cli/GraphQLIntrospection.js +33 -41
  3. package/dist/cli/TypeSource.d.ts +1 -1
  4. package/dist/cli/URLGrammar.js +4 -3
  5. package/dist/cli/index.js +363 -364
  6. package/dist/quicktype-core/Annotation.js +2 -0
  7. package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
  8. package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
  9. package/dist/quicktype-core/DateTime.js +1 -0
  10. package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
  11. package/dist/quicktype-core/DeclarationIR.js +13 -10
  12. package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
  13. package/dist/quicktype-core/GatherNames.js +47 -25
  14. package/dist/quicktype-core/Graph.d.ts +2 -2
  15. package/dist/quicktype-core/Graph.js +23 -19
  16. package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
  17. package/dist/quicktype-core/GraphRewriting.js +65 -54
  18. package/dist/quicktype-core/MakeTransformations.js +23 -22
  19. package/dist/quicktype-core/MarkovChain.d.ts +3 -3
  20. package/dist/quicktype-core/MarkovChain.js +9 -8
  21. package/dist/quicktype-core/Messages.d.ts +3 -3
  22. package/dist/quicktype-core/Messages.js +8 -3
  23. package/dist/quicktype-core/Naming.d.ts +11 -11
  24. package/dist/quicktype-core/Naming.js +76 -61
  25. package/dist/quicktype-core/Renderer.d.ts +6 -6
  26. package/dist/quicktype-core/Renderer.js +34 -17
  27. package/dist/quicktype-core/RendererOptions.d.ts +5 -5
  28. package/dist/quicktype-core/RendererOptions.js +6 -3
  29. package/dist/quicktype-core/Run.d.ts +9 -9
  30. package/dist/quicktype-core/Run.js +72 -67
  31. package/dist/quicktype-core/Source.d.ts +3 -3
  32. package/dist/quicktype-core/Source.js +19 -18
  33. package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
  34. package/dist/quicktype-core/TargetLanguage.js +6 -2
  35. package/dist/quicktype-core/Transformers.d.ts +25 -25
  36. package/dist/quicktype-core/Transformers.js +94 -66
  37. package/dist/quicktype-core/Type.d.ts +41 -43
  38. package/dist/quicktype-core/Type.js +96 -71
  39. package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
  40. package/dist/quicktype-core/TypeBuilder.js +53 -47
  41. package/dist/quicktype-core/TypeGraph.d.ts +4 -4
  42. package/dist/quicktype-core/TypeGraph.js +49 -40
  43. package/dist/quicktype-core/TypeUtils.d.ts +2 -2
  44. package/dist/quicktype-core/TypeUtils.js +23 -22
  45. package/dist/quicktype-core/UnifyClasses.js +16 -12
  46. package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
  47. package/dist/quicktype-core/UnionBuilder.js +33 -30
  48. package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
  49. package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
  50. package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
  51. package/dist/quicktype-core/attributes/Constraints.js +8 -4
  52. package/dist/quicktype-core/attributes/Description.js +6 -5
  53. package/dist/quicktype-core/attributes/EnumValues.js +4 -3
  54. package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
  55. package/dist/quicktype-core/attributes/StringTypes.js +24 -21
  56. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
  57. package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
  58. package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
  59. package/dist/quicktype-core/attributes/TypeNames.js +49 -21
  60. package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
  61. package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
  62. package/dist/quicktype-core/index.js +128 -125
  63. package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
  64. package/dist/quicktype-core/input/CompressedJSON.js +49 -54
  65. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
  66. package/dist/quicktype-core/input/Inference.d.ts +2 -2
  67. package/dist/quicktype-core/input/Inference.js +25 -17
  68. package/dist/quicktype-core/input/Inputs.d.ts +2 -2
  69. package/dist/quicktype-core/input/Inputs.js +38 -54
  70. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
  71. package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
  72. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
  73. package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
  74. package/dist/quicktype-core/input/PostmanCollection.js +2 -1
  75. package/dist/quicktype-core/input/io/NodeIO.js +55 -44
  76. package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
  77. package/dist/quicktype-core/language/All.js +3 -2
  78. package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
  79. package/dist/quicktype-core/language/CPlusPlus.js +185 -151
  80. package/dist/quicktype-core/language/CSharp.d.ts +7 -7
  81. package/dist/quicktype-core/language/CSharp.js +82 -72
  82. package/dist/quicktype-core/language/Crystal.d.ts +2 -2
  83. package/dist/quicktype-core/language/Crystal.js +18 -17
  84. package/dist/quicktype-core/language/Dart.d.ts +4 -4
  85. package/dist/quicktype-core/language/Dart.js +36 -34
  86. package/dist/quicktype-core/language/Elm.d.ts +6 -6
  87. package/dist/quicktype-core/language/Elm.js +47 -45
  88. package/dist/quicktype-core/language/Golang.d.ts +4 -4
  89. package/dist/quicktype-core/language/Golang.js +23 -20
  90. package/dist/quicktype-core/language/Haskell.d.ts +5 -5
  91. package/dist/quicktype-core/language/Haskell.js +25 -23
  92. package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
  93. package/dist/quicktype-core/language/JSONSchema.js +17 -16
  94. package/dist/quicktype-core/language/Java.d.ts +2 -2
  95. package/dist/quicktype-core/language/Java.js +97 -97
  96. package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
  97. package/dist/quicktype-core/language/JavaScript.js +19 -17
  98. package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
  99. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
  100. package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
  101. package/dist/quicktype-core/language/Kotlin.js +39 -37
  102. package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
  103. package/dist/quicktype-core/language/Objective-C.js +45 -41
  104. package/dist/quicktype-core/language/Php.d.ts +2 -2
  105. package/dist/quicktype-core/language/Php.js +66 -41
  106. package/dist/quicktype-core/language/Pike.d.ts +1 -1
  107. package/dist/quicktype-core/language/Pike.js +18 -17
  108. package/dist/quicktype-core/language/Python.d.ts +8 -8
  109. package/dist/quicktype-core/language/Python.js +63 -64
  110. package/dist/quicktype-core/language/Rust.d.ts +2 -2
  111. package/dist/quicktype-core/language/Rust.js +21 -19
  112. package/dist/quicktype-core/language/Swift.d.ts +7 -7
  113. package/dist/quicktype-core/language/Swift.js +568 -565
  114. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
  115. package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
  116. package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
  117. package/dist/quicktype-core/language/ruby/index.js +49 -24
  118. package/dist/quicktype-core/language/ruby/keywords.js +1 -0
  119. package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
  120. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
  121. package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
  122. package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
  123. package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
  124. package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
  125. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
  126. package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
  127. package/dist/quicktype-core/support/Acronyms.js +3 -1
  128. package/dist/quicktype-core/support/Chance.js +10 -0
  129. package/dist/quicktype-core/support/Converters.js +1 -0
  130. package/dist/quicktype-core/support/Strings.d.ts +4 -4
  131. package/dist/quicktype-core/support/Strings.js +17 -16
  132. package/dist/quicktype-core/support/Support.d.ts +1 -1
  133. package/dist/quicktype-core/support/Support.js +30 -6
  134. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
  135. package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
  136. package/dist/quicktype-graphql-input/index.d.ts +1 -1
  137. package/dist/quicktype-graphql-input/index.js +229 -212
  138. package/dist/quicktype-typescript-input/index.js +30 -5
  139. package/package.json +25 -19
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.messageAssert = exports.messageError = exports.QuickTypeError = void 0;
3
4
  const errorMessages = {
4
5
  InternalError: "Internal error: ${message}",
5
6
  // Misc
@@ -65,6 +66,9 @@ const errorMessages = {
65
66
  TypeScriptCompilerError: "TypeScript error: ${message}"
66
67
  };
67
68
  class QuickTypeError extends Error {
69
+ errorMessage;
70
+ messageName;
71
+ properties;
68
72
  constructor(errorMessage, messageName, userMessage, properties) {
69
73
  super(userMessage);
70
74
  this.errorMessage = errorMessage;
@@ -76,8 +80,9 @@ exports.QuickTypeError = QuickTypeError;
76
80
  function messageError(kind, properties) {
77
81
  const message = errorMessages[kind];
78
82
  let userMessage = message;
79
- for (const name of Object.getOwnPropertyNames(properties)) {
80
- let value = properties[name];
83
+ const propertiesMap = properties;
84
+ for (const name of Object.getOwnPropertyNames(propertiesMap)) {
85
+ let value = propertiesMap[name];
81
86
  if (typeof value === "object" && typeof value.toString === "function") {
82
87
  value = value.toString();
83
88
  }
@@ -89,7 +94,7 @@ function messageError(kind, properties) {
89
94
  }
90
95
  userMessage = userMessage.replace("${" + name + "}", value);
91
96
  }
92
- throw new QuickTypeError(message, kind, userMessage, properties);
97
+ throw new QuickTypeError(message, kind, userMessage, propertiesMap);
93
98
  }
94
99
  exports.messageError = messageError;
95
100
  function messageAssert(assertion, kind, properties) {
@@ -5,12 +5,12 @@ export declare class Namespace {
5
5
  private readonly _members;
6
6
  constructor(_name: string, parent: Namespace | undefined, forbiddenNamespaces: Iterable<Namespace>, additionalForbidden: Iterable<Name>);
7
7
  private addChild;
8
- readonly children: ReadonlySet<Namespace>;
9
- readonly members: ReadonlySet<Name>;
10
- readonly forbiddenNameds: ReadonlySet<Name>;
8
+ get children(): ReadonlySet<Namespace>;
9
+ get members(): ReadonlySet<Name>;
10
+ get forbiddenNameds(): ReadonlySet<Name>;
11
11
  add<TName extends Name>(named: TName): TName;
12
12
  }
13
- export declare type NameStyle = (rawName: string) => string;
13
+ export type NameStyle = (rawName: string) => string;
14
14
  export declare class Namer {
15
15
  readonly name: string;
16
16
  readonly nameStyle: NameStyle;
@@ -25,9 +25,9 @@ export declare abstract class Name {
25
25
  private readonly _associates;
26
26
  constructor(_namingFunction: Namer | undefined, order: number);
27
27
  addAssociate(associate: AssociatedName): void;
28
- abstract readonly dependencies: ReadonlyArray<Name>;
28
+ abstract get dependencies(): ReadonlyArray<Name>;
29
29
  isFixed(): this is FixedName;
30
- readonly namingFunction: Namer;
30
+ get namingFunction(): Namer;
31
31
  abstract proposeUnstyledNames(names: ReadonlyMap<Name, string>): ReadonlySet<string>;
32
32
  firstProposedName(names: ReadonlyMap<Name, string>): string;
33
33
  nameAssignments(forbiddenNames: ReadonlySet<string>, assignedName: string): ReadonlyMap<Name, string> | null;
@@ -35,29 +35,29 @@ export declare abstract class Name {
35
35
  export declare class FixedName extends Name {
36
36
  private readonly _fixedName;
37
37
  constructor(_fixedName: string);
38
- readonly dependencies: ReadonlyArray<Name>;
38
+ get dependencies(): ReadonlyArray<Name>;
39
39
  addAssociate(_: AssociatedName): never;
40
- readonly fixedName: string;
40
+ get fixedName(): string;
41
41
  proposeUnstyledNames(_?: ReadonlyMap<Name, string>): ReadonlySet<string>;
42
42
  }
43
43
  export declare class SimpleName extends Name {
44
44
  private readonly _unstyledNames;
45
45
  constructor(unstyledNames: Iterable<string>, namingFunction: Namer, order: number);
46
- readonly dependencies: ReadonlyArray<Name>;
46
+ get dependencies(): ReadonlyArray<Name>;
47
47
  proposeUnstyledNames(_?: ReadonlyMap<Name, string>): ReadonlySet<string>;
48
48
  }
49
49
  export declare class AssociatedName extends Name {
50
50
  private readonly _sponsor;
51
51
  readonly getName: (sponsorName: string) => string;
52
52
  constructor(_sponsor: Name, order: number, getName: (sponsorName: string) => string);
53
- readonly dependencies: ReadonlyArray<Name>;
53
+ get dependencies(): ReadonlyArray<Name>;
54
54
  proposeUnstyledNames(_?: ReadonlyMap<Name, string>): never;
55
55
  }
56
56
  export declare class DependencyName extends Name {
57
57
  private readonly _proposeUnstyledName;
58
58
  private readonly _dependencies;
59
59
  constructor(namingFunction: Namer | undefined, order: number, _proposeUnstyledName: (lookup: (n: Name) => string) => string);
60
- readonly dependencies: ReadonlyArray<Name>;
60
+ get dependencies(): ReadonlyArray<Name>;
61
61
  proposeUnstyledNames(names: ReadonlyMap<Name, string>): ReadonlySet<string>;
62
62
  }
63
63
  export declare function keywordNamespace(name: string, keywords: string[]): Namespace;
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assignNames = exports.keywordNamespace = exports.DependencyName = exports.AssociatedName = exports.SimpleName = exports.FixedName = exports.Name = exports.funPrefixNamer = exports.Namer = exports.Namespace = void 0;
3
4
  const collection_utils_1 = require("collection-utils");
4
5
  const Support_1 = require("./support/Support");
5
6
  class Namespace {
7
+ forbiddenNamespaces;
8
+ additionalForbidden;
9
+ _children = new Set();
10
+ _members = new Set();
6
11
  constructor(_name, parent, forbiddenNamespaces, additionalForbidden) {
7
- this._children = new Set();
8
- this._members = new Set();
9
12
  this.forbiddenNamespaces = new Set(forbiddenNamespaces);
10
13
  this.additionalForbidden = new Set(additionalForbidden);
11
14
  if (parent !== undefined) {
@@ -23,7 +26,7 @@ class Namespace {
23
26
  }
24
27
  get forbiddenNameds() {
25
28
  // FIXME: cache
26
- return collection_utils_1.setUnion(this.additionalForbidden, ...Array.from(this.forbiddenNamespaces).map(ns => ns.members));
29
+ return (0, collection_utils_1.setUnion)(this.additionalForbidden, ...Array.from(this.forbiddenNamespaces).map(ns => ns.members));
27
30
  }
28
31
  add(named) {
29
32
  this._members.add(named);
@@ -46,6 +49,9 @@ exports.Namespace = Namespace;
46
49
  // `Namer` is a class so that we can compare namers and put them into immutable
47
50
  // collections.
48
51
  class Namer {
52
+ name;
53
+ nameStyle;
54
+ _prefixes;
49
55
  constructor(name, nameStyle, prefixes) {
50
56
  this.name = name;
51
57
  this.nameStyle = nameStyle;
@@ -56,7 +62,7 @@ class Namer {
56
62
  assignNames(names, forbiddenNamesIterable, namesToAssignIterable) {
57
63
  const forbiddenNames = new Set(forbiddenNamesIterable);
58
64
  const namesToAssign = Array.from(namesToAssignIterable);
59
- Support_1.assert(namesToAssign.length > 0, "Number of names can't be less than 1");
65
+ (0, Support_1.assert)(namesToAssign.length > 0, "Number of names can't be less than 1");
60
66
  const allAssignedNames = new Map();
61
67
  let namesToPrefix = [];
62
68
  for (const name of namesToAssign) {
@@ -64,14 +70,14 @@ class Namer {
64
70
  const namingFunction = name.namingFunction;
65
71
  // Find the first proposed name that isn't proposed by
66
72
  // any of the other names and that isn't already forbidden.
67
- const maybeUniqueName = collection_utils_1.iterableFind(proposedNames, proposed => !forbiddenNames.has(namingFunction.nameStyle(proposed)) &&
73
+ const maybeUniqueName = (0, collection_utils_1.iterableFind)(proposedNames, proposed => !forbiddenNames.has(namingFunction.nameStyle(proposed)) &&
68
74
  namesToAssign.every(n => n === name || !n.proposeUnstyledNames(names).has(proposed)));
69
75
  if (maybeUniqueName !== undefined) {
70
76
  const styledName = namingFunction.nameStyle(maybeUniqueName);
71
77
  const assigned = name.nameAssignments(forbiddenNames, styledName);
72
78
  if (assigned !== null) {
73
- collection_utils_1.mapMergeInto(allAssignedNames, assigned);
74
- collection_utils_1.setUnionInto(forbiddenNames, assigned.values());
79
+ (0, collection_utils_1.mapMergeInto)(allAssignedNames, assigned);
80
+ (0, collection_utils_1.setUnionInto)(forbiddenNames, assigned.values());
75
81
  continue;
76
82
  }
77
83
  }
@@ -82,7 +88,7 @@ class Namer {
82
88
  let prefixes = this._prefixes.values();
83
89
  let suffixNumber = 1;
84
90
  for (const name of namesToPrefix) {
85
- const originalName = Support_1.defined(collection_utils_1.iterableFirst(name.proposeUnstyledNames(names)));
91
+ const originalName = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(name.proposeUnstyledNames(names)));
86
92
  for (;;) {
87
93
  let nameToTry;
88
94
  const { done, value: prefix } = prefixes.next();
@@ -97,8 +103,8 @@ class Namer {
97
103
  const assigned = name.nameAssignments(forbiddenNames, styledName);
98
104
  if (assigned === null)
99
105
  continue;
100
- collection_utils_1.mapMergeInto(allAssignedNames, assigned);
101
- collection_utils_1.setUnionInto(forbiddenNames, assigned.values());
106
+ (0, collection_utils_1.mapMergeInto)(allAssignedNames, assigned);
107
+ (0, collection_utils_1.setUnionInto)(forbiddenNames, assigned.values());
102
108
  break;
103
109
  }
104
110
  }
@@ -130,11 +136,13 @@ exports.funPrefixNamer = funPrefixNamer;
130
136
  // own common superclass. Most methods of `Name` make sense only either
131
137
  // for `FixedName` or the non-fixed names.
132
138
  class Name {
139
+ _namingFunction;
140
+ order;
141
+ _associates = new Set();
133
142
  // If a Named is fixed, the namingFunction is undefined.
134
143
  constructor(_namingFunction, order) {
135
144
  this._namingFunction = _namingFunction;
136
145
  this.order = order;
137
- this._associates = new Set();
138
146
  }
139
147
  addAssociate(associate) {
140
148
  this._associates.add(associate);
@@ -143,10 +151,10 @@ class Name {
143
151
  return this instanceof FixedName;
144
152
  }
145
153
  get namingFunction() {
146
- return Support_1.defined(this._namingFunction);
154
+ return (0, Support_1.defined)(this._namingFunction);
147
155
  }
148
156
  firstProposedName(names) {
149
- return Support_1.defined(collection_utils_1.iterableFirst(this.proposeUnstyledNames(names)));
157
+ return (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(this.proposeUnstyledNames(names)));
150
158
  }
151
159
  nameAssignments(forbiddenNames, assignedName) {
152
160
  if (forbiddenNames.has(assignedName))
@@ -165,6 +173,7 @@ class Name {
165
173
  exports.Name = Name;
166
174
  // FIXME: FixedNameds should optionally be user-configurable
167
175
  class FixedName extends Name {
176
+ _fixedName;
168
177
  constructor(_fixedName) {
169
178
  super(undefined, 0);
170
179
  this._fixedName = _fixedName;
@@ -173,17 +182,18 @@ class FixedName extends Name {
173
182
  return [];
174
183
  }
175
184
  addAssociate(_) {
176
- return Support_1.panic("Cannot add associates to fixed names");
185
+ return (0, Support_1.panic)("Cannot add associates to fixed names");
177
186
  }
178
187
  get fixedName() {
179
188
  return this._fixedName;
180
189
  }
181
190
  proposeUnstyledNames(_) {
182
- return Support_1.panic("Only fixedName should be called on FixedName.");
191
+ return (0, Support_1.panic)("Only fixedName should be called on FixedName.");
183
192
  }
184
193
  }
185
194
  exports.FixedName = FixedName;
186
195
  class SimpleName extends Name {
196
+ _unstyledNames;
187
197
  constructor(unstyledNames, namingFunction, order) {
188
198
  super(namingFunction, order);
189
199
  this._unstyledNames = new Set(unstyledNames);
@@ -197,6 +207,8 @@ class SimpleName extends Name {
197
207
  }
198
208
  exports.SimpleName = SimpleName;
199
209
  class AssociatedName extends Name {
210
+ _sponsor;
211
+ getName;
200
212
  constructor(_sponsor, order, getName) {
201
213
  super(undefined, order);
202
214
  this._sponsor = _sponsor;
@@ -206,11 +218,13 @@ class AssociatedName extends Name {
206
218
  return [this._sponsor];
207
219
  }
208
220
  proposeUnstyledNames(_) {
209
- return Support_1.panic("AssociatedName must be assigned via its sponsor");
221
+ return (0, Support_1.panic)("AssociatedName must be assigned via its sponsor");
210
222
  }
211
223
  }
212
224
  exports.AssociatedName = AssociatedName;
213
225
  class DependencyName extends Name {
226
+ _proposeUnstyledName;
227
+ _dependencies;
214
228
  constructor(namingFunction, order, _proposeUnstyledName) {
215
229
  super(namingFunction, order);
216
230
  this._proposeUnstyledName = _proposeUnstyledName;
@@ -227,8 +241,8 @@ class DependencyName extends Name {
227
241
  proposeUnstyledNames(names) {
228
242
  return new Set([
229
243
  this._proposeUnstyledName(n => {
230
- Support_1.assert(this._dependencies.has(n), "DependencyName proposer is not pure");
231
- return Support_1.defined(names.get(n));
244
+ (0, Support_1.assert)(this._dependencies.has(n), "DependencyName proposer is not pure");
245
+ return (0, Support_1.defined)(names.get(n));
232
246
  })
233
247
  ]);
234
248
  }
@@ -243,49 +257,50 @@ function keywordNamespace(name, keywords) {
243
257
  }
244
258
  exports.keywordNamespace = keywordNamespace;
245
259
  function allNamespacesRecursively(namespaces) {
246
- return collection_utils_1.setUnion(namespaces, ...Array.from(collection_utils_1.setMap(namespaces, ns => allNamespacesRecursively(ns.children))));
260
+ return (0, collection_utils_1.setUnion)(namespaces, ...Array.from((0, collection_utils_1.setMap)(namespaces, ns => allNamespacesRecursively(ns.children))));
247
261
  }
248
262
  class NamingContext {
263
+ _names = new Map();
264
+ _namedsForName = new Map();
265
+ namespaces;
249
266
  constructor(rootNamespaces) {
250
- this._names = new Map();
251
- this._namedsForName = new Map();
252
- this.isReadyToBeNamed = (named) => {
253
- if (this._names.has(named))
254
- return false;
255
- return named.dependencies.every((n) => this._names.has(n));
256
- };
257
- this.isConflicting = (namedNamespace, proposed) => {
258
- const namedsForProposed = this._namedsForName.get(proposed);
259
- // If the name is not assigned at all, there is no conflict.
260
- if (namedsForProposed === undefined)
261
- return false;
262
- // The name is assigned, but it might still not be forbidden.
263
- for (const n of namedsForProposed) {
264
- if (namedNamespace.members.has(n) || namedNamespace.forbiddenNameds.has(n)) {
265
- return true;
266
- }
267
- }
268
- return false;
269
- };
270
- this.assign = (named, namedNamespace, name) => {
271
- Support_1.assert(!this.names.has(named), `Name "${name}" assigned twice`);
272
- Support_1.assert(!this.isConflicting(namedNamespace, name), `Assigned name "${name}" conflicts`);
273
- this._names.set(named, name);
274
- let namedsForName = this._namedsForName.get(name);
275
- if (namedsForName === undefined) {
276
- namedsForName = new Set();
277
- this._namedsForName.set(name, namedsForName);
278
- }
279
- namedsForName.add(named);
280
- };
281
267
  this.namespaces = allNamespacesRecursively(rootNamespaces);
282
268
  }
283
269
  get names() {
284
270
  return this._names;
285
271
  }
272
+ isReadyToBeNamed = (named) => {
273
+ if (this._names.has(named))
274
+ return false;
275
+ return named.dependencies.every((n) => this._names.has(n));
276
+ };
286
277
  areForbiddensFullyNamed(namespace) {
287
- return collection_utils_1.iterableEvery(namespace.forbiddenNameds, n => this._names.has(n));
278
+ return (0, collection_utils_1.iterableEvery)(namespace.forbiddenNameds, n => this._names.has(n));
288
279
  }
280
+ isConflicting = (namedNamespace, proposed) => {
281
+ const namedsForProposed = this._namedsForName.get(proposed);
282
+ // If the name is not assigned at all, there is no conflict.
283
+ if (namedsForProposed === undefined)
284
+ return false;
285
+ // The name is assigned, but it might still not be forbidden.
286
+ for (const n of namedsForProposed) {
287
+ if (namedNamespace.members.has(n) || namedNamespace.forbiddenNameds.has(n)) {
288
+ return true;
289
+ }
290
+ }
291
+ return false;
292
+ };
293
+ assign = (named, namedNamespace, name) => {
294
+ (0, Support_1.assert)(!this.names.has(named), `Name "${name}" assigned twice`);
295
+ (0, Support_1.assert)(!this.isConflicting(namedNamespace, name), `Assigned name "${name}" conflicts`);
296
+ this._names.set(named, name);
297
+ let namedsForName = this._namedsForName.get(name);
298
+ if (namedsForName === undefined) {
299
+ namedsForName = new Set();
300
+ this._namedsForName.set(name, namedsForName);
301
+ }
302
+ namedsForName.add(named);
303
+ };
289
304
  }
290
305
  // Naming algorithm
291
306
  function assignNames(rootNamespaces) {
@@ -303,36 +318,36 @@ function assignNames(rootNamespaces) {
303
318
  // at least one unnamed Named that has all its dependencies satisfied.
304
319
  // If no such namespace exists we're either done, or there's an unallowed
305
320
  // cycle.
306
- const unfinishedNamespaces = collection_utils_1.setFilter(ctx.namespaces, ns => ctx.areForbiddensFullyNamed(ns));
307
- const readyNamespace = collection_utils_1.iterableFind(unfinishedNamespaces, ns => collection_utils_1.iterableSome(ns.members, ctx.isReadyToBeNamed));
321
+ const unfinishedNamespaces = (0, collection_utils_1.setFilter)(ctx.namespaces, ns => ctx.areForbiddensFullyNamed(ns));
322
+ const readyNamespace = (0, collection_utils_1.iterableFind)(unfinishedNamespaces, ns => (0, collection_utils_1.iterableSome)(ns.members, ctx.isReadyToBeNamed));
308
323
  if (readyNamespace === undefined) {
309
324
  // FIXME: Check for cycles?
310
325
  return ctx.names;
311
326
  }
312
- const allForbiddenNames = collection_utils_1.setUnion(readyNamespace.members, readyNamespace.forbiddenNameds);
313
- let forbiddenNames = collection_utils_1.setFilterMap(allForbiddenNames, n => ctx.names.get(n));
327
+ const allForbiddenNames = (0, collection_utils_1.setUnion)(readyNamespace.members, readyNamespace.forbiddenNameds);
328
+ let forbiddenNames = (0, collection_utils_1.setFilterMap)(allForbiddenNames, n => ctx.names.get(n));
314
329
  // 2. From low order to high order, sort those names into sets where all
315
330
  // members of a set propose the same name and have the same naming
316
331
  // function.
317
332
  for (;;) {
318
- const allReadyNames = collection_utils_1.setFilter(readyNamespace.members, ctx.isReadyToBeNamed);
319
- const minOrderName = collection_utils_1.iterableMinBy(allReadyNames, n => n.order);
333
+ const allReadyNames = (0, collection_utils_1.setFilter)(readyNamespace.members, ctx.isReadyToBeNamed);
334
+ const minOrderName = (0, collection_utils_1.iterableMinBy)(allReadyNames, n => n.order);
320
335
  if (minOrderName === undefined)
321
336
  break;
322
337
  const minOrder = minOrderName.order;
323
- const readyNames = collection_utils_1.setFilter(allReadyNames, n => n.order === minOrder);
338
+ const readyNames = (0, collection_utils_1.setFilter)(allReadyNames, n => n.order === minOrder);
324
339
  // It would be nice if we had tuples, then we wouldn't have to do this in
325
340
  // two steps.
326
- const byNamingFunction = collection_utils_1.setGroupBy(readyNames, n => n.namingFunction);
341
+ const byNamingFunction = (0, collection_utils_1.setGroupBy)(readyNames, n => n.namingFunction);
327
342
  for (const [namer, namedsForNamingFunction] of byNamingFunction) {
328
- const byProposed = collection_utils_1.setGroupBy(namedsForNamingFunction, n => n.namingFunction.nameStyle(n.firstProposedName(ctx.names)));
343
+ const byProposed = (0, collection_utils_1.setGroupBy)(namedsForNamingFunction, n => n.namingFunction.nameStyle(n.firstProposedName(ctx.names)));
329
344
  for (const [, nameds] of byProposed) {
330
345
  // 3. Use each set's naming function to name its members.
331
346
  const names = namer.assignNames(ctx.names, forbiddenNames, nameds);
332
347
  for (const [name, assigned] of names) {
333
348
  ctx.assign(name, readyNamespace, assigned);
334
349
  }
335
- collection_utils_1.setUnionInto(forbiddenNames, names.values());
350
+ (0, collection_utils_1.setUnionInto)(forbiddenNames, names.values());
336
351
  }
337
352
  }
338
353
  }
@@ -3,17 +3,17 @@ import { Name, Namespace } from "./Naming";
3
3
  import { Source, Sourcelike } from "./Source";
4
4
  import { AnnotationData } from "./Annotation";
5
5
  import { TargetLanguage } from "./TargetLanguage";
6
- export declare type RenderResult = {
6
+ export type RenderResult = {
7
7
  sources: ReadonlyMap<string, Source>;
8
8
  names: ReadonlyMap<Name, string>;
9
9
  };
10
- export declare type BlankLinePosition = "none" | "interposing" | "leading" | "leading-and-interposing";
11
- export declare type BlankLineConfig = BlankLinePosition | [BlankLinePosition, number];
12
- export declare type RenderContext = {
10
+ export type BlankLinePosition = "none" | "interposing" | "leading" | "leading-and-interposing";
11
+ export type BlankLineConfig = BlankLinePosition | [BlankLinePosition, number];
12
+ export type RenderContext = {
13
13
  typeGraph: TypeGraph;
14
14
  leadingComments: string[] | undefined;
15
15
  };
16
- export declare type ForEachPosition = "first" | "last" | "middle" | "only";
16
+ export type ForEachPosition = "first" | "last" | "middle" | "only";
17
17
  export declare abstract class Renderer {
18
18
  protected readonly targetLanguage: TargetLanguage;
19
19
  protected readonly typeGraph: TypeGraph;
@@ -46,5 +46,5 @@ export declare abstract class Renderer {
46
46
  protected initializeEmitContextForFilename(filename: string): void;
47
47
  protected finishFile(filename: string): void;
48
48
  render(givenOutputFilename: string): RenderResult;
49
- readonly names: ReadonlyMap<Name, string>;
49
+ get names(): ReadonlyMap<Name, string>;
50
50
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Renderer = void 0;
3
4
  const collection_utils_1 = require("collection-utils");
4
5
  const Naming_1 = require("./Naming");
5
6
  const Source_1 = require("./Source");
@@ -29,6 +30,15 @@ function lineIndentation(line) {
29
30
  return { indent: 0, text: null };
30
31
  }
31
32
  class EmitContext {
33
+ _lastNewline;
34
+ // @ts-ignore: Initialized in startEmit, which is called from the constructor
35
+ _emitted;
36
+ // @ts-ignore: Initialized in startEmit, which is called from the constructor
37
+ _currentEmitTarget;
38
+ // @ts-ignore: Initialized in startEmit, which is called from the constructor
39
+ _numBlankLinesNeeded;
40
+ // @ts-ignore: Initialized in startEmit, which is called from the constructor
41
+ _preventBlankLine;
32
42
  constructor() {
33
43
  this._currentEmitTarget = this._emitted = [];
34
44
  this._numBlankLinesNeeded = 0;
@@ -48,7 +58,7 @@ class EmitContext {
48
58
  this._preventBlankLine = false;
49
59
  }
50
60
  emitNewline() {
51
- const nl = Source_1.newline();
61
+ const nl = (0, Source_1.newline)();
52
62
  this.pushItem(nl);
53
63
  this._lastNewline = nl;
54
64
  }
@@ -76,21 +86,21 @@ class EmitContext {
76
86
  }
77
87
  changeIndent(offset) {
78
88
  if (this._lastNewline === undefined) {
79
- return Support_1.panic("Cannot change indent for the first line");
89
+ return (0, Support_1.panic)("Cannot change indent for the first line");
80
90
  }
81
91
  this._lastNewline.indentationChange += offset;
82
92
  }
83
93
  }
84
94
  class Renderer {
95
+ targetLanguage;
96
+ typeGraph;
97
+ leadingComments;
98
+ _names;
99
+ _finishedFiles;
100
+ _finishedEmitContexts;
101
+ _emitContext;
85
102
  constructor(targetLanguage, renderContext) {
86
103
  this.targetLanguage = targetLanguage;
87
- this.emitTable = (tableArray) => {
88
- if (tableArray.length === 0)
89
- return;
90
- const table = tableArray.map(r => r.map(sl => Source_1.sourcelikeToSource(sl)));
91
- this._emitContext.emitItem({ kind: "table", table });
92
- this._emitContext.emitNewline();
93
- };
94
104
  this.typeGraph = renderContext.typeGraph;
95
105
  this.leadingComments = renderContext.leadingComments;
96
106
  this._finishedFiles = new Map();
@@ -144,7 +154,7 @@ class Renderer {
144
154
  for (let i = 1; i < numLines; i++) {
145
155
  const line = lines[i];
146
156
  const { indent, text } = lineIndentation(line);
147
- Support_1.assert(indent % 4 === 0, "Indentation is not a multiple of 4.");
157
+ (0, Support_1.assert)(indent % 4 === 0, "Indentation is not a multiple of 4.");
148
158
  if (text !== null) {
149
159
  const newIndent = indent / 4;
150
160
  this.changeIndent(newIndent - currentIndent);
@@ -163,7 +173,7 @@ class Renderer {
163
173
  const oldEmitContext = this._emitContext;
164
174
  this._emitContext = new EmitContext();
165
175
  emitter();
166
- Support_1.assert(!this._emitContext.isNested, "emit context not restored correctly");
176
+ (0, Support_1.assert)(!this._emitContext.isNested, "emit context not restored correctly");
167
177
  const source = this._emitContext.source;
168
178
  this._emitContext = oldEmitContext;
169
179
  return source;
@@ -175,19 +185,26 @@ class Renderer {
175
185
  }
176
186
  emitAnnotated(annotation, emitter) {
177
187
  const lines = this.gatherSource(emitter);
178
- const source = Source_1.sourcelikeToSource(lines);
179
- this._emitContext.emitItem(Source_1.annotated(annotation, source));
188
+ const source = (0, Source_1.sourcelikeToSource)(lines);
189
+ this._emitContext.emitItem((0, Source_1.annotated)(annotation, source));
180
190
  }
181
191
  emitIssue(message, emitter) {
182
192
  this.emitAnnotated(new Annotation_1.IssueAnnotationData(message), emitter);
183
193
  }
194
+ emitTable = (tableArray) => {
195
+ if (tableArray.length === 0)
196
+ return;
197
+ const table = tableArray.map(r => r.map(sl => (0, Source_1.sourcelikeToSource)(sl)));
198
+ this._emitContext.emitItem({ kind: "table", table });
199
+ this._emitContext.emitNewline();
200
+ };
184
201
  changeIndent(offset) {
185
202
  this._emitContext.changeIndent(offset);
186
203
  }
187
204
  iterableForEach(iterable, emitter) {
188
205
  const items = Array.from(iterable);
189
206
  let onFirst = true;
190
- for (const [i, v] of collection_utils_1.iterableEnumerate(items)) {
207
+ for (const [i, v] of (0, collection_utils_1.iterableEnumerate)(items)) {
191
208
  const position = items.length === 1 ? "only" : onFirst ? "first" : i === items.length - 1 ? "last" : "middle";
192
209
  emitter(v, position);
193
210
  onFirst = false;
@@ -219,7 +236,7 @@ class Renderer {
219
236
  this.changeIndent(-1);
220
237
  }
221
238
  assignNames() {
222
- return Naming_1.assignNames(this.setUpNaming());
239
+ return (0, Naming_1.assignNames)(this.setUpNaming());
223
240
  }
224
241
  initializeEmitContextForFilename(filename) {
225
242
  if (this._finishedEmitContexts.has(filename.toLowerCase())) {
@@ -233,7 +250,7 @@ class Renderer {
233
250
  if (this._finishedFiles.has(filename)) {
234
251
  console.log(`[WARNING] Tried to emit file ${filename} more than once. If performing multi-file output this warning can be safely ignored.`);
235
252
  }
236
- const source = Source_1.sourcelikeToSource(this._emitContext.source);
253
+ const source = (0, Source_1.sourcelikeToSource)(this._emitContext.source);
237
254
  this._finishedFiles.set(filename, source);
238
255
  // [Michael Fey (@MrRooni), 2019-5-9] We save the current EmitContext for possible reuse later. We put it into the map with a lowercased version of the key so we can do a case-insensitive lookup later. The reason we lowercase it is because some schema (looking at you keyword-unions.schema) define objects of the same name with different casing. BOOL vs. bool, for example.
239
256
  this._finishedEmitContexts.set(filename.toLowerCase(), this._emitContext);
@@ -249,7 +266,7 @@ class Renderer {
249
266
  }
250
267
  get names() {
251
268
  if (this._names === undefined) {
252
- return Support_1.panic("Names accessed before they were assigned");
269
+ return (0, Support_1.panic)("Names accessed before they were assigned");
253
270
  }
254
271
  return this._names;
255
272
  }
@@ -2,7 +2,7 @@
2
2
  * Primary options show up in the web UI in the "Language" settings tab,
3
3
  * secondary options in "Other".
4
4
  */
5
- export declare type OptionKind = "primary" | "secondary";
5
+ export type OptionKind = "primary" | "secondary";
6
6
  export interface OptionDefinition {
7
7
  name: string;
8
8
  type: StringConstructor | BooleanConstructor;
@@ -26,13 +26,13 @@ export declare abstract class Option<T> {
26
26
  getValue(values: {
27
27
  [name: string]: any;
28
28
  }): T;
29
- readonly cliDefinitions: {
29
+ get cliDefinitions(): {
30
30
  display: OptionDefinition[];
31
31
  actual: OptionDefinition[];
32
32
  };
33
33
  }
34
- export declare type OptionValueType<O> = O extends Option<infer T> ? T : never;
35
- export declare type OptionValues<T> = {
34
+ export type OptionValueType<O> = O extends Option<infer T> ? T : never;
35
+ export type OptionValues<T> = {
36
36
  [P in keyof T]: OptionValueType<T[P]>;
37
37
  };
38
38
  export declare function getOptionValues<T extends {
@@ -51,7 +51,7 @@ export declare class BooleanOption extends Option<boolean> {
51
51
  * @param kind Whether it's a primary or secondary option.
52
52
  */
53
53
  constructor(name: string, description: string, defaultValue: boolean, kind?: OptionKind);
54
- readonly cliDefinitions: {
54
+ get cliDefinitions(): {
55
55
  display: OptionDefinition[];
56
56
  actual: OptionDefinition[];
57
57
  };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnumOption = exports.StringOption = exports.BooleanOption = exports.getOptionValues = exports.Option = void 0;
3
4
  const Support_1 = require("./support/Support");
4
5
  const Messages_1 = require("./Messages");
5
6
  const collection_utils_1 = require("collection-utils");
@@ -8,10 +9,11 @@ const collection_utils_1 = require("collection-utils");
8
9
  * subclasses, `BooleanOption`, `EnumOption`, or `StringOption`.
9
10
  */
10
11
  class Option {
12
+ definition;
11
13
  constructor(definition) {
12
14
  definition.renderer = true;
13
15
  this.definition = definition;
14
- Support_1.assert(definition.kind !== undefined, "Renderer option kind must be defined");
16
+ (0, Support_1.assert)(definition.kind !== undefined, "Renderer option kind must be defined");
15
17
  }
16
18
  getValue(values) {
17
19
  const value = values[this.definition.name];
@@ -105,6 +107,7 @@ class StringOption extends Option {
105
107
  }
106
108
  exports.StringOption = StringOption;
107
109
  class EnumOption extends Option {
110
+ _values;
108
111
  constructor(name, description, values, defaultValue = undefined, kind = "primary") {
109
112
  if (defaultValue === undefined) {
110
113
  defaultValue = values[0][0];
@@ -129,8 +132,8 @@ class EnumOption extends Option {
129
132
  if (name === undefined) {
130
133
  name = this.definition.defaultValue;
131
134
  }
132
- if (!collection_utils_1.hasOwnProperty(this._values, name)) {
133
- return Messages_1.messageError("RendererUnknownOptionValue", { value: name, name: this.definition.name });
135
+ if (!(0, collection_utils_1.hasOwnProperty)(this._values, name)) {
136
+ return (0, Messages_1.messageError)("RendererUnknownOptionValue", { value: name, name: this.definition.name });
134
137
  }
135
138
  return this._values[name];
136
139
  }