@glutinum/cli 1.0.0-beta.14 → 1.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/Glutinum.Converter/GlueAST.js +19 -14
  2. package/dist/Glutinum.Converter/Merge.js +490 -206
  3. package/dist/Glutinum.Converter/Packages.js +2 -2
  4. package/dist/Glutinum.Converter/Printer.js +26 -21
  5. package/dist/Glutinum.Converter/Read.js +377 -169
  6. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +25 -8
  7. package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +2 -2
  8. package/dist/Glutinum.Converter/Reader/Declaration.js +15 -15
  9. package/dist/Glutinum.Converter/Reader/Deferred.js +114 -43
  10. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +98 -44
  11. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +2 -2
  12. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +61 -46
  13. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +31 -26
  14. package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +38 -25
  15. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +6 -5
  16. package/dist/Glutinum.Converter/Reader/Node.js +1 -1
  17. package/dist/Glutinum.Converter/Reader/TypeNode.js +292 -30
  18. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +1 -1
  19. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +143 -35
  20. package/dist/Glutinum.Converter/Reader/UtilityType.js +179 -34
  21. package/dist/Glutinum.Converter/Reader/Utils.js +186 -17
  22. package/dist/Glutinum.Converter/Reader/VariableStatement.js +46 -16
  23. package/dist/Glutinum.Converter/Transform.js +1073 -638
  24. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +2 -2
  25. package/dist/Glutinum.Converter/Transformer/Conditionals.js +17 -16
  26. package/dist/Glutinum.Converter/Transformer/Context.js +12 -4
  27. package/dist/Glutinum.Converter/Transformer/Exports.js +242 -66
  28. package/dist/Glutinum.Converter/Transformer/Heritage.js +449 -17
  29. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +4 -4
  30. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +105 -19
  31. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +2 -2
  32. package/dist/Glutinum.Converter/Transformer/Utils.js +3 -3
  33. package/dist/Glutinum.Converter/Utils/Naming.js +10 -3
  34. package/package.json +1 -1
@@ -1,18 +1,20 @@
1
1
 
2
2
  import { ts } from "@ts-morph/bootstrap";
3
- import { ambientModuleSpecifier, ambientModuleNames as ambientModuleNames_1, isMergedInterfaceDeclaration, promotedAmbientModule } from "./Reader/Utils.js";
4
- import { FSharpSet__Contains, ofSeq } from "../fable_modules/fable-library-js.5.21.0/Set.js";
5
- import { exists, sortBy, reverse, concat, partition, ofSeq as ofSeq_1, fold, append, head as head_1, tail, isEmpty, filter, map, cons, foldBack, choose, singleton, ofArray, empty, collect } from "../fable_modules/fable-library-js.5.21.0/List.js";
6
- import { safeHash, stringHash, equals, comparePrimitives, compareArrays } from "../fable_modules/fable-library-js.5.21.0/Util.js";
7
- import { ofSeq as ofSeq_2, toSeq, FSharpMap__Add, fold as fold_1, empty as empty_1, add, tryFind } from "../fable_modules/fable-library-js.5.21.0/Map.js";
3
+ import { ambientModuleSpecifier, ambientModuleNames as ambientModuleNames_1, isMergedInterfaceDeclaration, resolveAlias, promotedAmbientModule } from "./Reader/Utils.js";
4
+ import { collect, exists, choose, map } from "../fable_modules/fable-library-js.5.21.0/Seq.js";
5
+ import { unwrap, value as value_3, toArray, defaultArg } from "../fable_modules/fable-library-js.5.21.0/Option.js";
6
+ import { FSharpSet__Contains, empty as empty_1, difference, ofSeq } from "../fable_modules/fable-library-js.5.21.0/Set.js";
7
+ import { Lazy, safeHash, stringHash, equals, compareArrays, disposeSafe, getEnumerator, comparePrimitives } from "../fable_modules/fable-library-js.5.21.0/Util.js";
8
+ import { exists as exists_1, sortBy, reverse, concat, partition, fold, append, head as head_1, tail, isEmpty, filter, map as map_1, cons, foldBack, choose as choose_1, collect as collect_1, empty, singleton, ofArray, ofSeq as ofSeq_1 } from "../fable_modules/fable-library-js.5.21.0/List.js";
9
+ import { addToSet } from "../fable_modules/fable-library-js.5.21.0/MapUtil.js";
10
+ import { ofSeq as ofSeq_2, toSeq, FSharpMap__Add, fold as fold_1, empty as empty_2, add, tryFind } from "../fable_modules/fable-library-js.5.21.0/Map.js";
8
11
  import { GlueClassDeclaration, GlueModuleDeclaration, GlueType, GlueFileModule } from "./GlueAST.js";
9
12
  import { split, substring } from "../fable_modules/fable-library-js.5.21.0/String.js";
10
13
  import { List_groupBy } from "../fable_modules/fable-library-js.5.21.0/Seq2.js";
11
14
  import { addRangeInPlace, item } from "../fable_modules/fable-library-js.5.21.0/Array.js";
12
15
  import { TypeScriptReader_$ctor_26550FA4 } from "./Reader/TypeScriptReader.js";
