quicktype 17.0.4 → 17.0.5
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/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JacksonRenderer = exports.JavaRenderer = exports.javaNameStyle = exports.stringEscape = exports.JavaTargetLanguage = exports.javaOptions = void 0;
|
|
4
3
|
const Annotation_1 = require("../Annotation");
|
|
5
4
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
6
5
|
const Naming_1 = require("../Naming");
|
|
@@ -22,7 +21,7 @@ exports.javaOptions = {
|
|
|
22
21
|
["java8", "java8"],
|
|
23
22
|
["legacy", "legacy"]
|
|
24
23
|
], "java8"),
|
|
25
|
-
acronymStyle:
|
|
24
|
+
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
26
25
|
// FIXME: Do this via a configurable named eventually.
|
|
27
26
|
packageName: new RendererOptions_1.StringOption("package", "Generated package name", "NAME", "io.quicktype"),
|
|
28
27
|
lombok: new RendererOptions_1.BooleanOption("lombok", "Use lombok", false, "primary"),
|
|
@@ -47,7 +46,7 @@ class JavaTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
47
46
|
return true;
|
|
48
47
|
}
|
|
49
48
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
50
|
-
const options =
|
|
49
|
+
const options = RendererOptions_1.getOptionValues(exports.javaOptions, untypedOptionValues);
|
|
51
50
|
if (options.justTypes) {
|
|
52
51
|
return new JavaRenderer(this, renderContext, options);
|
|
53
52
|
}
|
|
@@ -131,62 +130,63 @@ const javaKeywords = [
|
|
|
131
130
|
"false",
|
|
132
131
|
"true"
|
|
133
132
|
];
|
|
134
|
-
exports.stringEscape =
|
|
133
|
+
exports.stringEscape = Strings_1.utf16ConcatMap(Strings_1.escapeNonPrintableMapper(Strings_1.isAscii, Strings_1.standardUnicodeHexEscape));
|
|
135
134
|
function isStartCharacter(codePoint) {
|
|
136
135
|
if (codePoint === 0x5f)
|
|
137
136
|
return true; // underscore
|
|
138
|
-
return
|
|
137
|
+
return Strings_1.isAscii(codePoint) && Strings_1.isLetter(codePoint);
|
|
139
138
|
}
|
|
140
139
|
function isPartCharacter(codePoint) {
|
|
141
|
-
return isStartCharacter(codePoint) || (
|
|
140
|
+
return isStartCharacter(codePoint) || (Strings_1.isAscii(codePoint) && Strings_1.isDigit(codePoint));
|
|
142
141
|
}
|
|
143
|
-
const legalizeName =
|
|
142
|
+
const legalizeName = Strings_1.utf16LegalizeCharacters(isPartCharacter);
|
|
144
143
|
function javaNameStyle(startWithUpper, upperUnderscore, original, acronymsStyle = Strings_1.allUpperWordStyle) {
|
|
145
|
-
const words =
|
|
146
|
-
return
|
|
144
|
+
const words = Strings_1.splitIntoWords(original);
|
|
145
|
+
return Strings_1.combineWords(words, legalizeName, upperUnderscore ? Strings_1.allUpperWordStyle : startWithUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, upperUnderscore ? Strings_1.allUpperWordStyle : Strings_1.firstUpperWordStyle, upperUnderscore || startWithUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
147
146
|
}
|
|
148
147
|
exports.javaNameStyle = javaNameStyle;
|
|
149
148
|
class JavaDateTimeProvider {
|
|
150
|
-
_renderer;
|
|
151
|
-
_className;
|
|
152
149
|
constructor(_renderer, _className) {
|
|
153
150
|
this._renderer = _renderer;
|
|
154
151
|
this._className = _className;
|
|
152
|
+
this.shouldEmitDateTimeConverter = true;
|
|
153
|
+
this.shouldEmitTimeConverter = true;
|
|
154
|
+
this.shouldEmitDateConverter = true;
|
|
155
155
|
}
|
|
156
|
-
shouldEmitDateTimeConverter = true;
|
|
157
|
-
shouldEmitTimeConverter = true;
|
|
158
|
-
shouldEmitDateConverter = true;
|
|
159
156
|
}
|
|
160
157
|
class Java8DateTimeProvider extends JavaDateTimeProvider {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
"java.time.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
158
|
+
constructor() {
|
|
159
|
+
super(...arguments);
|
|
160
|
+
this.keywords = [
|
|
161
|
+
"LocalDate",
|
|
162
|
+
"OffsetDateTime",
|
|
163
|
+
"OffsetTime",
|
|
164
|
+
"ZoneOffset",
|
|
165
|
+
"ZonedDateTime",
|
|
166
|
+
"DateTimeFormatter",
|
|
167
|
+
"DateTimeFormatterBuilder",
|
|
168
|
+
"ChronoField"
|
|
169
|
+
];
|
|
170
|
+
this.dateTimeImports = ["java.time.OffsetDateTime"];
|
|
171
|
+
this.dateImports = ["java.time.LocalDate"];
|
|
172
|
+
this.timeImports = ["java.time.OffsetTime"];
|
|
173
|
+
this.converterImports = [
|
|
174
|
+
"java.time.LocalDate",
|
|
175
|
+
"java.time.OffsetDateTime",
|
|
176
|
+
"java.time.OffsetTime",
|
|
177
|
+
"java.time.ZoneOffset",
|
|
178
|
+
"java.time.ZonedDateTime",
|
|
179
|
+
"java.time.format.DateTimeFormatter",
|
|
180
|
+
"java.time.format.DateTimeFormatterBuilder",
|
|
181
|
+
"java.time.temporal.ChronoField"
|
|
182
|
+
];
|
|
183
|
+
this.dateTimeType = "OffsetDateTime";
|
|
184
|
+
this.dateType = "LocalDate";
|
|
185
|
+
this.timeType = "OffsetTime";
|
|
186
|
+
this.dateTimeJacksonAnnotations = [];
|
|
187
|
+
this.dateJacksonAnnotations = [];
|
|
188
|
+
this.timeJacksonAnnotations = [];
|
|
189
|
+
}
|
|
190
190
|
emitDateTimeConverters() {
|
|
191
191
|
this._renderer.ensureBlankLine();
|
|
192
192
|
this._renderer.emitLine("private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()");
|
|
@@ -240,17 +240,22 @@ class Java8DateTimeProvider extends JavaDateTimeProvider {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
243
|
+
constructor() {
|
|
244
|
+
super(...arguments);
|
|
245
|
+
this.keywords = ["SimpleDateFormat", "Date"];
|
|
246
|
+
this.dateTimeImports = ["java.util.Date"];
|
|
247
|
+
this.dateImports = ["java.util.Date"];
|
|
248
|
+
this.timeImports = ["java.util.Date"];
|
|
249
|
+
this.converterImports = ["java.util.Date", "java.text.SimpleDateFormat"];
|
|
250
|
+
this.dateTimeType = "Date";
|
|
251
|
+
this.dateType = "Date";
|
|
252
|
+
this.timeType = "Date";
|
|
253
|
+
this.dateTimeJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd\'T\'HH:mm:ssX", timezone = "UTC")'];
|
|
254
|
+
this.dateJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd")'];
|
|
255
|
+
this.timeJacksonAnnotations = ['@JsonFormat(pattern = "HH:mm:ssX", timezone = "UTC")'];
|
|
256
|
+
this.shouldEmitTimeConverter = false;
|
|
257
|
+
this.shouldEmitDateConverter = false;
|
|
258
|
+
}
|
|
254
259
|
emitDateTimeConverters() {
|
|
255
260
|
this._renderer.ensureBlankLine();
|
|
256
261
|
this._renderer.emitLine("private static final String[] DATE_TIME_FORMATS = {");
|
|
@@ -292,8 +297,6 @@ class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
|
292
297
|
this._renderer.emitLine('return new SimpleDateFormat("hh:mm:ssZ").format(datetime);');
|
|
293
298
|
});
|
|
294
299
|
}
|
|
295
|
-
shouldEmitTimeConverter = false;
|
|
296
|
-
shouldEmitDateConverter = false;
|
|
297
300
|
convertStringToDateTime(variable) {
|
|
298
301
|
return [this._className, ".parseAllDateTimeString(", variable, ")"];
|
|
299
302
|
}
|
|
@@ -314,16 +317,13 @@ class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
|
314
317
|
}
|
|
315
318
|
}
|
|
316
319
|
class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
317
|
-
_options;
|
|
318
|
-
_currentFilename;
|
|
319
|
-
_gettersAndSettersForPropertyName = new Map();
|
|
320
|
-
_haveEmittedLeadingComments = false;
|
|
321
|
-
_dateTimeProvider;
|
|
322
|
-
_converterClassname = "Converter";
|
|
323
|
-
_converterKeywords = [];
|
|
324
320
|
constructor(targetLanguage, renderContext, _options) {
|
|
325
321
|
super(targetLanguage, renderContext);
|
|
326
322
|
this._options = _options;
|
|
323
|
+
this._gettersAndSettersForPropertyName = new Map();
|
|
324
|
+
this._haveEmittedLeadingComments = false;
|
|
325
|
+
this._converterClassname = "Converter";
|
|
326
|
+
this._converterKeywords = [];
|
|
327
327
|
switch (_options.dateTimeProvider) {
|
|
328
328
|
default:
|
|
329
329
|
case "java8":
|
|
@@ -359,13 +359,13 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
359
359
|
return this.getNameStyling("enumCaseNamingFunction");
|
|
360
360
|
}
|
|
361
361
|
unionNeedsName(u) {
|
|
362
|
-
return
|
|
362
|
+
return TypeUtils_1.nullableFromUnion(u) === null;
|
|
363
363
|
}
|
|
364
364
|
namedTypeToNameForTopLevel(type) {
|
|
365
365
|
// If the top-level type doesn't contain any classes or unions
|
|
366
366
|
// we have to define a class just for the `FromJson` method, in
|
|
367
367
|
// emitFromJsonForTopLevel.
|
|
368
|
-
return
|
|
368
|
+
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
369
369
|
}
|
|
370
370
|
makeNamesForPropertyGetterAndSetter(_c, _className, _p, _jsonName, name) {
|
|
371
371
|
const getterName = new Naming_1.DependencyName(this.getNameStyling("propertyNamingFunction"), name.order, lookup => `get_${lookup(name)}`);
|
|
@@ -379,9 +379,9 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
379
379
|
}
|
|
380
380
|
getNameStyling(convention) {
|
|
381
381
|
const styling = {
|
|
382
|
-
typeNamingFunction:
|
|
383
|
-
propertyNamingFunction:
|
|
384
|
-
enumCaseNamingFunction:
|
|
382
|
+
typeNamingFunction: Naming_1.funPrefixNamer("types", n => javaNameStyle(true, false, n, Acronyms_1.acronymStyle(this._options.acronymStyle))),
|
|
383
|
+
propertyNamingFunction: Naming_1.funPrefixNamer("properties", n => javaNameStyle(false, false, n, Acronyms_1.acronymStyle(this._options.acronymStyle))),
|
|
384
|
+
enumCaseNamingFunction: Naming_1.funPrefixNamer("enum-cases", n => javaNameStyle(true, true, n, Acronyms_1.acronymStyle(this._options.acronymStyle)))
|
|
385
385
|
};
|
|
386
386
|
return styling[convention];
|
|
387
387
|
}
|
|
@@ -389,7 +389,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
389
389
|
if (this.topLevels.size === 1) {
|
|
390
390
|
return methodName;
|
|
391
391
|
}
|
|
392
|
-
return [topLevelName,
|
|
392
|
+
return [topLevelName, Strings_1.capitalize(methodName)];
|
|
393
393
|
}
|
|
394
394
|
methodName(prefix, suffix, topLevelName) {
|
|
395
395
|
if (this.topLevels.size === 1) {
|
|
@@ -410,7 +410,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
410
410
|
return this.methodName("get", "ObjectWriter", topLevelName);
|
|
411
411
|
}
|
|
412
412
|
startFile(basename) {
|
|
413
|
-
|
|
413
|
+
Support_1.assert(this._currentFilename === undefined, "Previous file wasn't finished");
|
|
414
414
|
// FIXME: The filenames should actually be Sourcelikes, too
|
|
415
415
|
this._currentFilename = `${this.sourcelikeToString(basename)}.java`;
|
|
416
416
|
// FIXME: Why is this necessary?
|
|
@@ -422,7 +422,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
424
|
finishFile() {
|
|
425
|
-
super.finishFile(
|
|
425
|
+
super.finishFile(Support_1.defined(this._currentFilename));
|
|
426
426
|
this._currentFilename = undefined;
|
|
427
427
|
}
|
|
428
428
|
emitPackageAndImports(imports) {
|
|
@@ -456,7 +456,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
456
456
|
this.emitTryCatch(f, () => this.emitLine("// Ignored"));
|
|
457
457
|
}
|
|
458
458
|
javaType(reference, t, withIssues = false) {
|
|
459
|
-
return
|
|
459
|
+
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "Object"), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "Object"), _boolType => (reference ? "Boolean" : "boolean"), _integerType => (reference ? "Long" : "long"), _doubleType => (reference ? "Double" : "double"), _stringType => "String", arrayType => {
|
|
460
460
|
if (this._options.useList) {
|
|
461
461
|
return ["List<", this.javaType(true, arrayType.items, withIssues), ">"];
|
|
462
462
|
}
|
|
@@ -464,7 +464,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
464
464
|
return [this.javaType(false, arrayType.items, withIssues), "[]"];
|
|
465
465
|
}
|
|
466
466
|
}, classType => this.nameForNamedType(classType), mapType => ["Map<String, ", this.javaType(true, mapType.values, withIssues), ">"], enumType => this.nameForNamedType(enumType), unionType => {
|
|
467
|
-
const nullable =
|
|
467
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
468
468
|
if (nullable !== null)
|
|
469
469
|
return this.javaType(true, nullable, withIssues);
|
|
470
470
|
return this.nameForNamedType(unionType);
|
|
@@ -485,7 +485,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
485
485
|
});
|
|
486
486
|
}
|
|
487
487
|
javaImport(t) {
|
|
488
|
-
return
|
|
488
|
+
return TypeUtils_1.matchType(t, _anyType => [], _nullType => [], _boolType => [], _integerType => [], _doubleType => [], _stringType => [], arrayType => {
|
|
489
489
|
if (this._options.useList) {
|
|
490
490
|
return [...this.javaImport(arrayType.items), "java.util.List"];
|
|
491
491
|
}
|
|
@@ -525,7 +525,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
525
525
|
return "Map";
|
|
526
526
|
}
|
|
527
527
|
else if (t instanceof Type_1.UnionType) {
|
|
528
|
-
const nullable =
|
|
528
|
+
const nullable = TypeUtils_1.nullableFromUnion(t);
|
|
529
529
|
if (nullable !== null)
|
|
530
530
|
return this.javaTypeWithoutGenerics(true, nullable);
|
|
531
531
|
return this.nameForNamedType(t);
|
|
@@ -552,7 +552,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
552
552
|
if (t instanceof Type_1.EnumType) {
|
|
553
553
|
return ["java.io.IOException"];
|
|
554
554
|
}
|
|
555
|
-
return
|
|
555
|
+
return Support_1.assertNever(t);
|
|
556
556
|
}
|
|
557
557
|
importsForClass(c) {
|
|
558
558
|
const imports = [];
|
|
@@ -564,7 +564,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
564
564
|
}
|
|
565
565
|
importsForUnionMembers(u) {
|
|
566
566
|
const imports = [];
|
|
567
|
-
const [, nonNulls] =
|
|
567
|
+
const [, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
568
568
|
this.forEachUnionMember(u, nonNulls, "none", null, (_fieldName, t) => {
|
|
569
569
|
this.javaImport(t).forEach(imp => imports.push(imp));
|
|
570
570
|
});
|
|
@@ -593,7 +593,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
593
593
|
if (!this._options.lombok) {
|
|
594
594
|
this.forEachClassProperty(c, "leading-and-interposing", (name, jsonName, p) => {
|
|
595
595
|
this.emitDescription(this.descriptionForClassProperty(c, jsonName));
|
|
596
|
-
const [getterName, setterName] =
|
|
596
|
+
const [getterName, setterName] = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
597
597
|
const rendered = this.javaType(false, p.type);
|
|
598
598
|
this.annotationsForAccessor(c, className, name, jsonName, p, false).forEach(annotation => this.emitLine(annotation));
|
|
599
599
|
this.emitLine("public ", rendered, " ", getterName, "() { return ", name, "; }");
|
|
@@ -620,7 +620,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
620
620
|
const imports = [...this.importsForType(u), ...this.importsForUnionMembers(u)];
|
|
621
621
|
this.emitFileHeader(unionName, imports);
|
|
622
622
|
this.emitDescription(this.descriptionForType(u));
|
|
623
|
-
const [, nonNulls] =
|
|
623
|
+
const [, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
624
624
|
this.emitUnionAttributes(u, unionName);
|
|
625
625
|
this.emitBlock(["public class ", unionName], () => {
|
|
626
626
|
for (const t of nonNulls) {
|
|
@@ -655,7 +655,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
655
655
|
this.emitLine("switch (this) {");
|
|
656
656
|
this.indent(() => {
|
|
657
657
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
658
|
-
this.emitLine("case ", name, ': return "',
|
|
658
|
+
this.emitLine("case ", name, ': return "', exports.stringEscape(jsonName), '";');
|
|
659
659
|
});
|
|
660
660
|
});
|
|
661
661
|
this.emitLine("}");
|
|
@@ -665,7 +665,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
665
665
|
this.emitEnumDeserializationAttributes(e);
|
|
666
666
|
this.emitBlock(["public static ", enumName, " forValue(String value) throws IOException"], () => {
|
|
667
667
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
668
|
-
this.emitLine('if (value.equals("',
|
|
668
|
+
this.emitLine('if (value.equals("', exports.stringEscape(jsonName), '")) return ', name, ";");
|
|
669
669
|
});
|
|
670
670
|
this.emitLine('throw new IOException("Cannot deserialize ', enumName, '");');
|
|
671
671
|
});
|
|
@@ -680,18 +680,18 @@ exports.JavaRenderer = JavaRenderer;
|
|
|
680
680
|
class JacksonRenderer extends JavaRenderer {
|
|
681
681
|
constructor(targetLanguage, renderContext, options) {
|
|
682
682
|
super(targetLanguage, renderContext, options);
|
|
683
|
+
this._converterKeywords = [
|
|
684
|
+
"JsonProperty",
|
|
685
|
+
"JsonDeserialize",
|
|
686
|
+
"JsonDeserializer",
|
|
687
|
+
"JsonSerialize",
|
|
688
|
+
"JsonSerializer",
|
|
689
|
+
"JsonParser",
|
|
690
|
+
"JsonProcessingException",
|
|
691
|
+
"DeserializationContext",
|
|
692
|
+
"SerializerProvider"
|
|
693
|
+
];
|
|
683
694
|
}
|
|
684
|
-
_converterKeywords = [
|
|
685
|
-
"JsonProperty",
|
|
686
|
-
"JsonDeserialize",
|
|
687
|
-
"JsonDeserializer",
|
|
688
|
-
"JsonSerialize",
|
|
689
|
-
"JsonSerializer",
|
|
690
|
-
"JsonParser",
|
|
691
|
-
"JsonProcessingException",
|
|
692
|
-
"DeserializationContext",
|
|
693
|
-
"SerializerProvider"
|
|
694
|
-
];
|
|
695
695
|
emitClassAttributes(c, _className) {
|
|
696
696
|
if (c.getProperties().size === 0)
|
|
697
697
|
this.emitLine("@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.NONE)");
|
|
@@ -699,7 +699,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
699
699
|
}
|
|
700
700
|
annotationsForAccessor(_c, _className, _propertyName, jsonName, p, _isSetter) {
|
|
701
701
|
const superAnnotations = super.annotationsForAccessor(_c, _className, _propertyName, jsonName, p, _isSetter);
|
|
702
|
-
const annotations = ['@JsonProperty("' +
|
|
702
|
+
const annotations = ['@JsonProperty("' + exports.stringEscape(jsonName) + '")'];
|
|
703
703
|
switch (p.type.kind) {
|
|
704
704
|
case "date-time":
|
|
705
705
|
this._dateTimeProvider.dateTimeJacksonAnnotations.forEach(annotation => annotations.push(annotation));
|
|
@@ -734,7 +734,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
734
734
|
imports.push("com.fasterxml.jackson.annotation.*");
|
|
735
735
|
return imports;
|
|
736
736
|
}
|
|
737
|
-
return
|
|
737
|
+
return Support_1.assertNever(t);
|
|
738
738
|
}
|
|
739
739
|
emitUnionAttributes(_u, unionName) {
|
|
740
740
|
this.emitLine("@JsonDeserialize(using = ", unionName, ".Deserializer.class)");
|
|
@@ -766,7 +766,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
766
766
|
this.emitLine("value.", fieldName, " = UUID.fromString(", parseFrom, ");");
|
|
767
767
|
break;
|
|
768
768
|
default:
|
|
769
|
-
return
|
|
769
|
+
return Support_1.panic("Requested type isnt an object!");
|
|
770
770
|
}
|
|
771
771
|
};
|
|
772
772
|
const emitDeserializeType = (t, variableFieldName = "") => {
|
|
@@ -868,7 +868,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
868
868
|
case "date-time":
|
|
869
869
|
return this._dateTimeProvider.convertDateTimeToString(fieldName);
|
|
870
870
|
default:
|
|
871
|
-
return
|
|
871
|
+
return Support_1.panic("Requested type doesn't have custom serializer code!");
|
|
872
872
|
}
|
|
873
873
|
};
|
|
874
874
|
const emitSerializeType = (t) => {
|
|
@@ -883,7 +883,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
883
883
|
this.emitLine("return;");
|
|
884
884
|
});
|
|
885
885
|
};
|
|
886
|
-
const [maybeNull, nonNulls] =
|
|
886
|
+
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
887
887
|
this.ensureBlankLine();
|
|
888
888
|
this.emitBlock(["static class Deserializer extends JsonDeserializer<", unionName, ">"], () => {
|
|
889
889
|
this.emitLine("@Override");
|
|
@@ -15,7 +15,7 @@ export declare const javaScriptOptions: {
|
|
|
15
15
|
converters: EnumOption<ConvertersOptions>;
|
|
16
16
|
rawType: EnumOption<"any" | "json">;
|
|
17
17
|
};
|
|
18
|
-
export type JavaScriptTypeAnnotations = {
|
|
18
|
+
export declare type JavaScriptTypeAnnotations = {
|
|
19
19
|
any: string;
|
|
20
20
|
anyArray: string;
|
|
21
21
|
anyMap: string;
|
|
@@ -27,9 +27,9 @@ export type JavaScriptTypeAnnotations = {
|
|
|
27
27
|
export declare class JavaScriptTargetLanguage extends TargetLanguage {
|
|
28
28
|
constructor(displayName?: string, names?: string[], extension?: string);
|
|
29
29
|
protected getOptions(): Option<any>[];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
readonly stringTypeMapping: StringTypeMapping;
|
|
31
|
+
readonly supportsOptionalClassProperties: boolean;
|
|
32
|
+
readonly supportsFullObjectType: boolean;
|
|
33
33
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
34
34
|
[name: string]: any;
|
|
35
35
|
}): JavaScriptRenderer;
|
|
@@ -54,9 +54,9 @@ export declare class JavaScriptRenderer extends ConvenienceRenderer {
|
|
|
54
54
|
protected deserializerFunctionLine(_t: Type, name: Name): Sourcelike;
|
|
55
55
|
protected serializerFunctionName(name: Name): Sourcelike;
|
|
56
56
|
protected serializerFunctionLine(_t: Type, name: Name): Sourcelike;
|
|
57
|
-
protected
|
|
58
|
-
protected
|
|
59
|
-
protected
|
|
57
|
+
protected readonly moduleLine: string | undefined;
|
|
58
|
+
protected readonly castFunctionLines: [string, string];
|
|
59
|
+
protected readonly typeAnnotations: JavaScriptTypeAnnotations;
|
|
60
60
|
protected emitConvertModuleBody(): void;
|
|
61
61
|
protected emitConvertModuleHelpers(): void;
|
|
62
62
|
protected emitConvertModule(): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JavaScriptRenderer = exports.legalizeName = exports.JavaScriptTargetLanguage = exports.javaScriptOptions = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const TypeUtils_1 = require("../TypeUtils");
|
|
6
5
|
const Acronyms_1 = require("../support/Acronyms");
|
|
@@ -14,10 +13,10 @@ const TargetLanguage_1 = require("../TargetLanguage");
|
|
|
14
13
|
const RendererOptions_1 = require("../RendererOptions");
|
|
15
14
|
const JavaScriptUnicodeMaps_1 = require("./JavaScriptUnicodeMaps");
|
|
16
15
|
exports.javaScriptOptions = {
|
|
17
|
-
acronymStyle:
|
|
16
|
+
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
18
17
|
runtimeTypecheck: new RendererOptions_1.BooleanOption("runtime-typecheck", "Verify JSON.parse results at runtime", true),
|
|
19
18
|
runtimeTypecheckIgnoreUnknownProperties: new RendererOptions_1.BooleanOption("runtime-typecheck-ignore-unknown-properties", "Ignore unknown properties when verifying at runtime", false, "secondary"),
|
|
20
|
-
converters:
|
|
19
|
+
converters: Converters_1.convertersOption(),
|
|
21
20
|
rawType: new RendererOptions_1.EnumOption("raw-type", "Type of raw input (json by default)", [
|
|
22
21
|
["json", "json"],
|
|
23
22
|
["any", "any"]
|
|
@@ -50,25 +49,24 @@ class JavaScriptTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
50
49
|
return true;
|
|
51
50
|
}
|
|
52
51
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
53
|
-
return new JavaScriptRenderer(this, renderContext,
|
|
52
|
+
return new JavaScriptRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.javaScriptOptions, untypedOptionValues));
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
exports.JavaScriptTargetLanguage = JavaScriptTargetLanguage;
|
|
57
|
-
exports.legalizeName =
|
|
58
|
-
const identityNamingFunction =
|
|
56
|
+
exports.legalizeName = Strings_1.utf16LegalizeCharacters(JavaScriptUnicodeMaps_1.isES3IdentifierPart);
|
|
57
|
+
const identityNamingFunction = Naming_1.funPrefixNamer("properties", s => s);
|
|
59
58
|
class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
60
|
-
_jsOptions;
|
|
61
59
|
constructor(targetLanguage, renderContext, _jsOptions) {
|
|
62
60
|
super(targetLanguage, renderContext);
|
|
63
61
|
this._jsOptions = _jsOptions;
|
|
64
62
|
}
|
|
65
63
|
nameStyle(original, upper) {
|
|
66
|
-
const acronyms =
|
|
67
|
-
const words =
|
|
68
|
-
return
|
|
64
|
+
const acronyms = Acronyms_1.acronymStyle(this._jsOptions.acronymStyle);
|
|
65
|
+
const words = Strings_1.splitIntoWords(original);
|
|
66
|
+
return Strings_1.combineWords(words, exports.legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? s => Strings_1.capitalize(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
69
67
|
}
|
|
70
68
|
makeNamedTypeNamer() {
|
|
71
|
-
return
|
|
69
|
+
return Naming_1.funPrefixNamer("types", s => this.nameStyle(s, true));
|
|
72
70
|
}
|
|
73
71
|
namerForObjectProperty() {
|
|
74
72
|
return identityNamingFunction;
|
|
@@ -77,10 +75,10 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
77
75
|
return null;
|
|
78
76
|
}
|
|
79
77
|
makeEnumCaseNamer() {
|
|
80
|
-
return
|
|
78
|
+
return Naming_1.funPrefixNamer("enum-cases", s => this.nameStyle(s, true));
|
|
81
79
|
}
|
|
82
80
|
namedTypeToNameForTopLevel(type) {
|
|
83
|
-
return
|
|
81
|
+
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
84
82
|
}
|
|
85
83
|
makeNameForProperty(c, className, p, jsonName, _assignedName) {
|
|
86
84
|
// Ignore the assigned name
|
|
@@ -93,9 +91,9 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
93
91
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
94
92
|
return ['r("', this.nameForNamedType(t), '")'];
|
|
95
93
|
}
|
|
96
|
-
return
|
|
94
|
+
return TypeUtils_1.matchType(t, _anyType => '"any"', _nullType => `null`, _boolType => `true`, _integerType => `0`, _doubleType => `3.14`, _stringType => `""`, arrayType => ["a(", this.typeMapTypeFor(arrayType.items), ")"], _classType => Support_1.panic("We handled this above"), mapType => ["m(", this.typeMapTypeFor(mapType.values), ")"], _enumType => Support_1.panic("We handled this above"), unionType => {
|
|
97
95
|
const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type));
|
|
98
|
-
return ["u(", ...
|
|
96
|
+
return ["u(", ...collection_utils_1.arrayIntercalate(", ", children), ")"];
|
|
99
97
|
}, transformedStringType => {
|
|
100
98
|
if (transformedStringType.kind === "date-time") {
|
|
101
99
|
return "Date";
|
|
@@ -124,7 +122,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
124
122
|
this.emitLine('"', name, '": o([');
|
|
125
123
|
this.indent(() => {
|
|
126
124
|
this.forEachClassProperty(t, "none", (propName, jsonName, property) => {
|
|
127
|
-
this.emitLine('{ json: "',
|
|
125
|
+
this.emitLine('{ json: "', Strings_1.utf16StringEscape(jsonName), '", js: "', Source_1.modifySource(Strings_1.utf16StringEscape, propName), '", typ: ', this.typeMapTypeForProperty(property), " },");
|
|
128
126
|
});
|
|
129
127
|
});
|
|
130
128
|
this.emitLine("], ", additional, "),");
|
|
@@ -133,7 +131,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
133
131
|
this.emitLine('"', name, '": [');
|
|
134
132
|
this.indent(() => {
|
|
135
133
|
this.forEachEnumCase(e, "none", (_caseName, jsonName) => {
|
|
136
|
-
this.emitLine(`"${
|
|
134
|
+
this.emitLine(`"${Strings_1.utf16StringEscape(jsonName)}",`);
|
|
137
135
|
});
|
|
138
136
|
});
|
|
139
137
|
this.emitLine("],");
|
|
@@ -147,7 +145,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
147
145
|
return ["function ", this.deserializerFunctionName(name), "(json)"];
|
|
148
146
|
}
|
|
149
147
|
serializerFunctionName(name) {
|
|
150
|
-
const camelCaseName =
|
|
148
|
+
const camelCaseName = Source_1.modifySource(Strings_1.camelCase, name);
|
|
151
149
|
return [camelCaseName, "ToJson"];
|
|
152
150
|
}
|
|
153
151
|
serializerFunctionLine(_t, name) {
|
|
@@ -399,7 +397,7 @@ function r(name${stringAnnotation}) {
|
|
|
399
397
|
this.emitUsageImportComment();
|
|
400
398
|
this.emitLine("//");
|
|
401
399
|
this.forEachTopLevel("none", (_t, name) => {
|
|
402
|
-
const camelCaseName =
|
|
400
|
+
const camelCaseName = Source_1.modifySource(Strings_1.camelCase, name);
|
|
403
401
|
this.emitLine("// const ", camelCaseName, " = Convert.to", name, "(json);");
|
|
404
402
|
});
|
|
405
403
|
if (this._jsOptions.runtimeTypecheck) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JavaScriptPropTypesRenderer = exports.JavaScriptPropTypesTargetLanguage = exports.javaScriptPropTypesOptions = void 0;
|
|
4
3
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
5
4
|
const RendererOptions_1 = require("../RendererOptions");
|
|
6
5
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
@@ -15,8 +14,8 @@ const TypeUtils_1 = require("../TypeUtils");
|
|
|
15
14
|
const collection_utils_1 = require("collection-utils");
|
|
16
15
|
const Type_1 = require("../Type");
|
|
17
16
|
exports.javaScriptPropTypesOptions = {
|
|
18
|
-
acronymStyle:
|
|
19
|
-
converters:
|
|
17
|
+
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
18
|
+
converters: Converters_1.convertersOption(),
|
|
20
19
|
moduleSystem: new RendererOptions_1.EnumOption("module-system", "Which module system to use", [
|
|
21
20
|
["common-js", false],
|
|
22
21
|
["es6", true]
|
|
@@ -30,24 +29,23 @@ class JavaScriptPropTypesTargetLanguage extends TargetLanguage_1.TargetLanguage
|
|
|
30
29
|
super(displayName, names, extension);
|
|
31
30
|
}
|
|
32
31
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
33
|
-
return new JavaScriptPropTypesRenderer(this, renderContext,
|
|
32
|
+
return new JavaScriptPropTypesRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.javaScriptPropTypesOptions, untypedOptionValues));
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
exports.JavaScriptPropTypesTargetLanguage = JavaScriptPropTypesTargetLanguage;
|
|
37
|
-
const identityNamingFunction =
|
|
36
|
+
const identityNamingFunction = Naming_1.funPrefixNamer("properties", s => s);
|
|
38
37
|
class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
39
|
-
_jsOptions;
|
|
40
38
|
constructor(targetLanguage, renderContext, _jsOptions) {
|
|
41
39
|
super(targetLanguage, renderContext);
|
|
42
40
|
this._jsOptions = _jsOptions;
|
|
43
41
|
}
|
|
44
42
|
nameStyle(original, upper) {
|
|
45
|
-
const acronyms =
|
|
46
|
-
const words =
|
|
47
|
-
return
|
|
43
|
+
const acronyms = Acronyms_1.acronymStyle(this._jsOptions.acronymStyle);
|
|
44
|
+
const words = __1.splitIntoWords(original);
|
|
45
|
+
return __1.combineWords(words, JavaScript_1.legalizeName, upper ? __1.firstUpperWordStyle : Strings_1.allLowerWordStyle, __1.firstUpperWordStyle, upper ? s => __1.capitalize(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
48
46
|
}
|
|
49
47
|
makeNamedTypeNamer() {
|
|
50
|
-
return
|
|
48
|
+
return Naming_1.funPrefixNamer("types", s => this.nameStyle(s, true));
|
|
51
49
|
}
|
|
52
50
|
namerForObjectProperty() {
|
|
53
51
|
return identityNamingFunction;
|
|
@@ -56,10 +54,10 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
56
54
|
return null;
|
|
57
55
|
}
|
|
58
56
|
makeEnumCaseNamer() {
|
|
59
|
-
return
|
|
57
|
+
return Naming_1.funPrefixNamer("enum-cases", s => this.nameStyle(s, false));
|
|
60
58
|
}
|
|
61
59
|
namedTypeToNameForTopLevel(type) {
|
|
62
|
-
return
|
|
60
|
+
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
63
61
|
}
|
|
64
62
|
makeNameForProperty(c, className, p, jsonName, _assignedName) {
|
|
65
63
|
// Ignore the assigned name
|
|
@@ -69,9 +67,9 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
69
67
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
70
68
|
return ["_", this.nameForNamedType(t)];
|
|
71
69
|
}
|
|
72
|
-
const match =
|
|
70
|
+
const match = __1.matchType(t, _anyType => "PropTypes.any", _nullType => "PropTypes.any", _boolType => "PropTypes.bool", _integerType => "PropTypes.number", _doubleType => "PropTypes.number", _stringType => "PropTypes.string", arrayType => ["PropTypes.arrayOf(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => __1.panic("Should already be handled."), _mapType => "PropTypes.object", _enumType => __1.panic("Should already be handled."), unionType => {
|
|
73
71
|
const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
|
|
74
|
-
return ["PropTypes.oneOfType([", ...
|
|
72
|
+
return ["PropTypes.oneOfType([", ...collection_utils_1.arrayIntercalate(", ", children), "])"];
|
|
75
73
|
}, _transformedStringType => {
|
|
76
74
|
return "PropTypes.string";
|
|
77
75
|
});
|
|
@@ -194,7 +192,7 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
194
192
|
this.emitLine("_", name, " = PropTypes.shape({");
|
|
195
193
|
this.indent(() => {
|
|
196
194
|
this.forEachClassProperty(t, "none", (_, jsonName, property) => {
|
|
197
|
-
this.emitLine(`"${
|
|
195
|
+
this.emitLine(`"${Strings_1.utf16StringEscape(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
|
|
198
196
|
});
|
|
199
197
|
});
|
|
200
198
|
this.emitLine("});");
|