@glutinum/cli 0.14.1 → 1.0.0-beta.10

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 (64) hide show
  1. package/README.md +16 -0
  2. package/dist/Glutinum.Converter/Abbreviations.js +9 -32
  3. package/dist/Glutinum.Converter/DelegateExtensions.js +378 -0
  4. package/dist/Glutinum.Converter/FreeTypeParameters.js +211 -0
  5. package/dist/Glutinum.Converter/FsharpAST.js +154 -69
  6. package/dist/Glutinum.Converter/Generate.js +44 -23
  7. package/dist/Glutinum.Converter/GlueAST.js +122 -74
  8. package/dist/Glutinum.Converter/Hosting.js +892 -0
  9. package/dist/Glutinum.Converter/Merge.js +469 -301
  10. package/dist/Glutinum.Converter/Packages.js +403 -77
  11. package/dist/Glutinum.Converter/Printer.js +455 -388
  12. package/dist/Glutinum.Converter/Read.js +366 -104
  13. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +9 -9
  14. package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +90 -0
  15. package/dist/Glutinum.Converter/Reader/Declaration.js +24 -30
  16. package/dist/Glutinum.Converter/Reader/Deferred.js +706 -0
  17. package/dist/Glutinum.Converter/Reader/Documentation.js +56 -67
  18. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +105 -38
  19. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +52 -55
  20. package/dist/Glutinum.Converter/Reader/ExpressionWithTypeArguments.js +59 -0
  21. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +28 -16
  22. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +46 -45
  23. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +48 -5
  24. package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +178 -0
  25. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
  26. package/dist/Glutinum.Converter/Reader/MemberTypes.js +126 -0
  27. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +55 -7
  28. package/dist/Glutinum.Converter/Reader/Node.js +23 -26
  29. package/dist/Glutinum.Converter/Reader/Parameters.js +39 -30
  30. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
  31. package/dist/Glutinum.Converter/Reader/TypeNode.js +410 -1545
  32. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +78 -51
  33. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +116 -71
  34. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +25 -7
  35. package/dist/Glutinum.Converter/Reader/Types.js +296 -16
  36. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +21 -34
  37. package/dist/Glutinum.Converter/Reader/UtilityType.js +811 -0
  38. package/dist/Glutinum.Converter/Reader/Utils.js +584 -148
  39. package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
  40. package/dist/Glutinum.Converter/Transform.js +2971 -6875
  41. package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
  42. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
  43. package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
  44. package/dist/Glutinum.Converter/Transformer/Conditionals.js +1087 -0
  45. package/dist/Glutinum.Converter/Transformer/Context.js +678 -0
  46. package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
  47. package/dist/Glutinum.Converter/Transformer/Exports.js +704 -0
  48. package/dist/Glutinum.Converter/Transformer/Heritage.js +493 -0
  49. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
  50. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
  51. package/dist/Glutinum.Converter/Transformer/TypeParameter.js +219 -0
  52. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
  53. package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +356 -0
  54. package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
  55. package/dist/Glutinum.Converter/TypeScript.Extensions.js +193 -211
  56. package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
  57. package/dist/Glutinum.Converter/Utils/String.js +15 -4
  58. package/dist/Program.js +107 -232
  59. package/package.json +4 -3
  60. package/dist/Glutinum.Converter/TypeScript.js +0 -12
  61. package/src/Glutinum.Converter/js/bootstrap.js +0 -123
  62. package/src/Glutinum.Converter/js/host.js +0 -144
  63. package/src/Glutinum.Converter/js/npm.js +0 -137
  64. package/src/Glutinum.Converter/js/resolve.js +0 -402
@@ -1,37 +1,23 @@
1
1
 
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.17.2/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.17.2/List.js";
6
+ import { safeHash, stringHash, equals, comparePrimitives, compareArrays } from "../fable_modules/fable-library-js.5.17.2/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.17.2/Map.js";
8
+ import { GlueClassDeclaration, GlueModuleDeclaration, GlueType, GlueFileModule } from "./GlueAST.js";
9
+ import { split, substring } from "../fable_modules/fable-library-js.5.17.2/String.js";
10
+ import { List_groupBy } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
11
+ import { addRangeInPlace, item } from "../fable_modules/fable-library-js.5.17.2/Array.js";
2
12
  import { TypeScriptReader_$ctor_26550FA4 } from "./Reader/TypeScriptReader.js";