13
- import { unwrap, value as value_1 } from "../fable_modules/fable-library-js.5.21.0/Option.js";
14
16
  import { removeSurroundingQuotes } from "./Utils/Naming.js";
15
- import { PackageContext__TryFindPackage_Z721C83C5, PackageContext__IsImportable_Z384F8060, PackageContext__IsHoisted_32BC514A, PackageContext__SymbolSpecifiers_Z721C83C5, PackageContext__ImportSpecifier_Z721C83C5, PackageContext__FileModuleName_Z11793CAF, PackageContext__AmbientSpecifier_Z721C83C5, PackageContext__NestedAmbientModuleSegments_32BC514A } from "./Reader/Types.js";
17
+ import { PackageContext__IsImportable_Z384F8060, PackageContext__IsHoisted_32BC514A, PackageContext__SymbolSpecifiers_Z721C83C5, PackageContext__ImportSpecifier_Z721C83C5, PackageContext__FileModuleName_Z11793CAF, PackageContext__TryFindPackage_Z721C83C5, PackageContext__AmbientSpecifier_Z721C83C5, PackageContext__NestedAmbientModuleSegments_32BC514A } from "./Reader/Types.js";
16
18
  import { normalizePath } from "./Utils/String.js";
17
19
  import { FSharpChoice$2 } from "../fable_modules/fable-library-js.5.21.0/Choice.js";
18
20
 
@@ -25,6 +27,102 @@ function isScript(sourceFile) {
25
27
  }
26
28
  }
27
29
 
