@glutinum/cli 1.0.0-beta.1 → 1.0.0-beta.3

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 (47) 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 +116 -65
  6. package/dist/Glutinum.Converter/Generate.js +38 -25
  7. package/dist/Glutinum.Converter/GlueAST.js +79 -41
  8. package/dist/Glutinum.Converter/Hosting.js +141 -167
  9. package/dist/Glutinum.Converter/Merge.js +369 -337
  10. package/dist/Glutinum.Converter/Packages.js +391 -92
  11. package/dist/Glutinum.Converter/Printer.js +398 -387
  12. package/dist/Glutinum.Converter/Read.js +387 -88
  13. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
  14. package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
  15. package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
  16. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
  17. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
  18. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
  19. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +14 -20
  20. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
  21. package/dist/Glutinum.Converter/Reader/Node.js +8 -11
  22. package/dist/Glutinum.Converter/Reader/Parameters.js +34 -26
  23. package/dist/Glutinum.Converter/Reader/TypeNode.js +1988 -1342
  24. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +32 -44
  25. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
  26. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
  27. package/dist/Glutinum.Converter/Reader/Types.js +290 -15
  28. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
  29. package/dist/Glutinum.Converter/Reader/Utils.js +325 -25
  30. package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
  31. package/dist/Glutinum.Converter/Transform.js +3572 -8415
  32. package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
  33. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
  34. package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
  35. package/dist/Glutinum.Converter/Transformer/Conditionals.js +1149 -0
  36. package/dist/Glutinum.Converter/Transformer/Context.js +666 -0
  37. package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
  38. package/dist/Glutinum.Converter/Transformer/Heritage.js +406 -0
  39. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
  40. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +596 -0
  41. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
  42. package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +353 -0
  43. package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
  44. package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
  45. package/dist/Glutinum.Converter/Utils/String.js +14 -3
  46. package/dist/Program.js +102 -239
  47. package/package.json +3 -2
@@ -1,21 +1,25 @@
1
1
 
2
2
  import { toString, Record } from "../fable_modules/fable-library-js.5.17.2/Types.js";
3
3
  import { GlueModuleDeclaration, GlueType, GlueFileModule, GlueType_$reflection } from "./GlueAST.js";
4
- import { tuple_type, option_type, bool_type, record_type, string_type, list_type } from "../fable_modules/fable-library-js.5.17.2/Reflection.js";
4
+ import { int32_type, tuple_type, option_type, bool_type, record_type, string_type, list_type } from "../fable_modules/fable-library-js.5.17.2/Reflection.js";
5
5
  import { FSharpType_$reflection } from "./FsharpAST.js";