3
- import { unwrap, value } from "../fable_modules/fable-library-js.5.17.2/Option.js";
4
- import { isMergedInterfaceDeclaration, promotedAmbientModule } from "./Reader/Utils.js";
13
+ import { unwrap, value as value_1 } from "../fable_modules/fable-library-js.5.17.2/Option.js";
5
14
  import { removeSurroundingQuotes } from "./Utils/Naming.js";
6
- import { exists, filter, sortBy, isEmpty, partition, collect, singleton, append, fold, empty as empty_1, cons, foldBack, choose, ofSeq } from "../fable_modules/fable-library-js.5.17.2/List.js";
7
- import { ts } from "@ts-morph/bootstrap";
8
- import { FSharpSet__Contains, ofSeq as ofSeq_1 } from "../fable_modules/fable-library-js.5.17.2/Set.js";
9
- import { comparePrimitives, equals, compareArrays } from "../fable_modules/fable-library-js.5.17.2/Util.js";
10
- import { empty, add, tryFind } from "../fable_modules/fable-library-js.5.17.2/Map.js";
11
- import { GlueFileModule, GlueType, GlueModuleDeclaration } from "./GlueAST.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";
12
16
  import { normalizePath } from "./Utils/String.js";
13
- import { addRangeInPlace } from "../fable_modules/fable-library-js.5.17.2/Array.js";
14
- import { PackageContext__TryFindPackage_Z721C83C5, PackageContext__FileModuleName_Z11793CAF, PackageContext__ImportSpecifier_Z721C83C5 } from "./Reader/Types.js";
15
17
  import { FSharpChoice$2 } from "../fable_modules/fable-library-js.5.17.2/Choice.js";
16
18
 