30
+ function unexportedDeclarationNames(checker, sourceFile) {
31
+ let moduleSymbol;
32
+ const matchValue = checker.getSymbolAtLocation(sourceFile);
33
+ let matchResult, moduleSymbol_1;
34
+ if (matchValue != null) {
35
+ if ((moduleSymbol = matchValue, !((moduleSymbol.exports != null) && value_3(moduleSymbol.exports).has("export=")))) {
36
+ matchResult = 0;
37
+ moduleSymbol_1 = matchValue;
38
+ }
39
+ else {
40
+ matchResult = 1;
41
+ }
42
+ }
43
+ else {
44
+ matchResult = 1;
45
+ }
46
+ switch (matchResult) {
47
+ case 0: {
48
+ const exports = checker.getExportsOfModule(moduleSymbol_1);
49
+ let exported;
50
+ const collection = map((symbol) => defaultArg(resolveAlias(checker, symbol), symbol), exports);
51
+ exported = Array.from(collection);
52
+ const exportNames = ofSeq(map((_arg) => _arg.name, exports), {
53
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
54
+ });
55
+ return difference(ofSeq(choose((name) => {
56
+ let arg, _arg_1;
57
+ let option_10;
58
+ const option_8 = checker.getSymbolAtLocation(name);
59
+ option_10 = ((option_8 != null) ? (((arg = option_8, !exists((candidate) => (candidate === arg), exported))) ? option_8 : undefined) : undefined);
60
+ if (option_10 != null) {
61
+ return (_arg_1 = option_10, _arg_1.name);
62
+ }
63
+ else {
64
+ return undefined;
65
+ }
66
+ }, collect((statement) => {
67
+ let option_2, option_5;
68
+ const matchValue_1 = statement.kind;
69
+ switch (matchValue_1) {
70
+ case 244:
71
+ return ofSeq_1(map((declaration) => declaration.name, statement.declarationList.declarations));
72
+ case 263:
73
+ return ofArray(toArray((option_2 = statement.name, (option_2 != null) ? option_2 : undefined)));
74
+ case 264:
75
+ return ofArray(toArray((option_5 = statement.name, (option_5 != null) ? option_5 : undefined)));
76
+ case 268:
77
+ return singleton(statement.name);
78
+ default:
79
+ return empty();
80
+ }
81
+ }, sourceFile.statements)), {
82
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
83
+ }), exportNames);
84
+ }
85
+ default:
86
+ return empty_1({
87
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
88
+ });
89
+ }
90
+ }
91
+
92
+ function typeofRoots(sourceFiles) {
93
+ const roots = new Set([]);
94
+ const leftmost = (entityName_mut) => {
95
+ leftmost:
96
+ while (true) {
97
+ const entityName = entityName_mut;
98
+ if (entityName.kind === 167) {
99
+ entityName_mut = entityName.left;
100
+ continue leftmost;
101
+ }
102
+ else {
103
+ return entityName.getText();
104
+ }
105
+ break;
106
+ }
107
+ };
108
+ const visit = (node) => {
109
+ if (node.kind === 187) {
110
+ addToSet(leftmost(node.exprName), roots);
111
+ }
112
+ return ts.forEachChild(node, visit);
113
+ };
114
+ const enumerator = getEnumerator(sourceFiles);
115
+ try {
116
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
117
+ visit(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]());
118
+ }
119
+ }
120
+ finally {
121
+ disposeSafe(enumerator);
122
+ }
123
+ return roots;
124
+ }
125
+
28
126
  function declarationKey(glueType) {
29
127
  switch (glueType.tag) {
30
128
  case 1:
@@ -45,8 +143,8 @@ function declarationKey(glueType) {
45
143
  }
46
144
 
47
145
  function dropShadowedReExports(types) {
48
- const localKeys = ofSeq(collect((glueType) => {
49
- if (glueType.tag === 32) {
146
+ const localKeys = ofSeq(collect_1((glueType) => {
147
+ if (glueType.tag === 33) {
50
148
  return empty();
51
149
  }
52
150
  else {
@@ -66,8 +164,8 @@ function dropShadowedReExports(types) {
66
164
  }, types), {
67
165
  Compare: (x, y) => (compareArrays(x, y) | 0),
68
166
  });
69
- const localNames = ofSeq(choose((glueType_1) => {
70
- if (glueType_1.tag === 32) {
167
+ const localNames = ofSeq(choose_1((glueType_1) => {
168
+ if (glueType_1.tag === 33) {
71
169
  return undefined;
72
170
  }
73
171
  else {
@@ -86,7 +184,7 @@ function dropShadowedReExports(types) {
86
184
  let modulePath;
87
185
  const seen = tupledArg[0];
88
186
  const acc = tupledArg[1];
89
- if (glueType_2.tag === 32) {
187
+ if (glueType_2.tag === 33) {
90
188
  const reExport = glueType_2.fields[0];
91
189
  const matchValue_1 = declarationKey(reExport.Declaration);
92
190
  if (matchValue_1 == null) {
@@ -121,13 +219,13 @@ function dropShadowedReExports(types) {
121
219
  else {
122
220
  return [seen, cons(glueType_2, acc)];
123
221
  }
124
- }, types, [empty_1({
222
+ }, types, [empty_2({
125
223
  Compare: (x_2, y_2) => (compareArrays(x_2, y_2) | 0),
126
224
  }), empty()])[1];
127
225
  }
128
226
 
129
227
  function nestByName(fileModules) {
130
- return map((tupledArg) => {
228
+ return map_1((tupledArg) => {
131
229
  let Types;
132
230
  const head = tupledArg[0];
133
231
  const group = tupledArg[1];
@@ -136,24 +234,24 @@ function nestByName(fileModules) {
136
234
  if (!isEmpty(ownModules)) {
137
235
  const rest = tail(ownModules);
138
236
  const first = head_1(ownModules);
139
- ownModule = ((Types = dropShadowedReExports(append(first.Types, collect((_arg) => _arg.Types, rest))), new GlueFileModule(first.Name, first.ImportSpecifier, fold((acc, other) => fold_1(FSharpMap__Add, acc, other.SymbolSpecifiers), first.SymbolSpecifiers, rest), first.IsGlobal, first.HasRuntime, Types)));
237
+ ownModule = ((Types = dropShadowedReExports(append(first.Types, collect_1((_arg) => _arg.Types, rest))), new GlueFileModule(first.Name, first.ImportSpecifier, fold((acc, other) => fold_1(FSharpMap__Add, acc, other.SymbolSpecifiers), first.SymbolSpecifiers, rest), first.IsGlobal, first.HasRuntime, Types)));
140
238
  }
141
239
  else {
142
240
  ownModule = undefined;
143
241
  }
144
- const nested = nestByName(map((fileModule_3) => (new GlueFileModule(substring(fileModule_3.Name, head.length + 1), fileModule_3.ImportSpecifier, fileModule_3.SymbolSpecifiers, fileModule_3.IsGlobal, fileModule_3.HasRuntime, fileModule_3.Types)), filter((fileModule_2) => (fileModule_2.Name !== head), group)));
242
+ const nested = nestByName(map_1((fileModule_3) => (new GlueFileModule(substring(fileModule_3.Name, head.length + 1), fileModule_3.ImportSpecifier, fileModule_3.SymbolSpecifiers, fileModule_3.IsGlobal, fileModule_3.HasRuntime, fileModule_3.Types)), filter((fileModule_2) => (fileModule_2.Name !== head), group)));
145
243
  if (ownModule == null) {
146
- return new GlueType(/* FileModule */ 31, [new GlueFileModule(head, "", empty_1({
244
+ return new GlueType(/* FileModule */ 32, [new GlueFileModule(head, "", empty_2({
147
245
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
148
246
  }), false, false, nested)]);
149
247
  }
150
248
  else if (isEmpty(nested)) {
151
249
  const fileModule_4 = ownModule;
152
- return new GlueType(/* FileModule */ 31, [fileModule_4]);
250
+ return new GlueType(/* FileModule */ 32, [fileModule_4]);
153
251
  }
154
252
  else {
155
253
  const fileModule_5 = ownModule;
156
- return new GlueType(/* FileModule */ 31, [new GlueFileModule(fileModule_5.Name, fileModule_5.ImportSpecifier, fileModule_5.SymbolSpecifiers, fileModule_5.IsGlobal, fileModule_5.HasRuntime, append(fileModule_5.Types, nested))]);
254
+ return new GlueType(/* FileModule */ 32, [new GlueFileModule(fileModule_5.Name, fileModule_5.ImportSpecifier, fileModule_5.SymbolSpecifiers, fileModule_5.IsGlobal, fileModule_5.HasRuntime, append(fileModule_5.Types, nested))]);
157
255
  }
158
256
  }, List_groupBy((fileModule) => item(0, split(fileModule.Name, ["."], undefined, 0)), fileModules, {
159
257
  Equals: (x, y) => (x === y),
@@ -182,7 +280,7 @@ function extractGlobals(types) {
182
280
 
183
281
  function readStatements(reader, sourceFile) {
184
282
  const promoted = promotedAmbientModule(sourceFile);
185
- return dropShadowedReExports(collect((statement) => {
283
+ return dropShadowedReExports(collect_1((statement) => {
186
284
  const matchValue = statement.kind;
187
285
  let matchResult;
188
286
  switch (matchValue) {
@@ -233,9 +331,9 @@ function readStatements(reader, sourceFile) {
233
331
 
234
332
  export function readSourceFile(checker, sourceFile) {
235
333
  const reader = TypeScriptReader_$ctor_26550FA4(checker);
236
- const GlueAST = readStatements(reader, value_1(sourceFile));
334
+ const GlueAST = readStatements(reader, value_3(sourceFile));
237
335
  let ImportSpecifier;
238
- const option = promotedAmbientModule(value_1(sourceFile));
336
+ const option = promotedAmbientModule(value_3(sourceFile));
239
337
  let mapping;
240
338
  const ambientModuleNames = ambientModuleNames_1(checker);
241
339
  mapping = ((moduleDeclaration) => ambientModuleSpecifier(ambientModuleNames, moduleDeclaration));
@@ -265,10 +363,10 @@ function nestAmbientModules(packageContext, package$, fileName, types) {
265
363
  return false;
266
364
  }
267
365
  }, types);
268
- const patternInput_2 = partition((tupledArg_3) => isEmpty(tupledArg_3[0]), map((tupledArg_1) => {
366
+ const patternInput_2 = partition((tupledArg_3) => isEmpty(tupledArg_3[0]), map_1((tupledArg_1) => {
269
367
  const group = tupledArg_1[1];
270
- return [tupledArg_1[0], head_1(group)[1], dropShadowedReExports(collect((tupledArg_2) => tupledArg_2[2], group))];
271
- }, List_groupBy((tupledArg) => tupledArg[0], choose((_arg_1) => {
368
+ return [tupledArg_1[0], head_1(group)[1], dropShadowedReExports(collect_1((tupledArg_2) => tupledArg_2[2], group))];
369
+ }, List_groupBy((tupledArg) => tupledArg[0], choose_1((_arg_1) => {
272
370
  if (_arg_1.tag === 11) {
273
371
  const info_1 = _arg_1.fields[0];
274
372
  const name = removeSurroundingQuotes(info_1.Name);
@@ -283,7 +381,7 @@ function nestAmbientModules(packageContext, package$, fileName, types) {
283
381
  })));
284
382
  const own = patternInput_2[0];
285
383
  const patternInput_3 = !isEmpty(own) ? (isEmpty(tail(own)) ? [head_1(own)[2], head_1(own)[1]] : [empty(), undefined]) : [empty(), undefined];
286
- return [patternInput[1], append(patternInput_3[0], concat(map((tupledArg_4) => fold((types_3, segment) => singleton(new GlueType(/* FileModule */ 31, [new GlueFileModule(segment, tupledArg_4[1], empty_1({
384
+ return [patternInput[1], append(patternInput_3[0], concat(map_1((tupledArg_4) => fold((types_3, segment) => singleton(new GlueType(/* FileModule */ 32, [new GlueFileModule(segment, tupledArg_4[1], empty_2({
287
385
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
288
386
  }), false, package$.HasRuntime, types_3)])), tupledArg_4[2], reverse(tupledArg_4[0])), patternInput_2[1]))), patternInput_3[1]];
289
387
  }
@@ -295,57 +393,213 @@ function nestAmbientModules(packageContext, package$, fileName, types) {
295
393
  export function readPackages(checker, packageContext, sourceFiles) {
296
394
  const reader = TypeScriptReader_$ctor_26550FA4(checker, packageContext);
297
395
  const ambientModules = ambientModuleNames_1(checker);
298
- const glueAst = collect((package$_2) => {
299
- let package$;
396
+ const filesOfPackage = (package$) => sortBy((sourceFile_2) => {
397
+ if (normalizePath(sourceFile_2.fileName) === package$.EntryFile) {
398
+ return 0;
399
+ }
400
+ else {
401
+ return 1;
402
+ }
403
+ }, sortBy((sourceFile_1) => normalizePath(sourceFile_1.fileName), filter((sourceFile) => {
404
+ const matchValue = PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile.fileName);
405
+ if (matchValue == null) {
406
+ return false;
407
+ }
408
+ else {
409
+ return matchValue.Dir === package$.Dir;
410
+ }
411
+ }, sourceFiles), {
412
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
413
+ }), {
414
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
415
+ });
416
+ const glueAst = collect_1((package$_2) => {
300
417
  let patternInput_5;
301
418
  const package$_1 = package$_2;
302
419
  const globals = [];
303
420
  const unexported = [];
304
421
  const hoistedSpecifiers = [];
305
422
  const hoistedTypes = [];
306
- const patternInput_4 = partition((_arg_1) => {
307
- if (_arg_1.tag === 1) {
423
+ const typeofRoots_1 = new Lazy(() => typeofRoots(filesOfPackage(package$_1)));
424
+ const markUnexported = (isExported, types_1) => {
425
+ const isUnexported = (name) => {
426
+ if (isExported(name)) {
427
+ return false;
428
+ }
429
+ else {
430
+ void (unexported.push(name));
431
+ return true;
432
+ }
433
+ };
434
+ return choose_1((_arg_1) => {
435
+ let info_6;
436
+ let matchResult, info_3, info_4, info_5;
437
+ switch (_arg_1.tag) {
438
+ case 12: {
439
+ if (isUnexported(_arg_1.fields[0].Name)) {
440
+ matchResult = 0;
441
+ info_3 = _arg_1.fields[0];
442
+ }
443
+ else {
444
+ matchResult = 4;
445
+ }
446
+ break;
447
+ }
448
+ case 6: {
449
+ if (isUnexported(_arg_1.fields[0].Name)) {
450
+ matchResult = 1;
451
+ info_4 = _arg_1.fields[0];
452
+ }
453
+ else {
454
+ matchResult = 4;
455
+ }
456
+ break;
457
+ }
458
+ case 2: {
459
+ if (isUnexported(_arg_1.fields[0].Name)) {
460
+ matchResult = 2;
461
+ info_5 = _arg_1.fields[0];
462
+ }
463
+ else {
464
+ matchResult = 4;
465
+ }
466
+ break;
467
+ }
468
+ case 25: {
469
+ switch (_arg_1.fields[0].tag) {
470
+ case 6: {
471
+ if (isUnexported("default")) {
472
+ matchResult = 3;
473
+ }
474
+ else {
475
+ matchResult = 4;
476
+ }
477
+ break;
478
+ }
479
+ case 2: {
480
+ if (isUnexported("default")) {
481
+ matchResult = 3;
482
+ }
483
+ else {
484
+ matchResult = 4;
485
+ }
486
+ break;
487
+ }
488
+ default:
489
+ matchResult = 4;
490
+ }
491
+ break;
492
+ }
493
+ default:
494
+ matchResult = 4;
495
+ }
496
+ switch (matchResult) {
497
+ case 0:
498
+ return new GlueType(/* ClassDeclaration */ 12, [new GlueClassDeclaration(info_3.Documentation, info_3.FullName, info_3.Name, info_3.Constructors, info_3.Members, info_3.TypeParameters, info_3.HeritageClauses, false)]);
499
+ case 1:
500
+ return undefined;
501
+ case 2:
502
+ return undefined;
503
+ case 3:
504
+ return undefined;
505
+ default: {
506
+ let matchResult_1, info_7, glueType;
507
+ if (_arg_1.tag === 11) {
508
+ if ((info_6 = _arg_1.fields[0], (!info_6.IsGlobal && !(info_6.Name.startsWith("\"") ? true : info_6.Name.startsWith("\'"))) && isUnexported(info_6.Name))) {
509
+ matchResult_1 = 0;
510
+ info_7 = _arg_1.fields[0];
511
+ }
512
+ else {
513
+ matchResult_1 = 1;
514
+ glueType = _arg_1;
515
+ }
516
+ }
517
+ else {
518
+ matchResult_1 = 1;
519
+ glueType = _arg_1;
520
+ }
521
+ switch (matchResult_1) {
522
+ case 0:
523
+ return new GlueType(/* ModuleDeclaration */ 11, [new GlueModuleDeclaration(info_7.Documentation, info_7.Name, info_7.IsTopLevel, info_7.IsNamespace, info_7.IsGlobal, false, info_7.IsRecursive, typeofRoots_1.Value.has(info_7.Name) ? info_7.Types : filter((_arg) => {
524
+ let matchResult_2;
525
+ switch (_arg.tag) {
526
+ case 6:
527
+ case 2: {
528
+ matchResult_2 = 0;
529
+ break;
530
+ }
531
+ case 25: {
532
+ switch (_arg.fields[0].tag) {
533
+ case 6:
534
+ case 2: {
535
+ matchResult_2 = 0;
536
+ break;
537
+ }
538
+ default:
539
+ matchResult_2 = 1;
540
+ }
541
+ break;
542
+ }
543
+ default:
544
+ matchResult_2 = 1;
545
+ }
546
+ switch (matchResult_2) {
547
+ case 0:
548
+ return false;
549
+ default:
550
+ return true;
551
+ }
552
+ }, info_7.Types))]);
553
+ default:
554
+ return glueType;
555
+ }
556
+ }
557
+ }
558
+ }, types_1);
559
+ };
560
+ const patternInput_4 = partition((_arg_4) => {
561
+ if (_arg_4.tag === 1) {
308
562
  return false;
309
563
  }
310
564
  else {
311
565
  return true;
312
566
  }
313
- }, choose((sourceFile_3) => {
314
- let specifier, isUnexported;
315
- const fileName_1 = normalizePath(sourceFile_3.fileName);
567
+ }, choose_1((sourceFile_3) => {
568
+ let specifier, unexportedNames;
569
+ const fileName = normalizePath(sourceFile_3.fileName);
316
570
  const patternInput = extractGlobals(readStatements(reader, sourceFile_3));
317
- const types_2 = patternInput[0];
571
+ const types_4 = patternInput[0];
318
572
  addRangeInPlace(patternInput[1], globals);
319
573
  let promotedSpecifier;
320
574
  const option_1 = promotedAmbientModule(sourceFile_3);
321
575
  promotedSpecifier = ((option_1 != null) ? ambientModuleSpecifier(ambientModules, option_1) : undefined);
322
- const moduleName = PackageContext__FileModuleName_Z11793CAF(packageContext, package$_1, fileName_1);
576
+ const moduleName = PackageContext__FileModuleName_Z11793CAF(packageContext, package$_1, fileName);
323
577
  let patternInput_2;
324
578
  if (ts.isExternalModule(sourceFile_3)) {
325
- patternInput_2 = [empty(), types_2, undefined];
579
+ patternInput_2 = [empty(), types_4, undefined];
326
580
  }
327
581
  else if (isScript(sourceFile_3)) {
328
- patternInput_2 = nestAmbientModules(packageContext, package$_1, fileName_1, types_2);
582
+ patternInput_2 = nestAmbientModules(packageContext, package$_1, fileName, types_4);
329
583
  }
330
584
  else {
331
- const patternInput_1 = nestAmbientModules(packageContext, package$_1, fileName_1, types_2);
585
+ const patternInput_1 = nestAmbientModules(packageContext, package$_1, fileName, types_4);
332
586
  patternInput_2 = [empty(), append(patternInput_1[0], patternInput_1[1]), patternInput_1[2]];
333
587
  }
334
- const types_3 = patternInput_2[1];
588
+ const types_5 = patternInput_2[1];
335
589
  const scriptGlobals = patternInput_2[0];
336
590
  const ownSpecifier_1 = patternInput_2[2];
337
- const importSpecifier = (promotedSpecifier == null) ? ((ownSpecifier_1 == null) ? PackageContext__ImportSpecifier_Z721C83C5(packageContext, fileName_1) : ((specifier = ownSpecifier_1, specifier))) : ((specifier = promotedSpecifier, specifier));
338
- const fileModule = (types_4) => (new FSharpChoice$2(/* Choice2Of2 */ 1, [new GlueType(/* FileModule */ 31, [new GlueFileModule(moduleName, importSpecifier, PackageContext__SymbolSpecifiers_Z721C83C5(packageContext, fileName_1), false, package$_1.HasRuntime, types_4)])]));
339
- if (fileName_1 === package$_1.EntryFile) {
340
- return new FSharpChoice$2(/* Choice1Of2 */ 0, [[append(scriptGlobals, types_3), isScript(sourceFile_3)]]);
591
+ const importSpecifier = (promotedSpecifier == null) ? ((ownSpecifier_1 == null) ? PackageContext__ImportSpecifier_Z721C83C5(packageContext, fileName) : ((specifier = ownSpecifier_1, specifier))) : ((specifier = promotedSpecifier, specifier));
592
+ const fileModule = (types_6) => (new FSharpChoice$2(/* Choice2Of2 */ 1, [new GlueType(/* FileModule */ 32, [new GlueFileModule(moduleName, importSpecifier, PackageContext__SymbolSpecifiers_Z721C83C5(packageContext, fileName), false, package$_1.HasRuntime, types_6)])]));
593
+ if (fileName === package$_1.EntryFile) {
594
+ return new FSharpChoice$2(/* Choice1Of2 */ 0, [[append(scriptGlobals, (ts.isExternalModule(sourceFile_3)) ? ((unexportedNames = unexportedDeclarationNames(checker, sourceFile_3), markUnexported((arg) => !FSharpSet__Contains(unexportedNames, arg), types_5))) : types_5), isScript(sourceFile_3)]]);
341
595
  }
342
596
  else if (isScript(sourceFile_3)) {
343
597
  addRangeInPlace(scriptGlobals, globals);
344
- if (isEmpty(types_3)) {
598
+ if (isEmpty(types_5)) {
345
599
  return undefined;
346
600
  }
347
601
  else {
348
- return fileModule(types_3);
602
+ return fileModule(types_5);
349
603
  }
350
604
  }
351
605
  else {
@@ -355,117 +609,90 @@ export function readPackages(checker, packageContext, sourceFiles) {
355
609
  return false;
356
610
  }
357
611
  else {
358
- return PackageContext__IsHoisted_32BC514A(packageContext, package$_1, fileName_1, matchValue_2[1]);
612
+ return PackageContext__IsHoisted_32BC514A(packageContext, package$_1, fileName, matchValue_2[1]);
359
613
  }
360
- }, (isUnexported = ((name) => {
361
- if (PackageContext__IsImportable_Z384F8060(packageContext, fileName_1, name)) {
362
- return false;
363
- }
364
- else {
365
- void (unexported.push(name));
366
- return true;
367
- }
368
- }), choose((_arg) => {
369
- let info_6;
370
- let matchResult, info_3, info_4, info_5;
371
- switch (_arg.tag) {
372
- case 12: {
373
- if (isUnexported(_arg.fields[0].Name)) {
374
- matchResult = 0;
375
- info_3 = _arg.fields[0];
376
- }
377
- else {
378
- matchResult = 4;
379
- }
380
- break;
381
- }
614
+ }, markUnexported((name_1) => PackageContext__IsImportable_Z384F8060(packageContext, fileName, name_1), types_5));
615
+ const kept = patternInput_3[1];
616
+ const hoisted = patternInput_3[0];
617
+ let hoisted_1;
618
+ const declaredValues = ofSeq(choose_1((_arg_2) => {
619
+ let matchResult_3, info_8, info_9;
620
+ switch (_arg_2.tag) {
382
621
  case 6: {
383
- if (isUnexported(_arg.fields[0].Name)) {
384
- matchResult = 1;
385
- info_4 = _arg.fields[0];
386
- }
387
- else {
388
- matchResult = 4;
389
- }
390
- break;
391
- }
392
- case 2: {
393
- if (isUnexported(_arg.fields[0].Name)) {
394
- matchResult = 2;
395
- info_5 = _arg.fields[0];
396
- }
397
- else {
398
- matchResult = 4;
399
- }
622
+ matchResult_3 = 0;
623
+ info_8 = _arg_2.fields[0];
400
624
  break;
401
625
  }
402
626
  case 25: {
403
- switch (_arg.fields[0].tag) {
627
+ switch (_arg_2.fields[0].tag) {
404
628
  case 6: {
405
- if (isUnexported("default")) {
406
- matchResult = 3;
407
- }
408
- else {
409
- matchResult = 4;
410
- }
629
+ matchResult_3 = 0;
630
+ info_8 = _arg_2.fields[0].fields[0];
411
631
  break;
412
632
  }
413
- case 2: {
414
- if (isUnexported("default")) {
415
- matchResult = 3;
416
- }
417
- else {
418
- matchResult = 4;
419
- }
633
+ case 12: {
634
+ matchResult_3 = 1;
635
+ info_9 = _arg_2.fields[0].fields[0];
420
636
  break;
421
637
  }
422
638
  default:
423
- matchResult = 4;
639
+ matchResult_3 = 2;
424
640
  }
425
641
  break;
426
642
  }
643
+ case 12: {
644
+ matchResult_3 = 1;
645
+ info_9 = _arg_2.fields[0];
646
+ break;
647
+ }
427
648
  default:
428
- matchResult = 4;
649
+ matchResult_3 = 2;
429
650
  }
430
- switch (matchResult) {
651
+ switch (matchResult_3) {
431
652
  case 0:
432
- return new GlueType(/* ClassDeclaration */ 12, [new GlueClassDeclaration(info_3.Documentation, info_3.FullName, info_3.Name, info_3.Constructors, info_3.Members, info_3.TypeParameters, info_3.HeritageClauses, false)]);
653
+ return info_8.Name;
433
654
  case 1:
655
+ return info_9.Name;
656
+ default:
434
657
  return undefined;
435
- case 2:
436
- return undefined;
437
- case 3:
438
- return undefined;
439
- default: {
440
- let matchResult_1, info_7, glueType;
441
- if (_arg.tag === 11) {
442
- if ((info_6 = _arg.fields[0], (!info_6.IsGlobal && !(info_6.Name.startsWith("\"") ? true : info_6.Name.startsWith("\'"))) && isUnexported(info_6.Name))) {
443
- matchResult_1 = 0;
444
- info_7 = _arg.fields[0];
445
- }
446
- else {
447
- matchResult_1 = 1;
448
- glueType = _arg;
449
- }
658
+ }
659
+ }, hoisted), {
660
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
661
+ });
662
+ hoisted_1 = choose_1((_arg_3) => {
663
+ let matchResult_4, info_11, inner_1, glueType_2;
664
+ if (_arg_3.tag === 25) {
665
+ if (_arg_3.fields[0].tag === 2) {
666
+ if (FSharpSet__Contains(declaredValues, _arg_3.fields[0].fields[0].Name)) {
667
+ matchResult_4 = 0;
668
+ info_11 = _arg_3.fields[0].fields[0];
450
669
  }
451
670
  else {
452
- matchResult_1 = 1;
453
- glueType = _arg;
454
- }
455
- switch (matchResult_1) {
456
- case 0:
457
- return new GlueType(/* ModuleDeclaration */ 11, [new GlueModuleDeclaration(info_7.Documentation, info_7.Name, info_7.IsTopLevel, info_7.IsNamespace, info_7.IsGlobal, false, info_7.IsRecursive, info_7.Types)]);
458
- default:
459
- return glueType;
671
+ matchResult_4 = 1;
672
+ inner_1 = _arg_3.fields[0];
460
673
  }
461
674
  }
675
+ else {
676
+ matchResult_4 = 1;
677
+ inner_1 = _arg_3.fields[0];
678
+ }
462
679
  }
463
- }, types_3)));
464
- const kept = patternInput_3[1];
465
- const hoisted = patternInput_3[0];
466
- if (!isEmpty(hoisted)) {
467
- addRangeInPlace(toSeq(PackageContext__SymbolSpecifiers_Z721C83C5(packageContext, fileName_1)), hoistedSpecifiers);
468
- addRangeInPlace(hoisted, hoistedTypes);
680
+ else {
681
+ matchResult_4 = 2;
682
+ glueType_2 = _arg_3;
683
+ }
684
+ switch (matchResult_4) {
685
+ case 0:
686
+ return undefined;
687
+ case 1:
688
+ return inner_1;
689
+ default:
690
+ return glueType_2;
691
+ }
692
+ }, hoisted);
693
+ if (!isEmpty(hoisted_1)) {
694
+ addRangeInPlace(toSeq(PackageContext__SymbolSpecifiers_Z721C83C5(packageContext, fileName)), hoistedSpecifiers);
695
+ addRangeInPlace(hoisted_1, hoistedTypes);
469
696
  }
470
697
  if (isEmpty(kept)) {
471
698
  return undefined;
@@ -474,58 +701,39 @@ export function readPackages(checker, packageContext, sourceFiles) {
474
701
  return fileModule(kept);
475
702
  }
476
703
  }
477
- }, (package$ = package$_1, sortBy((sourceFile_2) => {
478
- if (normalizePath(sourceFile_2.fileName) === package$.EntryFile) {
479
- return 0;
480
- }
481
- else {
482
- return 1;
483
- }
484
- }, sortBy((sourceFile_1) => normalizePath(sourceFile_1.fileName), filter((sourceFile) => {
485
- const matchValue = PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile.fileName);
486
- if (matchValue == null) {
487
- return false;
488
- }
489
- else {
490
- return matchValue.Dir === package$.Dir;
491
- }
492
- }, sourceFiles), {
493
- Compare: (x, y) => (comparePrimitives(x, y) | 0),
494
- }), {
495
- Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
496
- }))));
704
+ }, filesOfPackage(package$_1)));
497
705
  const entryTypes = patternInput_4[0];
498
- const entryIsGlobal = exists((_arg_2) => {
499
- if (_arg_2.tag === 1) {
706
+ const entryIsGlobal = exists_1((_arg_5) => {
707
+ if (_arg_5.tag === 1) {
500
708
  return false;
501
709
  }
502
710
  else {
503
- return _arg_2.fields[0][1];
711
+ return _arg_5.fields[0][1];
504
712
  }
505
713
  }, entryTypes);
506
- const entryTypes_1 = dropShadowedReExports(append(collect((_arg_3) => {
507
- if (_arg_3.tag === 1) {
714
+ const entryTypes_1 = dropShadowedReExports(append(collect_1((_arg_6) => {
715
+ if (_arg_6.tag === 1) {
508
716
  return empty();
509
717
  }
510
718
  else {
511
- return _arg_3.fields[0][0];
719
+ return _arg_6.fields[0][0];
512
720
  }
513
721
  }, entryTypes), ofSeq_1(hoistedTypes)));
514
- const fileModules_2 = nestByName(choose((_arg_4) => {
515
- let matchResult_2, fileModule_1;
516
- if (_arg_4.tag === 1) {
517
- if (_arg_4.fields[0].tag === 31) {
518
- matchResult_2 = 0;
519
- fileModule_1 = _arg_4.fields[0].fields[0];
722
+ const fileModules_2 = nestByName(choose_1((_arg_7) => {
723
+ let matchResult_5, fileModule_1;
724
+ if (_arg_7.tag === 1) {
725
+ if (_arg_7.fields[0].tag === 32) {
726
+ matchResult_5 = 0;
727
+ fileModule_1 = _arg_7.fields[0].fields[0];
520
728
  }
521
729
  else {
522
- matchResult_2 = 1;
730
+ matchResult_5 = 1;
523
731
  }
524
732
  }
525
733
  else {
526
- matchResult_2 = 1;
734
+ matchResult_5 = 1;
527
735
  }
528
- switch (matchResult_2) {
736
+ switch (matchResult_5) {
529
737
  case 0:
530
738
  return fileModule_1;
531
739
  default:
@@ -537,9 +745,9 @@ export function readPackages(checker, packageContext, sourceFiles) {
537
745
  void (reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]().push(`${package$_1.RuntimeName}: ${unexported.length} declarations are not exported by any entry, they are generated as types only`));
538
746
  }
539
747
  patternInput_5 = [append(entryTypes_1, append(globalsModule, fileModules_2)), entryIsGlobal, ofSeq_2(hoistedSpecifiers, {
540
- Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
748
+ Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
541
749
  })];
542
- return singleton(new GlueType(/* FileModule */ 31, [new GlueFileModule(package$_2.ModuleName, package$_2.RuntimeName, patternInput_5[2], patternInput_5[1], package$_2.HasRuntime, patternInput_5[0])]));
750
+ return singleton(new GlueType(/* FileModule */ 32, [new GlueFileModule(package$_2.ModuleName, package$_2.RuntimeName, patternInput_5[2], patternInput_5[1], package$_2.HasRuntime, patternInput_5[0])]));
543
751
  }, packageContext.Packages);
544
752
  const Warnings = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
545
753
  return {