quicktype 18.0.6 → 19.0.4
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.
- package/README.md +1 -1
- package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
- package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
- package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
- package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
- package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
- package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
- package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
- package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
- package/dist/{cli/index.d.ts → index.d.ts} +1 -1
- package/dist/{cli/index.js → index.js} +4 -5
- package/package.json +61 -77
- package/dist/quicktype-core/Annotation.d.ts +0 -8
- package/dist/quicktype-core/Annotation.js +0 -16
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
- package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
- package/dist/quicktype-core/DateTime.d.ts +0 -10
- package/dist/quicktype-core/DateTime.js +0 -57
- package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
- package/dist/quicktype-core/DeclarationIR.js +0 -167
- package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
- package/dist/quicktype-core/GatherNames.d.ts +0 -2
- package/dist/quicktype-core/GatherNames.js +0 -333
- package/dist/quicktype-core/Graph.d.ts +0 -12
- package/dist/quicktype-core/Graph.js +0 -220
- package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
- package/dist/quicktype-core/GraphRewriting.js +0 -421
- package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
- package/dist/quicktype-core/MakeTransformations.js +0 -193
- package/dist/quicktype-core/MarkovChain.d.ts +0 -15
- package/dist/quicktype-core/MarkovChain.js +0 -154
- package/dist/quicktype-core/Messages.d.ts +0 -294
- package/dist/quicktype-core/Messages.js +0 -105
- package/dist/quicktype-core/Naming.d.ts +0 -64
- package/dist/quicktype-core/Naming.js +0 -356
- package/dist/quicktype-core/Renderer.d.ts +0 -50
- package/dist/quicktype-core/Renderer.js +0 -274
- package/dist/quicktype-core/RendererOptions.d.ts +0 -71
- package/dist/quicktype-core/RendererOptions.js +0 -141
- package/dist/quicktype-core/Run.d.ts +0 -174
- package/dist/quicktype-core/Run.js +0 -393
- package/dist/quicktype-core/Source.d.ts +0 -65
- package/dist/quicktype-core/Source.js +0 -204
- package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
- package/dist/quicktype-core/TargetLanguage.js +0 -66
- package/dist/quicktype-core/Transformers.d.ts +0 -209
- package/dist/quicktype-core/Transformers.js +0 -836
- package/dist/quicktype-core/Type.d.ts +0 -206
- package/dist/quicktype-core/Type.js +0 -716
- package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
- package/dist/quicktype-core/TypeBuilder.js +0 -324
- package/dist/quicktype-core/TypeGraph.d.ts +0 -75
- package/dist/quicktype-core/TypeGraph.js +0 -420
- package/dist/quicktype-core/TypeUtils.d.ts +0 -33
- package/dist/quicktype-core/TypeUtils.js +0 -230
- package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
- package/dist/quicktype-core/UnifyClasses.js +0 -159
- package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
- package/dist/quicktype-core/UnionBuilder.js +0 -282
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
- package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
- package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
- package/dist/quicktype-core/attributes/Constraints.js +0 -172
- package/dist/quicktype-core/attributes/Description.d.ts +0 -9
- package/dist/quicktype-core/attributes/Description.js +0 -97
- package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
- package/dist/quicktype-core/attributes/EnumValues.js +0 -31
- package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
- package/dist/quicktype-core/attributes/StringTypes.js +0 -189
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
- package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
- package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
- package/dist/quicktype-core/attributes/TypeNames.js +0 -274
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
- package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
- package/dist/quicktype-core/index.d.ts +0 -48
- package/dist/quicktype-core/index.js +0 -180
- package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
- package/dist/quicktype-core/input/CompressedJSON.js +0 -276
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
- package/dist/quicktype-core/input/Inference.d.ts +0 -22
- package/dist/quicktype-core/input/Inference.js +0 -240
- package/dist/quicktype-core/input/Inputs.d.ts +0 -48
- package/dist/quicktype-core/input/Inputs.js +0 -145
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
- package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
- package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
- package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
- package/dist/quicktype-core/input/PostmanCollection.js +0 -60
- package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
- package/dist/quicktype-core/input/io/NodeIO.js +0 -87
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
- package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
- package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
- package/dist/quicktype-core/language/All.d.ts +0 -3
- package/dist/quicktype-core/language/All.js +0 -57
- package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
- package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
- package/dist/quicktype-core/language/CSharp.d.ts +0 -201
- package/dist/quicktype-core/language/CSharp.js +0 -1850
- package/dist/quicktype-core/language/Crystal.d.ts +0 -37
- package/dist/quicktype-core/language/Crystal.js +0 -337
- package/dist/quicktype-core/language/Dart.d.ts +0 -66
- package/dist/quicktype-core/language/Dart.js +0 -576
- package/dist/quicktype-core/language/Elm.d.ts +0 -58
- package/dist/quicktype-core/language/Elm.js +0 -522
- package/dist/quicktype-core/language/Golang.d.ts +0 -51
- package/dist/quicktype-core/language/Golang.js +0 -460
- package/dist/quicktype-core/language/Haskell.d.ts +0 -56
- package/dist/quicktype-core/language/Haskell.js +0 -411
- package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
- package/dist/quicktype-core/language/JSONSchema.js +0 -169
- package/dist/quicktype-core/language/Java.d.ts +0 -125
- package/dist/quicktype-core/language/Java.js +0 -1081
- package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
- package/dist/quicktype-core/language/JavaScript.js +0 -435
- package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
- package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
- package/dist/quicktype-core/language/Kotlin.js +0 -832
- package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
- package/dist/quicktype-core/language/Objective-C.js +0 -777
- package/dist/quicktype-core/language/Php.d.ts +0 -80
- package/dist/quicktype-core/language/Php.js +0 -702
- package/dist/quicktype-core/language/Pike.d.ts +0 -37
- package/dist/quicktype-core/language/Pike.js +0 -276
- package/dist/quicktype-core/language/Python.d.ts +0 -107
- package/dist/quicktype-core/language/Python.js +0 -969
- package/dist/quicktype-core/language/Rust.d.ts +0 -56
- package/dist/quicktype-core/language/Rust.js +0 -309
- package/dist/quicktype-core/language/Swift.d.ts +0 -96
- package/dist/quicktype-core/language/Swift.js +0 -1211
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
- package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
- package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
- package/dist/quicktype-core/language/ruby/index.js +0 -557
- package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
- package/dist/quicktype-core/language/ruby/keywords.js +0 -358
- package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
- package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
- package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
- package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
- package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
- package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
- package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
- package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
- package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
- package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
- package/dist/quicktype-core/support/Acronyms.js +0 -1128
- package/dist/quicktype-core/support/Chance.d.ts +0 -38
- package/dist/quicktype-core/support/Chance.js +0 -2146
- package/dist/quicktype-core/support/Converters.d.ts +0 -6
- package/dist/quicktype-core/support/Converters.js +0 -16
- package/dist/quicktype-core/support/Strings.d.ts +0 -44
- package/dist/quicktype-core/support/Strings.js +0 -525
- package/dist/quicktype-core/support/Support.d.ts +0 -29
- package/dist/quicktype-core/support/Support.js +0 -162
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
- package/dist/quicktype-graphql-input/index.d.ts +0 -17
- package/dist/quicktype-graphql-input/index.js +0 -407
- package/dist/quicktype-typescript-input/index.d.ts +0 -2
- package/dist/quicktype-typescript-input/index.js +0 -98
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const Support_1 = require("./support/Support");
|
|
6
|
-
class Namespace {
|
|
7
|
-
forbiddenNamespaces;
|
|
8
|
-
additionalForbidden;
|
|
9
|
-
_children = new Set();
|
|
10
|
-
_members = new Set();
|
|
11
|
-
constructor(_name, parent, forbiddenNamespaces, additionalForbidden) {
|
|
12
|
-
this.forbiddenNamespaces = new Set(forbiddenNamespaces);
|
|
13
|
-
this.additionalForbidden = new Set(additionalForbidden);
|
|
14
|
-
if (parent !== undefined) {
|
|
15
|
-
parent.addChild(this);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
addChild(child) {
|
|
19
|
-
this._children.add(child);
|
|
20
|
-
}
|
|
21
|
-
get children() {
|
|
22
|
-
return this._children;
|
|
23
|
-
}
|
|
24
|
-
get members() {
|
|
25
|
-
return this._members;
|
|
26
|
-
}
|
|
27
|
-
get forbiddenNameds() {
|
|
28
|
-
// FIXME: cache
|
|
29
|
-
return (0, collection_utils_1.setUnion)(this.additionalForbidden, ...Array.from(this.forbiddenNamespaces).map(ns => ns.members));
|
|
30
|
-
}
|
|
31
|
-
add(named) {
|
|
32
|
-
this._members.add(named);
|
|
33
|
-
return named;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.Namespace = Namespace;
|
|
37
|
-
// `Namer`s are invoked to figure out what names to assign non-fixed `Name`s,
|
|
38
|
-
// and in particular to resolve conflicts. Those arise under two circumstances,
|
|
39
|
-
// which can also combine:
|
|
40
|
-
//
|
|
41
|
-
// 1. A proposed name is the same as an already assigned name that's forbidden
|
|
42
|
-
// for the name to be assigned.
|
|
43
|
-
// 2. There is more than one `Name` about to be assigned a name that all have
|
|
44
|
-
// the same proposed name.
|
|
45
|
-
//
|
|
46
|
-
// The namer is invoked with the set of all assigned, forbidden names,
|
|
47
|
-
// the requested name, and the `Name`s to assign names to.
|
|
48
|
-
//
|
|
49
|
-
// `Namer` is a class so that we can compare namers and put them into immutable
|
|
50
|
-
// collections.
|
|
51
|
-
class Namer {
|
|
52
|
-
name;
|
|
53
|
-
nameStyle;
|
|
54
|
-
_prefixes;
|
|
55
|
-
constructor(name, nameStyle, prefixes) {
|
|
56
|
-
this.name = name;
|
|
57
|
-
this.nameStyle = nameStyle;
|
|
58
|
-
this._prefixes = new Set(prefixes);
|
|
59
|
-
}
|
|
60
|
-
// The namesIterable comes directly out of the context and will
|
|
61
|
-
// be modified if we assign
|
|
62
|
-
assignNames(names, forbiddenNamesIterable, namesToAssignIterable) {
|
|
63
|
-
const forbiddenNames = new Set(forbiddenNamesIterable);
|
|
64
|
-
const namesToAssign = Array.from(namesToAssignIterable);
|
|
65
|
-
(0, Support_1.assert)(namesToAssign.length > 0, "Number of names can't be less than 1");
|
|
66
|
-
const allAssignedNames = new Map();
|
|
67
|
-
let namesToPrefix = [];
|
|
68
|
-
for (const name of namesToAssign) {
|
|
69
|
-
const proposedNames = name.proposeUnstyledNames(names);
|
|
70
|
-
const namingFunction = name.namingFunction;
|
|
71
|
-
// Find the first proposed name that isn't proposed by
|
|
72
|
-
// any of the other names and that isn't already forbidden.
|
|
73
|
-
const maybeUniqueName = (0, collection_utils_1.iterableFind)(proposedNames, proposed => !forbiddenNames.has(namingFunction.nameStyle(proposed)) &&
|
|
74
|
-
namesToAssign.every(n => n === name || !n.proposeUnstyledNames(names).has(proposed)));
|
|
75
|
-
if (maybeUniqueName !== undefined) {
|
|
76
|
-
const styledName = namingFunction.nameStyle(maybeUniqueName);
|
|
77
|
-
const assigned = name.nameAssignments(forbiddenNames, styledName);
|
|
78
|
-
if (assigned !== null) {
|
|
79
|
-
(0, collection_utils_1.mapMergeInto)(allAssignedNames, assigned);
|
|
80
|
-
(0, collection_utils_1.setUnionInto)(forbiddenNames, assigned.values());
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// There's no unique name, or it couldn't be assigned, so
|
|
85
|
-
// we need to prefix-name this one.
|
|
86
|
-
namesToPrefix.push(name);
|
|
87
|
-
}
|
|
88
|
-
let prefixes = this._prefixes.values();
|
|
89
|
-
let suffixNumber = 1;
|
|
90
|
-
for (const name of namesToPrefix) {
|
|
91
|
-
const originalName = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(name.proposeUnstyledNames(names)));
|
|
92
|
-
for (;;) {
|
|
93
|
-
let nameToTry;
|
|
94
|
-
const { done, value: prefix } = prefixes.next();
|
|
95
|
-
if (!done) {
|
|
96
|
-
nameToTry = `${prefix}_${originalName}`;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
nameToTry = `${originalName}_${suffixNumber.toString()}`;
|
|
100
|
-
suffixNumber++;
|
|
101
|
-
}
|
|
102
|
-
const styledName = name.namingFunction.nameStyle(nameToTry);
|
|
103
|
-
const assigned = name.nameAssignments(forbiddenNames, styledName);
|
|
104
|
-
if (assigned === null)
|
|
105
|
-
continue;
|
|
106
|
-
(0, collection_utils_1.mapMergeInto)(allAssignedNames, assigned);
|
|
107
|
-
(0, collection_utils_1.setUnionInto)(forbiddenNames, assigned.values());
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return allAssignedNames;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.Namer = Namer;
|
|
115
|
-
const funPrefixes = [
|
|
116
|
-
"Purple",
|
|
117
|
-
"Fluffy",
|
|
118
|
-
"Tentacled",
|
|
119
|
-
"Sticky",
|
|
120
|
-
"Indigo",
|
|
121
|
-
"Indecent",
|
|
122
|
-
"Hilarious",
|
|
123
|
-
"Ambitious",
|
|
124
|
-
"Cunning",
|
|
125
|
-
"Magenta",
|
|
126
|
-
"Frisky",
|
|
127
|
-
"Mischievous",
|
|
128
|
-
"Braggadocious"
|
|
129
|
-
];
|
|
130
|
-
function funPrefixNamer(name, nameStyle) {
|
|
131
|
-
return new Namer(name, nameStyle, funPrefixes);
|
|
132
|
-
}
|
|
133
|
-
exports.funPrefixNamer = funPrefixNamer;
|
|
134
|
-
// FIXME: I think the type hierarchy is somewhat wrong here. `FixedName`
|
|
135
|
-
// should be a `Name`, but the non-fixed names should probably have their
|
|
136
|
-
// own common superclass. Most methods of `Name` make sense only either
|
|
137
|
-
// for `FixedName` or the non-fixed names.
|
|
138
|
-
class Name {
|
|
139
|
-
_namingFunction;
|
|
140
|
-
order;
|
|
141
|
-
_associates = new Set();
|
|
142
|
-
// If a Named is fixed, the namingFunction is undefined.
|
|
143
|
-
constructor(_namingFunction, order) {
|
|
144
|
-
this._namingFunction = _namingFunction;
|
|
145
|
-
this.order = order;
|
|
146
|
-
}
|
|
147
|
-
addAssociate(associate) {
|
|
148
|
-
this._associates.add(associate);
|
|
149
|
-
}
|
|
150
|
-
isFixed() {
|
|
151
|
-
return this instanceof FixedName;
|
|
152
|
-
}
|
|
153
|
-
get namingFunction() {
|
|
154
|
-
return (0, Support_1.defined)(this._namingFunction);
|
|
155
|
-
}
|
|
156
|
-
firstProposedName(names) {
|
|
157
|
-
return (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(this.proposeUnstyledNames(names)));
|
|
158
|
-
}
|
|
159
|
-
nameAssignments(forbiddenNames, assignedName) {
|
|
160
|
-
if (forbiddenNames.has(assignedName))
|
|
161
|
-
return null;
|
|
162
|
-
const assignments = new Map([[this, assignedName]]);
|
|
163
|
-
for (const an of this._associates) {
|
|
164
|
-
const associatedAssignedName = an.getName(assignedName);
|
|
165
|
-
if (forbiddenNames.has(associatedAssignedName)) {
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
assignments.set(an, associatedAssignedName);
|
|
169
|
-
}
|
|
170
|
-
return assignments;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.Name = Name;
|
|
174
|
-
// FIXME: FixedNameds should optionally be user-configurable
|
|
175
|
-
class FixedName extends Name {
|
|
176
|
-
_fixedName;
|
|
177
|
-
constructor(_fixedName) {
|
|
178
|
-
super(undefined, 0);
|
|
179
|
-
this._fixedName = _fixedName;
|
|
180
|
-
}
|
|
181
|
-
get dependencies() {
|
|
182
|
-
return [];
|
|
183
|
-
}
|
|
184
|
-
addAssociate(_) {
|
|
185
|
-
return (0, Support_1.panic)("Cannot add associates to fixed names");
|
|
186
|
-
}
|
|
187
|
-
get fixedName() {
|
|
188
|
-
return this._fixedName;
|
|
189
|
-
}
|
|
190
|
-
proposeUnstyledNames(_) {
|
|
191
|
-
return (0, Support_1.panic)("Only fixedName should be called on FixedName.");
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.FixedName = FixedName;
|
|
195
|
-
class SimpleName extends Name {
|
|
196
|
-
_unstyledNames;
|
|
197
|
-
constructor(unstyledNames, namingFunction, order) {
|
|
198
|
-
super(namingFunction, order);
|
|
199
|
-
this._unstyledNames = new Set(unstyledNames);
|
|
200
|
-
}
|
|
201
|
-
get dependencies() {
|
|
202
|
-
return [];
|
|
203
|
-
}
|
|
204
|
-
proposeUnstyledNames(_) {
|
|
205
|
-
return this._unstyledNames;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
exports.SimpleName = SimpleName;
|
|
209
|
-
class AssociatedName extends Name {
|
|
210
|
-
_sponsor;
|
|
211
|
-
getName;
|
|
212
|
-
constructor(_sponsor, order, getName) {
|
|
213
|
-
super(undefined, order);
|
|
214
|
-
this._sponsor = _sponsor;
|
|
215
|
-
this.getName = getName;
|
|
216
|
-
}
|
|
217
|
-
get dependencies() {
|
|
218
|
-
return [this._sponsor];
|
|
219
|
-
}
|
|
220
|
-
proposeUnstyledNames(_) {
|
|
221
|
-
return (0, Support_1.panic)("AssociatedName must be assigned via its sponsor");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.AssociatedName = AssociatedName;
|
|
225
|
-
class DependencyName extends Name {
|
|
226
|
-
_proposeUnstyledName;
|
|
227
|
-
_dependencies;
|
|
228
|
-
constructor(namingFunction, order, _proposeUnstyledName) {
|
|
229
|
-
super(namingFunction, order);
|
|
230
|
-
this._proposeUnstyledName = _proposeUnstyledName;
|
|
231
|
-
const dependencies = [];
|
|
232
|
-
_proposeUnstyledName(n => {
|
|
233
|
-
dependencies.push(n);
|
|
234
|
-
return "0xDEADBEEF";
|
|
235
|
-
});
|
|
236
|
-
this._dependencies = new Set(dependencies);
|
|
237
|
-
}
|
|
238
|
-
get dependencies() {
|
|
239
|
-
return Array.from(this._dependencies);
|
|
240
|
-
}
|
|
241
|
-
proposeUnstyledNames(names) {
|
|
242
|
-
return new Set([
|
|
243
|
-
this._proposeUnstyledName(n => {
|
|
244
|
-
(0, Support_1.assert)(this._dependencies.has(n), "DependencyName proposer is not pure");
|
|
245
|
-
return (0, Support_1.defined)(names.get(n));
|
|
246
|
-
})
|
|
247
|
-
]);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
exports.DependencyName = DependencyName;
|
|
251
|
-
function keywordNamespace(name, keywords) {
|
|
252
|
-
const ns = new Namespace(name, undefined, [], []);
|
|
253
|
-
for (const kw of keywords) {
|
|
254
|
-
ns.add(new FixedName(kw));
|
|
255
|
-
}
|
|
256
|
-
return ns;
|
|
257
|
-
}
|
|
258
|
-
exports.keywordNamespace = keywordNamespace;
|
|
259
|
-
function allNamespacesRecursively(namespaces) {
|
|
260
|
-
return (0, collection_utils_1.setUnion)(namespaces, ...Array.from((0, collection_utils_1.setMap)(namespaces, ns => allNamespacesRecursively(ns.children))));
|
|
261
|
-
}
|
|
262
|
-
class NamingContext {
|
|
263
|
-
_names = new Map();
|
|
264
|
-
_namedsForName = new Map();
|
|
265
|
-
namespaces;
|
|
266
|
-
constructor(rootNamespaces) {
|
|
267
|
-
this.namespaces = allNamespacesRecursively(rootNamespaces);
|
|
268
|
-
}
|
|
269
|
-
get names() {
|
|
270
|
-
return this._names;
|
|
271
|
-
}
|
|
272
|
-
isReadyToBeNamed = (named) => {
|
|
273
|
-
if (this._names.has(named))
|
|
274
|
-
return false;
|
|
275
|
-
return named.dependencies.every((n) => this._names.has(n));
|
|
276
|
-
};
|
|
277
|
-
areForbiddensFullyNamed(namespace) {
|
|
278
|
-
return (0, collection_utils_1.iterableEvery)(namespace.forbiddenNameds, n => this._names.has(n));
|
|
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
|
-
};
|
|
304
|
-
}
|
|
305
|
-
// Naming algorithm
|
|
306
|
-
function assignNames(rootNamespaces) {
|
|
307
|
-
const ctx = new NamingContext(rootNamespaces);
|
|
308
|
-
// Assign all fixed names.
|
|
309
|
-
for (const ns of ctx.namespaces) {
|
|
310
|
-
for (const n of ns.members) {
|
|
311
|
-
if (!n.isFixed())
|
|
312
|
-
continue;
|
|
313
|
-
ctx.assign(n, ns, n.fixedName);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
for (;;) {
|
|
317
|
-
// 1. Find a namespace whose forbiddens are all fully named, and which has
|
|
318
|
-
// at least one unnamed Named that has all its dependencies satisfied.
|
|
319
|
-
// If no such namespace exists we're either done, or there's an unallowed
|
|
320
|
-
// cycle.
|
|
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));
|
|
323
|
-
if (readyNamespace === undefined) {
|
|
324
|
-
// FIXME: Check for cycles?
|
|
325
|
-
return ctx.names;
|
|
326
|
-
}
|
|
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));
|
|
329
|
-
// 2. From low order to high order, sort those names into sets where all
|
|
330
|
-
// members of a set propose the same name and have the same naming
|
|
331
|
-
// function.
|
|
332
|
-
for (;;) {
|
|
333
|
-
const allReadyNames = (0, collection_utils_1.setFilter)(readyNamespace.members, ctx.isReadyToBeNamed);
|
|
334
|
-
const minOrderName = (0, collection_utils_1.iterableMinBy)(allReadyNames, n => n.order);
|
|
335
|
-
if (minOrderName === undefined)
|
|
336
|
-
break;
|
|
337
|
-
const minOrder = minOrderName.order;
|
|
338
|
-
const readyNames = (0, collection_utils_1.setFilter)(allReadyNames, n => n.order === minOrder);
|
|
339
|
-
// It would be nice if we had tuples, then we wouldn't have to do this in
|
|
340
|
-
// two steps.
|
|
341
|
-
const byNamingFunction = (0, collection_utils_1.setGroupBy)(readyNames, n => n.namingFunction);
|
|
342
|
-
for (const [namer, namedsForNamingFunction] of byNamingFunction) {
|
|
343
|
-
const byProposed = (0, collection_utils_1.setGroupBy)(namedsForNamingFunction, n => n.namingFunction.nameStyle(n.firstProposedName(ctx.names)));
|
|
344
|
-
for (const [, nameds] of byProposed) {
|
|
345
|
-
// 3. Use each set's naming function to name its members.
|
|
346
|
-
const names = namer.assignNames(ctx.names, forbiddenNames, nameds);
|
|
347
|
-
for (const [name, assigned] of names) {
|
|
348
|
-
ctx.assign(name, readyNamespace, assigned);
|
|
349
|
-
}
|
|
350
|
-
(0, collection_utils_1.setUnionInto)(forbiddenNames, names.values());
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
exports.assignNames = assignNames;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { TypeGraph } from "./TypeGraph";
|
|
2
|
-
import { Name, Namespace } from "./Naming";
|
|
3
|
-
import { Source, Sourcelike } from "./Source";
|
|
4
|
-
import { AnnotationData } from "./Annotation";
|
|
5
|
-
import { TargetLanguage } from "./TargetLanguage";
|
|
6
|
-
export type RenderResult = {
|
|
7
|
-
sources: ReadonlyMap<string, Source>;
|
|
8
|
-
names: ReadonlyMap<Name, string>;
|
|
9
|
-
};
|
|
10
|
-
export type BlankLinePosition = "none" | "interposing" | "leading" | "leading-and-interposing";
|
|
11
|
-
export type BlankLineConfig = BlankLinePosition | [BlankLinePosition, number];
|
|
12
|
-
export type RenderContext = {
|
|
13
|
-
typeGraph: TypeGraph;
|
|
14
|
-
leadingComments: string[] | undefined;
|
|
15
|
-
};
|
|
16
|
-
export type ForEachPosition = "first" | "last" | "middle" | "only";
|
|
17
|
-
export declare abstract class Renderer {
|
|
18
|
-
protected readonly targetLanguage: TargetLanguage;
|
|
19
|
-
protected readonly typeGraph: TypeGraph;
|
|
20
|
-
protected readonly leadingComments: string[] | undefined;
|
|
21
|
-
private _names;
|
|
22
|
-
private _finishedFiles;
|
|
23
|
-
private _finishedEmitContexts;
|
|
24
|
-
private _emitContext;
|
|
25
|
-
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext);
|
|
26
|
-
ensureBlankLine(numBlankLines?: number): void;
|
|
27
|
-
preventBlankLine(): void;
|
|
28
|
-
emitItem(item: Sourcelike): void;
|
|
29
|
-
emitItemOnce(item: Sourcelike): boolean;
|
|
30
|
-
emitLineOnce(...lineParts: Sourcelike[]): void;
|
|
31
|
-
emitLine(...lineParts: Sourcelike[]): void;
|
|
32
|
-
emitMultiline(linesString: string): void;
|
|
33
|
-
gatherSource(emitter: () => void): Sourcelike[];
|
|
34
|
-
emitGatheredSource(items: Sourcelike[]): void;
|
|
35
|
-
emitAnnotated(annotation: AnnotationData, emitter: () => void): void;
|
|
36
|
-
emitIssue(message: string, emitter: () => void): void;
|
|
37
|
-
protected emitTable: (tableArray: Sourcelike[][]) => void;
|
|
38
|
-
changeIndent(offset: number): void;
|
|
39
|
-
iterableForEach<T>(iterable: Iterable<T>, emitter: (v: T, position: ForEachPosition) => void): void;
|
|
40
|
-
forEach<K, V>(iterable: Iterable<[K, V]>, interposedBlankLines: number, leadingBlankLines: number, emitter: (v: V, k: K, position: ForEachPosition) => void): boolean;
|
|
41
|
-
forEachWithBlankLines<K, V>(iterable: Iterable<[K, V]>, blankLineConfig: BlankLineConfig, emitter: (v: V, k: K, position: ForEachPosition) => void): boolean;
|
|
42
|
-
indent(fn: () => void): void;
|
|
43
|
-
protected abstract setUpNaming(): Iterable<Namespace>;
|
|
44
|
-
protected abstract emitSource(givenOutputFilename: string): void;
|
|
45
|
-
private assignNames;
|
|
46
|
-
protected initializeEmitContextForFilename(filename: string): void;
|
|
47
|
-
protected finishFile(filename: string): void;
|
|
48
|
-
render(givenOutputFilename: string): RenderResult;
|
|
49
|
-
get names(): ReadonlyMap<Name, string>;
|
|
50
|
-
}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Renderer = void 0;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const Naming_1 = require("./Naming");
|
|
6
|
-
const Source_1 = require("./Source");
|
|
7
|
-
const Annotation_1 = require("./Annotation");
|
|
8
|
-
const Support_1 = require("./support/Support");
|
|
9
|
-
function getBlankLineConfig(cfg) {
|
|
10
|
-
if (Array.isArray(cfg)) {
|
|
11
|
-
return { position: cfg[0], count: cfg[1] };
|
|
12
|
-
}
|
|
13
|
-
return { position: cfg, count: 1 };
|
|
14
|
-
}
|
|
15
|
-
function lineIndentation(line) {
|
|
16
|
-
const len = line.length;
|
|
17
|
-
let indent = 0;
|
|
18
|
-
for (let i = 0; i < len; i++) {
|
|
19
|
-
const c = line.charAt(i);
|
|
20
|
-
if (c === " ") {
|
|
21
|
-
indent += 1;
|
|
22
|
-
}
|
|
23
|
-
else if (c === "\t") {
|
|
24
|
-
indent = (indent / 4 + 1) * 4;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return { indent, text: line.substring(i) };
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return { indent: 0, text: null };
|
|
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;
|
|
42
|
-
constructor() {
|
|
43
|
-
this._currentEmitTarget = this._emitted = [];
|
|
44
|
-
this._numBlankLinesNeeded = 0;
|
|
45
|
-
this._preventBlankLine = true; // no blank lines at start of file
|
|
46
|
-
}
|
|
47
|
-
get isEmpty() {
|
|
48
|
-
return this._emitted.length === 0;
|
|
49
|
-
}
|
|
50
|
-
get isNested() {
|
|
51
|
-
return this._emitted !== this._currentEmitTarget;
|
|
52
|
-
}
|
|
53
|
-
get source() {
|
|
54
|
-
return this._emitted;
|
|
55
|
-
}
|
|
56
|
-
pushItem(item) {
|
|
57
|
-
this._currentEmitTarget.push(item);
|
|
58
|
-
this._preventBlankLine = false;
|
|
59
|
-
}
|
|
60
|
-
emitNewline() {
|
|
61
|
-
const nl = (0, Source_1.newline)();
|
|
62
|
-
this.pushItem(nl);
|
|
63
|
-
this._lastNewline = nl;
|
|
64
|
-
}
|
|
65
|
-
emitItem(item) {
|
|
66
|
-
if (!this.isEmpty) {
|
|
67
|
-
for (let i = 0; i < this._numBlankLinesNeeded; i++) {
|
|
68
|
-
this.emitNewline();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
this._numBlankLinesNeeded = 0;
|
|
72
|
-
this.pushItem(item);
|
|
73
|
-
}
|
|
74
|
-
containsItem(item) {
|
|
75
|
-
const existingItem = this._currentEmitTarget.find((value) => item === value);
|
|
76
|
-
return existingItem !== undefined;
|
|
77
|
-
}
|
|
78
|
-
ensureBlankLine(numBlankLines) {
|
|
79
|
-
if (this._preventBlankLine)
|
|
80
|
-
return;
|
|
81
|
-
this._numBlankLinesNeeded = Math.max(this._numBlankLinesNeeded, numBlankLines);
|
|
82
|
-
}
|
|
83
|
-
preventBlankLine() {
|
|
84
|
-
this._numBlankLinesNeeded = 0;
|
|
85
|
-
this._preventBlankLine = true;
|
|
86
|
-
}
|
|
87
|
-
changeIndent(offset) {
|
|
88
|
-
if (this._lastNewline === undefined) {
|
|
89
|
-
return (0, Support_1.panic)("Cannot change indent for the first line");
|
|
90
|
-
}
|
|
91
|
-
this._lastNewline.indentationChange += offset;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class Renderer {
|
|
95
|
-
targetLanguage;
|
|
96
|
-
typeGraph;
|
|
97
|
-
leadingComments;
|
|
98
|
-
_names;
|
|
99
|
-
_finishedFiles;
|
|
100
|
-
_finishedEmitContexts;
|
|
101
|
-
_emitContext;
|
|
102
|
-
constructor(targetLanguage, renderContext) {
|
|
103
|
-
this.targetLanguage = targetLanguage;
|
|
104
|
-
this.typeGraph = renderContext.typeGraph;
|
|
105
|
-
this.leadingComments = renderContext.leadingComments;
|
|
106
|
-
this._finishedFiles = new Map();
|
|
107
|
-
this._finishedEmitContexts = new Map();
|
|
108
|
-
this._emitContext = new EmitContext();
|
|
109
|
-
}
|
|
110
|
-
ensureBlankLine(numBlankLines = 1) {
|
|
111
|
-
this._emitContext.ensureBlankLine(numBlankLines);
|
|
112
|
-
}
|
|
113
|
-
preventBlankLine() {
|
|
114
|
-
this._emitContext.preventBlankLine();
|
|
115
|
-
}
|
|
116
|
-
emitItem(item) {
|
|
117
|
-
this._emitContext.emitItem(item);
|
|
118
|
-
}
|
|
119
|
-
emitItemOnce(item) {
|
|
120
|
-
if (this._emitContext.containsItem(item)) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
this.emitItem(item);
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
emitLineOnce(...lineParts) {
|
|
127
|
-
let lineEmitted = true;
|
|
128
|
-
if (lineParts.length === 1) {
|
|
129
|
-
lineEmitted = this.emitItemOnce(lineParts[0]);
|
|
130
|
-
}
|
|
131
|
-
else if (lineParts.length > 1) {
|
|
132
|
-
lineEmitted = this.emitItemOnce(lineParts);
|
|
133
|
-
}
|
|
134
|
-
if (lineEmitted) {
|
|
135
|
-
this._emitContext.emitNewline();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
emitLine(...lineParts) {
|
|
139
|
-
if (lineParts.length === 1) {
|
|
140
|
-
this._emitContext.emitItem(lineParts[0]);
|
|
141
|
-
}
|
|
142
|
-
else if (lineParts.length > 1) {
|
|
143
|
-
this._emitContext.emitItem(lineParts);
|
|
144
|
-
}
|
|
145
|
-
this._emitContext.emitNewline();
|
|
146
|
-
}
|
|
147
|
-
emitMultiline(linesString) {
|
|
148
|
-
const lines = linesString.split("\n");
|
|
149
|
-
const numLines = lines.length;
|
|
150
|
-
if (numLines === 0)
|
|
151
|
-
return;
|
|
152
|
-
this.emitLine(lines[0]);
|
|
153
|
-
let currentIndent = 0;
|
|
154
|
-
for (let i = 1; i < numLines; i++) {
|
|
155
|
-
const line = lines[i];
|
|
156
|
-
const { indent, text } = lineIndentation(line);
|
|
157
|
-
(0, Support_1.assert)(indent % 4 === 0, "Indentation is not a multiple of 4.");
|
|
158
|
-
if (text !== null) {
|
|
159
|
-
const newIndent = indent / 4;
|
|
160
|
-
this.changeIndent(newIndent - currentIndent);
|
|
161
|
-
currentIndent = newIndent;
|
|
162
|
-
this.emitLine(text);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
this._emitContext.emitNewline();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (currentIndent !== 0) {
|
|
169
|
-
this.changeIndent(-currentIndent);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
gatherSource(emitter) {
|
|
173
|
-
const oldEmitContext = this._emitContext;
|
|
174
|
-
this._emitContext = new EmitContext();
|
|
175
|
-
emitter();
|
|
176
|
-
(0, Support_1.assert)(!this._emitContext.isNested, "emit context not restored correctly");
|
|
177
|
-
const source = this._emitContext.source;
|
|
178
|
-
this._emitContext = oldEmitContext;
|
|
179
|
-
return source;
|
|
180
|
-
}
|
|
181
|
-
emitGatheredSource(items) {
|
|
182
|
-
for (const item of items) {
|
|
183
|
-
this._emitContext.emitItem(item);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
emitAnnotated(annotation, emitter) {
|
|
187
|
-
const lines = this.gatherSource(emitter);
|
|
188
|
-
const source = (0, Source_1.sourcelikeToSource)(lines);
|
|
189
|
-
this._emitContext.emitItem((0, Source_1.annotated)(annotation, source));
|
|
190
|
-
}
|
|
191
|
-
emitIssue(message, emitter) {
|
|
192
|
-
this.emitAnnotated(new Annotation_1.IssueAnnotationData(message), emitter);
|
|
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
|
-
};
|
|
201
|
-
changeIndent(offset) {
|
|
202
|
-
this._emitContext.changeIndent(offset);
|
|
203
|
-
}
|
|
204
|
-
iterableForEach(iterable, emitter) {
|
|
205
|
-
const items = Array.from(iterable);
|
|
206
|
-
let onFirst = true;
|
|
207
|
-
for (const [i, v] of (0, collection_utils_1.iterableEnumerate)(items)) {
|
|
208
|
-
const position = items.length === 1 ? "only" : onFirst ? "first" : i === items.length - 1 ? "last" : "middle";
|
|
209
|
-
emitter(v, position);
|
|
210
|
-
onFirst = false;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
forEach(iterable, interposedBlankLines, leadingBlankLines, emitter) {
|
|
214
|
-
let didEmit = false;
|
|
215
|
-
this.iterableForEach(iterable, ([k, v], position) => {
|
|
216
|
-
if (position === "only" || position === "first") {
|
|
217
|
-
this.ensureBlankLine(leadingBlankLines);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
this.ensureBlankLine(interposedBlankLines);
|
|
221
|
-
}
|
|
222
|
-
emitter(v, k, position);
|
|
223
|
-
didEmit = true;
|
|
224
|
-
});
|
|
225
|
-
return didEmit;
|
|
226
|
-
}
|
|
227
|
-
forEachWithBlankLines(iterable, blankLineConfig, emitter) {
|
|
228
|
-
const { position, count } = getBlankLineConfig(blankLineConfig);
|
|
229
|
-
const interposing = ["interposing", "leading-and-interposing"].indexOf(position) >= 0;
|
|
230
|
-
const leading = ["leading", "leading-and-interposing"].indexOf(position) >= 0;
|
|
231
|
-
return this.forEach(iterable, interposing ? count : 0, leading ? count : 0, emitter);
|
|
232
|
-
}
|
|
233
|
-
indent(fn) {
|
|
234
|
-
this.changeIndent(1);
|
|
235
|
-
fn();
|
|
236
|
-
this.changeIndent(-1);
|
|
237
|
-
}
|
|
238
|
-
assignNames() {
|
|
239
|
-
return (0, Naming_1.assignNames)(this.setUpNaming());
|
|
240
|
-
}
|
|
241
|
-
initializeEmitContextForFilename(filename) {
|
|
242
|
-
if (this._finishedEmitContexts.has(filename.toLowerCase())) {
|
|
243
|
-
const existingEmitContext = this._finishedEmitContexts.get(filename.toLowerCase());
|
|
244
|
-
if (existingEmitContext !== undefined) {
|
|
245
|
-
this._emitContext = existingEmitContext;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
finishFile(filename) {
|
|
250
|
-
if (this._finishedFiles.has(filename)) {
|
|
251
|
-
console.log(`[WARNING] Tried to emit file ${filename} more than once. If performing multi-file output this warning can be safely ignored.`);
|
|
252
|
-
}
|
|
253
|
-
const source = (0, Source_1.sourcelikeToSource)(this._emitContext.source);
|
|
254
|
-
this._finishedFiles.set(filename, source);
|
|
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.
|
|
256
|
-
this._finishedEmitContexts.set(filename.toLowerCase(), this._emitContext);
|
|
257
|
-
this._emitContext = new EmitContext();
|
|
258
|
-
}
|
|
259
|
-
render(givenOutputFilename) {
|
|
260
|
-
this._names = this.assignNames();
|
|
261
|
-
this.emitSource(givenOutputFilename);
|
|
262
|
-
if (!this._emitContext.isEmpty) {
|
|
263
|
-
this.finishFile(givenOutputFilename);
|
|
264
|
-
}
|
|
265
|
-
return { sources: this._finishedFiles, names: this._names };
|
|
266
|
-
}
|
|
267
|
-
get names() {
|
|
268
|
-
if (this._names === undefined) {
|
|
269
|
-
return (0, Support_1.panic)("Names accessed before they were assigned");
|
|
270
|
-
}
|
|
271
|
-
return this._names;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
exports.Renderer = Renderer;
|