17
- export function readSourceFile(checker, sourceFile) {
18
- let moduleDeclaration;
19
- const reader = TypeScriptReader_$ctor_26550FA4(checker);
20
- const GlueAST = readStatements(reader, value(sourceFile));
21
- let ImportSpecifier;
22
- const option_1 = promotedAmbientModule(value(sourceFile));
23
- ImportSpecifier = ((option_1 != null) ? ((moduleDeclaration = option_1, removeSurroundingQuotes(moduleDeclaration.name.text))) : undefined);
24
- const Warnings = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
25
- return {
26
- GlueAST: GlueAST,
27
- ImportSpecifier: unwrap(ImportSpecifier),
28
- TypeMemory: ofSeq(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_TypeMemory"]()),
29
- Warnings: Warnings,
30
- };
31
- }
32
-
33
19
  function isScript(sourceFile) {
34
- if (!ts.isExternalModule(sourceFile)) {
20
+ if (!(ts.isExternalModule(sourceFile))) {
35
21
  return promotedAmbientModule(sourceFile) == null;
36
22
  }
37
23
  else {
@@ -59,40 +45,72 @@ function declarationKey(glueType) {
59
45
  }
60
46
 
61
47
  function dropShadowedReExports(types) {
62
- const localKeys = ofSeq_1(choose((glueType) => {
63
- if (glueType.tag === 31) {
64
- return undefined;
48
+ const localKeys = ofSeq(collect((glueType) => {
49
+ if (glueType.tag === 32) {
50
+ return empty();
65
51
  }
66
52
  else {
67
- return declarationKey(glueType);
53
+ const matchValue = declarationKey(glueType);
54
+ if (matchValue == null) {
55
+ return empty();
56
+ }
57
+ else if (matchValue[0] === "class") {
58
+ const name = matchValue[1];
59
+ return ofArray([["class", name], ["type", name], ["value", name]]);
60
+ }
61
+ else {
62
+ const key = matchValue;
63
+ return singleton(key);
64
+ }
68
65
  }
69
66
  }, types), {
70
67
  Compare: (x, y) => (compareArrays(x, y) | 0),
71
68
  });
72
- return foldBack((glueType_1, tupledArg) => {
69
+ const localNames = ofSeq(choose((glueType_1) => {
70
+ if (glueType_1.tag === 32) {
71
+ return undefined;
72
+ }
73
+ else {
74
+ const option_1 = declarationKey(glueType_1);
75
+ if (option_1 != null) {
76
+ return option_1[1];
77
+ }
78
+ else {
79
+ return undefined;
80
+ }
81
+ }
82
+ }, types), {
83
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
84
+ });
85
+ return foldBack((glueType_2, tupledArg) => {
73
86
  let modulePath;
74
87
  const seen = tupledArg[0];
75
88
  const acc = tupledArg[1];
76
- if (glueType_1.tag === 31) {
77
- const reExport = glueType_1.fields[0];
78
- const matchValue = declarationKey(reExport.Declaration);
79
- if (matchValue == null) {
80
- return [seen, cons(glueType_1, acc)];
89
+ if (glueType_2.tag === 32) {
90
+ const reExport = glueType_2.fields[0];
91
+ const matchValue_1 = declarationKey(reExport.Declaration);
92
+ if (matchValue_1 == null) {
93
+ if (FSharpSet__Contains(localNames, reExport.Name)) {
94
+ return [seen, acc];
95
+ }
96
+ else {
97
+ return [seen, cons(glueType_2, acc)];
98
+ }
81
99
  }
82
100
  else {
83
- const category = matchValue[0];
84
- const key = [category, reExport.Name];
85
- if (FSharpSet__Contains(localKeys, key)) {
101
+ const category = matchValue_1[0];
102
+ const key_1 = [category, reExport.Name];
103
+ if (FSharpSet__Contains(localKeys, key_1)) {
86
104
  return [seen, acc];
87
105
  }
88
106
  else {
89
- const matchValue_1 = tryFind(key, seen);
90
- if (matchValue_1 == null) {
91
- return [add(key, reExport.ModulePath, seen), cons(glueType_1, acc)];
107
+ const matchValue_2 = tryFind(key_1, seen);
108
+ if (matchValue_2 == null) {
109
+ return [add(key_1, reExport.ModulePath, seen), cons(glueType_2, acc)];
92
110
  }
93
- else if ((modulePath = matchValue_1, (category === "value") && equals(modulePath, reExport.ModulePath))) {
94
- const modulePath_1 = matchValue_1;
95
- return [seen, cons(glueType_1, acc)];
111
+ else if ((modulePath = matchValue_2, (category === "value") && equals(modulePath, reExport.ModulePath))) {
112
+ const modulePath_1 = matchValue_2;
113
+ return [seen, cons(glueType_2, acc)];
96
114
  }
97
115
  else {
98
116
  return [seen, acc];
@@ -101,11 +119,46 @@ function dropShadowedReExports(types) {
101
119
  }
102
120
  }
103
121
  else {
104
- return [seen, cons(glueType_1, acc)];
122
+ return [seen, cons(glueType_2, acc)];
105
123
  }
106
- }, types, [empty({
107
- Compare: (x_1, y_1) => (compareArrays(x_1, y_1) | 0),
108
- }), empty_1()])[1];
124
+ }, types, [empty_1({
125
+ Compare: (x_2, y_2) => (compareArrays(x_2, y_2) | 0),
126
+ }), empty()])[1];
127
+ }
128
+
129
+ function nestByName(fileModules) {
130
+ return map((tupledArg) => {
131
+ let Types;
132
+ const head = tupledArg[0];
133
+ const group = tupledArg[1];
134
+ const ownModules = filter((fileModule_1) => (fileModule_1.Name === head), group);
135
+ let ownModule;
136
+ if (!isEmpty(ownModules)) {
137
+ const rest = tail(ownModules);
138
+ 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)));
140
+ }
141
+ else {
142
+ ownModule = undefined;
143
+ }
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)));
145
+ if (ownModule == null) {
146
+ return new GlueType(/* FileModule */ 31, [new GlueFileModule(head, "", empty_1({
147
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
148
+ }), false, false, nested)]);
149
+ }
150
+ else if (isEmpty(nested)) {
151
+ const fileModule_4 = ownModule;
152
+ return new GlueType(/* FileModule */ 31, [fileModule_4]);
153
+ }
154
+ else {
155
+ 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))]);
157
+ }
158
+ }, List_groupBy((fileModule) => item(0, split(fileModule.Name, ["."], undefined, 0)), fileModules, {
159
+ Equals: (x, y) => (x === y),
160
+ GetHashCode: (x) => (stringHash(x) | 0),
161
+ }));
109
162
  }
110
163
 
111
164
  function extractGlobals(types) {
@@ -118,13 +171,13 @@ function extractGlobals(types) {
118
171
  }
119
172
  else {
120
173
  const patternInput = extractGlobals(glueType.fields[0].Types);
121
- return [append(remaining, singleton(new GlueType(/* ModuleDeclaration */ 11, [new GlueModuleDeclaration(glueType.fields[0].Documentation, glueType.fields[0].Name, glueType.fields[0].IsTopLevel, glueType.fields[0].IsNamespace, glueType.fields[0].IsGlobal, glueType.fields[0].IsRecursive, patternInput[0])]))), append(globals, patternInput[1])];
174
+ return [append(remaining, singleton(new GlueType(/* ModuleDeclaration */ 11, [new GlueModuleDeclaration(glueType.fields[0].Documentation, glueType.fields[0].Name, glueType.fields[0].IsTopLevel, glueType.fields[0].IsNamespace, glueType.fields[0].IsGlobal, glueType.fields[0].IsExported, glueType.fields[0].IsRecursive, patternInput[0])]))), append(globals, patternInput[1])];
122
175
  }
123
176
  }
124
177
  else {
125
178
  return [append(remaining, singleton(glueType)), globals];
126
179
  }
127
- }, [empty_1(), empty_1()], types);
180
+ }, [empty(), empty()], types);
128
181
  }
129
182
 
130
183
  function readStatements(reader, sourceFile) {
@@ -133,7 +186,7 @@ function readStatements(reader, sourceFile) {
133
186
  const matchValue = statement.kind;
134
187
  let matchResult;
135
188
  switch (matchValue) {
136
- case 264: {
189
+ case 265: {
137
190
  if (isMergedInterfaceDeclaration(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"](), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_PackageContext"](), statement)) {
138
191
  matchResult = 1;
139
192
  }
@@ -142,7 +195,7 @@ function readStatements(reader, sourceFile) {
142
195
  }
143
196
  break;
144
197
  }
145
- case 267: {
198
+ case 268: {
146
199
  if ((promoted == null) ? false : (promoted === statement)) {
147
200
  matchResult = 2;
148
201
  }
@@ -151,7 +204,7 @@ function readStatements(reader, sourceFile) {
151
204
  }
152
205
  break;
153
206
  }
154
- case 278: {
207
+ case 279: {
155
208
  matchResult = 0;
156
209
  break;
157
210
  }
@@ -162,7 +215,7 @@ function readStatements(reader, sourceFile) {
162
215
  case 0:
163
216
  return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadExportDeclarationEF24BD1"](statement);
164
217
  case 1:
165
- return empty_1();
218
+ return empty();
166
219
  case 2: {
167
220
  const matchValue_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadNode6C0FD055"](statement);
168
221
  if (matchValue_1.tag === 11) {
@@ -175,7 +228,64 @@ function readStatements(reader, sourceFile) {
175
228
  default:
176
229
  return singleton(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadNode6C0FD055"](statement));
177
230
  }
178
- }, ofSeq(sourceFile.statements)));
231
+ }, ofSeq_1(sourceFile.statements)));
232
+ }
233
+
234
+ export function readSourceFile(checker, sourceFile) {
235
+ const reader = TypeScriptReader_$ctor_26550FA4(checker);
236
+ const GlueAST = readStatements(reader, value_1(sourceFile));
237
+ let ImportSpecifier;
238
+ const option = promotedAmbientModule(value_1(sourceFile));
239
+ let mapping;
240
+ const ambientModuleNames = ambientModuleNames_1(checker);
241
+ mapping = ((moduleDeclaration) => ambientModuleSpecifier(ambientModuleNames, moduleDeclaration));
242
+ const option_1 = option;
243
+ ImportSpecifier = ((option_1 != null) ? mapping(option_1) : undefined);
244
+ const Warnings = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
245
+ return {
246
+ GlueAST: GlueAST,
247
+ ImportSpecifier: unwrap(ImportSpecifier),
248
+ TypeMemory: ofSeq_1(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_TypeMemory"]()),
249
+ Warnings: Warnings,
250
+ };
251
+ }
252
+
253
+ function nestAmbientModules(packageContext, package$, fileName, types) {
254
+ const patternInput = partition((_arg) => {
255
+ if (_arg.tag === 11) {
256
+ const info = _arg.fields[0];
257
+ if (info.Name.startsWith("\"")) {
258
+ return true;
259
+ }
260
+ else {
261
+ return info.Name.startsWith("\'");
262
+ }
263
+ }
264
+ else {
265
+ return false;
266
+ }
267
+ }, types);
268
+ const patternInput_2 = partition((tupledArg_3) => isEmpty(tupledArg_3[0]), map((tupledArg_1) => {
269
+ 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) => {
272
+ if (_arg_1.tag === 11) {
273
+ const info_1 = _arg_1.fields[0];
274
+ const name = removeSurroundingQuotes(info_1.Name);
275
+ return [PackageContext__NestedAmbientModuleSegments_32BC514A(packageContext, package$, fileName, name), PackageContext__AmbientSpecifier_Z721C83C5(packageContext, name), info_1.Types];
276
+ }
277
+ else {
278
+ return undefined;
279
+ }
280
+ }, patternInput[0]), {
281
+ Equals: equals,
282
+ GetHashCode: (x) => (safeHash(x) | 0),
283
+ })));
284
+ const own = patternInput_2[0];
285
+ 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({
287
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
288
+ }), false, package$.HasRuntime, types_3)])), tupledArg_4[2], reverse(tupledArg_4[0])), patternInput_2[1]))), patternInput_3[1]];
179
289
  }
