@glutinum/cli 0.8.0 → 0.9.0

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.
@@ -1,19 +1,35 @@
1
+ import { bool_type, array_type, string_type, record_type, list_type, class_type } from "../fable_modules/fable-library-js.4.14.0/Reflection.js";
1
2
  import { printf, toFail, interpolate, toText, join, trimStart } from "../fable_modules/fable-library-js.4.14.0/String.js";
2
- import { record_type, list_type, class_type } from "../fable_modules/fable-library-js.4.14.0/Reflection.js";
3
3
  import { Record } from "../fable_modules/fable-library-js.4.14.0/Types.js";
4
- import { FSharpTypeParameter_Create_Z6CFD3565, FSharpTypeAlias, FSharpEnum, FSharpEnumCase, FSharpStaticMemberInfo, FSharpAccessor, FSharpMapped, FSharpMember, FSharpMemberInfo, FSharpMemberInfoBody, FSharpInterface, FSharpClass, FSharpConstructor, FSharpAccessibility, FSharpExplicitField, FSharpParameter, FSharpFunctionType, FSharpTypeReference, FSharpUnion, FSharpUnionCase, FSharpPrimitive, FSharpLiteral, FSharpCommentTypeParam, FSharpCommentParam, FSharpXmlDoc, FSharpAttribute, FSharpType, FSharpModule, FSharpXmlDoc_$reflection, FSharpAttribute_$reflection } from "./FsharpAST.js";
4
+ import { FSharpTypeParameter_Create_Z6CFD3565, FSharpTypeAlias, FSharpEnum, FSharpEnumCase, FSharpUnionCaseNamed, FSharpStaticMemberInfo, FSharpAccessor, FSharpMember, FSharpMemberInfo, FSharpMemberInfoBody, FSharpMapped, FSharpInterface, FSharpClass, FSharpConstructor, FSharpAccessibility, FSharpExplicitField, FSharpParameter, FSharpFunctionType, FSharpTypeReference, FSharpUnion, FSharpUnionCase, FSharpPrimitive, FSharpLiteral, FSharpCommentTypeParam, FSharpCommentParam, FSharpXmlDoc, FSharpAttribute, FSharpType, FSharpModule, FSharpType_$reflection, FSharpXmlDoc_$reflection, FSharpAttribute_$reflection } from "./FsharpAST.js";
5
5
  import { empty as empty_1, singleton as singleton_1, collect, append, delay, toList } from "../fable_modules/fable-library-js.4.14.0/Seq.js";
6
- import { exists, filter, tryFind, choose, collect as collect_1, ofArray, forAll, length, partition, sortBy, map, append as append_1, head as head_1, tail, singleton, empty, isEmpty } from "../fable_modules/fable-library-js.4.14.0/List.js";
7
- import { sanitizeNameWithResult, removeSurroundingQuotes, mapTypeNameToFableCoreAwareName, sanitizeName } from "./Utils/Naming.js";
8
- import { unwrap, value as value_4, map as map_1, defaultArg } from "../fable_modules/fable-library-js.4.14.0/Option.js";
6
+ import { exists, filter, tryFind, choose, collect as collect_1, ofArray, forAll, mapIndexed, length, partition, sortBy, map, append as append_1, head as head_1, tail, singleton, empty, isEmpty } from "../fable_modules/fable-library-js.4.14.0/List.js";
7
+ import { sanitizeNameWithResult, removeSurroundingQuotes, sanitizeName } from "./Utils/Naming.js";
8
+ import { bind, unwrap, value as value_4, map as map_1, defaultArg } from "../fable_modules/fable-library-js.4.14.0/Option.js";
9
9
  import { int32ToString, safeHash, equals, comparePrimitives } from "../fable_modules/fable-library-js.4.14.0/Util.js";
10
- import { GlueType, GlueTypeUnion, GlueMember, GlueProperty, GlueAccessor, GlueConstructor, GlueType__get_Name } from "./GlueAST.js";
11
- import { warn, error } from "./Log.js";
10
+ import { GlueType, GlueTypeUnion, GlueMember, GlueProperty, GlueAccessor, GlueType__get_Name, GlueConstructor } from "./GlueAST.js";
12
11
  import { List_distinct } from "../fable_modules/fable-library-js.4.14.0/Seq2.js";
13
12
 