6
- import { Bootstrap_reachableFiles, Bootstrap_createProgramFromFiles, Resolve_listInstalledPackages, Resolve_findPackageDir, Resolve_describePackage, Resolve_resolveInput, Npm_installPackage, createInMemoryHost as createInMemoryHost_1 } from "./Hosting.js";
7
- import { toNullable } from "../fable_modules/fable-library-js.5.17.2/Option.js";
8
- import { FSharpSet__get_IsEmpty, FSharpSet__Contains, filter, map as map_2, ofSeq } from "../fable_modules/fable-library-js.5.17.2/Set.js";
9
- import { stringHash, Exception, defaultOf, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.17.2/Util.js";
6
+ import { Bootstrap_reachableFiles, Bootstrap_createProgramFromFiles, Resolve_findNodeModules, Resolve_findPackageDir, Resolve_resolveInput, Resolve_listInstalledPackages, Resolve_describePackage, Npm_installPackage, createInMemoryHost as createInMemoryHost_1 } from "./Hosting.js";
7
+ import { FSharpSet__get_IsEmpty, filter as filter_2, map as map_3, union, difference, FSharpSet__Contains, empty as empty_1, ofSeq } from "../fable_modules/fable-library-js.5.17.2/Set.js";
8
+ import { stringHash, Exception, defaultOf, equals, compareArrays, comparePrimitives } from "../fable_modules/fable-library-js.5.17.2/Util.js";
10
9
  import { replace, concat, split, substring, join } from "../fable_modules/fable-library-js.5.17.2/String.js";
11
10
  import { map } from "../fable_modules/fable-library-js.5.17.2/Array.js";
12
11
  import { normalizePath } from "./Utils/String.js";
13
- import { append as append_1, contains, sortBy, tryFind, filter as filter_1, exists, cons, collect, toArray, singleton, isEmpty, choose, empty, ofArray, map as map_1 } from "../fable_modules/fable-library-js.5.17.2/List.js";
12
+ import { contains, sortBy, tryFind as tryFind_1, collect, toArray, singleton, isEmpty, choose, empty as empty_2, filter as filter_1, sort, append, exists as exists_1, cons, fold, ofArray, map as map_1 } from "../fable_modules/fable-library-js.5.17.2/List.js";
13
+ import { add, ofSeq as ofSeq_1, toList, FSharpMap__TryFind, FSharpMap__ContainsKey, FSharpMap__Add, containsKey, empty } from "../fable_modules/fable-library-js.5.17.2/Map.js";
14
14
  import { PackageContext__TryFindPackage_Z721C83C5, PackageContext, ExternalPackage, PackageInfo } from "./Reader/Types.js";
15
- import { List_distinct } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
16
- import { singleton as singleton_1, collect as collect_1, empty as empty_1, append, delay, toList } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
15
+ import { choose as choose_1, singleton as singleton_1, collect as collect_1, empty as empty_3, append as append_1, delay, sort as sort_1, toList as toList_1, exists, filter, tryPick, map as map_2, tryFind, fold as fold_1 } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
16
+ import { ambientModuleSpecifier, promotedAmbientModule, ambientModuleNames, $007CHasSymbolFlags$007C_$007C } from "./Reader/Utils.js";
17
+ import { toArray as toArray_1, defaultArg } from "../fable_modules/fable-library-js.5.17.2/Option.js";
18
+ import { defaultMaxOverloads } from "./Transformer/UnionOverloads.js";
19
+ import { List_distinctBy, List_distinct } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
17
20
  import { readPackages } from "./Read.js";
18
- import { applyWith } from "./Transform.js";
21
+ import { TransformOptions, applyWithOptions } from "./Transform.js";
22
+ import { ImportSource } from "./Transformer/Context.js";
19
23
  import { printFileWith, Printer_$ctor } from "./Printer.js";
20
24
 
21
25
  export class GenerationResult extends Record {
@@ -45,40 +49,289 @@ export function installPackage(fileSystem, spec, options) {
45
49
  return Npm_installPackage(fileSystem, spec, options);
46
50
  }
47
51
 
48
- function resolveInput(host, input) {
49
- return Resolve_resolveInput(host, input);
50
- }
52
+ const domLibReplacements = ofSeq(["@types/web", "@typescript/lib-dom"], {
53
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
54
+ });
51
55
 
52
- function describePackage(host, packageDir) {
53
- return toNullable(Resolve_describePackage(host, packageDir));
56
+ function moduleNameForPackage(runtimeName) {
57
+ return join("", map((part) => (part[0].toLocaleUpperCase() + substring(part, 1)), split(runtimeName, ["@", "/", "-", ".", "_"], undefined, 1)));
54
58
  }
55
59
 
56
- function findPackageDir(host, file) {
57
- return toNullable(Resolve_findPackageDir(host, file));
60
+ function toPackageInfo(description) {
61
+ return new PackageInfo(moduleNameForPackage(description.runtimeName), description.runtimeName, description.hasRuntime, normalizePath(description.dir) + "/", normalizePath(description.typesRoot) + "/", normalizePath(description.entryFile), map_1((entry) => [normalizePath(entry.file), entry.subpath], ofArray(description.subpathEntries)), empty({
62
+ Compare: (x, y) => (compareArrays(x, y) | 0),
63
+ }), empty({
64
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
65
+ }), empty({
66
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
67
+ }), empty({
68
+ Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
69
+ }), false, empty_1({
70
+ Compare: (x_4, y_4) => (compareArrays(x_4, y_4) | 0),
71
+ }), empty({
72
+ Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
73
+ }));
58
74
  }
59
75
 
60
- function listInstalledPackages(host) {
61
- return Resolve_listInstalledPackages(host);
76
+ function reExportedNames(program, checker, hasExportsMap, package$) {
77
+ if (!hasExportsMap) {
78
+ return empty({
79
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
80
+ });
81
+ }
82
+ else {
83
+ return fold((acc, tupledArg) => {
84
+ const matchValue = program.getSourceFile(tupledArg[0]);
85
+ if (matchValue != null) {
86
+ const sourceFile = matchValue;
87
+ const matchValue_1 = checker.getSymbolAtLocation(sourceFile);
88
+ if (matchValue_1 != null) {
89
+ const moduleSymbol = matchValue_1;
90
+ return fold_1((acc_1, exportedSymbol) => {
91
+ if (containsKey(exportedSymbol.name, acc_1)) {
92
+ return acc_1;
93
+ }
94
+ else {
95
+ return FSharpMap__Add(acc_1, exportedSymbol.name, tupledArg[1]);
96
+ }
97
+ }, acc, checker.getExportsOfModule(moduleSymbol));
98
+ }
99
+ else {
100
+ return acc;
101
+ }
102
+ }
103
+ else {
104
+ return acc;
105
+ }
106
+ }, empty({
107
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
108
+ }), cons([package$.EntryFile, ""], package$.SubpathEntries));
109
+ }
62
110
  }
63
111
 
64
- function createProgramFromFiles(host, entryFiles, options) {
65
- return Bootstrap_createProgramFromFiles(host, entryFiles, options.withoutDomLib, options.noLib);
112
+ function resolveAlias(checker, symbol) {
113
+ const matchValue = symbol.flags;
114
+ if ($007CHasSymbolFlags$007C_$007C(2097152, matchValue) != null) {
115
+ return checker.getAliasedSymbol(symbol);
116
+ }
117
+ else {
118
+ return symbol;
119
+ }
66
120
  }
67
121
 
68
- function reachableFiles(host, program, entryFiles, excludedRuntimeNames) {
69
- return Bootstrap_reachableFiles(host, program, entryFiles, excludedRuntimeNames);
122
+ function defaultExportOf(program, checker, fileName) {
123
+ let option_5;
124
+ let option_3;
125
+ const option_1 = program.getSourceFile(fileName);
126
+ if (option_1 != null) {
127
+ const sourceFile = option_1;
128
+ option_3 = checker.getSymbolAtLocation(sourceFile);
129
+ }
130
+ else {
131
+ option_3 = undefined;
132
+ }
133
+ if (option_3 != null) {
134
+ const moduleSymbol = option_3;
135
+ option_5 = tryFind((exported) => (exported.name === "default"), checker.getExportsOfModule(moduleSymbol));
136
+ }
137
+ else {
138
+ option_5 = undefined;
139
+ }
140
+ if (option_5 != null) {
141
+ return resolveAlias(checker, option_5);
142
+ }
143
+ else {
144
+ return undefined;
145
+ }
70
146
  }
71
147
 
72
- const domLibReplacements = ofSeq(["@types/web", "@typescript/lib-dom"], {
73
- Compare: (x, y) => (comparePrimitives(x, y) | 0),
74
- });
148
+ function reExportedSymbols(program, checker, hasExportsMap, package$) {
149
+ if (!hasExportsMap) {
150
+ return [empty({
151
+ Compare: (x, y) => (compareArrays(x, y) | 0),
152
+ }), empty({
153
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
154
+ })];
155
+ }
156
+ else {
157
+ const entries = cons([package$.EntryFile, ""], package$.SubpathEntries);
158
+ const entryFiles = ofSeq(map_1((tuple) => tuple[0], entries), {
159
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
160
+ });
161
+ return fold((acc, tupledArg) => {
162
+ const matchValue = program.getSourceFile(tupledArg[0]);
163
+ if (matchValue != null) {
164
+ const sourceFile = matchValue;
165
+ const matchValue_1 = checker.getSymbolAtLocation(sourceFile);
166
+ if (matchValue_1 != null) {
167
+ const moduleSymbol = matchValue_1;
168
+ const tupledArg_3 = acc;
169
+ return fold_1((acc_1, exportedSymbol) => {
170
+ const exportName = exportedSymbol.name;
171
+ const exportedSymbol_1 = resolveAlias(checker, exportedSymbol);
172
+ const matchValue_2 = exportedSymbol_1.declarations;
173
+ if (matchValue_2 != null) {
174
+ const tupledArg_2 = acc_1;
175
+ return fold_1((tupledArg_1, declaration) => {
176
+ const symbols = tupledArg_1[0];
177
+ const defaults = tupledArg_1[1];
178
+ const declaringFile = normalizePath(declaration.getSourceFile().fileName);
179
+ const key = [declaringFile, exportName];
180
+ if ((declaringFile.startsWith(package$.Dir) && !FSharpSet__Contains(entryFiles, declaringFile)) && !FSharpMap__ContainsKey(symbols, key)) {
181
+ let isDefault;
182
+ if (!FSharpMap__ContainsKey(defaults, declaringFile)) {
183
+ const matchValue_3 = defaultExportOf(program, checker, declaringFile);
184
+ isDefault = ((matchValue_3 == null) ? false : (matchValue_3 === exportedSymbol_1));
185
+ }
186
+ else {
187
+ isDefault = false;
188
+ }
189
+ return [FSharpMap__Add(symbols, key, tupledArg[1]), isDefault ? FSharpMap__Add(defaults, declaringFile, exportName) : defaults];
190
+ }
191
+ else {
192
+ return [symbols, defaults];
193
+ }
194
+ }, [tupledArg_2[0], tupledArg_2[1]], matchValue_2);
195
+ }
196
+ else {
197
+ return acc_1;
198
+ }
199
+ }, [tupledArg_3[0], tupledArg_3[1]], checker.getExportsOfModule(moduleSymbol));
200
+ }
201
+ else {
202
+ return acc;
203
+ }
204
+ }
205
+ else {
206
+ return acc;
207
+ }
208
+ }, [empty({
209
+ Compare: (x_3, y_3) => (compareArrays(x_3, y_3) | 0),
210
+ }), empty({
211
+ Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
212
+ })], entries);
213
+ }
214
+ }
75
215
 
76
- function moduleNameForPackage(runtimeName) {
77
- return join("", map((part) => (part[0].toLocaleUpperCase() + substring(part, 1)), split(runtimeName, ["@", "/", "-", ".", "_"], undefined, 1)));
216
+ function declaredNames(program, checker, defaultExportNames, fileName) {
217
+ const matchValue = program.getSourceFile(fileName);
218
+ if (matchValue != null) {
219
+ const sourceFile = matchValue;
220
+ const matchValue_1 = checker.getSymbolAtLocation(sourceFile);
221
+ if (matchValue_1 != null) {
222
+ const moduleSymbol = matchValue_1;
223
+ const normalized = normalizePath(fileName);
224
+ return ofSeq(map_2((exportedSymbol_2) => {
225
+ let option_1;
226
+ if (exportedSymbol_2.name === "default") {
227
+ const matchValue_4 = FSharpMap__TryFind(defaultExportNames, normalized);
228
+ if (matchValue_4 == null) {
229
+ return defaultArg((option_1 = exportedSymbol_2.declarations, (option_1 != null) ? tryPick((declaration_1) => {
230
+ const matchValue_5 = declaration_1.name;
231
+ if (equals(matchValue_5, defaultOf())) {
232
+ return undefined;
233
+ }
234
+ else {
235
+ return matchValue_5.getText();
236
+ }
237
+ }, option_1) : undefined), exportedSymbol_2.name);
238
+ }
239
+ else {
240
+ return matchValue_4;
241
+ }
242
+ }
243
+ else {
244
+ return exportedSymbol_2.name;
245
+ }
246
+ }, filter((exportedSymbol_1) => {
247
+ const matchValue_3 = resolveAlias(checker, exportedSymbol_1).declarations;
248
+ if (matchValue_3 == null) {
249
+ return false;
250
+ }
251
+ else {
252
+ return exists((declaration) => {
253
+ if ((declaration.kind !== 282) && (declaration.kind !== 278)) {
254
+ return normalizePath(declaration.getSourceFile().fileName) === normalized;
255
+ }
256
+ else {
257
+ return false;
258
+ }
259
+ }, matchValue_3);
260
+ }
261
+ }, filter((exportedSymbol) => {
262
+ const matchValue_2 = exportedSymbol.flags;
263
+ let matchResult;
264
+ if ($007CHasSymbolFlags$007C_$007C(512, matchValue_2) != null) {
265
+ matchResult = 0;
266
+ }
267
+ else if ($007CHasSymbolFlags$007C_$007C(1024, matchValue_2) != null) {
268
+ matchResult = 0;
269
+ }
270
+ else {
271
+ matchResult = 1;
272
+ }
273
+ switch (matchResult) {
274
+ case 0:
275
+ return false;
276
+ default:
277
+ return true;
278
+ }
279
+ }, checker.getExportsOfModule(moduleSymbol)))), {
280
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
281
+ });
282
+ }
283
+ else {
284
+ return empty_1({
285
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
286
+ });
287
+ }
288
+ }
289
+ else {
290
+ return empty_1({
291
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
292
+ });
293
+ }
78
294
  }
79
295
 
80
- function toPackageInfo(description) {
81
- return new PackageInfo(moduleNameForPackage(description.runtimeName), description.runtimeName, description.hasRuntime, normalizePath(description.dir) + "/", normalizePath(description.typesRoot) + "/", normalizePath(description.entryFile), map_1((entry) => [normalizePath(entry.file), entry.subpath], ofArray(description.subpathEntries)));
296
+ function hoistableDeclarations(program, checker, package$, reExportedFiles, defaultExportNames) {
297
+ const declaredNames_1 = (fileName) => declaredNames(program, checker, defaultExportNames, fileName);
298
+ const entryNames = declaredNames_1(package$.EntryFile);
299
+ const isEntry = (file) => {
300
+ if (file === package$.EntryFile) {
301
+ return true;
302
+ }
303
+ else {
304
+ return exists_1((tupledArg) => (tupledArg[0] === file), package$.SubpathEntries);
305
+ }
306
+ };
307
+ const candidates = append(sort(map_1((tuple) => tuple[0], filter_1((tupledArg_1) => {
308
+ if (tupledArg_1[1] === "") {
309
+ return !isEntry(tupledArg_1[0]);
310
+ }
311
+ else {
312
+ return false;
313
+ }
314
+ }, toList(reExportedFiles))), {
315
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
316
+ }), toList_1(sort_1(filter((file_2) => {
317
+ if ((file_2.startsWith(package$.Dir) && !(substring(file_2, package$.Dir.length).indexOf("node_modules/") >= 0)) && !isEntry(file_2)) {
318
+ return !FSharpMap__ContainsKey(reExportedFiles, file_2);
319
+ }
320
+ else {
321
+ return false;
322
+ }
323
+ }, map_2((sourceFile) => normalizePath(sourceFile.fileName), program.getSourceFiles())), {
324
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
325
+ })));
326
+ return fold((tupledArg_2, file_3) => {
327
+ const taken = tupledArg_2[0];
328
+ const free = difference(declaredNames_1(file_3), taken);
329
+ return [union(taken, free), union(tupledArg_2[1], map_3((name) => [file_3, name], free, {
330
+ Compare: (x_3, y_3) => (compareArrays(x_3, y_3) | 0),
331
+ }))];
332
+ }, [entryNames, empty_1({
333
+ Compare: (x_2, y_2) => (compareArrays(x_2, y_2) | 0),
334
+ })], candidates)[1];
82
335
  }
83
336
 
84
337
  function isTypeScriptLibFile(fileName) {
@@ -86,21 +339,23 @@ function isTypeScriptLibFile(fileName) {
86
339
  }
87
340
 
88
341
  export class GenerateOptions extends Record {
89
- constructor(ExternalPackages, Externals, ModuleName, Include, NoLib) {
342
+ constructor(ExternalPackages, Externals, ModuleName, GlobalScript, MaxOverloads, Include, NoLib) {
90
343
  super();
91
344
  this.ExternalPackages = ExternalPackages;
92
345
  this.Externals = Externals;
93
346
  this.ModuleName = ModuleName;
347
+ this.GlobalScript = GlobalScript;
348
+ this.MaxOverloads = (MaxOverloads | 0);
94
349
  this.Include = Include;
95
350
  this.NoLib = NoLib;
96
351
  }
97
352
  }
98
353
 
99
354
  export function GenerateOptions_$reflection() {
100
- return record_type("Glutinum.Converter.Packages.GenerateOptions", [], GenerateOptions, () => [["ExternalPackages", bool_type], ["Externals", list_type(tuple_type(string_type, option_type(string_type)))], ["ModuleName", option_type(string_type)], ["Include", list_type(string_type)], ["NoLib", bool_type]]);
355
+ return record_type("Glutinum.Converter.Packages.GenerateOptions", [], GenerateOptions, () => [["ExternalPackages", bool_type], ["Externals", list_type(tuple_type(string_type, option_type(string_type)))], ["ModuleName", option_type(string_type)], ["GlobalScript", bool_type], ["MaxOverloads", int32_type], ["Include", list_type(string_type)], ["NoLib", bool_type]]);
101
356
  }
102
357
 
103
- export const defaultOptions = new GenerateOptions(true, empty(), undefined, empty(), false);
358
+ export const defaultOptions = new GenerateOptions(true, empty_2(), undefined, false, defaultMaxOverloads, empty_2(), false);
104
359
 
105
360
  function splitModuleName(fullName) {
106
361
  const matchValue = fullName.lastIndexOf(".") | 0;
@@ -161,7 +416,7 @@ function isValue(glueType_mut) {
161
416
  }
162
417
 
163
418
  function keepIncluded(included, types) {
164
- const values = map_2((name_1) => substring(name_1, "value:".length), filter((name) => name.startsWith("value:"), included), {
419
+ const values = map_3((name_1) => substring(name_1, "value:".length), filter_2((name) => name.startsWith("value:"), included), {
165
420
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
166
421
  });
167
422
  return choose((glueType) => {
@@ -172,7 +427,7 @@ function keepIncluded(included, types) {
172
427
  return undefined;
173
428
  }
174
429
  else {
175
- return new GlueType(/* FileModule */ 31, [new GlueFileModule(glueType.fields[0].Name, glueType.fields[0].ImportSpecifier, glueType.fields[0].IsGlobal, glueType.fields[0].HasRuntime, matchValue)]);
430
+ return new GlueType(/* FileModule */ 31, [new GlueFileModule(glueType.fields[0].Name, glueType.fields[0].ImportSpecifier, glueType.fields[0].SymbolSpecifiers, glueType.fields[0].IsGlobal, glueType.fields[0].HasRuntime, matchValue)]);
176
431
  }
177
432
  }
178
433
  case 11:
@@ -220,34 +475,34 @@ function keepIncluded(included, types) {
220
475
  }, types);
221
476
  }
222
477
 
223
- const builtInExternalPackageNames = ofArray([["@types/node", "Node", empty()], ["@types/web", "Web", singleton("/typescript/lib/lib.dom")]]);
478
+ const builtInExternalPackageNames = ofArray([["@types/node", "Node", empty_2()], ["@types/web", "Web", singleton("/typescript/lib/lib.dom")]]);
224
479
 
225
480
  /**
226
481
  * Generate a single binding file for the packages, and the packages they depend on.
227
482
  * An empty list generates every package installed in the nearest <c>node_modules</c>.
228
483
  */
229
484
  export function generateWith(options, host, inputs) {
230
- let matchValue_8;
485
+ let option_11, option_8, option_6, option_5, nodeModules, predicate_3, objectArg, option_7, mapping_6, objectArg_1, option_9;
231
486
  const targets = map_1((dir) => {
232
- const matchValue_2 = describePackage(host, dir);
233
- if (equals(matchValue_2, defaultOf())) {
234
- throw new Exception(concat("Could not find a declaration file for the package in ", dir));
487
+ const option_3 = Resolve_describePackage(host, dir);
488
+ if (option_3 != null) {
489
+ return option_3;
235
490
  }
236
491
  else {
237
- return matchValue_2;
492
+ throw new Exception(concat("Could not find a declaration file for the package in ", dir));
238
493
  }
239
- }, isEmpty(inputs) ? ofArray(listInstalledPackages(host)) : List_distinct(map_1((input) => {
240
- const resolved = resolveInput(host, input);
494
+ }, isEmpty(inputs) ? ofArray(Resolve_listInstalledPackages(host)) : List_distinct(map_1((input) => {
495
+ const resolved = Resolve_resolveInput(host, input);
241
496
  if (resolved.kind === "package") {
242
497
  return resolved.packageDir;
243
498
  }
244
499
  else {
245
- const matchValue_1 = findPackageDir(host, resolved.file);
246
- if (matchValue_1 === defaultOf()) {
247
- throw new Exception(concat("Could not find the package of ", resolved.file));
500
+ const option_1 = Resolve_findPackageDir(host, resolved.file);
501
+ if (option_1 != null) {
502
+ return option_1;
248
503
  }
249
504
  else {
250
- return matchValue_1;
505
+ throw new Exception(concat("Could not find the package of ", resolved.file));
251
506
  }
252
507
  }
253
508
  }, inputs), {
@@ -255,87 +510,131 @@ export function generateWith(options, host, inputs) {
255
510
  GetHashCode: (x) => (stringHash(x) | 0),
256
511
  }));
257
512
  const entryFiles = toArray(collect((target) => cons(target.entryFile, map_1((_arg) => _arg.file, ofArray(target.subpathEntries))), targets));
258
- const program = createProgramFromFiles(host, entryFiles, {
259
- noLib: options.NoLib,
260
- withoutDomLib: exists((target_1) => FSharpSet__Contains(domLibReplacements, target_1.name), targets),
261
- });
513
+ const withoutDomLib = exists_1((target_1) => FSharpSet__Contains(domLibReplacements, target_1.name), targets);
514
+ let globalTypePackages;
515
+ const isRuntime = exists_1((target_2) => exists_1((tupledArg) => (tupledArg[0] === target_2.name), builtInExternalPackageNames), targets);
516
+ globalTypePackages = ((options.ExternalPackages && !isRuntime) ? ofArray(toArray_1((option_11 = ((option_8 = ((option_6 = ((option_5 = Resolve_findNodeModules(host, host.cwd), (option_5 != null) ? ((nodeModules = option_5, host.path.join([nodeModules, "@types/node"]))) : undefined)), (predicate_3 = ((objectArg = host.fs, (path) => objectArg.directoryExists(path))), (option_7 = option_6, (option_7 != null) ? (predicate_3(option_7) ? option_7 : undefined) : undefined)))), (mapping_6 = ((objectArg_1 = host.fs, (path_1) => objectArg_1.realPath(path_1))), (option_9 = option_8, (option_9 != null) ? mapping_6(option_9) : undefined)))), (option_11 != null) ? Resolve_describePackage(host, option_11) : undefined))) : empty_2());
517
+ const program = Bootstrap_createProgramFromFiles(host, entryFiles, map_1((_arg_3) => _arg_3.runtimeName, globalTypePackages), withoutDomLib, options.NoLib);
262
518
  const checker = program.getTypeChecker();
263
- const targetDirs_1 = ofSeq(map_1((target_2) => normalizePath(target_2.dir), targets), {
519
+ const targetDirSet = ofSeq(map_1((target_3) => normalizePath(target_3.dir), targets), {
264
520
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
265
521
  });
266
- const describeReachable = (excludedRuntimeNames) => choose((dir_3) => {
267
- const matchValue_4 = describePackage(host, dir_3);
268
- if (equals(matchValue_4, defaultOf())) {
269
- return undefined;
522
+ const describeReachable = (excludedRuntimeNames) => choose((packageDir_1) => Resolve_describePackage(host, packageDir_1), filter_1((dir_1) => !FSharpSet__Contains(targetDirSet, dir_1), List_distinct(choose((arg) => {
523
+ const option_14 = Resolve_findPackageDir(host, arg);
524
+ if (option_14 != null) {
525
+ return normalizePath(option_14);
270
526
  }
271
527
  else {
272
- return matchValue_4;
273
- }
274
- }, filter_1((dir_2) => !FSharpSet__Contains(targetDirs_1, dir_2), List_distinct(choose((fileName_1) => {
275
- const matchValue_3 = findPackageDir(host, fileName_1);
276
- if (matchValue_3 === defaultOf()) {
277
528
  return undefined;
278
529
  }
279
- else {
280
- return normalizePath(matchValue_3);
281
- }
282
- }, filter_1((fileName) => !isTypeScriptLibFile(fileName), ofArray(reachableFiles(host, program, entryFiles, toArray(excludedRuntimeNames))))), {
530
+ }, filter_1((fileName) => !isTypeScriptLibFile(fileName), ofArray(Bootstrap_reachableFiles(host, program, entryFiles, toArray(excludedRuntimeNames))))), {
283
531
  Equals: (x_2, y_2) => (x_2 === y_2),
284
532
  GetHashCode: (x_2) => (stringHash(x_2) | 0),
285
533
  })));
286
- const externalPackageNames = toList(delay(() => append(options.ExternalPackages ? builtInExternalPackageNames : empty_1(), delay(() => collect_1((matchValue_5) => singleton_1([matchValue_5[0], matchValue_5[1], empty()]), options.Externals)))));
534
+ const externalPackageNames = toList_1(delay(() => append_1(options.ExternalPackages ? builtInExternalPackageNames : empty_3(), delay(() => collect_1((matchValue_1) => singleton_1([matchValue_1[0], matchValue_1[1], empty_2()]), options.Externals)))));
287
535
  let externals;
288
536
  if (isEmpty(externalPackageNames)) {
289
- externals = empty();
537
+ externals = empty_2();
290
538
  }
291
539
  else {
292
- const reachable = describeReachable(empty());
293
- externals = map_1((tupledArg_1) => {
294
- let package$_1, option_1;
295
- const name_2 = tupledArg_1[0];
296
- const moduleName_1 = tupledArg_1[1];
297
- const package$ = tryFind((description_2) => (description_2.name === name_2), reachable);
298
- return new ExternalPackage((moduleName_1 == null) ? ((package$ == null) ? moduleNameForPackage(replace(name_2, "@types/", "")) : ((package$_1 = package$, moduleNameForPackage(package$_1.runtimeName)))) : moduleName_1, (option_1 = package$, (option_1 != null) ? toPackageInfo(option_1) : undefined), tupledArg_1[2]);
299
- }, filter_1((tupledArg) => !exists((target_3) => (target_3.name === tupledArg[0]), targets), externalPackageNames));
540
+ const reachable = List_distinctBy((_arg_4) => _arg_4.name, append(describeReachable(empty_2()), globalTypePackages), {
541
+ Equals: (x_3, y_3) => (x_3 === y_3),
542
+ GetHashCode: (x_3) => (stringHash(x_3) | 0),
543
+ });
544
+ externals = map_1((tupledArg_2) => {
545
+ let package$_1, option_16;
546
+ const name_3 = tupledArg_2[0];
547
+ const moduleName_1 = tupledArg_2[1];
548
+ const package$ = tryFind_1((description) => (description.name === name_3), reachable);
549
+ return new ExternalPackage((moduleName_1 == null) ? ((package$ == null) ? moduleNameForPackage(replace(name_3, "@types/", "")) : ((package$_1 = package$, moduleNameForPackage(package$_1.runtimeName)))) : moduleName_1, (option_16 = package$, (option_16 != null) ? toPackageInfo(option_16) : undefined), tupledArg_2[2]);
550
+ }, filter_1((tupledArg_1) => !exists_1((target_4) => (target_4.name === tupledArg_1[0]), targets), externalPackageNames));
300
551
  }
301
552
  const externalRuntimeNames = choose((external) => {
302
- const option_3 = external.Package;
303
- if (option_3 != null) {
304
- return option_3.RuntimeName;
553
+ const option_18 = external.Package;
554
+ if (option_18 != null) {
555
+ return option_18.RuntimeName;
305
556
  }
306
557
  else {
307
558
  return undefined;
308
559
  }
309
560
  }, externals);
310
- const dependencies = sortBy((_arg_4) => _arg_4.runtimeName, filter_1((description_4) => !contains(description_4.runtimeName, externalRuntimeNames, {
311
- Equals: (x_3, y_3) => (x_3 === y_3),
312
- GetHashCode: (x_3) => (stringHash(x_3) | 0),
561
+ const dependencies = sortBy((_arg_8) => _arg_8.runtimeName, filter_1((description_2) => !contains(description_2.runtimeName, externalRuntimeNames, {
562
+ Equals: (x_4, y_4) => (x_4 === y_4),
563
+ GetHashCode: (x_4) => (stringHash(x_4) | 0),
313
564
  }), describeReachable(externalRuntimeNames)), {
314
- Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
565
+ Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
315
566
  });
316
567
  let patternInput;
317
- const matchValue_7 = options.ModuleName;
318
- patternInput = ((matchValue_7 == null) ? ["Glutinum", ""] : splitModuleName(matchValue_7));
568
+ const matchValue_3 = options.ModuleName;
569
+ patternInput = ((matchValue_3 == null) ? ["Glutinum", ""] : splitModuleName(matchValue_3));
319
570
  const moduleName_3 = patternInput[1];
320
571
  const targetPackages = map_1((package$_2) => {
321
572
  if (moduleName_3 === "") {
322
573
  return package$_2;
323
574
  }
324
575
  else {
325
- return new PackageInfo(moduleName_3, package$_2.RuntimeName, package$_2.HasRuntime, package$_2.Dir, package$_2.TypesRoot, package$_2.EntryFile, package$_2.SubpathEntries);
576
+ return new PackageInfo(moduleName_3, package$_2.RuntimeName, package$_2.HasRuntime, package$_2.Dir, package$_2.TypesRoot, package$_2.EntryFile, package$_2.SubpathEntries, package$_2.ReExportedSymbols, package$_2.ReExportedFiles, package$_2.ReExportedNames, package$_2.DefaultExportNames, package$_2.HasExportsMap, package$_2.HoistableDeclarations, package$_2.AmbientModuleFiles);
326
577
  }
327
578
  }, map_1(toPackageInfo, targets));
328
579
  const included = ofSeq(options.Include, {
329
- Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
330
- });
331
- const packageContext = new PackageContext(append_1(targetPackages, map_1(toPackageInfo, dependencies)), externals, (name_3) => ((options.NoLib && !FSharpSet__get_IsEmpty(included)) && !FSharpSet__Contains(included, name_3)));
332
- const readerResult = readPackages(checker, packageContext, filter_1((sourceFile) => (PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile.fileName) != null), toList(program.getSourceFiles())));
333
- const transformResult = applyWith("REPLACE_ME_WITH_MODULE_NAME", readerResult.TypeMemory, (matchValue_8 = options.Include, isEmpty(matchValue_8) ? readerResult.GlueAST : keepIncluded(ofSeq(matchValue_8, {
334
580
  Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
335
- }), readerResult.GlueAST)));
581
+ });
582
+ const exportsMapPackages = ofSeq(map_1((description_5) => (normalizePath(description_5.dir) + "/"), filter_1((description_4) => description_4.hasExportsMap, append(targets, dependencies))), {
583
+ Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
584
+ });
585
+ const ambientNames = ambientModuleNames(checker);
586
+ const packageContext = new PackageContext(map_1((package$_3) => {
587
+ const hasExportsMap = FSharpSet__Contains(exportsMapPackages, package$_3.Dir);
588
+ const ambientModuleFiles = ofSeq_1(choose_1((sourceFile) => {
589
+ const fileName_1 = normalizePath(sourceFile.fileName);
590
+ if (fileName_1.startsWith(package$_3.Dir)) {
591
+ const option_20 = promotedAmbientModule(sourceFile);
592
+ if (option_20 != null) {
593
+ return [fileName_1, ambientModuleSpecifier(ambientNames, option_20)];
594
+ }
595
+ else {
596
+ return undefined;
597
+ }
598
+ }
599
+ else {
600
+ return undefined;
601
+ }
602
+ }, program.getSourceFiles()), {
603
+ Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
604
+ });
605
+ const patternInput_1 = reExportedSymbols(program, checker, hasExportsMap, package$_3);
606
+ const symbols = patternInput_1[0];
607
+ const defaultExportNames = patternInput_1[1];
608
+ let reExportedFiles;
609
+ const list_28 = toList(symbols);
610
+ reExportedFiles = fold((acc, tupledArg_3) => {
611
+ const file_1 = tupledArg_3[0][0];
612
+ if (containsKey(file_1, acc)) {
613
+ return acc;
614
+ }
615
+ else {
616
+ return add(file_1, tupledArg_3[1], acc);
617
+ }
618
+ }, empty({
619
+ Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
620
+ }), list_28);
621
+ const HoistableDeclarations = hasExportsMap ? hoistableDeclarations(program, checker, package$_3, reExportedFiles, defaultExportNames) : empty_1({
622
+ Compare: (x_10, y_10) => (compareArrays(x_10, y_10) | 0),
623
+ });
624
+ return new PackageInfo(package$_3.ModuleName, package$_3.RuntimeName, package$_3.HasRuntime, package$_3.Dir, package$_3.TypesRoot, package$_3.EntryFile, package$_3.SubpathEntries, symbols, reExportedFiles, reExportedNames(program, checker, hasExportsMap, package$_3), defaultExportNames, hasExportsMap, HoistableDeclarations, ambientModuleFiles);
625
+ }, append(targetPackages, map_1(toPackageInfo, dependencies))), externals, (name_4) => ((options.NoLib && !FSharpSet__get_IsEmpty(included)) && !FSharpSet__Contains(included, name_4)), ambientNames);
626
+ const readerResult = readPackages(checker, packageContext, filter_1((sourceFile_1) => (PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile_1.fileName) != null), toList_1(program.getSourceFiles())));
627
+ let glueAst;
628
+ const matchValue_4 = options.Include;
629
+ glueAst = (isEmpty(matchValue_4) ? readerResult.GlueAST : keepIncluded(ofSeq(matchValue_4, {
630
+ Compare: (x_11, y_11) => (comparePrimitives(x_11, y_11) | 0),
631
+ }), readerResult.GlueAST));
632
+ const transformResult = applyWithOptions(new TransformOptions(new ImportSource(/* Module */ 0, ["REPLACE_ME_WITH_MODULE_NAME", empty({
633
+ Compare: (x_12, y_12) => (comparePrimitives(x_12, y_12) | 0),
634
+ })]), options.MaxOverloads), readerResult.TypeMemory, glueAst);
336
635
  const printer = Printer_$ctor();
337
- printFileWith(patternInput[0], true, map_1((_arg_5) => _arg_5.ModuleName, externals), printer, transformResult);
338
- return new GenerationResult(readerResult.GlueAST, transformResult.FSharpAST, toString(printer), toList(delay(() => append(readerResult.Warnings, delay(() => transformResult.Warnings)))), toList(transformResult.Errors));
636
+ printFileWith(patternInput[0], true, map_1((_arg_10) => _arg_10.ModuleName, externals), printer, transformResult);
637
+ return new GenerationResult(readerResult.GlueAST, transformResult.FSharpAST, toString(printer), toList_1(delay(() => append_1(readerResult.Warnings, delay(() => transformResult.Warnings)))), toList_1(transformResult.Errors));
339
638
  }
340
639
 
341
640
  export function generate(host, inputs) {