180
290
 
181
291
  /**
@@ -184,61 +294,192 @@ function readStatements(reader, sourceFile) {
184
294
  */
185
295
  export function readPackages(checker, packageContext, sourceFiles) {
186
296
  const reader = TypeScriptReader_$ctor_26550FA4(checker, packageContext);
297
+ const ambientModules = ambientModuleNames_1(checker);
187
298
  const glueAst = collect((package$_2) => {
188
- let patternInput_3;
299
+ let package$;
300
+ let patternInput_5;
189
301
  const package$_1 = package$_2;
190
302
  const globals = [];
191
- const patternInput_2 = partition((_arg_1) => {
303
+ const unexported = [];
304
+ const hoistedSpecifiers = [];
305
+ const hoistedTypes = [];
306
+ const patternInput_4 = partition((_arg_1) => {
192
307
  if (_arg_1.tag === 1) {
193
308
  return false;
194
309
  }
195
310
  else {
196
311
  return true;
197
312
  }
198
- }, choose((sourceFile_2) => {
199
- const fileName = normalizePath(sourceFile_2.fileName);
200
- const patternInput = extractGlobals(readStatements(reader, sourceFile_2));
201
- const types_1 = patternInput[0];
313
+ }, choose((sourceFile_3) => {
314
+ let specifier, isUnexported;
315
+ const fileName_1 = normalizePath(sourceFile_3.fileName);
316
+ const patternInput = extractGlobals(readStatements(reader, sourceFile_3));
317
+ const types_2 = patternInput[0];
202
318
  addRangeInPlace(patternInput[1], globals);
203
- let importSpecifier;
204
- const matchValue_1 = promotedAmbientModule(sourceFile_2);
205
- if (matchValue_1 == null) {
206
- importSpecifier = PackageContext__ImportSpecifier_Z721C83C5(packageContext, fileName);
319
+ let promotedSpecifier;
320
+ const option_1 = promotedAmbientModule(sourceFile_3);
321
+ promotedSpecifier = ((option_1 != null) ? ambientModuleSpecifier(ambientModules, option_1) : undefined);
322
+ const moduleName = PackageContext__FileModuleName_Z11793CAF(packageContext, package$_1, fileName_1);
323
+ let patternInput_2;
324
+ if (ts.isExternalModule(sourceFile_3)) {
325
+ patternInput_2 = [empty(), types_2, undefined];
326
+ }
327
+ else if (isScript(sourceFile_3)) {
328
+ patternInput_2 = nestAmbientModules(packageContext, package$_1, fileName_1, types_2);
207
329
  }
208
330
  else {
209
- const moduleDeclaration = matchValue_1;
210
- importSpecifier = removeSurroundingQuotes(moduleDeclaration.name.text);
211
- }
212
- const fileModule = (types_2) => (new FSharpChoice$2(/* Choice2Of2 */ 1, [new GlueType(/* FileModule */ 30, [new GlueFileModule(PackageContext__FileModuleName_Z11793CAF(packageContext, package$_1, fileName), importSpecifier, false, types_2)])]));
213
- if (fileName === package$_1.EntryFile) {
214
- return new FSharpChoice$2(/* Choice1Of2 */ 0, [[types_1, isScript(sourceFile_2)]]);
215
- }
216
- else if (isScript(sourceFile_2)) {
217
- const patternInput_1 = partition((_arg) => {
218
- if (_arg.tag === 11) {
219
- const info = _arg.fields[0];
220
- if (info.Name.startsWith("\"")) {
221
- return true;
222
- }
223
- else {
224
- return info.Name.startsWith("\'");
225
- }
331
+ const patternInput_1 = nestAmbientModules(packageContext, package$_1, fileName_1, types_2);
332
+ patternInput_2 = [empty(), append(patternInput_1[0], patternInput_1[1]), patternInput_1[2]];
333
+ }
334
+ const types_3 = patternInput_2[1];
335
+ const scriptGlobals = patternInput_2[0];
336
+ 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)]]);
341
+ }
342
+ else if (isScript(sourceFile_3)) {
343
+ addRangeInPlace(scriptGlobals, globals);
344
+ if (isEmpty(types_3)) {
345
+ return undefined;
346
+ }
347
+ else {
348
+ return fileModule(types_3);
349
+ }
350
+ }
351
+ else {
352
+ const patternInput_3 = partition((glueType_1) => {
353
+ const matchValue_2 = declarationKey((glueType_1.tag === 25) ? glueType_1.fields[0] : glueType_1);
354
+ if (matchValue_2 == null) {
355
+ return false;
226
356
  }
227
357
  else {
358
+ return PackageContext__IsHoisted_32BC514A(packageContext, package$_1, fileName_1, matchValue_2[1]);
359
+ }
360
+ }, (isUnexported = ((name) => {
361
+ if (PackageContext__IsImportable_Z384F8060(packageContext, fileName_1, name)) {
228
362
  return false;
229
363
  }
230
- }, types_1);
231
- const ambientModules = patternInput_1[0];
232
- addRangeInPlace(patternInput_1[1], globals);
233
- if (isEmpty(ambientModules)) {
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
+ }
382
+ 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
+ }
400
+ break;
401
+ }
402
+ case 25: {
403
+ switch (_arg.fields[0].tag) {
404
+ case 6: {
405
+ if (isUnexported("default")) {
406
+ matchResult = 3;
407
+ }
408
+ else {
409
+ matchResult = 4;
410
+ }
411
+ break;
412
+ }
413
+ case 2: {
414
+ if (isUnexported("default")) {
415
+ matchResult = 3;
416
+ }
417
+ else {
418
+ matchResult = 4;
419
+ }
420
+ break;
421
+ }
422
+ default:
423
+ matchResult = 4;
424
+ }
425
+ break;
426
+ }
427
+ default:
428
+ matchResult = 4;
429
+ }
430
+ switch (matchResult) {
431
+ 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)]);
433
+ case 1:
434
+ 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
+ }
450
+ }
451
+ 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;
460
+ }
461
+ }
462
+ }
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);
469
+ }
470
+ if (isEmpty(kept)) {
234
471
  return undefined;
235
472
  }