13
+ export class Reporter {
14
+ constructor() {
15
+ this["Warnings@"] = [];
16
+ this["Errors@"] = [];
17
+ this["HasRegEpx@"] = false;
18
+ }
19
+ }
20
+
21
+ export function Reporter_$reflection() {
22
+ return class_type("Glutinum.Converter.Transform.Reporter", void 0, Reporter);
23
+ }
24
+
25
+ export function Reporter_$ctor() {
26
+ return new Reporter();
27
+ }
28
+
14
29
  export class TransformContext {
15
- constructor(currentScopeName, parent) {
30
+ constructor(reporter, currentScopeName, parent) {
16
31
  let matchValue;
32
+ this.reporter = reporter;
17
33
  this.currentScopeName = currentScopeName;
18
34
  this.parent = parent;
19
35
  this.types = [];
@@ -21,6 +37,7 @@ export class TransformContext {
21
37
  this["FullName@"] = ((matchValue = this.parent, (matchValue != null) ? trimStart((TransformContext__get_FullName(matchValue) + ".") + this.currentScopeName, ".") : ""));
22
38
  this["CurrentScopeName@"] = this.currentScopeName;
23
39
  this["_types@"] = this.types;
40
+ this["_Reporter@"] = this.reporter;
24
41
  }
25
42
  }
26
43
 
@@ -28,8 +45,8 @@ export function TransformContext_$reflection() {
28
45
  return class_type("Glutinum.Converter.Transform.TransformContext", void 0, TransformContext);
29
46
  }
30
47
 
31
- export function TransformContext_$ctor_Z535BF207(currentScopeName, parent) {
32
- return new TransformContext(currentScopeName, parent);
48
+ export function TransformContext_$ctor_Z20656E4E(reporter, currentScopeName, parent) {
49
+ return new TransformContext(reporter, currentScopeName, parent);
33
50
  }
34
51
 
35
52
  export class TransformCommentResult extends Record {
@@ -44,6 +61,36 @@ export function TransformCommentResult_$reflection() {
44
61
  return record_type("Glutinum.Converter.Transform.TransformCommentResult", [], TransformCommentResult, () => [["ObsoleteAttributes", list_type(FSharpAttribute_$reflection())], ["XmlDoc", list_type(FSharpXmlDoc_$reflection())]]);
45
62
  }
46
63
 
64
+ export class TransformResult extends Record {
65
+ constructor(FSharpAST, Warnings, Errors, IncludeRegExpAlias) {
66
+ super();
67
+ this.FSharpAST = FSharpAST;
68
+ this.Warnings = Warnings;
69
+ this.Errors = Errors;
70
+ this.IncludeRegExpAlias = IncludeRegExpAlias;
71
+ }
72
+ }
73
+
74
+ export function TransformResult_$reflection() {
75
+ return record_type("Glutinum.Converter.Transform.TransformResult", [], TransformResult, () => [["FSharpAST", list_type(FSharpType_$reflection())], ["Warnings", array_type(string_type)], ["Errors", array_type(string_type)], ["IncludeRegExpAlias", bool_type]]);
76
+ }
77
+
78
+ export function Reporter__get_Warnings(__) {
79
+ return __["Warnings@"];
80
+ }
81
+
82
+ export function Reporter__get_Errors(__) {
83
+ return __["Errors@"];
84
+ }
85
+
86
+ export function Reporter__get_HasRegEpx(__) {
87
+ return __["HasRegEpx@"];
88
+ }
89
+
90
+ export function Reporter__set_HasRegEpx_Z1FBCCD16(__, v) {
91
+ __["HasRegEpx@"] = v;
92
+ }
93
+
47
94
  export function TransformContext__get_FullName(__) {
48
95
  return __["FullName@"];
49
96
  }
@@ -56,6 +103,14 @@ export function TransformContext__get__types(__) {
56
103
  return __["_types@"];
57
104
  }
58
105
 
106
+ export function TransformContext__get__Reporter(__) {
107
+ return __["_Reporter@"];
108
+ }
109
+
110
+ export function TransformContext__ExposeRegExp(_) {
111
+ Reporter__set_HasRegEpx_Z1FBCCD16(_.reporter, true);
112
+ }
113
+
59
114
  export function TransformContext__ExposeType_Z1D58A540(_, typ) {
60
115
  const matchValue = _.parent;
61
116
  if (matchValue != null) {
@@ -68,7 +123,7 @@ export function TransformContext__ExposeType_Z1D58A540(_, typ) {
68
123
  }
69
124
 
70
125
  export function TransformContext__PushScope_Z721C83C5(this$, scopeName) {
71
- const childContext = TransformContext_$ctor_Z535BF207(scopeName, this$);
126
+ const childContext = TransformContext_$ctor_Z20656E4E(this$.reporter, scopeName, this$);
72
127
  void (this$.modules.push(childContext));
73
128
  return childContext;
74
129
  }
@@ -88,6 +143,58 @@ export function TransformContext__ToList(_) {
88
143
  }
89
144
  }
90
145
 
146
+ export function TransformContext__AddWarning_Z721C83C5(_, warning) {
147
+ void (Reporter__get_Warnings(_.reporter).push(warning));
148
+ }
149
+
150
+ export function TransformContext__AddError_Z721C83C5(_, error) {
151
+ void (Reporter__get_Errors(_.reporter).push(error));
152
+ }
153
+
154
+ function mapTypeNameToFableCoreAwareName(context, typeReference) {
155
+ if (typeReference.IsStandardLibrary) {
156
+ const matchValue = typeReference.Name;
157
+ switch (matchValue) {
158
+ case "Date":
159
+ return "JS.Date";
160
+ case "Promise":
161
+ return "JS.Promise";
162
+ case "Uint8Array":
163
+ return "JS.Uint8Array";
164
+ case "ReadonlyArray":
165
+ return "ResizeArray";
166
+ case "Array":
167
+ return "ResizeArray";
168
+ case "Boolean":
169
+ return "bool";
170
+ case "RegExp": {
171
+ TransformContext__ExposeRegExp(context);
172
+ return "RegExp";
173
+ }
174
+ default:
175
+ return matchValue;
176
+ }
177
+ }
178
+ else {
179
+ return typeReference.Name;
180
+ }
181
+ }
182
+
183
+ function unwrapOptionIfAlreadyOptional(context, typ, isOptional) {
184
+ const typ$0027 = transformType(context, typ);
185
+ if (isOptional) {
186
+ if (typ$0027.tag === 2) {
187
+ return typ$0027.fields[0];
188
+ }
189
+ else {
190
+ return typ$0027;
191
+ }
192
+ }
193
+ else {
194
+ return typ$0027;
195
+ }
196
+ }
197
+
91
198
  function sanitizeNameAndPushScope(name, context) {
92
199
  const name_1 = sanitizeName(name);
93
200
  return [name_1, TransformContext__PushScope_Z721C83C5(context, name_1)];
@@ -256,11 +363,13 @@ function transformType(context_mut, glueType_mut) {
256
363
  switch (glueType.tag) {
257
364
  case 3:
258
365
  return new FSharpType(7, [transformPrimitive(glueType.fields[0])]);
259
- case 23:
366
+ case 27:
367
+ return new FSharpType(7, [new FSharpPrimitive(0, [])]);
368
+ case 24:
260
369
  return new FSharpType(2, [transformType(context, glueType.fields[0])]);
261
- case 18:
262
- return new FSharpType(14, [glueType.fields[0]]);
263
370
  case 19:
371
+ return new FSharpType(14, [glueType.fields[0]]);
372
+ case 20:
264
373
  return transformTupleType(context, glueType.fields[0]);
265
374
  case 7: {
266
375
  const patternInput = partition((glueType_2) => {
@@ -291,7 +400,8 @@ function transformType(context_mut, glueType_mut) {
291
400
  else {
292
401
  const matchValue = tryOptimizeUnionType(context, TransformContext__get_CurrentScopeName(context), others);
293
402
  if (matchValue == null) {
294
- return new FSharpType(1, [new FSharpUnion(empty(), `U${length(others)}`, map((caseType) => (new FSharpUnionCase(empty(), mapTypeNameToFableCoreAwareName(GlueType__get_Name(caseType)))), others), isOptional)]);
403
+ const patternInput_1 = sanitizeNameAndPushScope(`U${length(others)}`, context);
404
+ return new FSharpType(1, [new FSharpUnion(empty(), patternInput_1[0], mapIndexed((index, caseType) => (new FSharpUnionCase(1, [transformType(TransformContext__PushScope_Z721C83C5(patternInput_1[1], `Case${index + 1}`), caseType)])), others), isOptional)]);
295
405
  }
296
406
  else {
297
407
  TransformContext__ExposeType_Z1D58A540(context, matchValue);
@@ -301,23 +411,23 @@ function transformType(context_mut, glueType_mut) {
301
411
  }
302
412
  case 13: {
303
413
  const typeReference = glueType.fields[0];
304
- return new FSharpType(10, [new FSharpTypeReference(mapTypeNameToFableCoreAwareName(typeReference.Name), typeReference.FullName, map((glueType_3) => transformType(context, glueType_3), typeReference.TypeArguments), new FSharpType(7, [new FSharpPrimitive(0, [])]))]);
414
+ return new FSharpType(10, [new FSharpTypeReference(mapTypeNameToFableCoreAwareName(context, typeReference), typeReference.FullName, map((glueType_3) => transformType(context, glueType_3), typeReference.TypeArguments), new FSharpType(7, [new FSharpPrimitive(0, [])]))]);
305
415
  }
306
- case 15:
416
+ case 16:
307
417
  return new FSharpType(13, [transformType(context, glueType.fields[0])]);
308
418
  case 12: {
309
419
  const classDeclaration = glueType.fields[0];
310
420
  return new FSharpType(10, [new FSharpTypeReference(classDeclaration.Name, classDeclaration.Name, empty(), new FSharpType(9, []))]);
311
421
  }
312
- case 17:
422
+ case 18:
313
423
  return new FSharpType(12, [glueType.fields[0]]);
314
- case 16: {
424
+ case 17: {
315
425
  const functionTypeInfo = glueType.fields[0];
316
- return new FSharpType(15, [new FSharpFunctionType(map((parameter) => transformParameter(context, parameter), functionTypeInfo.Parameters), empty(), transformType(context, functionTypeInfo.Type))]);
426
+ return new FSharpType(15, [new FSharpFunctionType(map((parameter) => transformParameter(context, parameter), functionTypeInfo.Parameters), transformType(context, functionTypeInfo.Type))]);
317
427
  }
318
428
  case 1:
319
429
  return new FSharpType(4, [transformInterface(context, glueType.fields[0])]);
320
- case 22: {
430
+ case 23: {
321
431
  const typeLiteralInfo = glueType.fields[0];
322
432
  if (forAll((_arg) => {
323
433
  switch (_arg.tag) {
@@ -352,7 +462,7 @@ function transformType(context_mut, glueType_mut) {
352
462
  }
353
463
  return new FSharpType(10, [new FSharpTypeReference(TransformContext__get_FullName(context), TransformContext__get_FullName(context), empty(), new FSharpType(9, []))]);
354
464
  }
355
- case 25: {
465
+ case 26: {
356
466
  context_mut = context;
357
467
  glueType_mut = glueType.fields[0];
358
468
  continue transformType;
@@ -372,7 +482,7 @@ function transformType(context_mut, glueType_mut) {
372
482
  return new FSharpType(10, [new FSharpTypeReference(TransformContext__get_FullName(context), TransformContext__get_FullName(context), empty(), new FSharpType(9, []))]);
373
483
  }
374
484
  }
375
- case 20: {
485
+ case 21: {
376
486
  context_mut = context;
377
487
  glueType_mut = glueType.fields[0].Type;
378
488
  continue transformType;
@@ -383,14 +493,45 @@ function transformType(context_mut, glueType_mut) {
383
493
  }
384
494
  case 0:
385
495
  return new FSharpType(17, []);
496
+ case 8: {
497
+ const glueLiteral = glueType.fields[0];
498
+ switch (glueLiteral.tag) {
499
+ case 1:
500
+ return new FSharpType(7, [new FSharpPrimitive(1, [])]);
501
+ case 2:
502
+ return new FSharpType(7, [new FSharpPrimitive(2, [])]);
503
+ case 3:
504
+ return new FSharpType(7, [new FSharpPrimitive(3, [])]);
505
+ case 4:
506
+ return new FSharpType(7, [new FSharpPrimitive(6, [])]);
507
+ default:
508
+ return new FSharpType(7, [new FSharpPrimitive(0, [])]);
509
+ }
510
+ }
511
+ case 6: {
512
+ const functionDeclaration = glueType.fields[0];
513
+ return new FSharpType(15, [new FSharpFunctionType(map((parameter_3) => transformParameter(context, parameter_3), functionDeclaration.Parameters), transformType(context, functionDeclaration.Type))]);
514
+ }
515
+ case 22: {
516
+ const members_1 = glueType.fields[0];
517
+ if (isEmpty(members_1)) {
518
+ return new FSharpType(17, []);
519
+ }
520
+ else {
521
+ TransformContext__ExposeType_Z1D58A540(context, new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), TransformContext__get_CurrentScopeName(context), TransformContext__get_CurrentScopeName(context), empty(), TransformMembers_toFSharpMember(context, members_1), empty())]));
522
+ return new FSharpType(6, [new FSharpMapped(TransformContext__get_FullName(context), empty())]);
523
+ }
524
+ }
525
+ case 15: {
526
+ TransformContext__ExposeType_Z1D58A540(context, transformRecord(context, TransformContext__get_CurrentScopeName(context), empty(), glueType.fields[0]));
527
+ return new FSharpType(6, [new FSharpMapped(TransformContext__get_FullName(context), empty())]);
528
+ }
529
+ case 5:
530
+ return new FSharpType(6, [new FSharpMapped(glueType.fields[0].Name, empty())]);
386
531
  case 11:
387
532
  case 10:
388
- case 8:
389
- case 4:
390
- case 5:
391
- case 21:
392
- case 6: {
393
- error(toText(interpolate("Could not transform type: %A%P()", [glueType])));
533
+ case 4: {
534
+ TransformContext__AddError_Z721C83C5(context, toText(interpolate("Could not transform type: %A%P()", [glueType])));
394
535
  return new FSharpType(9, []);
395
536
  }
396
537
  default:
@@ -425,23 +566,15 @@ function transformExports(context, isTopLevel, exports) {
425
566
  return map((constructorInfo) => {
426
567
  let Attributes_2, Parameters_2;
427
568
  const xmlDocInfo_2 = transformComment(constructorInfo.Documentation);
428
- return new FSharpMember(0, [(Attributes_2 = toList(delay(() => append(isTopLevel ? append(singleton_1(new FSharpAttribute(3, [info_2.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => singleton_1(new FSharpAttribute(13, [])))) : singleton_1(new FSharpAttribute(14, [info_2.Name])), delay(() => xmlDocInfo_2.ObsoleteAttributes)))), (Parameters_2 = map((parameter_1) => transformParameter(context_4, parameter_1), constructorInfo.Parameters), new FSharpMemberInfo(Attributes_2, patternInput_2[0], info_2.Name, transformTypeParameters(context_4, info_2.TypeParameters), Parameters_2, new FSharpType(6, [new FSharpMapped(sanitizeName(info_2.Name), empty(), transformTypeParameters(context_4, info_2.TypeParameters))]), false, isTopLevel, void 0, new FSharpAccessibility(0, []), xmlDocInfo_2.XmlDoc, new FSharpMemberInfoBody(0, []))))]);
569
+ return new FSharpMember(0, [(Attributes_2 = toList(delay(() => append(isTopLevel ? append(singleton_1(new FSharpAttribute(3, [info_2.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => singleton_1(new FSharpAttribute(13, [])))) : singleton_1(new FSharpAttribute(14, [info_2.Name])), delay(() => xmlDocInfo_2.ObsoleteAttributes)))), (Parameters_2 = map((parameter_1) => transformParameter(context_4, parameter_1), constructorInfo.Parameters), new FSharpMemberInfo(Attributes_2, patternInput_2[0], info_2.Name, transformTypeParameters(context_4, info_2.TypeParameters), Parameters_2, new FSharpType(6, [new FSharpMapped(sanitizeName(info_2.Name), transformTypeParameters(context_4, info_2.TypeParameters))]), false, isTopLevel, void 0, new FSharpAccessibility(0, []), xmlDocInfo_2.XmlDoc, new FSharpMemberInfoBody(0, []))))]);
429
570
  }, isEmpty(info_2.Constructors) ? singleton(new GlueConstructor(empty(), empty())) : info_2.Constructors);
430
571
  }
431
572
  case 11: {
432
573
  const moduleDeclaration = _arg.fields[0];
433
- return choose((typ) => {
434
- switch (typ.tag) {
435
- case 12:
436
- return new FSharpMember(1, [new FSharpMemberInfo(ofArray([new FSharpAttribute(4, ["REPLACE_ME_WITH_MODULE_NAME"]), new FSharpAttribute(0, [`Emit("$0.${moduleDeclaration.Name}")`])]), moduleDeclaration.Name + "_", moduleDeclaration.Name, empty(), empty(), new FSharpType(6, [new FSharpMapped(`${moduleDeclaration.Name}.Exports`, empty(), empty())]), false, true, new FSharpAccessor(0, []), new FSharpAccessibility(0, []), empty(), new FSharpMemberInfoBody(0, []))]);
437
- case 6:
438
- return new FSharpMember(1, [new FSharpMemberInfo(ofArray([new FSharpAttribute(4, ["REPLACE_ME_WITH_MODULE_NAME"]), new FSharpAttribute(0, [`Emit("$0.${moduleDeclaration.Name}")`])]), moduleDeclaration.Name + "_", `${moduleDeclaration.Name}.Exports`, empty(), empty(), new FSharpType(6, [new FSharpMapped(`${moduleDeclaration.Name}.Exports`, empty(), empty())]), false, isTopLevel, new FSharpAccessor(0, []), new FSharpAccessibility(0, []), empty(), new FSharpMemberInfoBody(0, []))]);
439
- default:
440
- return void 0;
441
- }
442
- }, moduleDeclaration.Types);
574
+ const sanitizedName = sanitizeName(moduleDeclaration.Name);
575
+ return singleton(new FSharpMember(1, [new FSharpMemberInfo(ofArray([new FSharpAttribute(4, ["REPLACE_ME_WITH_MODULE_NAME"]), new FSharpAttribute(0, [`Emit("$0.${removeSurroundingQuotes(moduleDeclaration.Name)}")`])]), sanitizedName + "_", `${moduleDeclaration.Name}.Exports`, empty(), empty(), new FSharpType(6, [new FSharpMapped(`${sanitizedName}.Exports`, empty())]), false, isTopLevel, new FSharpAccessor(0, []), new FSharpAccessibility(0, []), empty(), new FSharpMemberInfoBody(0, []))]));
443
576
  }
444
- case 25: {
577
+ case 26: {
445
578
  const glueType = _arg.fields[0];
446
579
  const patternInput_3 = sanitizeNameAndPushScope(GlueType__get_Name(glueType), context_1);
447
580
  return singleton(new FSharpMember(1, [new FSharpMemberInfo(singleton(new FSharpAttribute(5, ["REPLACE_ME_WITH_MODULE_NAME"])), patternInput_3[0], GlueType__get_Name(glueType), empty(), empty(), transformType(patternInput_3[1], glueType), false, true, void 0, new FSharpAccessibility(0, []), empty(), new FSharpMemberInfoBody(0, []))]));
@@ -454,7 +587,7 @@ function transformExports(context, isTopLevel, exports) {
454
587
 
455
588
  function transformParameter(context, parameter) {
456
589
  let typ;
457
- const computedType = transformType(TransformContext__PushScope_Z721C83C5(context, parameter.Name), parameter.Type);
590
+ const computedType = unwrapOptionIfAlreadyOptional(TransformContext__PushScope_Z721C83C5(context, parameter.Name), parameter.Type, parameter.IsOptional);
458
591
  typ = (parameter.IsSpread ? ((computedType.tag === 13) ? computedType.fields[0] : computedType) : computedType);
459
592
  return new FSharpParameter(toList(delay(() => (parameter.IsSpread ? singleton_1(new FSharpAttribute(19, [])) : empty_1()))), sanitizeName(parameter.Name), parameter.IsOptional, typ);
460
593
  }
@@ -487,10 +620,7 @@ function TransformMembers_toFSharpMember(context, members) {
487
620
  return void 0;
488
621
  }
489
622
  else {
490
- let typ;
491
- const typ$0027 = transformType(patternInput_2[1], propertyInfo.Type);
492
- typ = (propertyInfo.IsOptional ? ((typ$0027.tag === 2) ? typ$0027.fields[0] : typ$0027) : typ$0027);
493
- return new FSharpMember(1, [new FSharpMemberInfo(toList(delay(() => xmlDocInfo.ObsoleteAttributes)), patternInput_2[0], propertyInfo.Name, empty(), empty(), typ, propertyInfo.IsOptional, propertyInfo.IsStatic, transformAccessor(propertyInfo.Accessor), propertyInfo.IsPrivate ? (new FSharpAccessibility(1, [])) : (new FSharpAccessibility(0, [])), xmlDocInfo.XmlDoc, new FSharpMemberInfoBody(1, []))]);
623
+ return new FSharpMember(1, [new FSharpMemberInfo(toList(delay(() => xmlDocInfo.ObsoleteAttributes)), patternInput_2[0], propertyInfo.Name, empty(), empty(), unwrapOptionIfAlreadyOptional(patternInput_2[1], propertyInfo.Type, propertyInfo.IsOptional), propertyInfo.IsOptional, propertyInfo.IsStatic, transformAccessor(propertyInfo.Accessor), propertyInfo.IsPrivate ? (new FSharpAccessibility(1, [])) : (new FSharpAccessibility(0, [])), xmlDocInfo.XmlDoc, new FSharpMemberInfoBody(1, []))]);
494
624
  }
495
625
  }
496
626
  case 2: {
@@ -693,7 +823,7 @@ function transformEnum(glueEnum) {
693
823
  throw new Error("Should not happen");
694
824
  }
695
825
  const caseName = sanitizeName(glueMember_1.Name);
696
- return new FSharpUnionCase(toList(delay(() => ((caseName !== caseValue) ? singleton_1(new FSharpAttribute(11, [removeSurroundingQuotes(caseValue)])) : empty_1()))), caseName);
826
+ return new FSharpUnionCase(0, [new FSharpUnionCaseNamed(toList(delay(() => ((caseName !== caseValue) ? singleton_1(new FSharpAttribute(11, [removeSurroundingQuotes(caseValue)])) : empty_1()))), caseName)]);
697
827
  }, stringValues), {
698
828
  Equals: equals,
699
829
  GetHashCode: safeHash,
@@ -716,7 +846,6 @@ Errored enum: ${glueEnum.Name}
716
846
 
717
847
  export function TypeAliasDeclaration_tryTransformKeyOf(aliasName, glueType) {
718
848
  const cases = (glueType.tag === 1) ? choose((m) => {
719
- let sanitizeResult;
720
849
  let matchResult, caseName;
721
850
  switch (m.tag) {
722
851
  case 4:
@@ -751,8 +880,10 @@ export function TypeAliasDeclaration_tryTransformKeyOf(aliasName, glueType) {
751
880
  }
752
881
  }
753
882
  switch (matchResult) {
754
- case 0:
755
- return (sanitizeResult = sanitizeNameWithResult(caseName), new FSharpUnionCase(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(11, [removeSurroundingQuotes(caseName)])) : empty_1()))), sanitizeResult.Name));
883
+ case 0: {
884
+ const sanitizeResult = sanitizeNameWithResult(caseName);
885
+ return new FSharpUnionCase(0, [new FSharpUnionCaseNamed(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(11, [removeSurroundingQuotes(caseName)])) : empty_1()))), sanitizeResult.Name)]);
886
+ }
756
887
  default:
757
888
  return void 0;
758
889
  }
@@ -765,10 +896,10 @@ export function TypeAliasDeclaration_tryTransformKeyOf(aliasName, glueType) {
765
896
  }
766
897
  }
767
898
 
768
- export function TypeAliasDeclaration_transformKeyOf(aliasName, glueType) {
899
+ export function TypeAliasDeclaration_transformKeyOf(context, aliasName, glueType) {
769
900
  const matchValue = TypeAliasDeclaration_tryTransformKeyOf(aliasName, glueType);
770
901
  if (matchValue == null) {
771
- warn(`Could not transform KeyOf: ${aliasName}`);
902
+ TransformContext__AddWarning_Z721C83C5(context, `Could not transform KeyOf: ${aliasName}`);
772
903
  return new FSharpType(9, []);
773
904
  }
774
905
  else {
@@ -788,12 +919,30 @@ export function TypeAliasDeclaration_transformLiteral(xmlDoc, typeAliasName, lit
788
919
  case 4:
789
920
  return makeTypeAlias(new FSharpPrimitive(6, []));
790
921
  default:
791
- return new FSharpType(1, [new FSharpUnion(ofArray([new FSharpAttribute(12, []), new FSharpAttribute(10, [0])]), typeAliasName, singleton(new FSharpUnionCase(empty(), sanitizeName(literalInfo.fields[0]))), false)]);
922
+ return new FSharpType(1, [new FSharpUnion(ofArray([new FSharpAttribute(12, []), new FSharpAttribute(10, [0])]), typeAliasName, singleton(new FSharpUnionCase(0, [new FSharpUnionCaseNamed(empty(), sanitizeName(literalInfo.fields[0]))])), false)]);
792
923
  }
793
924
  }
794
925
 
926
+ function transformRecord(context, name, typeParameters, recordInfo) {
927
+ const patternInput = sanitizeNameAndPushScope(name, context);
928
+ const name_1 = patternInput[0];
929
+ const context_1 = patternInput[1];
930
+ let parameters;
931
+ const patternInput_1 = sanitizeNameAndPushScope("key", context_1);
932
+ parameters = singleton(new FSharpParameter(empty(), patternInput_1[0], false, transformType(patternInput_1[1], recordInfo.KeyType)));
933
+ return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), name_1, name_1, transformTypeParameters(context_1, typeParameters), singleton(new FSharpMember(1, [new FSharpMemberInfo(singleton(new FSharpAttribute(16, [])), "Item", "Item", empty(), parameters, transformType(context_1, recordInfo.ValueType), false, false, new FSharpAccessor(2, []), new FSharpAccessibility(0, []), empty(), new FSharpMemberInfoBody(0, []))])), empty())]);
934
+ }
935
+
795
936
  function transformTypeParameters(context, typeParameters) {
796
- return map((typeParameter) => FSharpTypeParameter_Create_Z6CFD3565(typeParameter.Name, unwrap(map_1((glueType) => transformType(context, glueType), typeParameter.Constraint)), unwrap(map_1((glueType_1) => transformType(context, glueType_1), typeParameter.Default))), typeParameters);
937
+ return map((typeParameter) => FSharpTypeParameter_Create_Z6CFD3565(typeParameter.Name, unwrap(bind((glueType) => {
938
+ const matchValue = transformType(context, glueType);
939
+ if (matchValue.tag === 15) {
940
+ return void 0;
941
+ }
942
+ else {
943
+ return matchValue;
944
+ }
945
+ }, typeParameter.Constraint)), unwrap(map_1((glueType_1) => transformType(context, glueType_1), typeParameter.Default))), typeParameters);
797
946
  }
798
947
 
799
948
  function tryOptimizeUnionType(context, typeName, cases) {
@@ -875,7 +1024,7 @@ function tryOptimizeUnionType(context, typeName, cases) {
875
1024
  switch (matchResult_2) {
876
1025
  case 0: {
877
1026
  const sanitizeResult = sanitizeNameWithResult(value_1);
878
- return new FSharpUnionCase(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(11, [removeSurroundingQuotes(value_1)])) : empty_1()))), sanitizeResult.Name);
1027
+ return new FSharpUnionCase(0, [new FSharpUnionCaseNamed(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(11, [removeSurroundingQuotes(value_1)])) : empty_1()))), sanitizeResult.Name)]);
879
1028
  }
880
1029
  default:
881
1030
  throw new Error("Should not happen");
@@ -912,7 +1061,7 @@ function tryOptimizeUnionType(context, typeName, cases) {
912
1061
  }))]);
913
1062
  }
914
1063
  else if (forAll((_arg_3) => {
915
- if (_arg_3.tag === 22) {
1064
+ if (_arg_3.tag === 23) {
916
1065
  return true;
917
1066
  }
918
1067
  else {
@@ -920,7 +1069,7 @@ function tryOptimizeUnionType(context, typeName, cases) {
920
1069
  }
921
1070
  }, cases)) {
922
1071
  const members = collect_1((_arg_4) => {
923
- if (_arg_4.tag === 22) {
1072
+ if (_arg_4.tag === 23) {
924
1073
  return TransformMembers_toFSharpMember(context, _arg_4.fields[0].Members);
925
1074
  }
926
1075
  else {
@@ -942,7 +1091,7 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
942
1091
  const matchValue = glueTypeAliasDeclaration.Type;
943
1092
  switch (matchValue.tag) {
944
1093
  case 9:
945
- return TypeAliasDeclaration_transformKeyOf(glueTypeAliasDeclaration.Name, matchValue.fields[0]);
1094
+ return TypeAliasDeclaration_transformKeyOf(context_1, glueTypeAliasDeclaration.Name, matchValue.fields[0]);
946
1095
  case 10: {
947
1096
  const glueType_1 = matchValue.fields[0];
948
1097
  let typ_2;
@@ -1002,9 +1151,12 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
1002
1151
  return TypeAliasDeclaration_transformLiteral(xmlDoc, typeAliasName, matchValue.fields[0]);
1003
1152
  case 3:
1004
1153
  return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(7, [transformPrimitive(matchValue.fields[0])]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1154
+ case 27:
1155
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(7, [new FSharpPrimitive(0, [])]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1005
1156
  case 13: {
1006
1157
  const typeReference = matchValue.fields[0];
1007
- const context_2 = TransformContext__PushScope_Z721C83C5(context_1, typeReference.Name);
1158
+ const mappedName = mapTypeNameToFableCoreAwareName(context_1, typeReference);
1159
+ const context_2 = TransformContext__PushScope_Z721C83C5(context_1, mappedName);
1008
1160
  const handleDefaultCase = () => (new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformType(context_2, new GlueType(13, [typeReference])), transformTypeParameters(context_2, glueTypeAliasDeclaration.TypeParameters))]));
1009
1161
  const matchValue_2 = typeReference.TypeArguments;
1010
1162
  let matchResult_1, head;
@@ -1022,12 +1174,12 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
1022
1174
  }
1023
1175
  switch (matchResult_1) {
1024
1176
  case 0:
1025
- if (head.tag === 21) {
1177
+ if (head.tag === 22) {
1026
1178
  const makeInterfaceTyp = (name) => (new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), name, glueTypeAliasDeclaration.Name, empty(), TransformMembers_toFSharpMember(context_2, head.fields[0]), empty()));
1027
1179
  const exposedType = makeInterfaceTyp("ReturnType");
1028
1180
  const typeArgument = makeInterfaceTyp(TransformContext__get_FullName(context_2) + ".ReturnType");
1029
1181
  TransformContext__ExposeType_Z1D58A540(TransformContext__PushScope_Z721C83C5(context_2, typeReference.Name), new FSharpType(4, [exposedType]));
1030
- return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(10, [new FSharpTypeReference(typeReference.Name, typeReference.FullName, singleton(new FSharpType(4, [typeArgument])), new FSharpType(9, []))]), empty())]);
1182
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(10, [new FSharpTypeReference(mappedName, typeReference.FullName, singleton(new FSharpType(4, [typeArgument])), new FSharpType(9, []))]), empty())]);
1031
1183
  }
1032
1184
  else {
1033
1185
  return handleDefaultCase();
@@ -1036,23 +1188,25 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
1036
1188
  return handleDefaultCase();
1037
1189
  }
1038
1190
  }
1039
- case 15:
1040
- return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformType(context_1, new GlueType(15, [matchValue.fields[0]])), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1191
+ case 16:
1192
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformType(context_1, new GlueType(16, [matchValue.fields[0]])), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1041
1193
  case 14:
1042
1194
  return new FSharpType(4, [Interface_makePartial(typeAliasName, transformInterface(context_1, matchValue.fields[0]))]);
1043
- case 16: {
1195
+ case 15:
1196
+ return transformRecord(context_1, typeAliasName, glueTypeAliasDeclaration.TypeParameters, matchValue.fields[0]);
1197
+ case 17: {
1044
1198
  const functionType = matchValue.fields[0];
1045
1199
  return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), singleton(new FSharpMember(0, [new FSharpMemberInfo(singleton(new FSharpAttribute(1, [])), "Invoke", "Invoke", empty(), map((parameter) => transformParameter(context_1, parameter), functionType.Parameters), transformType(context_1, functionType.Type), false, false, void 0, new FSharpAccessibility(0, []), empty(), new FSharpMemberInfoBody(0, []))])), empty())]);
1046
1200
  }
1047
- case 19:
1201
+ case 20:
1048
1202
  return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformTupleType(context_1, matchValue.fields[0]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1049
- case 21:
1050
- return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), TransformMembers_toFSharpMember(context_1, matchValue.fields[0]), empty())]);
1051
1203
  case 22:
1204
+ return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), TransformMembers_toFSharpMember(context_1, matchValue.fields[0]), empty())]);
1205
+ case 23:
1052
1206
  return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(8, []), new FSharpAttribute(20, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), TransformMembers_toFSharpMember(context_1, matchValue.fields[0].Members), empty())]);
1053
- case 24:
1207
+ case 25:
1054
1208
  return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(17, []), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1055
- case 17:
1209
+ case 18:
1056
1210
  return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(12, [matchValue.fields[0]]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
1057
1211
  case 12:
1058
1212
  case 4:
@@ -1061,11 +1215,11 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
1061
1215
  case 5:
1062
1216
  case 0:
1063
1217
  case 6:
1064
- case 18:
1218
+ case 19:
1065
1219
  case 2:
1066
- case 25:
1067
- case 20:
1068
- case 23:
1220
+ case 26:
1221
+ case 21:
1222
+ case 24:
1069
1223
  return new FSharpType(9, []);
1070
1224
  default: {
1071
1225
  const matchValue_1 = tryOptimizeUnionType(context_1, typeAliasName, matchValue.fields[0].fields[0]);
@@ -1079,8 +1233,8 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
1079
1233
  }
1080
1234
  }
1081
1235
 
1082
- function transformModuleDeclaration(moduleDeclaration) {
1083
- return new FSharpType(3, [new FSharpModule(sanitizeName(moduleDeclaration.Name), moduleDeclaration.IsRecursive, transform(false, moduleDeclaration.Types))]);
1236
+ function transformModuleDeclaration(reporter, moduleDeclaration) {
1237
+ return new FSharpType(3, [new FSharpModule(sanitizeName(moduleDeclaration.Name), moduleDeclaration.IsRecursive, transform(reporter, false, moduleDeclaration.Types))]);
1084
1238
  }
1085
1239
 
1086
1240
  function transformClassDeclaration(context, classDeclaration) {
@@ -1098,10 +1252,10 @@ function transformToFsharp(context, glueTypes) {
1098
1252
  case 5:
1099
1253
  return transformTypeAliasDeclaration(context, _arg.fields[0]);
1100
1254
  case 11:
1101
- return transformModuleDeclaration(_arg.fields[0]);
1255
+ return transformModuleDeclaration(TransformContext__get__Reporter(context), _arg.fields[0]);
1102
1256
  case 12:
1103
1257
  return transformClassDeclaration(context, _arg.fields[0]);
1104
- case 25: {
1258
+ case 26: {
1105
1259
  const exportedType = _arg.fields[0];
1106
1260
  if (exportedType.tag === 12) {
1107
1261
  return transformClassDeclaration(context, exportedType.fields[0]);
@@ -1110,10 +1264,10 @@ function transformToFsharp(context, glueTypes) {
1110
1264
  return new FSharpType(9, []);
1111
1265
  }
1112
1266
  }
1113
- case 16:
1114
1267
  case 17:
1268
+ case 18:
1115
1269
  case 14:
1116
- case 15:
1270
+ case 16:
1117
1271
  case 13:
1118
1272
  case 6:
1119
1273
  case 10:
@@ -1121,15 +1275,17 @@ function transformToFsharp(context, glueTypes) {
1121
1275
  case 8:
1122
1276
  case 2:
1123
1277
  case 3:
1124
- case 24:
1278
+ case 25:
1125
1279
  case 9:
1126
1280
  case 0:
1127
- case 19:
1128
- case 21:
1281
+ case 20:
1129
1282
  case 22:
1130
1283
  case 23:
1131
- case 20:
1132
- case 18:
1284
+ case 15:
1285
+ case 24:
1286
+ case 21:
1287
+ case 27:
1288
+ case 19:
1133
1289
  return new FSharpType(9, []);
1134
1290
  default:
1135
1291
  return new FSharpType(4, [transformInterface(context, _arg.fields[0])]);
@@ -1137,13 +1293,13 @@ function transformToFsharp(context, glueTypes) {
1137
1293
  }, glueTypes);
1138
1294
  }
1139
1295
 
1140
- export function transform(isTopLevel, glueAst) {
1296
+ function transform(reporter, isTopLevel, glueAst) {
1141
1297
  const patternInput = partition((glueType) => {
1142
1298
  switch (glueType.tag) {
1143
1299
  case 2:
1144
1300
  case 6:
1145
1301
  return true;
1146
- case 25:
1302
+ case 26:
1147
1303
  if (glueType.fields[0].tag === 2) {
1148
1304
  return true;
1149
1305
  }
@@ -1169,7 +1325,7 @@ export function transform(isTopLevel, glueAst) {
1169
1325
  return false;
1170
1326
  }
1171
1327
  }, glueType_1.fields[0].Types);
1172
- case 25:
1328
+ case 26:
1173
1329
  if (glueType_1.fields[0].tag === 12) {
1174
1330
  return true;
1175
1331
  }
@@ -1180,9 +1336,14 @@ export function transform(isTopLevel, glueAst) {
1180
1336
  return false;
1181
1337
  }
1182
1338
  }, rest));
1183
- const rootTransformContext = TransformContext_$ctor_Z535BF207("");
1339
+ const rootTransformContext = TransformContext_$ctor_Z20656E4E(reporter, "");
1184
1340
  const rest_1 = transformToFsharp(rootTransformContext, rest);
1185
1341
  return toList(delay(() => append(!isEmpty(exports_1) ? singleton_1(transformExports(rootTransformContext, isTopLevel, exports_1)) : empty_1(), delay(() => append(rest_1, delay(() => TransformContext__ToList(rootTransformContext)))))));
1186
1342
  }
1187
1343
 
1344
+ export function apply(glueAst) {
1345
+ const reporter = Reporter_$ctor();
1346
+ return new TransformResult(transform(reporter, true, glueAst), Reporter__get_Warnings(reporter), Reporter__get_Errors(reporter), Reporter__get_HasRegEpx(reporter));
1347
+ }
1348
+
1188
1349
  //# sourceMappingURL=Transform.js.map