236
473
  else {
237
- return fileModule(ambientModules);
474
+ return fileModule(kept);
238
475
  }
239
476
  }
477
+ }, (package$ = package$_1, sortBy((sourceFile_2) => {
478
+ if (normalizePath(sourceFile_2.fileName) === package$.EntryFile) {
479
+ return 0;
480
+ }
240
481
  else {
241
- return fileModule(types_1);
482
+ return 1;
242
483
  }
243
484
  }, sortBy((sourceFile_1) => normalizePath(sourceFile_1.fileName), filter((sourceFile) => {
244
485
  const matchValue = PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile.fileName);
@@ -246,12 +487,14 @@ export function readPackages(checker, packageContext, sourceFiles) {
246
487
  return false;
247
488
  }
248
489
  else {
249
- return matchValue.Dir === package$_1.Dir;
490
+ return matchValue.Dir === package$.Dir;
250
491
  }
251
492
  }, sourceFiles), {
252
493
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
253
- })));
254
- const entryTypes = patternInput_2[0];
494
+ }), {
495
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
496
+ }))));
497
+ const entryTypes = patternInput_4[0];
255
498
  const entryIsGlobal = exists((_arg_2) => {
256
499
  if (_arg_2.tag === 1) {
257
500
  return false;
@@ -260,29 +503,48 @@ export function readPackages(checker, packageContext, sourceFiles) {
260
503
  return _arg_2.fields[0][1];
261
504
  }
262
505
  }, entryTypes);
263
- const entryTypes_1 = collect((_arg_3) => {
506
+ const entryTypes_1 = dropShadowedReExports(append(collect((_arg_3) => {
264
507
  if (_arg_3.tag === 1) {
265
- return empty_1();
508
+ return empty();
266
509
  }
267
510
  else {
268
511
  return _arg_3.fields[0][0];
269
512
  }
270
- }, entryTypes);
271
- const fileModules_1 = choose((_arg_4) => {
272
- if (_arg_4.tag === 0) {
273
- return undefined;
513
+ }, 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];
520
+ }
521
+ else {
522
+ matchResult_2 = 1;
523
+ }
274
524
  }
275
525
  else {
276
- return _arg_4.fields[0];
526
+ matchResult_2 = 1;
277
527
  }
278
- }, patternInput_2[1]);
279
- patternInput_3 = [append(entryTypes_1, append((globals.length === 0) ? empty_1() : singleton(new GlueType(/* ModuleDeclaration */ 11, [new GlueModuleDeclaration(empty_1(), "global", false, false, true, false, ofSeq(globals))])), fileModules_1)), entryIsGlobal];
280
- return singleton(new GlueType(/* FileModule */ 30, [new GlueFileModule(package$_2.ModuleName, package$_2.RuntimeName, patternInput_3[1], patternInput_3[0])]));
528
+ switch (matchResult_2) {
529
+ case 0:
530
+ return fileModule_1;
531
+ default:
532
+ return undefined;
533
+ }
534
+ }, patternInput_4[1]));
535
+ const globalsModule = (globals.length === 0) ? empty() : singleton(new GlueType(/* ModuleDeclaration */ 11, [new GlueModuleDeclaration(empty(), "global", false, false, true, true, false, ofSeq_1(globals))]));
536
+ if (unexported.length > 0) {
537
+ 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
+ }
539
+ 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),
541
+ })];
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])]));
281
543
  }, packageContext.Packages);
282
544
  const Warnings = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
283
545
  return {
284
546
  GlueAST: glueAst,
285
- TypeMemory: ofSeq(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_TypeMemory"]()),
547
+ TypeMemory: ofSeq_1(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_TypeMemory"]()),
286
548
  Warnings: Warnings,
287
549
  };
288
550
  }