@powerlines/deepkit 0.5.1 → 0.5.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 (62) hide show
  1. package/dist/capnp.cjs +49 -48
  2. package/dist/capnp.js +4 -3
  3. package/dist/{chunk-U5O6DHJ2.js → chunk-35PNVYKI.js} +4 -4
  4. package/dist/chunk-3GQAWCBQ.js +10 -0
  5. package/dist/{chunk-PKLLVKY2.cjs → chunk-3GRTJOID.cjs} +9 -9
  6. package/dist/{chunk-ESVH44QW.cjs → chunk-3PKIT7K2.cjs} +4 -4
  7. package/dist/{chunk-MEMIQ5AA.js → chunk-47WBQTA6.js} +1 -1
  8. package/dist/chunk-4UQ4UDET.cjs +19685 -0
  9. package/dist/{chunk-VMRRVNO2.cjs → chunk-B47NLUDW.cjs} +2 -2
  10. package/dist/chunk-BGYQAVKQ.cjs +13 -0
  11. package/dist/chunk-F5QUFY7D.cjs +135 -0
  12. package/dist/{chunk-4V4LIAN2.js → chunk-GVS5O43Z.js} +2 -2
  13. package/dist/{chunk-YQQIT5YX.js → chunk-JSH5MVQG.js} +2 -2
  14. package/dist/{chunk-VWKKT7CM.cjs → chunk-KDKCOXXC.cjs} +5 -5
  15. package/dist/chunk-KWUXT6EF.js +127 -0
  16. package/dist/{chunk-J2FVIV7W.cjs → chunk-MSO7PT57.cjs} +126 -126
  17. package/dist/chunk-O2LKJ62Q.cjs +2863 -0
  18. package/dist/chunk-U7WEV6HK.js +19678 -0
  19. package/dist/chunk-W423FBJ2.js +2854 -0
  20. package/dist/{chunk-I5CVIT7W.js → chunk-XI47ZADG.js} +42 -42
  21. package/dist/chunk-XU55W26B.js +109 -0
  22. package/dist/esbuild-plugin.cjs +6 -5
  23. package/dist/esbuild-plugin.js +5 -4
  24. package/dist/index.cjs +68 -67
  25. package/dist/index.js +10 -9
  26. package/dist/reflect-type.cjs +8 -7
  27. package/dist/reflect-type.js +7 -6
  28. package/dist/resolve-reflections.cjs +3 -3
  29. package/dist/resolve-reflections.js +2 -2
  30. package/dist/transformer.cjs +5 -4
  31. package/dist/transformer.js +3 -2
  32. package/dist/transpile.cjs +5 -4
  33. package/dist/transpile.js +4 -3
  34. package/dist/utilities.cjs +11 -10
  35. package/dist/utilities.js +4 -3
  36. package/dist/vendor/chunk-5BKT4CS5.js +28 -0
  37. package/dist/vendor/{chunk-ZDFKNN7Y.cjs → chunk-BDXVTHBY.cjs} +322 -153
  38. package/dist/vendor/{chunk-7LAB3COT.js → chunk-BLN7QVCP.js} +154 -7
  39. package/dist/vendor/chunk-EQXMWOHO.cjs +115 -0
  40. package/dist/vendor/chunk-MO4O4UYI.cjs +42 -0
  41. package/dist/vendor/core.cjs +131 -130
  42. package/dist/vendor/core.js +2 -2
  43. package/dist/vendor/index.cjs +28 -0
  44. package/dist/vendor/index.d.cts +2 -0
  45. package/dist/vendor/index.d.ts +2 -0
  46. package/dist/vendor/index.js +1 -0
  47. package/dist/vendor/type-spec.cjs +6 -5
  48. package/dist/vendor/type-spec.js +1 -1
  49. package/dist/vendor/type.cjs +2346 -641
  50. package/dist/vendor/type.js +1661 -23
  51. package/package.json +5 -5
  52. package/dist/chunk-7J3ZDT6O.cjs +0 -30
  53. package/dist/chunk-B6GTAZEL.js +0 -37
  54. package/dist/chunk-FFBZWTR7.cjs +0 -63
  55. package/dist/chunk-GRNJVY7I.cjs +0 -19
  56. package/dist/chunk-IRPJW6HH.js +0 -16
  57. package/dist/chunk-J4SVRFV4.js +0 -127
  58. package/dist/chunk-QLKLDV3V.cjs +0 -135
  59. package/dist/chunk-XGQQM64U.js +0 -8
  60. package/dist/vendor/chunk-SHUYVCID.js +0 -4
  61. package/dist/vendor/chunk-USNT2KNT.cjs +0 -6
  62. /package/dist/{vendor/chunk-5NPGWGPO.cjs → chunk-5NPGWGPO.cjs} +0 -0
@@ -0,0 +1,2863 @@
1
+ 'use strict';
2
+
3
+ var chunk5NPGWGPO_cjs = require('./chunk-5NPGWGPO.cjs');
4
+ var chunkBGYQAVKQ_cjs = require('./chunk-BGYQAVKQ.cjs');
5
+ var ts4 = require('typescript');
6
+ var vfs = require('@typescript/vfs');
7
+ var path = require('path');
8
+ var fs = require('fs');
9
+ var micromatch = require('micromatch');
10
+ var tsCloneNode = require('@marcj/ts-clone-node');
11
+ var defu = require('defu');
12
+
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
+
15
+ var ts4__default = /*#__PURE__*/_interopDefault(ts4);
16
+ var micromatch__default = /*#__PURE__*/_interopDefault(micromatch);
17
+ var defu__default = /*#__PURE__*/_interopDefault(defu);
18
+
19
+ // ../../node_modules/.pnpm/@deepkit+type-compiler@1.0.5_patch_hash=88e8267ac73f46799c551ae3696181dc1f272895f490f8c_ef8b874d406bec4900e1fddc1ea375be/node_modules/@deepkit/type-compiler/dist/esm/src/debug.js
20
+ function isDebug(level = 1) {
21
+ const expected = "deepkit" + (level > 1 ? "+".repeat(level - 1) : "");
22
+ return "undefined" !== typeof process && "string" === typeof process.env.DEBUG && process.env.DEBUG.includes(expected);
23
+ }
24
+ chunkBGYQAVKQ_cjs.__name(isDebug, "isDebug");
25
+ function debug(...message) {
26
+ if (isDebug(1)) {
27
+ console.debug(...message);
28
+ }
29
+ }
30
+ chunkBGYQAVKQ_cjs.__name(debug, "debug");
31
+ function debug2(...message) {
32
+ if (isDebug(2)) {
33
+ console.debug(...message);
34
+ }
35
+ }
36
+ chunkBGYQAVKQ_cjs.__name(debug2, "debug2");
37
+ var { createSourceFile, resolveModuleName, isStringLiteral, JSDocParsingMode, ScriptTarget } = ts4__default.default;
38
+ function patternMatch(path, patterns, base) {
39
+ const include = patterns.filter((pattern) => pattern[0] !== "!");
40
+ const exclude = patterns.filter((pattern) => pattern[0] === "!").map((pattern) => pattern.substring(1));
41
+ return micromatch__default.default.isMatch(path, include, {
42
+ ignore: exclude
43
+ });
44
+ }
45
+ chunkBGYQAVKQ_cjs.__name(patternMatch, "patternMatch");
46
+ var Resolver = class {
47
+ static {
48
+ chunkBGYQAVKQ_cjs.__name(this, "Resolver");
49
+ }
50
+ constructor(compilerOptions, host, sourceFiles) {
51
+ this.compilerOptions = compilerOptions;
52
+ this.host = host;
53
+ this.sourceFiles = sourceFiles;
54
+ }
55
+ resolve(from, importOrExportNode) {
56
+ const moduleSpecifier = importOrExportNode.moduleSpecifier;
57
+ if (!moduleSpecifier) return;
58
+ if (!isStringLiteral(moduleSpecifier)) return;
59
+ return this.resolveSourceFile(from, moduleSpecifier);
60
+ }
61
+ resolveImpl(modulePath, sourceFile) {
62
+ if (this.host.resolveModuleNameLiterals !== void 0) {
63
+ const results = this.host.resolveModuleNameLiterals(
64
+ [
65
+ modulePath
66
+ ],
67
+ sourceFile.fileName,
68
+ /*reusedNames*/
69
+ void 0,
70
+ this.compilerOptions,
71
+ sourceFile,
72
+ void 0
73
+ );
74
+ if (results[0]) return results[0].resolvedModule;
75
+ return;
76
+ }
77
+ if (this.host.resolveModuleNames !== void 0) {
78
+ return this.host.resolveModuleNames(
79
+ [
80
+ modulePath.text
81
+ ],
82
+ sourceFile.fileName,
83
+ /*reusedNames*/
84
+ void 0,
85
+ /*redirectedReference*/
86
+ void 0,
87
+ this.compilerOptions
88
+ )[0];
89
+ }
90
+ const result = resolveModuleName(modulePath.text, sourceFile.fileName, this.compilerOptions, this.host);
91
+ return result.resolvedModule;
92
+ }
93
+ /**
94
+ * Tries to resolve the .ts/d.ts file path for a given module path.
95
+ * Scans relative paths. Looks into package.json "types" and "exports" (with new 4.7 support)
96
+ *
97
+ * @param sourceFile the SourceFile of the file that contains the import. modulePath is relative to that.
98
+ * @param modulePath the x in 'from x'.
99
+ */
100
+ resolveSourceFile(sourceFile, modulePath) {
101
+ const result = this.resolveImpl(modulePath, sourceFile);
102
+ if (!result) return;
103
+ if (!result.resolvedFileName.endsWith(".ts") && !result.resolvedFileName.endsWith(".tsx") && !result.resolvedFileName.endsWith(".d.ts")) {
104
+ return;
105
+ }
106
+ const fileName = result.resolvedFileName;
107
+ if (this.sourceFiles[fileName]) return this.sourceFiles[fileName];
108
+ const source = this.host.readFile(result.resolvedFileName);
109
+ if (!source) return;
110
+ const moduleSourceFile = this.sourceFiles[fileName] = createSourceFile(fileName, source, {
111
+ languageVersion: this.compilerOptions.target || ScriptTarget.ES2018,
112
+ // JSDocParsingMode is not available in TS < 5.3
113
+ jsDocParsingMode: JSDocParsingMode ? JSDocParsingMode.ParseNone : void 0
114
+ }, true);
115
+ this.sourceFiles[fileName] = moduleSourceFile;
116
+ ts4__default.default.bindSourceFile(moduleSourceFile, this.compilerOptions);
117
+ return moduleSourceFile;
118
+ }
119
+ };
120
+
121
+ // ../../node_modules/.pnpm/@deepkit+type-compiler@1.0.5_patch_hash=88e8267ac73f46799c551ae3696181dc1f272895f490f8c_ef8b874d406bec4900e1fddc1ea375be/node_modules/@deepkit/type-compiler/dist/esm/src/config.js
122
+ function isObject(obj) {
123
+ if (!obj) {
124
+ return false;
125
+ }
126
+ return typeof obj === "object" && !Array.isArray(obj);
127
+ }
128
+ chunkBGYQAVKQ_cjs.__name(isObject, "isObject");
129
+ var defaultMergeStrategy = "merge";
130
+ function readTsConfig(parseConfigHost, path$1) {
131
+ const configFile = ts4__default.default.readConfigFile(path$1, (path2) => parseConfigHost.readFile(path2));
132
+ if (configFile.error) {
133
+ debug(`Failed to read tsconfig ${path$1}: ${configFile.error.messageText}`);
134
+ return;
135
+ }
136
+ const parsed = ts4__default.default.parseJsonConfigFileContent(configFile.config, parseConfigHost, path.dirname(path$1));
137
+ const ignoredErrors = [
138
+ 18003
139
+ // No inputs were found in config file.
140
+ ];
141
+ const softErrors = [
142
+ 18e3
143
+ // Circularity detected while resolving configuration
144
+ ];
145
+ const errors = parsed.errors.filter((v) => !ignoredErrors.includes(v.code));
146
+ if (errors.length) {
147
+ debug(`Failed to parse tsconfig ${path$1}: ${parsed.errors.map((v) => v.messageText).join(", ")}`);
148
+ }
149
+ const hardErrors = errors.filter((v) => !softErrors.includes(v.code));
150
+ if (hardErrors.length) {
151
+ return;
152
+ }
153
+ const json = fs.readFileSync(path$1, "utf8");
154
+ const tsconfig = JSON.parse(json);
155
+ return Object.assign(configFile.config, {
156
+ compilerOptions: parsed.options,
157
+ reflectionLevel: tsconfig.reflectionLevel ? String(tsconfig.reflectionLevel) : void 0
158
+ });
159
+ }
160
+ chunkBGYQAVKQ_cjs.__name(readTsConfig, "readTsConfig");
161
+ function reflectionModeMatcher(config, filePath) {
162
+ if (Array.isArray(config.exclude)) {
163
+ if (patternMatch(filePath, config.exclude)) return "never";
164
+ }
165
+ if (Array.isArray(config.reflection)) {
166
+ return patternMatch(filePath, config.reflection) ? "default" : "never";
167
+ }
168
+ if (config.reflection === "default" || config.reflection === "explicit") return config.reflection;
169
+ return "never";
170
+ }
171
+ chunkBGYQAVKQ_cjs.__name(reflectionModeMatcher, "reflectionModeMatcher");
172
+ function ensureStringArray(value) {
173
+ if (Array.isArray(value)) return value.map((v) => "" + v);
174
+ if ("string" === typeof value) return [
175
+ value
176
+ ];
177
+ return [];
178
+ }
179
+ chunkBGYQAVKQ_cjs.__name(ensureStringArray, "ensureStringArray");
180
+ function parseRawMode(mode) {
181
+ if ("boolean" === typeof mode) return mode ? "default" : "never";
182
+ if (mode === "default" || mode === "explicit") return mode;
183
+ return ensureStringArray(mode);
184
+ }
185
+ chunkBGYQAVKQ_cjs.__name(parseRawMode, "parseRawMode");
186
+ function resolvePaths(baseDir, paths) {
187
+ if (!paths || !Array.isArray(paths)) return;
188
+ for (let i = 0; i < paths.length; i++) {
189
+ if ("string" !== typeof paths[i]) continue;
190
+ if (path.isAbsolute(paths[i])) continue;
191
+ let path$1 = paths[i];
192
+ let exclude = false;
193
+ if (path$1.startsWith("!")) {
194
+ exclude = true;
195
+ path$1 = path$1.substring(1);
196
+ }
197
+ if (path$1.startsWith("./") || path$1.includes("/")) {
198
+ path$1 = path.join(baseDir, path$1);
199
+ }
200
+ path$1 = path$1.replace(/\\/g, "/");
201
+ if (exclude) path$1 = "!" + path$1;
202
+ paths[i] = path$1;
203
+ }
204
+ }
205
+ chunkBGYQAVKQ_cjs.__name(resolvePaths, "resolvePaths");
206
+ function appendPaths(strategy = defaultMergeStrategy, parent, existing) {
207
+ if (strategy === "replace") {
208
+ return [
209
+ ...existing || parent
210
+ ];
211
+ }
212
+ if (!existing) return [
213
+ ...parent
214
+ ];
215
+ return [
216
+ ...parent,
217
+ ...existing
218
+ ];
219
+ }
220
+ chunkBGYQAVKQ_cjs.__name(appendPaths, "appendPaths");
221
+ function applyConfigValues(existing, parent, baseDir) {
222
+ const parentReflection = isObject(parent.deepkitCompilerOptions) ? parent.deepkitCompilerOptions?.reflection : parent.reflection;
223
+ const parentReflectionLevel = parent.deepkitCompilerOptions?.reflectionLevel || parent.reflectionLevel || parent.compilerOptions?.reflectionLevel;
224
+ if (isObject(parent.deepkitCompilerOptions) && "undefined" === typeof existing.mergeStrategy) {
225
+ existing.mergeStrategy = parent.deepkitCompilerOptions.mergeStrategy;
226
+ }
227
+ if ("undefined" !== typeof parentReflection) {
228
+ const next = parseRawMode(parentReflection);
229
+ if ("undefined" === typeof existing.reflection) {
230
+ existing.reflection = next;
231
+ } else if ("string" === typeof existing.reflection) ; else if (Array.isArray(next) && Array.isArray(existing.reflection)) {
232
+ existing.reflection = appendPaths(existing.mergeStrategy, next, existing.reflection);
233
+ } else if ("string" === typeof next && Array.isArray(existing.reflection)) ;
234
+ }
235
+ if ("undefined" !== typeof parentReflectionLevel) {
236
+ if ("undefined" === typeof existing.reflectionLevel) {
237
+ existing.reflectionLevel = parentReflectionLevel;
238
+ }
239
+ }
240
+ if (isObject(parent.deepkitCompilerOptions)) {
241
+ if (`undefined` !== typeof parent.deepkitCompilerOptions.exclude) {
242
+ const next = ensureStringArray(parent.deepkitCompilerOptions.exclude);
243
+ existing.exclude = appendPaths(existing.mergeStrategy, next, existing.exclude);
244
+ }
245
+ }
246
+ resolvePaths(baseDir, existing.reflection);
247
+ resolvePaths(baseDir, existing.exclude);
248
+ if (parent.compilerOptions) {
249
+ if (Object.keys(existing.compilerOptions).length === 0) {
250
+ Object.assign(existing.compilerOptions, parent.compilerOptions);
251
+ }
252
+ }
253
+ existing.extends = parent.extends;
254
+ }
255
+ chunkBGYQAVKQ_cjs.__name(applyConfigValues, "applyConfigValues");
256
+ var defaultExcluded = [
257
+ "lib.dom*.d.ts",
258
+ "*typedarrays.d.ts",
259
+ "lib.webworker*.d.ts",
260
+ "lib.decorator*.d.ts",
261
+ "lib.es2015.proxy.d.ts",
262
+ "lib.es2020.sharedmemory.d.ts",
263
+ "lib.es2015.core.d.ts"
264
+ ];
265
+ function getConfigResolver(cache3, host, compilerOptions, sourceFile, tsConfigPath = "") {
266
+ let config = {
267
+ // We use the parameter `compilerOptions` only for compilerOptions.configFilePath.
268
+ // We load the compilerOptions manually since transformers don't get the full picture
269
+ // (path aliases are missing for example).
270
+ // It's important to load compilerOptions manually if there is compilerOptions.configFilePath
271
+ // since not all build tools provide the full compilerOptions.
272
+ compilerOptions: {}
273
+ };
274
+ tsConfigPath = tsConfigPath || ("string" === typeof compilerOptions.configFilePath ? compilerOptions.configFilePath : "");
275
+ if (tsConfigPath) {
276
+ if (cache3[tsConfigPath]) {
277
+ return cache3[tsConfigPath];
278
+ }
279
+ const configFile = readTsConfig(host, tsConfigPath);
280
+ if (configFile) applyConfigValues(config, configFile, path.dirname(tsConfigPath));
281
+ } else {
282
+ if (!tsConfigPath && sourceFile) {
283
+ const baseDir = path.dirname(sourceFile.fileName);
284
+ const configPath = ts4__default.default.findConfigFile(baseDir, (path$1) => {
285
+ path$1 = path.isAbsolute(path$1) ? path$1 : path.join(baseDir, path$1);
286
+ return host.fileExists(path$1);
287
+ });
288
+ debug2(`No tsConfigPath|compilerOptions.configFilePath provided. Manually searching for tsconfig.json in ${baseDir} returned ${configPath}`);
289
+ if (configPath) {
290
+ tsConfigPath = path.isAbsolute(configPath) ? configPath : path.join(baseDir, configPath);
291
+ }
292
+ }
293
+ if (tsConfigPath) {
294
+ if (cache3[tsConfigPath]) return cache3[tsConfigPath];
295
+ const configFile = readTsConfig(host, tsConfigPath);
296
+ if (configFile) applyConfigValues(config, configFile, path.dirname(tsConfigPath));
297
+ }
298
+ }
299
+ if (tsConfigPath) {
300
+ let basePath = path.dirname(tsConfigPath);
301
+ let currentConfig = config;
302
+ const seen = /* @__PURE__ */ new Set();
303
+ seen.add(tsConfigPath);
304
+ while (currentConfig.extends) {
305
+ const path$1 = path.join(basePath, currentConfig.extends);
306
+ if (seen.has(path$1)) break;
307
+ seen.add(path$1);
308
+ const nextConfig = ts4__default.default.readConfigFile(path$1, (path2) => host.readFile(path2));
309
+ if (!nextConfig) break;
310
+ basePath = path.dirname(path$1);
311
+ applyConfigValues(currentConfig, nextConfig.config, basePath);
312
+ }
313
+ } else {
314
+ throw new Error(`No tsconfig found for ${sourceFile?.fileName}, that is weird. Either provide a tsconfig or compilerOptions.configFilePath`);
315
+ }
316
+ config.exclude = config.exclude ? [
317
+ ...defaultExcluded,
318
+ ...config.exclude
319
+ ] : [
320
+ ...defaultExcluded
321
+ ];
322
+ config.compilerOptions.configFilePath = tsConfigPath;
323
+ const resolvedConfig = {
324
+ path: tsConfigPath,
325
+ // we want to maintain options passed from tsc API (transpile, Program)
326
+ compilerOptions: Object.assign(config.compilerOptions, compilerOptions),
327
+ exclude: config.exclude,
328
+ reflection: config.reflection,
329
+ reflectionLevel: config.reflectionLevel || (config.compilerOptions?.reflectionLevel ? String(config.compilerOptions?.reflectionLevel) : void 0) || "normal",
330
+ mergeStrategy: config.mergeStrategy || defaultMergeStrategy
331
+ };
332
+ if (isDebug()) {
333
+ debug(`Found config ${resolvedConfig.path}:
334
+ reflection:`, resolvedConfig.reflection, `
335
+ exclude:`, resolvedConfig.exclude, `
336
+ paths:`, resolvedConfig.compilerOptions.paths);
337
+ }
338
+ const match = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((path) => {
339
+ const mode = reflectionModeMatcher(config, path);
340
+ return {
341
+ mode,
342
+ tsConfigPath,
343
+ level: resolvedConfig.reflectionLevel
344
+ };
345
+ }, "match");
346
+ return cache3[tsConfigPath] = {
347
+ config: resolvedConfig,
348
+ match
349
+ };
350
+ }
351
+ chunkBGYQAVKQ_cjs.__name(getConfigResolver, "getConfigResolver");
352
+ var { isArrowFunction, isComputedPropertyName, isIdentifier, isNamedImports, isNumericLiteral, isPrivateIdentifier, isStringLiteral: isStringLiteral2, isStringLiteralLike, setOriginalNode, getLeadingCommentRanges, isNoSubstitutionTemplateLiteral, NodeFlags, SyntaxKind } = ts4__default.default;
353
+ function is__String(value) {
354
+ return typeof value === "string";
355
+ }
356
+ chunkBGYQAVKQ_cjs.__name(is__String, "is__String");
357
+ function getIdentifierName(node) {
358
+ if (is__String(node)) return node;
359
+ if (isIdentifier(node) || isPrivateIdentifier(node)) {
360
+ return ts4__default.default.unescapeLeadingUnderscores(node.escapedText);
361
+ }
362
+ if (isStringLiteral2(node)) return node.text;
363
+ return "";
364
+ }
365
+ chunkBGYQAVKQ_cjs.__name(getIdentifierName, "getIdentifierName");
366
+ function getEscapedText(node) {
367
+ if (is__String(node)) return node;
368
+ if (isIdentifier(node) || isPrivateIdentifier(node)) return node.escapedText;
369
+ return getIdentifierName(node);
370
+ }
371
+ chunkBGYQAVKQ_cjs.__name(getEscapedText, "getEscapedText");
372
+ function findSourceFile(node) {
373
+ if (node.kind === SyntaxKind.SourceFile) return node;
374
+ let current = node.parent;
375
+ while (current && current.kind !== SyntaxKind.SourceFile) {
376
+ current = current.parent;
377
+ }
378
+ return current;
379
+ }
380
+ chunkBGYQAVKQ_cjs.__name(findSourceFile, "findSourceFile");
381
+ function joinQualifiedName(name) {
382
+ if (isIdentifier(name)) return getIdentifierName(name);
383
+ return joinQualifiedName(name.left) + "_" + getIdentifierName(name.right);
384
+ }
385
+ chunkBGYQAVKQ_cjs.__name(joinQualifiedName, "joinQualifiedName");
386
+ var BANNER_REGEX = /^\/\*\s---.*\n[\s\S]*\s*---\s*\*\//;
387
+ function getCommentOfNode(sourceFile, node) {
388
+ const commentLines = getLeadingCommentRanges(sourceFile.text, node.pos);
389
+ if (!commentLines || commentLines.length === 0) return;
390
+ const commentLine = commentLines.slice(-1)[0];
391
+ if (!commentLine) return;
392
+ const comment = sourceFile.text.slice(commentLine.pos, commentLine.end);
393
+ if (comment.match(BANNER_REGEX)) {
394
+ return void 0;
395
+ }
396
+ return comment;
397
+ }
398
+ chunkBGYQAVKQ_cjs.__name(getCommentOfNode, "getCommentOfNode");
399
+ function parseJSDocAttributeFromText(comment, attribute) {
400
+ const attributeStr = `@${attribute} `;
401
+ const index = comment.indexOf(attributeStr);
402
+ if (index === -1) {
403
+ let start2 = 0;
404
+ while (true) {
405
+ const withoutContent = comment.indexOf(`@${attribute}`, start2);
406
+ if (withoutContent === -1) {
407
+ return [
408
+ void 0,
409
+ -1
410
+ ];
411
+ }
412
+ const nextCharacter = comment[withoutContent + attribute.length + 1];
413
+ if (!nextCharacter || nextCharacter === " " || nextCharacter === "\n" || nextCharacter === "\r" || nextCharacter === " ") {
414
+ return [
415
+ void 0,
416
+ withoutContent + attribute.length + 1
417
+ ];
418
+ }
419
+ start2 = withoutContent + attribute.length + 1;
420
+ }
421
+ }
422
+ const start = index + attributeStr.length;
423
+ const nextAttribute = comment.indexOf("@", start);
424
+ const endOfComment = comment.indexOf("*/", start);
425
+ const end = nextAttribute === -1 ? endOfComment : Math.min(nextAttribute, endOfComment);
426
+ const content = comment.substring(start, end).trim();
427
+ return [
428
+ content.split("\n").map((v) => {
429
+ const indexOfStar = v.indexOf("*");
430
+ if (indexOfStar === -1) {
431
+ return v.trim();
432
+ }
433
+ return v.substring(indexOfStar + 1).trim();
434
+ }).join("\n").replace(/\n*$/g, ""),
435
+ end + 1
436
+ ];
437
+ }
438
+ chunkBGYQAVKQ_cjs.__name(parseJSDocAttributeFromText, "parseJSDocAttributeFromText");
439
+ function parseJSDocBooleanFromText(comment, attribute) {
440
+ return new RegExp(`^s*@(${attribute?.trim()})s*(false|False|FALSE|0|n|N|no|No|NO)s*$`, "gm").test(comment?.trim()) ? false : new RegExp(`^s*@(${attribute?.trim()})s*(true|True|TRUE|1|y|Y|yes|Yes|YES)?s*$`, "gm").test(comment?.trim()) ? true : void 0;
441
+ }
442
+ chunkBGYQAVKQ_cjs.__name(parseJSDocBooleanFromText, "parseJSDocBooleanFromText");
443
+ function parseJSDocDescription(comment) {
444
+ let lines = comment.split("\n").filter((line) => line && !line.includes("/**") && !line.includes("*/")).map((line) => line.replace(/^\s*\*\s*/g, "").replace(/^\*\s*/g, "").trim());
445
+ const attribute = lines.findIndex((line) => line.startsWith("@"));
446
+ if (attribute !== -1) {
447
+ lines = lines.slice(0, attribute);
448
+ }
449
+ return lines.join("\n").trim() || void 0;
450
+ }
451
+ chunkBGYQAVKQ_cjs.__name(parseJSDocDescription, "parseJSDocDescription");
452
+ function extractJSDocAttribute(sourceFile, node, attribute) {
453
+ if (!node) return void 0;
454
+ const comment = getCommentOfNode(sourceFile, node);
455
+ if (!comment) return void 0;
456
+ let result = parseJSDocAttributeFromText(comment, attribute);
457
+ if (!result[0] && attribute === "description") {
458
+ result[0] = parseJSDocDescription(comment);
459
+ }
460
+ return result[0];
461
+ }
462
+ chunkBGYQAVKQ_cjs.__name(extractJSDocAttribute, "extractJSDocAttribute");
463
+ function extractJSDocArray(sourceFile, node, attribute) {
464
+ if (!node) return void 0;
465
+ const comment = getCommentOfNode(sourceFile, node);
466
+ if (!comment) return void 0;
467
+ const results = [];
468
+ try {
469
+ let result = parseJSDocAttributeFromText(comment, attribute);
470
+ if (result.length < 2) {
471
+ return void 0;
472
+ }
473
+ if (result[0] && result[1] > -1) {
474
+ results.push(result[0]);
475
+ }
476
+ let currentComment = comment;
477
+ while (result[1] > -1 && currentComment.length > result[1]) {
478
+ currentComment = currentComment.substring(result[1]);
479
+ result = parseJSDocAttributeFromText(currentComment, attribute);
480
+ if (result[0]) {
481
+ results.push(result[0]);
482
+ }
483
+ }
484
+ } catch (error) {
485
+ console.error("Error parsing JSDoc attribute:", attribute, "in comment:", comment);
486
+ console.error(error);
487
+ }
488
+ return results;
489
+ }
490
+ chunkBGYQAVKQ_cjs.__name(extractJSDocArray, "extractJSDocArray");
491
+ function extractJSDocBoolean(sourceFile, node, attribute) {
492
+ if (!node) {
493
+ return void 0;
494
+ }
495
+ const comment = getCommentOfNode(sourceFile, node);
496
+ if (!comment) {
497
+ return void 0;
498
+ }
499
+ return parseJSDocBooleanFromText(comment, attribute);
500
+ }
501
+ chunkBGYQAVKQ_cjs.__name(extractJSDocBoolean, "extractJSDocBoolean");
502
+ function getPropertyName(f, node) {
503
+ if (!node) return "";
504
+ if (isIdentifier(node)) return getIdentifierName(node);
505
+ if (isStringLiteral2(node)) return node.text;
506
+ if (isNumericLiteral(node)) return +node.text;
507
+ if (isNoSubstitutionTemplateLiteral(node)) return node.text;
508
+ if (isComputedPropertyName(node)) {
509
+ return f.createArrowFunction(void 0, void 0, [], void 0, void 0, node.expression);
510
+ }
511
+ if (isPrivateIdentifier(node)) return getIdentifierName(node);
512
+ return "";
513
+ }
514
+ chunkBGYQAVKQ_cjs.__name(getPropertyName, "getPropertyName");
515
+ function getNameAsString(node) {
516
+ if (!node) return "";
517
+ if (isIdentifier(node)) return getIdentifierName(node);
518
+ if (isStringLiteral2(node)) return node.text;
519
+ if (isNumericLiteral(node)) return node.text;
520
+ if (ts4.isBigIntLiteral(node)) return node.text;
521
+ if (isNoSubstitutionTemplateLiteral(node)) return node.text;
522
+ if (isComputedPropertyName(node)) {
523
+ if (isStringLiteralLike(node) || isNumericLiteral(node)) return node.text;
524
+ return "";
525
+ }
526
+ if (isPrivateIdentifier(node)) return getIdentifierName(node);
527
+ return joinQualifiedName(node);
528
+ }
529
+ chunkBGYQAVKQ_cjs.__name(getNameAsString, "getNameAsString");
530
+ function hasModifier(node, modifier) {
531
+ if (!node.modifiers) return false;
532
+ return node.modifiers.some((v) => v.kind === modifier);
533
+ }
534
+ chunkBGYQAVKQ_cjs.__name(hasModifier, "hasModifier");
535
+ var cloneHook = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((node, payload) => {
536
+ if (isIdentifier(node)) {
537
+ return {
538
+ text: /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name(() => {
539
+ return getIdentifierName(node);
540
+ }, "text")
541
+ };
542
+ }
543
+ return;
544
+ }, "cloneHook");
545
+ var NodeConverter = class {
546
+ static {
547
+ chunkBGYQAVKQ_cjs.__name(this, "NodeConverter");
548
+ }
549
+ constructor(f) {
550
+ this.f = f;
551
+ }
552
+ toExpression(node) {
553
+ if (node === void 0) return this.f.createIdentifier("undefined");
554
+ if (Array.isArray(node)) {
555
+ return this.f.createArrayLiteralExpression(this.f.createNodeArray(node.map((v) => this.toExpression(v))));
556
+ }
557
+ if ("string" === typeof node) return this.f.createStringLiteral(node, true);
558
+ if ("number" === typeof node) return this.f.createNumericLiteral(node);
559
+ if ("bigint" === typeof node) return this.f.createBigIntLiteral(String(node));
560
+ if ("boolean" === typeof node) return node ? this.f.createTrue() : this.f.createFalse();
561
+ if (node.pos === -1 && node.end === -1 && node.parent === void 0) {
562
+ if (isArrowFunction(node)) {
563
+ if (node.body.pos === -1 && node.body.end === -1 && node.body.parent === void 0) return node;
564
+ return this.f.createArrowFunction(node.modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, this.toExpression(node.body));
565
+ }
566
+ return node;
567
+ }
568
+ switch (node.kind) {
569
+ case SyntaxKind.Identifier:
570
+ return finish(node, this.f.createIdentifier(getIdentifierName(node)));
571
+ case SyntaxKind.StringLiteral:
572
+ return finish(node, this.f.createStringLiteral(node.text));
573
+ case SyntaxKind.NumericLiteral:
574
+ return finish(node, this.f.createNumericLiteral(node.text));
575
+ case SyntaxKind.BigIntLiteral:
576
+ return finish(node, this.f.createBigIntLiteral(node.text));
577
+ case SyntaxKind.TrueKeyword:
578
+ return finish(node, this.f.createTrue());
579
+ case SyntaxKind.FalseKeyword:
580
+ return finish(node, this.f.createFalse());
581
+ }
582
+ try {
583
+ return tsCloneNode.cloneNode(node, {
584
+ preserveComments: false,
585
+ factory: this.f,
586
+ setOriginalNodes: true,
587
+ preserveSymbols: true,
588
+ setParents: true,
589
+ hook: cloneHook
590
+ });
591
+ } catch (error) {
592
+ console.error("could not clone node", node);
593
+ throw error;
594
+ }
595
+ }
596
+ };
597
+ function isExternalOrCommonJsModule(file) {
598
+ return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== void 0;
599
+ }
600
+ chunkBGYQAVKQ_cjs.__name(isExternalOrCommonJsModule, "isExternalOrCommonJsModule");
601
+ function isNodeWithLocals(node) {
602
+ return "locals" in node;
603
+ }
604
+ chunkBGYQAVKQ_cjs.__name(isNodeWithLocals, "isNodeWithLocals");
605
+ function getGlobalsOfSourceFile(file) {
606
+ if (file.redirectInfo) return;
607
+ if (!isNodeWithLocals(file)) return;
608
+ if (!isExternalOrCommonJsModule(file)) return file.locals;
609
+ if (file.jsGlobalAugmentations) return file.jsGlobalAugmentations;
610
+ if (file.symbol && file.symbol.globalExports) return file.symbol.globalExports;
611
+ }
612
+ chunkBGYQAVKQ_cjs.__name(getGlobalsOfSourceFile, "getGlobalsOfSourceFile");
613
+ function ensureImportIsEmitted(importDeclaration, specifierName) {
614
+ if (specifierName && importDeclaration.importClause && importDeclaration.importClause.namedBindings) {
615
+ if (isNamedImports(importDeclaration.importClause.namedBindings)) {
616
+ for (const element of importDeclaration.importClause.namedBindings.elements) {
617
+ if (element.name.escapedText === specifierName.escapedText) {
618
+ element.flags |= NodeFlags.Synthesized;
619
+ return;
620
+ }
621
+ }
622
+ }
623
+ }
624
+ importDeclaration.flags |= NodeFlags.Synthesized;
625
+ }
626
+ chunkBGYQAVKQ_cjs.__name(ensureImportIsEmitted, "ensureImportIsEmitted");
627
+ function serializeEntityNameAsExpression(f, node) {
628
+ switch (node.kind) {
629
+ case SyntaxKind.Identifier:
630
+ return finish(node, f.createIdentifier(getIdentifierName(node)));
631
+ case SyntaxKind.QualifiedName:
632
+ return finish(node, serializeQualifiedNameAsExpression(f, node));
633
+ }
634
+ return node;
635
+ }
636
+ chunkBGYQAVKQ_cjs.__name(serializeEntityNameAsExpression, "serializeEntityNameAsExpression");
637
+ function serializeQualifiedNameAsExpression(f, node) {
638
+ return f.createPropertyAccessExpression(serializeEntityNameAsExpression(f, node.left), node.right);
639
+ }
640
+ chunkBGYQAVKQ_cjs.__name(serializeQualifiedNameAsExpression, "serializeQualifiedNameAsExpression");
641
+ function finish(oldNode, newNode) {
642
+ setOriginalNode(newNode, oldNode);
643
+ newNode._original = newNode.original;
644
+ newNode._symbol = oldNode._symbol ?? oldNode.symbol;
645
+ newNode.symbol = newNode._symbol;
646
+ return newNode;
647
+ }
648
+ chunkBGYQAVKQ_cjs.__name(finish, "finish");
649
+
650
+ // ../../node_modules/.pnpm/@deepkit+type-compiler@1.0.5_patch_hash=88e8267ac73f46799c551ae3696181dc1f272895f490f8c_ef8b874d406bec4900e1fddc1ea375be/node_modules/@deepkit/type-compiler/dist/esm/src/compiler.js
651
+ var { visitEachChild, visitNode, isPropertyAssignment, isArrayTypeNode, isArrowFunction: isArrowFunction2, isBlock, isCallExpression, isCallSignatureDeclaration, isClassDeclaration, isClassExpression, isConstructorDeclaration, isConstructorTypeNode, isConstructSignatureDeclaration, isEnumDeclaration, isExportDeclaration, isExpression, isExpressionWithTypeArguments, isFunctionDeclaration, isFunctionExpression, isFunctionLike, isIdentifier: isIdentifier2, isImportClause, isImportDeclaration, isImportSpecifier, isInferTypeNode, isInterfaceDeclaration, isMethodDeclaration, isMethodSignature, isModuleDeclaration, isNamedExports, isNamedTupleMember, isNewExpression, isObjectLiteralExpression, isOptionalTypeNode, isParameter, isParenthesizedExpression, isParenthesizedTypeNode, isPropertyAccessExpression, isQualifiedName, isSourceFile, isStringLiteral: isStringLiteral3, isTypeAliasDeclaration, isTypeLiteralNode, isTypeParameterDeclaration, isTypeQueryNode, isTypeReferenceNode, isUnionTypeNode, isExpressionStatement, isVariableDeclaration, getEffectiveConstraintOfTypeParameter, addSyntheticLeadingComment, createCompilerHost, createPrinter, escapeLeadingUnderscores, EmitHint, NodeFlags: NodeFlags2, SyntaxKind: SyntaxKind2, ScriptTarget: ScriptTarget2, ModifierFlags, ScriptKind } = ts4__default.default;
652
+ function encodeOps(ops) {
653
+ return ops.map((v) => String.fromCharCode(v + 33)).join("");
654
+ }
655
+ chunkBGYQAVKQ_cjs.__name(encodeOps, "encodeOps");
656
+ function filterUndefined(object) {
657
+ return Object.fromEntries(Object.entries(object).filter(([, v]) => v !== void 0));
658
+ }
659
+ chunkBGYQAVKQ_cjs.__name(filterUndefined, "filterUndefined");
660
+ ({
661
+ [chunk5NPGWGPO_cjs.ReflectionOp.literal]: {
662
+ },
663
+ // [ReflectionOp.pointer]: { params: 1 },
664
+ // [ReflectionOp.arg]: { params: 1 },
665
+ [chunk5NPGWGPO_cjs.ReflectionOp.classReference]: {
666
+ },
667
+ [chunk5NPGWGPO_cjs.ReflectionOp.propertySignature]: {
668
+ },
669
+ [chunk5NPGWGPO_cjs.ReflectionOp.property]: {
670
+ },
671
+ [chunk5NPGWGPO_cjs.ReflectionOp.jump]: {
672
+ },
673
+ [chunk5NPGWGPO_cjs.ReflectionOp.enum]: {
674
+ },
675
+ [chunk5NPGWGPO_cjs.ReflectionOp.enumMember]: {
676
+ },
677
+ [chunk5NPGWGPO_cjs.ReflectionOp.typeParameter]: {
678
+ },
679
+ [chunk5NPGWGPO_cjs.ReflectionOp.typeParameterDefault]: {
680
+ },
681
+ [chunk5NPGWGPO_cjs.ReflectionOp.mappedType]: {
682
+ },
683
+ [chunk5NPGWGPO_cjs.ReflectionOp.call]: {
684
+ },
685
+ [chunk5NPGWGPO_cjs.ReflectionOp.inline]: {
686
+ },
687
+ [chunk5NPGWGPO_cjs.ReflectionOp.inlineCall]: {
688
+ },
689
+ [chunk5NPGWGPO_cjs.ReflectionOp.loads]: {
690
+ },
691
+ [chunk5NPGWGPO_cjs.ReflectionOp.extends]: {
692
+ },
693
+ [chunk5NPGWGPO_cjs.ReflectionOp.infer]: {
694
+ },
695
+ [chunk5NPGWGPO_cjs.ReflectionOp.defaultValue]: {
696
+ },
697
+ [chunk5NPGWGPO_cjs.ReflectionOp.parameter]: {
698
+ },
699
+ [chunk5NPGWGPO_cjs.ReflectionOp.method]: {
700
+ },
701
+ [chunk5NPGWGPO_cjs.ReflectionOp.function]: {
702
+ },
703
+ [chunk5NPGWGPO_cjs.ReflectionOp.description]: {
704
+ },
705
+ [chunk5NPGWGPO_cjs.ReflectionOp.numberBrand]: {
706
+ },
707
+ [chunk5NPGWGPO_cjs.ReflectionOp.typeof]: {
708
+ },
709
+ [chunk5NPGWGPO_cjs.ReflectionOp.classExtends]: {
710
+ },
711
+ [chunk5NPGWGPO_cjs.ReflectionOp.distribute]: {
712
+ },
713
+ [chunk5NPGWGPO_cjs.ReflectionOp.jumpCondition]: {
714
+ },
715
+ [chunk5NPGWGPO_cjs.ReflectionOp.typeName]: {
716
+ },
717
+ [chunk5NPGWGPO_cjs.ReflectionOp.implements]: {
718
+ },
719
+ [chunk5NPGWGPO_cjs.ReflectionOp.tags]: {
720
+ }
721
+ });
722
+ function findVariable(frame, name, frameOffset = 0) {
723
+ const variable = frame.variables.find((v) => v.name === name);
724
+ if (variable) {
725
+ return {
726
+ frameOffset,
727
+ stackIndex: variable.index
728
+ };
729
+ }
730
+ if (frame.previous) return findVariable(frame.previous, name, frameOffset + 1);
731
+ return;
732
+ }
733
+ chunkBGYQAVKQ_cjs.__name(findVariable, "findVariable");
734
+ function findConditionalFrame(frame) {
735
+ if (frame.conditional) return frame;
736
+ if (frame.previous) return findConditionalFrame(frame.previous);
737
+ return;
738
+ }
739
+ chunkBGYQAVKQ_cjs.__name(findConditionalFrame, "findConditionalFrame");
740
+ var CompilerProgram = class CompilerProgram2 {
741
+ static {
742
+ chunkBGYQAVKQ_cjs.__name(this, "CompilerProgram");
743
+ }
744
+ constructor(forNode, sourceFile) {
745
+ this.forNode = forNode;
746
+ this.sourceFile = sourceFile;
747
+ this.ops = [];
748
+ this.stack = [];
749
+ this.mainOffset = 0;
750
+ this.stackPosition = 0;
751
+ this.frame = {
752
+ variables: [],
753
+ opIndex: 0
754
+ };
755
+ this.activeCoRoutines = [];
756
+ this.coRoutines = [];
757
+ this.resolveFunctionParameters = /* @__PURE__ */ new Map();
758
+ }
759
+ buildPackStruct() {
760
+ const ops = [
761
+ ...this.ops
762
+ ];
763
+ if (this.coRoutines.length) {
764
+ for (let i = this.coRoutines.length - 1; i >= 0; i--) {
765
+ ops.unshift(...this.coRoutines[i].ops);
766
+ }
767
+ }
768
+ if (this.mainOffset) {
769
+ ops.unshift(chunk5NPGWGPO_cjs.ReflectionOp.jump, this.mainOffset);
770
+ }
771
+ return {
772
+ ops,
773
+ stack: this.stack
774
+ };
775
+ }
776
+ isEmpty() {
777
+ return this.ops.length === 0;
778
+ }
779
+ pushConditionalFrame() {
780
+ const frame = this.pushFrame();
781
+ frame.conditional = true;
782
+ }
783
+ pushStack(item) {
784
+ this.stack.push(item);
785
+ return this.stackPosition++;
786
+ }
787
+ pushCoRoutine() {
788
+ this.pushFrame(true);
789
+ this.activeCoRoutines.push({
790
+ ops: []
791
+ });
792
+ }
793
+ popCoRoutine() {
794
+ const coRoutine = this.activeCoRoutines.pop();
795
+ if (!coRoutine) throw new Error("No active co routine found");
796
+ this.popFrameImplicit();
797
+ if (this.mainOffset === 0) {
798
+ this.mainOffset = 2;
799
+ }
800
+ const startIndex = this.mainOffset;
801
+ coRoutine.ops.push(chunk5NPGWGPO_cjs.ReflectionOp.return);
802
+ this.coRoutines.push(coRoutine);
803
+ this.mainOffset += coRoutine.ops.length;
804
+ return startIndex;
805
+ }
806
+ pushOp(...ops) {
807
+ for (const op of ops) {
808
+ if ("number" !== typeof op) {
809
+ throw new Error("No valid OP added");
810
+ }
811
+ }
812
+ if (this.activeCoRoutines.length) {
813
+ this.activeCoRoutines[this.activeCoRoutines.length - 1].ops.push(...ops);
814
+ return;
815
+ }
816
+ this.ops.push(...ops);
817
+ }
818
+ pushOpAtFrame(frame, ...ops) {
819
+ if (this.activeCoRoutines.length) {
820
+ this.activeCoRoutines[this.activeCoRoutines.length - 1].ops.splice(frame.opIndex, 0, ...ops);
821
+ return;
822
+ }
823
+ this.ops.splice(frame.opIndex, 0, ...ops);
824
+ }
825
+ /**
826
+ * Returns the index of the `entry` in the stack, if already exists. If not, add it, and return that new index.
827
+ */
828
+ findOrAddStackEntry(entry) {
829
+ const index = this.stack.indexOf(entry);
830
+ if (index !== -1) return index;
831
+ return this.pushStack(entry);
832
+ }
833
+ /**
834
+ * To make room for a stack entry expected on the stack as input for example.
835
+ */
836
+ increaseStackPosition() {
837
+ return this.stackPosition++;
838
+ }
839
+ resolveFunctionParametersIncrease(fn) {
840
+ this.resolveFunctionParameters.set(fn, (this.resolveFunctionParameters.get(fn) || 0) + 1);
841
+ }
842
+ resolveFunctionParametersDecrease(fn) {
843
+ this.resolveFunctionParameters.set(fn, (this.resolveFunctionParameters.get(fn) || 1) - 1);
844
+ }
845
+ isResolveFunctionParameters(fn) {
846
+ return (this.resolveFunctionParameters.get(fn) || 0) > 0;
847
+ }
848
+ /**
849
+ *
850
+ * Each pushFrame() call needs a popFrame() call.
851
+ */
852
+ pushFrame(implicit = false) {
853
+ if (!implicit) this.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.frame);
854
+ const opIndex = this.activeCoRoutines.length ? this.activeCoRoutines[this.activeCoRoutines.length - 1].ops.length : this.ops.length;
855
+ this.frame = {
856
+ previous: this.frame,
857
+ variables: [],
858
+ opIndex
859
+ };
860
+ return this.frame;
861
+ }
862
+ findConditionalFrame() {
863
+ return findConditionalFrame(this.frame);
864
+ }
865
+ /**
866
+ * Remove stack without doing it as OP in the processor. Some other command calls popFrame() already, which makes popFrameImplicit() an implicit popFrame.
867
+ * e.g. union, class, etc. all call popFrame(). the current CompilerProgram needs to be aware of that, which this function is for.
868
+ */
869
+ popFrameImplicit() {
870
+ if (this.frame.previous) this.frame = this.frame.previous;
871
+ }
872
+ moveFrame() {
873
+ this.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.moveFrame);
874
+ if (this.frame.previous) this.frame = this.frame.previous;
875
+ }
876
+ pushVariable(name, frame = this.frame) {
877
+ this.pushOpAtFrame(frame, chunk5NPGWGPO_cjs.ReflectionOp.var);
878
+ frame.variables.push({
879
+ index: frame.variables.length,
880
+ name
881
+ });
882
+ return frame.variables.length - 1;
883
+ }
884
+ pushTemplateParameter(name, withDefault = false) {
885
+ this.pushOp(withDefault ? chunk5NPGWGPO_cjs.ReflectionOp.typeParameterDefault : chunk5NPGWGPO_cjs.ReflectionOp.typeParameter, this.findOrAddStackEntry(name));
886
+ this.frame.variables.push({
887
+ index: this.frame.variables.length,
888
+ name
889
+ });
890
+ return this.frame.variables.length - 1;
891
+ }
892
+ findVariable(name, frame = this.frame) {
893
+ return findVariable(frame, name);
894
+ }
895
+ };
896
+ function getAssignTypeExpression(call) {
897
+ if (isParenthesizedExpression(call) && isCallExpression(call.expression)) {
898
+ call = call.expression;
899
+ }
900
+ if (isCallExpression(call) && isIdentifier2(call.expression) && getIdentifierName(call.expression) === "__assignType" && call.arguments.length > 0) {
901
+ return call.arguments[0];
902
+ }
903
+ return;
904
+ }
905
+ chunkBGYQAVKQ_cjs.__name(getAssignTypeExpression, "getAssignTypeExpression");
906
+ function getReceiveTypeParameter(type) {
907
+ if (isUnionTypeNode(type)) {
908
+ for (const t of type.types) {
909
+ const rfn = getReceiveTypeParameter(t);
910
+ if (rfn) return rfn;
911
+ }
912
+ } else if (isTypeReferenceNode(type) && isIdentifier2(type.typeName) && getIdentifierName(type.typeName) === "ReceiveType" && !!type.typeArguments && type.typeArguments.length === 1) return type;
913
+ return;
914
+ }
915
+ chunkBGYQAVKQ_cjs.__name(getReceiveTypeParameter, "getReceiveTypeParameter");
916
+ var Cache = class {
917
+ static {
918
+ chunkBGYQAVKQ_cjs.__name(this, "Cache");
919
+ }
920
+ constructor() {
921
+ this.resolver = {};
922
+ this.sourceFiles = {};
923
+ }
924
+ /**
925
+ * Signals the cache to check if it needs to be cleared.
926
+ */
927
+ tick() {
928
+ if (Object.keys(this.sourceFiles).length > 300) {
929
+ this.sourceFiles = {};
930
+ }
931
+ }
932
+ };
933
+ var ReflectionTransformer = class {
934
+ static {
935
+ chunkBGYQAVKQ_cjs.__name(this, "ReflectionTransformer");
936
+ }
937
+ constructor(context, cache3 = new Cache()) {
938
+ this.context = context;
939
+ this.cache = cache3;
940
+ this.embedAssignType = false;
941
+ this.compileDeclarations = /* @__PURE__ */ new Map();
942
+ this.embedDeclarations = /* @__PURE__ */ new Map();
943
+ this.compiledDeclarations = /* @__PURE__ */ new Set();
944
+ this.addImports = [];
945
+ this.overriddenHost = false;
946
+ this.knownClasses = {
947
+ "Int8Array": chunk5NPGWGPO_cjs.ReflectionOp.int8Array,
948
+ "Uint8Array": chunk5NPGWGPO_cjs.ReflectionOp.uint8Array,
949
+ "Uint8ClampedArray": chunk5NPGWGPO_cjs.ReflectionOp.uint8ClampedArray,
950
+ "Int16Array": chunk5NPGWGPO_cjs.ReflectionOp.int16Array,
951
+ "Uint16Array": chunk5NPGWGPO_cjs.ReflectionOp.uint16Array,
952
+ "Int32Array": chunk5NPGWGPO_cjs.ReflectionOp.int32Array,
953
+ "Uint32Array": chunk5NPGWGPO_cjs.ReflectionOp.uint32Array,
954
+ "Float32Array": chunk5NPGWGPO_cjs.ReflectionOp.float32Array,
955
+ "Float64Array": chunk5NPGWGPO_cjs.ReflectionOp.float64Array,
956
+ "ArrayBuffer": chunk5NPGWGPO_cjs.ReflectionOp.arrayBuffer,
957
+ "BigInt64Array": chunk5NPGWGPO_cjs.ReflectionOp.bigInt64Array,
958
+ "Date": chunk5NPGWGPO_cjs.ReflectionOp.date,
959
+ "RegExp": chunk5NPGWGPO_cjs.ReflectionOp.regexp,
960
+ "String": chunk5NPGWGPO_cjs.ReflectionOp.string,
961
+ "Number": chunk5NPGWGPO_cjs.ReflectionOp.number,
962
+ "BigInt": chunk5NPGWGPO_cjs.ReflectionOp.bigint,
963
+ "Boolean": chunk5NPGWGPO_cjs.ReflectionOp.boolean
964
+ };
965
+ this.f = context.factory;
966
+ this.nodeConverter = new NodeConverter(this.f);
967
+ this.compilerOptions = {
968
+ ...filterUndefined(context.getCompilerOptions())
969
+ };
970
+ this.host = createCompilerHost(this.compilerOptions);
971
+ this.resolver = new Resolver(this.compilerOptions, this.host, this.cache.sourceFiles);
972
+ this.parseConfigHost = {
973
+ useCaseSensitiveFileNames: true,
974
+ fileExists: /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((path) => this.host.fileExists(path), "fileExists"),
975
+ readFile: /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((path) => this.host.readFile(path), "readFile"),
976
+ readDirectory: /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((path, extensions, exclude, include, depth) => {
977
+ if (!this.host.readDirectory) return [];
978
+ return this.host.readDirectory(path, extensions || [], exclude, include || [], depth);
979
+ }, "readDirectory")
980
+ };
981
+ {
982
+ const T = this.f.createIdentifier("T");
983
+ const Options = this.f.createIdentifier("Options");
984
+ this.intrinsicMetaDeclaration = this.f.createTypeAliasDeclaration([], "TypeAnnotation", [
985
+ this.f.createTypeParameterDeclaration([], T),
986
+ this.f.createTypeParameterDeclaration([], Options, void 0, this.f.createTypeReferenceNode("never"))
987
+ ], this.f.createTypeLiteralNode([
988
+ this.f.createPropertySignature(void 0, "__meta", this.f.createToken(SyntaxKind2.QuestionToken), this.f.createIntersectionTypeNode([
989
+ this.f.createTypeReferenceNode("never"),
990
+ this.f.createTupleTypeNode([
991
+ this.f.createTypeReferenceNode(T),
992
+ this.f.createTypeReferenceNode(Options)
993
+ ])
994
+ ]))
995
+ ]));
996
+ }
997
+ }
998
+ forHost(host) {
999
+ this.host = host;
1000
+ this.resolver.host = host;
1001
+ this.overriddenHost = true;
1002
+ return this;
1003
+ }
1004
+ withReflection(config) {
1005
+ const configResolver = {
1006
+ reflectionLevel: "normal",
1007
+ ...config,
1008
+ path: "",
1009
+ mergeStrategy: "replace",
1010
+ compilerOptions: this.compilerOptions
1011
+ };
1012
+ const match = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((path) => {
1013
+ const mode = reflectionModeMatcher(config, path);
1014
+ return {
1015
+ mode,
1016
+ tsConfigPath: "",
1017
+ level: configResolver.reflectionLevel
1018
+ };
1019
+ }, "match");
1020
+ this.overriddenConfigResolver = {
1021
+ config: configResolver,
1022
+ match
1023
+ };
1024
+ return this;
1025
+ }
1026
+ transformBundle(node) {
1027
+ return node;
1028
+ }
1029
+ getTempResultIdentifier() {
1030
+ if (this.tempResultIdentifier) return this.tempResultIdentifier;
1031
+ const locals = isNodeWithLocals(this.sourceFile) ? this.sourceFile.locals : void 0;
1032
+ if (locals) {
1033
+ let found = "\u03A9r";
1034
+ for (let i = 0; ; i++) {
1035
+ found = "\u03A9r" + (i ? i : "");
1036
+ if (!locals.has(escapeLeadingUnderscores(found))) break;
1037
+ }
1038
+ this.tempResultIdentifier = this.f.createIdentifier(found);
1039
+ } else {
1040
+ this.tempResultIdentifier = this.f.createIdentifier("\u03A9r");
1041
+ }
1042
+ return this.tempResultIdentifier;
1043
+ }
1044
+ getConfigResolver(sourceFile) {
1045
+ if (this.overriddenConfigResolver) {
1046
+ return this.overriddenConfigResolver;
1047
+ }
1048
+ return getConfigResolver(this.cache.resolver, this.parseConfigHost, this.compilerOptions, sourceFile);
1049
+ }
1050
+ getReflectionConfig(sourceFile) {
1051
+ const configResolver = this.getConfigResolver(sourceFile);
1052
+ return configResolver.match(sourceFile.fileName);
1053
+ }
1054
+ isWithReflection(sourceFile, node) {
1055
+ const mode = this.getExplicitReflectionMode(sourceFile, node);
1056
+ if (mode === false) return false;
1057
+ if (!sourceFile) return true;
1058
+ const reflection = this.getReflectionConfig(sourceFile);
1059
+ if (reflection.mode === "explicit") return mode === true;
1060
+ return reflection.mode === "default";
1061
+ }
1062
+ transformSourceFile(sourceFile) {
1063
+ this.sourceFile = sourceFile;
1064
+ if (sourceFile.scriptKind !== ScriptKind.TS && sourceFile.scriptKind !== ScriptKind.TSX) return sourceFile;
1065
+ if (sourceFile.deepkitTransformed) return sourceFile;
1066
+ this.embedAssignType = false;
1067
+ this.addImports = [];
1068
+ const start = Date.now();
1069
+ const configResolver = this.getConfigResolver(sourceFile);
1070
+ const reflection = configResolver.match(sourceFile.fileName);
1071
+ Object.assign(this.compilerOptions, configResolver.config.compilerOptions);
1072
+ if (reflection.mode === "never") {
1073
+ debug(`Transform file with reflection=${reflection.mode} took ${Date.now() - start}ms (${this.getModuleType()}) ${sourceFile.fileName} via config ${reflection.tsConfigPath || "none"}.`);
1074
+ return sourceFile;
1075
+ }
1076
+ if (!sourceFile.locals) {
1077
+ ts4__default.default.bindSourceFile(sourceFile, this.compilerOptions);
1078
+ }
1079
+ if (sourceFile.kind !== SyntaxKind2.SourceFile) {
1080
+ if ("undefined" === typeof chunkBGYQAVKQ_cjs.__require) {
1081
+ throw new Error(`Invalid TypeScript library imported. SyntaxKind different ${sourceFile.kind} !== ${SyntaxKind2.SourceFile}.`);
1082
+ }
1083
+ const path = chunkBGYQAVKQ_cjs.__require.resolve("typescript");
1084
+ throw new Error(`Invalid TypeScript library imported. SyntaxKind different ${sourceFile.kind} !== ${SyntaxKind2.SourceFile}. typescript package path: ${path}`);
1085
+ }
1086
+ const visitor = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((node) => {
1087
+ node = visitEachChild(node, visitor, this.context);
1088
+ if (isInterfaceDeclaration(node) || isTypeAliasDeclaration(node) || isEnumDeclaration(node)) {
1089
+ if (this.isWithReflection(sourceFile, node)) {
1090
+ this.compileDeclarations.set(node, {
1091
+ name: node.name,
1092
+ sourceFile: this.sourceFile
1093
+ });
1094
+ }
1095
+ }
1096
+ if (isMethodDeclaration(node) && node.parent && node.body && isObjectLiteralExpression(node.parent)) {
1097
+ let valid = true;
1098
+ if (node.name.kind === SyntaxKind2.Identifier && getIdentifierName(node.name) === "default") valid = false;
1099
+ if (valid) {
1100
+ const method = this.decorateFunctionExpression(this.f.createFunctionExpression(node.modifiers, node.asteriskToken, isIdentifier2(node.name) ? node.name : void 0, node.typeParameters, node.parameters, node.type, node.body));
1101
+ node = this.f.createPropertyAssignment(node.name, method);
1102
+ }
1103
+ }
1104
+ if (isClassDeclaration(node)) {
1105
+ return this.decorateClass(sourceFile, node);
1106
+ } else if (isParameter(node) && node.parent && node.type) {
1107
+ const typeParameters = isConstructorDeclaration(node.parent) ? node.parent.parent.typeParameters : node.parent.typeParameters;
1108
+ if (!typeParameters) return node;
1109
+ const receiveType = getReceiveTypeParameter(node.type);
1110
+ if (receiveType && receiveType.typeArguments) {
1111
+ const first = receiveType.typeArguments[0];
1112
+ if (first && isTypeReferenceNode(first) && isIdentifier2(first.typeName)) {
1113
+ const name = getIdentifierName(first.typeName);
1114
+ const index = typeParameters.findIndex((v) => getIdentifierName(v.name) === name);
1115
+ let container = this.f.createIdentifier("globalThis");
1116
+ if (isArrowFunction2(node.parent)) {
1117
+ const next = this.getArrowFunction\u03A9PropertyAccessIdentifier(node.parent);
1118
+ if (!next) return node;
1119
+ container = next;
1120
+ } else if ((isFunctionDeclaration(node.parent) || isFunctionExpression(node.parent)) && node.parent.name) {
1121
+ container = node.parent.name;
1122
+ } else if (isMethodDeclaration(node.parent) && isIdentifier2(node.parent.name)) {
1123
+ container = this.f.createPropertyAccessExpression(this.f.createIdentifier("this"), node.parent.name);
1124
+ } else if (isConstructorDeclaration(node.parent)) {
1125
+ container = this.f.createPropertyAccessExpression(this.f.createIdentifier("this"), "constructor");
1126
+ }
1127
+ return this.f.updateParameterDeclaration(node, node.modifiers, node.dotDotDotToken, node.name, node.questionToken, receiveType, this.f.createElementAccessChain(this.f.createPropertyAccessExpression(container, this.f.createIdentifier("\u03A9")), this.f.createToken(SyntaxKind2.QuestionDotToken), this.f.createNumericLiteral(index)));
1128
+ }
1129
+ }
1130
+ } else if (isClassExpression(node)) {
1131
+ return this.decorateClass(sourceFile, node);
1132
+ } else if (isFunctionExpression(node)) {
1133
+ return this.decorateFunctionExpression(this.injectReset\u03A9(node));
1134
+ } else if (isFunctionDeclaration(node)) {
1135
+ return this.decorateFunctionDeclaration(this.injectReset\u03A9(node));
1136
+ } else if (isMethodDeclaration(node) || isConstructorDeclaration(node)) {
1137
+ return this.injectReset\u03A9(node);
1138
+ } else if (isArrowFunction2(node)) {
1139
+ return this.decorateArrowFunction(this.injectReset\u03A9(node));
1140
+ } else if ((isNewExpression(node) || isCallExpression(node)) && node.typeArguments && node.typeArguments.length > 0) {
1141
+ if (isCallExpression(node)) {
1142
+ const autoTypeFunctions = [
1143
+ "valuesOf",
1144
+ "propertiesOf",
1145
+ "typeOf"
1146
+ ];
1147
+ if (isIdentifier2(node.expression) && autoTypeFunctions.includes(getIdentifierName(node.expression))) {
1148
+ const args = [
1149
+ ...node.arguments
1150
+ ];
1151
+ if (!args.length) {
1152
+ args.push(this.f.createArrayLiteralExpression());
1153
+ }
1154
+ const type = this.getTypeOfType(node.typeArguments[0]);
1155
+ if (!type) return node;
1156
+ args.push(type);
1157
+ return this.f.updateCallExpression(node, node.expression, node.typeArguments, this.f.createNodeArray(args));
1158
+ }
1159
+ }
1160
+ const expressionToCheck = getAssignTypeExpression(node.expression) || node.expression;
1161
+ if (isArrowFunction2(expressionToCheck)) {
1162
+ return node;
1163
+ }
1164
+ const typeExpressions = [];
1165
+ for (const a of node.typeArguments) {
1166
+ const type = this.getTypeOfType(a);
1167
+ typeExpressions.push(type || this.f.createIdentifier("undefined"));
1168
+ }
1169
+ let container = this.f.createIdentifier("globalThis");
1170
+ if (isIdentifier2(node.expression)) {
1171
+ container = node.expression;
1172
+ } else if (isPropertyAccessExpression(node.expression)) {
1173
+ container = node.expression;
1174
+ }
1175
+ const assignQ = this.f.createBinaryExpression(this.f.createPropertyAccessExpression(container, "\u03A9"), this.f.createToken(SyntaxKind2.EqualsToken), this.f.createArrayLiteralExpression(typeExpressions));
1176
+ const update = isNewExpression(node) ? this.f.updateNewExpression : this.f.updateCallExpression;
1177
+ if (isPropertyAccessExpression(node.expression)) {
1178
+ if (isCallExpression(node.expression.expression)) {
1179
+ const r = this.getTempResultIdentifier();
1180
+ const assignQ2 = this.f.createBinaryExpression(this.f.createPropertyAccessExpression(this.f.createPropertyAccessExpression(r, node.expression.name), "\u03A9"), this.f.createToken(SyntaxKind2.EqualsToken), this.f.createArrayLiteralExpression(typeExpressions));
1181
+ return update(node, this.f.createPropertyAccessExpression(this.f.createParenthesizedExpression(this.f.createBinaryExpression(this.f.createBinaryExpression(this.f.createBinaryExpression(r, this.f.createToken(ts4__default.default.SyntaxKind.EqualsToken), node.expression.expression), this.f.createToken(ts4__default.default.SyntaxKind.CommaToken), assignQ2), this.f.createToken(ts4__default.default.SyntaxKind.CommaToken), r)), node.expression.name), node.typeArguments, node.arguments);
1182
+ } else if (isParenthesizedExpression(node.expression.expression)) {
1183
+ const r = this.getTempResultIdentifier();
1184
+ const assignQ2 = this.f.createBinaryExpression(this.f.createPropertyAccessExpression(this.f.createPropertyAccessExpression(r, node.expression.name), "\u03A9"), this.f.createToken(SyntaxKind2.EqualsToken), this.f.createArrayLiteralExpression(typeExpressions));
1185
+ const updatedNode = update(node, this.f.updatePropertyAccessExpression(node.expression, this.f.updateParenthesizedExpression(node.expression.expression, this.f.createBinaryExpression(this.f.createBinaryExpression(this.f.createBinaryExpression(r, this.f.createToken(SyntaxKind2.EqualsToken), node.expression.expression.expression), this.f.createToken(SyntaxKind2.CommaToken), assignQ2), this.f.createToken(SyntaxKind2.CommaToken), r)), node.expression.name), node.typeArguments, node.arguments);
1186
+ return this.f.createParenthesizedExpression(updatedNode);
1187
+ } else ;
1188
+ }
1189
+ return this.f.createParenthesizedExpression(this.f.createBinaryExpression(assignQ, this.f.createToken(SyntaxKind2.CommaToken), node));
1190
+ }
1191
+ return node;
1192
+ }, "visitor");
1193
+ this.sourceFile = visitNode(this.sourceFile, visitor);
1194
+ const newTopStatements = [];
1195
+ while (true) {
1196
+ let allCompiled = true;
1197
+ for (const d of this.compileDeclarations.values()) {
1198
+ if (d.compiled) continue;
1199
+ allCompiled = false;
1200
+ break;
1201
+ }
1202
+ if (this.embedDeclarations.size === 0 && allCompiled) break;
1203
+ for (const [node, d] of [
1204
+ ...this.compileDeclarations.entries()
1205
+ ]) {
1206
+ if (d.compiled) continue;
1207
+ d.compiled = this.createProgramVarFromNode(node, d.name, this.sourceFile);
1208
+ }
1209
+ if (this.embedDeclarations.size) {
1210
+ for (const node of this.embedDeclarations.keys()) {
1211
+ this.compiledDeclarations.add(node);
1212
+ }
1213
+ const entries = Array.from(this.embedDeclarations.entries());
1214
+ this.embedDeclarations.clear();
1215
+ for (const [node, d] of entries) {
1216
+ newTopStatements.push(...this.createProgramVarFromNode(node, d.name, d.sourceFile));
1217
+ }
1218
+ }
1219
+ }
1220
+ const compileDeclarations = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((node) => {
1221
+ node = visitEachChild(node, compileDeclarations, this.context);
1222
+ if (isTypeAliasDeclaration(node) || isInterfaceDeclaration(node) || isEnumDeclaration(node)) {
1223
+ const d = this.compileDeclarations.get(node);
1224
+ if (!d) {
1225
+ return node;
1226
+ }
1227
+ this.compileDeclarations.delete(node);
1228
+ this.compiledDeclarations.add(node);
1229
+ if (d.compiled) {
1230
+ return [
1231
+ ...d.compiled,
1232
+ node
1233
+ ];
1234
+ }
1235
+ }
1236
+ return node;
1237
+ }, "compileDeclarations");
1238
+ this.sourceFile = visitNode(this.sourceFile, compileDeclarations);
1239
+ if (this.addImports.length) {
1240
+ const handledIdentifier = [];
1241
+ for (const imp of this.addImports) {
1242
+ if (handledIdentifier.includes(getIdentifierName(imp.identifier))) continue;
1243
+ handledIdentifier.push(getIdentifierName(imp.identifier));
1244
+ if (this.getModuleType() === "cjs") {
1245
+ const test = this.f.createIdentifier(getIdentifierName(imp.identifier));
1246
+ const variable = this.f.createVariableStatement(void 0, this.f.createVariableDeclarationList([
1247
+ this.f.createVariableDeclaration(this.f.createObjectBindingPattern([
1248
+ this.f.createBindingElement(void 0, void 0, test)
1249
+ ]), void 0, void 0, this.f.createCallExpression(this.f.createIdentifier("require"), void 0, [
1250
+ imp.from
1251
+ ]))
1252
+ ], NodeFlags2.Const));
1253
+ const typeDeclWithComment = addSyntheticLeadingComment(variable, SyntaxKind2.MultiLineCommentTrivia, "@ts-ignore", true);
1254
+ newTopStatements.push(typeDeclWithComment);
1255
+ } else {
1256
+ const specifier = this.f.createImportSpecifier(false, void 0, imp.identifier);
1257
+ const namedImports = this.f.createNamedImports([
1258
+ specifier
1259
+ ]);
1260
+ const importStatement = this.f.createImportDeclaration(void 0, this.f.createImportClause(false, void 0, namedImports), imp.from);
1261
+ const typeDeclWithComment = addSyntheticLeadingComment(importStatement, SyntaxKind2.MultiLineCommentTrivia, "@ts-ignore", true);
1262
+ newTopStatements.push(typeDeclWithComment);
1263
+ }
1264
+ }
1265
+ }
1266
+ if (this.embedAssignType) {
1267
+ const assignType = this.f.createFunctionDeclaration(void 0, void 0, this.f.createIdentifier("__assignType"), void 0, [
1268
+ this.f.createParameterDeclaration(void 0, void 0, this.f.createIdentifier("fn"), void 0, void 0, void 0),
1269
+ this.f.createParameterDeclaration(void 0, void 0, this.f.createIdentifier("args"), void 0, void 0, void 0)
1270
+ ], void 0, this.f.createBlock([
1271
+ this.f.createExpressionStatement(this.f.createBinaryExpression(this.f.createPropertyAccessExpression(this.f.createIdentifier("fn"), this.f.createIdentifier("__type")), this.f.createToken(SyntaxKind2.EqualsToken), this.f.createIdentifier("args"))),
1272
+ this.f.createReturnStatement(this.f.createIdentifier("fn"))
1273
+ ], true));
1274
+ newTopStatements.push(assignType);
1275
+ }
1276
+ if (this.tempResultIdentifier) {
1277
+ newTopStatements.push(this.f.createVariableStatement(void 0, this.f.createVariableDeclarationList([
1278
+ this.f.createVariableDeclaration(this.tempResultIdentifier, void 0, void 0, void 0)
1279
+ ], ts4__default.default.NodeFlags.None)));
1280
+ }
1281
+ if (newTopStatements.length) {
1282
+ const indexOfFirstLiteralExpression = this.sourceFile.statements.findIndex((v) => isExpressionStatement(v) && isStringLiteral3(v.expression));
1283
+ const newStatements = indexOfFirstLiteralExpression === -1 ? [
1284
+ ...newTopStatements,
1285
+ ...this.sourceFile.statements
1286
+ ] : [
1287
+ ...this.sourceFile.statements.slice(0, indexOfFirstLiteralExpression + 1),
1288
+ ...newTopStatements,
1289
+ ...this.sourceFile.statements.slice(indexOfFirstLiteralExpression + 1)
1290
+ ];
1291
+ this.sourceFile = this.f.updateSourceFile(this.sourceFile, newStatements);
1292
+ }
1293
+ const took = Date.now() - start;
1294
+ debug(`Transform file with reflection=${reflection.mode} took ${took}ms (${this.getModuleType()}) ${sourceFile.fileName} via config ${reflection.tsConfigPath || "none"}.`);
1295
+ this.sourceFile.deepkitTransformed = true;
1296
+ return this.sourceFile;
1297
+ }
1298
+ getModuleType() {
1299
+ if (this.compilerOptions.module === ts4__default.default.ModuleKind.Node16 || this.compilerOptions.module === ts4__default.default.ModuleKind.NodeNext) {
1300
+ if (this.sourceFile.impliedNodeFormat === ts4__default.default.ModuleKind.ESNext) {
1301
+ return "esm";
1302
+ }
1303
+ return "cjs";
1304
+ }
1305
+ return this.compilerOptions.module === ts4__default.default.ModuleKind.CommonJS ? "cjs" : "esm";
1306
+ }
1307
+ getArrowFunction\u03A9PropertyAccessIdentifier(node) {
1308
+ let { parent } = node.original || node;
1309
+ if (isVariableDeclaration(parent) && isIdentifier2(parent.name)) {
1310
+ return parent.name;
1311
+ } else if (isPropertyAssignment(parent) && isIdentifier2(parent.name)) {
1312
+ const names = [];
1313
+ while (parent) {
1314
+ if (isObjectLiteralExpression(parent)) {
1315
+ parent = parent.parent;
1316
+ } else if (isVariableDeclaration(parent)) {
1317
+ names.unshift(getIdentifierName(parent.name));
1318
+ break;
1319
+ } else if (isIdentifier2(parent.name)) {
1320
+ names.unshift(getIdentifierName(parent.name));
1321
+ parent = parent.parent;
1322
+ } else {
1323
+ return;
1324
+ }
1325
+ }
1326
+ return this.f.createIdentifier(names.join("."));
1327
+ }
1328
+ return;
1329
+ }
1330
+ injectReset\u03A9(node) {
1331
+ let hasReceiveType = false;
1332
+ for (const param of node.parameters) {
1333
+ if (param.type && getReceiveTypeParameter(param.type)) hasReceiveType = true;
1334
+ }
1335
+ if (!hasReceiveType) return node;
1336
+ let container = this.f.createIdentifier("globalThis");
1337
+ if (isArrowFunction2(node)) {
1338
+ const next = this.getArrowFunction\u03A9PropertyAccessIdentifier(node);
1339
+ if (!next) return node;
1340
+ container = next;
1341
+ } else if ((isFunctionDeclaration(node) || isFunctionExpression(node)) && node.name) {
1342
+ container = node.name;
1343
+ } else if (isMethodDeclaration(node) && isIdentifier2(node.name)) {
1344
+ container = this.f.createPropertyAccessExpression(this.f.createIdentifier("this"), node.name);
1345
+ } else if (isConstructorDeclaration(node)) {
1346
+ container = this.f.createPropertyAccessExpression(this.f.createIdentifier("this"), "constructor");
1347
+ }
1348
+ const reset = this.f.createExpressionStatement(this.f.createBinaryExpression(this.f.createPropertyAccessExpression(container, this.f.createIdentifier("\u03A9")), this.f.createToken(ts4__default.default.SyntaxKind.EqualsToken), this.f.createIdentifier("undefined")));
1349
+ let body = node.body && isBlock(node.body) ? node.body : void 0;
1350
+ let bodyStatements = node.body && isBlock(node.body) ? [
1351
+ ...node.body.statements
1352
+ ] : [];
1353
+ if (node.body) {
1354
+ if (isExpression(node.body)) {
1355
+ bodyStatements = [
1356
+ this.f.createReturnStatement(node.body)
1357
+ ];
1358
+ }
1359
+ body = this.f.updateBlock(node.body, [
1360
+ reset,
1361
+ ...bodyStatements
1362
+ ]);
1363
+ }
1364
+ if (isArrowFunction2(node)) {
1365
+ return this.f.updateArrowFunction(node, node.modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, body);
1366
+ } else if (isFunctionDeclaration(node)) {
1367
+ return this.f.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, body);
1368
+ } else if (isFunctionExpression(node)) {
1369
+ return this.f.updateFunctionExpression(node, node.modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, body || node.body);
1370
+ } else if (isMethodDeclaration(node)) {
1371
+ return this.f.updateMethodDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, body);
1372
+ } else if (isConstructorDeclaration(node)) {
1373
+ return this.f.updateConstructorDeclaration(node, node.modifiers, node.parameters, body);
1374
+ }
1375
+ return node;
1376
+ }
1377
+ createProgramVarFromNode(node, name, sourceFile) {
1378
+ const typeProgram = new CompilerProgram(node, sourceFile);
1379
+ if ((isTypeAliasDeclaration(node) || isInterfaceDeclaration(node)) && node.typeParameters) {
1380
+ for (const param of node.typeParameters) {
1381
+ if (param.default) {
1382
+ this.extractPackStructOfType(param.default, typeProgram);
1383
+ }
1384
+ typeProgram.pushTemplateParameter(getIdentifierName(param.name), !!param.default);
1385
+ }
1386
+ }
1387
+ this.extractPackStructOfType(node, typeProgram);
1388
+ if (isTypeAliasDeclaration(node) || isInterfaceDeclaration(node) || isClassDeclaration(node) || isClassExpression(node)) {
1389
+ typeProgram.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.nominal);
1390
+ }
1391
+ const typeProgramExpression = this.packOpsAndStack(typeProgram);
1392
+ const variable = this.f.createVariableStatement([], this.f.createVariableDeclarationList([
1393
+ this.f.createVariableDeclaration(this.getDeclarationVariableName(name), void 0, void 0, typeProgramExpression)
1394
+ ], NodeFlags2.Const));
1395
+ if (hasModifier(node, SyntaxKind2.ExportKeyword)) {
1396
+ const exportNode = this.f.createExportDeclaration(void 0, false, this.f.createNamedExports([
1397
+ this.f.createExportSpecifier(false, this.getDeclarationVariableName(name), this.getDeclarationVariableName(name))
1398
+ ]));
1399
+ return [
1400
+ variable,
1401
+ exportNode
1402
+ ];
1403
+ }
1404
+ return [
1405
+ variable
1406
+ ];
1407
+ }
1408
+ extractPackStructOfExpression(node, program) {
1409
+ switch (node.kind) {
1410
+ case SyntaxKind2.StringLiteral: {
1411
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.string);
1412
+ return;
1413
+ }
1414
+ case SyntaxKind2.NumericLiteral: {
1415
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.number);
1416
+ return;
1417
+ }
1418
+ case SyntaxKind2.FalseKeyword:
1419
+ case SyntaxKind2.TrueKeyword: {
1420
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.boolean);
1421
+ return;
1422
+ }
1423
+ case SyntaxKind2.BigIntLiteral: {
1424
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.bigint);
1425
+ return;
1426
+ }
1427
+ //Symbol() is a function call, so we need to check for that
1428
+ case SyntaxKind2.CallExpression: {
1429
+ const call = node;
1430
+ if (isIdentifier2(call.expression) && getIdentifierName(call.expression) === "Symbol") {
1431
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.symbol);
1432
+ return;
1433
+ }
1434
+ break;
1435
+ }
1436
+ //new Date()
1437
+ case SyntaxKind2.NewExpression: {
1438
+ const call = node;
1439
+ if (isIdentifier2(call.expression)) {
1440
+ const map = {
1441
+ "Date": chunk5NPGWGPO_cjs.ReflectionOp.date,
1442
+ "RegExp": chunk5NPGWGPO_cjs.ReflectionOp.regexp,
1443
+ "Uint8Array": chunk5NPGWGPO_cjs.ReflectionOp.uint8Array,
1444
+ "Uint8ClampedArray": chunk5NPGWGPO_cjs.ReflectionOp.uint8ClampedArray,
1445
+ "Uint16Array": chunk5NPGWGPO_cjs.ReflectionOp.uint16Array,
1446
+ "Uint32Array": chunk5NPGWGPO_cjs.ReflectionOp.uint32Array,
1447
+ "Int8Array": chunk5NPGWGPO_cjs.ReflectionOp.int8Array,
1448
+ "Int16Array": chunk5NPGWGPO_cjs.ReflectionOp.int16Array,
1449
+ "Int32Array": chunk5NPGWGPO_cjs.ReflectionOp.int32Array,
1450
+ "Float32Array": chunk5NPGWGPO_cjs.ReflectionOp.float32Array,
1451
+ "Float64Array": chunk5NPGWGPO_cjs.ReflectionOp.float64Array,
1452
+ "ArrayBuffer": chunk5NPGWGPO_cjs.ReflectionOp.arrayBuffer
1453
+ };
1454
+ const op = map[getIdentifierName(call.expression)];
1455
+ if (op) {
1456
+ program.pushOp(op);
1457
+ return;
1458
+ }
1459
+ }
1460
+ break;
1461
+ }
1462
+ }
1463
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
1464
+ }
1465
+ parseDefaultValue(kind, defaultValue) {
1466
+ switch (kind) {
1467
+ case SyntaxKind2.NumberKeyword: {
1468
+ return Number.isInteger(Number.parseFloat(defaultValue)) ? Number.parseInt(defaultValue) : Number.parseFloat(defaultValue);
1469
+ }
1470
+ case SyntaxKind2.BooleanKeyword: {
1471
+ return Boolean(defaultValue?.trim());
1472
+ }
1473
+ case SyntaxKind2.BigIntKeyword: {
1474
+ return Number.parseInt(defaultValue);
1475
+ }
1476
+ case SyntaxKind2.ObjectKeyword: {
1477
+ return JSON.parse(defaultValue);
1478
+ }
1479
+ case SyntaxKind2.NullKeyword: {
1480
+ return null;
1481
+ }
1482
+ case SyntaxKind2.TrueKeyword: {
1483
+ return true;
1484
+ }
1485
+ case SyntaxKind2.FalseKeyword: {
1486
+ return false;
1487
+ }
1488
+ case SyntaxKind2.UndefinedKeyword: {
1489
+ return void 0;
1490
+ }
1491
+ case SyntaxKind2.StringLiteral:
1492
+ case SyntaxKind2.StringKeyword:
1493
+ default: {
1494
+ if (defaultValue?.trim().toLowerCase() === "false") {
1495
+ return false;
1496
+ } else if (defaultValue?.trim().toLowerCase() === "true") {
1497
+ return true;
1498
+ }
1499
+ return defaultValue;
1500
+ }
1501
+ }
1502
+ }
1503
+ parseTagReflection(node) {
1504
+ const tags = {};
1505
+ tags.hidden = extractJSDocBoolean(this.sourceFile, node, "hidden");
1506
+ tags.ignore = extractJSDocBoolean(this.sourceFile, node, "ignore");
1507
+ tags.internal = extractJSDocBoolean(this.sourceFile, node, "internal");
1508
+ tags.alias = extractJSDocArray(this.sourceFile, node, "alias");
1509
+ tags.permission = extractJSDocArray(this.sourceFile, node, "permission");
1510
+ tags.domain = extractJSDocAttribute(this.sourceFile, node, "domain");
1511
+ if (this.getReflectionConfig(this.sourceFile).level === "verbose") {
1512
+ tags.title = extractJSDocAttribute(this.sourceFile, node, "title");
1513
+ }
1514
+ return tags;
1515
+ }
1516
+ extractTagReflections(program, node) {
1517
+ if (!node) return;
1518
+ const tags = this.parseTagReflection(node);
1519
+ if (Object.entries(tags).filter(([, value]) => value !== void 0 && (!Array.isArray(value) || value.length > 0) && (typeof value !== "string" || value?.trim().replace(/^"/gm, "").replace(/"$/gm, ""))).length > 0) {
1520
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.tags, program.findOrAddStackEntry(this.f.createObjectLiteralExpression(this.f.createNodeArray(Object.entries(tags).filter(([, value]) => value !== void 0 && (!Array.isArray(value) || value.length > 0) && (typeof value !== "string" || value.trim().replace(/^"/gm, "").replace(/"$/gm, ""))).map(([key, value]) => {
1521
+ return this.f.createPropertyAssignment(key, Array.isArray(value) ? this.f.createArrayLiteralExpression(value.map((item) => this.valueToExpression(item))) : typeof value === "boolean" ? value ? this.f.createTrue() : this.f.createFalse() : this.valueToExpression(value));
1522
+ })))));
1523
+ }
1524
+ }
1525
+ extractDefaultValueReflection(program, node) {
1526
+ if (!node) return;
1527
+ let defaultValue = extractJSDocAttribute(this.sourceFile, node, "defaultValue");
1528
+ if (!defaultValue) {
1529
+ defaultValue = extractJSDocAttribute(this.sourceFile, node, "default");
1530
+ }
1531
+ if (defaultValue) {
1532
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.defaultValue, program.findOrAddStackEntry(this.parseDefaultValue((node.kind === SyntaxKind2.ClassDeclaration || node.kind === SyntaxKind2.ClassExpression ? node?.name?.parent?.kind : node.kind === SyntaxKind2.PropertySignature || node.kind === SyntaxKind2.PropertyDeclaration ? node.type?.kind : node.kind) || SyntaxKind2.StringKeyword, defaultValue.trim().replace(/^"/gm, "").replace(/"$/gm, ""))));
1533
+ }
1534
+ }
1535
+ extractDescriptionReflection(program, node) {
1536
+ if (!node || this.getReflectionConfig(this.sourceFile).level !== "verbose") return;
1537
+ const description = extractJSDocAttribute(this.sourceFile, node, "description");
1538
+ if (description) {
1539
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.description, program.findOrAddStackEntry(description.trim().replace(/^"/gm, "").replace(/"$/gm, "")));
1540
+ }
1541
+ }
1542
+ extractPackStructOfType(node, program) {
1543
+ if (isParenthesizedTypeNode(node)) return this.extractPackStructOfType(node.type, program);
1544
+ switch (node.kind) {
1545
+ case SyntaxKind2.StringKeyword: {
1546
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.string);
1547
+ break;
1548
+ }
1549
+ case SyntaxKind2.NumberKeyword: {
1550
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.number);
1551
+ break;
1552
+ }
1553
+ case SyntaxKind2.BooleanKeyword: {
1554
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.boolean);
1555
+ break;
1556
+ }
1557
+ case SyntaxKind2.BigIntKeyword: {
1558
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.bigint);
1559
+ break;
1560
+ }
1561
+ case SyntaxKind2.VoidKeyword: {
1562
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.void);
1563
+ break;
1564
+ }
1565
+ case SyntaxKind2.UnknownKeyword: {
1566
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.unknown);
1567
+ break;
1568
+ }
1569
+ case SyntaxKind2.ObjectKeyword: {
1570
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.object);
1571
+ break;
1572
+ }
1573
+ case SyntaxKind2.SymbolKeyword: {
1574
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.symbol);
1575
+ break;
1576
+ }
1577
+ case SyntaxKind2.NullKeyword: {
1578
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.null);
1579
+ break;
1580
+ }
1581
+ case SyntaxKind2.NeverKeyword: {
1582
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
1583
+ break;
1584
+ }
1585
+ case SyntaxKind2.AnyKeyword: {
1586
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
1587
+ break;
1588
+ }
1589
+ case SyntaxKind2.UndefinedKeyword: {
1590
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.undefined);
1591
+ break;
1592
+ }
1593
+ case SyntaxKind2.TrueKeyword: {
1594
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.literal, program.pushStack(this.f.createTrue()));
1595
+ break;
1596
+ }
1597
+ case SyntaxKind2.FalseKeyword: {
1598
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.literal, program.pushStack(this.f.createFalse()));
1599
+ break;
1600
+ }
1601
+ case SyntaxKind2.ClassDeclaration:
1602
+ case SyntaxKind2.ClassExpression: {
1603
+ const narrowed = node;
1604
+ if (node) {
1605
+ const members = [];
1606
+ if (narrowed.typeParameters) {
1607
+ for (const typeParameter of narrowed.typeParameters) {
1608
+ const name = getNameAsString(typeParameter.name);
1609
+ if (typeParameter.default) {
1610
+ this.extractPackStructOfType(typeParameter.default, program);
1611
+ }
1612
+ program.pushTemplateParameter(name, !!typeParameter.default);
1613
+ }
1614
+ }
1615
+ if (narrowed.heritageClauses) {
1616
+ for (const heritage of narrowed.heritageClauses) {
1617
+ if (heritage.token === SyntaxKind2.ExtendsKeyword) {
1618
+ for (const extendType of heritage.types) {
1619
+ program.pushFrame();
1620
+ if (extendType.typeArguments) {
1621
+ for (const typeArgument of extendType.typeArguments) {
1622
+ this.extractPackStructOfType(typeArgument, program);
1623
+ }
1624
+ }
1625
+ const index = program.pushStack(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, this.nodeConverter.toExpression(extendType.expression)));
1626
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.classReference, index);
1627
+ program.popFrameImplicit();
1628
+ }
1629
+ }
1630
+ }
1631
+ }
1632
+ for (const member of narrowed.members) {
1633
+ const name = getNameAsString(member.name);
1634
+ if (name) {
1635
+ const has = members.some((v) => getNameAsString(v.name) === name);
1636
+ if (has) continue;
1637
+ }
1638
+ members.push(member);
1639
+ this.extractPackStructOfType(member, program);
1640
+ }
1641
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.class);
1642
+ if (narrowed.heritageClauses) {
1643
+ for (const heritageClause of narrowed.heritageClauses) {
1644
+ if (heritageClause.token === SyntaxKind2.ExtendsKeyword) {
1645
+ const first = heritageClause.types[0];
1646
+ if (isExpressionWithTypeArguments(first) && first.typeArguments) {
1647
+ for (const typeArgument of first.typeArguments) {
1648
+ this.extractPackStructOfType(typeArgument, program);
1649
+ }
1650
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.classExtends, first.typeArguments.length);
1651
+ }
1652
+ } else if (heritageClause.token === SyntaxKind2.ImplementsKeyword) {
1653
+ for (const type of heritageClause.types) {
1654
+ this.extractPackStructOfTypeReference(type, program);
1655
+ }
1656
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.implements, heritageClause.types.length);
1657
+ }
1658
+ }
1659
+ }
1660
+ if (narrowed.name) this.resolveTypeName(getIdentifierName(narrowed.name), program);
1661
+ this.extractDefaultValueReflection(program, narrowed.name?.parent);
1662
+ this.extractDescriptionReflection(program, narrowed.name?.parent);
1663
+ this.extractTagReflections(program, narrowed.name?.parent);
1664
+ }
1665
+ break;
1666
+ }
1667
+ case SyntaxKind2.IntersectionType: {
1668
+ const narrowed = node;
1669
+ program.pushFrame();
1670
+ for (const type of narrowed.types) {
1671
+ this.extractPackStructOfType(type, program);
1672
+ }
1673
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.intersection);
1674
+ program.popFrameImplicit();
1675
+ break;
1676
+ }
1677
+ case SyntaxKind2.MappedType: {
1678
+ const narrowed = node;
1679
+ program.pushFrame();
1680
+ program.pushVariable(getIdentifierName(narrowed.typeParameter.name));
1681
+ const constraint = getEffectiveConstraintOfTypeParameter(narrowed.typeParameter);
1682
+ if (constraint) {
1683
+ this.extractPackStructOfType(constraint, program);
1684
+ } else {
1685
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
1686
+ }
1687
+ let modifier = 0;
1688
+ if (narrowed.questionToken) {
1689
+ if (narrowed.questionToken.kind === SyntaxKind2.QuestionToken) {
1690
+ modifier |= 1;
1691
+ }
1692
+ if (narrowed.questionToken.kind === SyntaxKind2.MinusToken) {
1693
+ modifier |= 2;
1694
+ }
1695
+ }
1696
+ if (narrowed.readonlyToken) {
1697
+ if (narrowed.readonlyToken.kind === SyntaxKind2.ReadonlyKeyword) {
1698
+ modifier |= 4;
1699
+ }
1700
+ if (narrowed.readonlyToken.kind === SyntaxKind2.MinusToken) {
1701
+ modifier |= 8;
1702
+ }
1703
+ }
1704
+ program.pushCoRoutine();
1705
+ if (narrowed.nameType) program.pushFrame();
1706
+ if (narrowed.type) {
1707
+ this.extractPackStructOfType(narrowed.type, program);
1708
+ } else {
1709
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
1710
+ }
1711
+ if (narrowed.nameType) {
1712
+ this.extractPackStructOfType(narrowed.nameType, program);
1713
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.tuple);
1714
+ program.popFrameImplicit();
1715
+ }
1716
+ const coRoutineIndex = program.popCoRoutine();
1717
+ if (narrowed.nameType) {
1718
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.mappedType2, coRoutineIndex, modifier);
1719
+ } else {
1720
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.mappedType, coRoutineIndex, modifier);
1721
+ }
1722
+ program.popFrameImplicit();
1723
+ break;
1724
+ }
1725
+ case SyntaxKind2.TypeAliasDeclaration: {
1726
+ let narrowed = node;
1727
+ if (program.sourceFile && getNameAsString(narrowed.name) === "TypeAnnotation") {
1728
+ const attribute = extractJSDocAttribute(program.sourceFile, narrowed, "intrinsic");
1729
+ if (attribute !== void 0) {
1730
+ narrowed = this.intrinsicMetaDeclaration;
1731
+ }
1732
+ }
1733
+ this.extractPackStructOfType(narrowed.type, program);
1734
+ if (narrowed.name) this.resolveTypeName(getIdentifierName(narrowed.name), program);
1735
+ break;
1736
+ }
1737
+ case SyntaxKind2.TypeLiteral:
1738
+ case SyntaxKind2.InterfaceDeclaration: {
1739
+ const narrowed = node;
1740
+ let descriptionNode = narrowed;
1741
+ program.pushFrame();
1742
+ if (isInterfaceDeclaration(narrowed) && narrowed.heritageClauses) {
1743
+ for (const heritage of narrowed.heritageClauses) {
1744
+ if (heritage.token === SyntaxKind2.ExtendsKeyword) {
1745
+ for (const extendType of heritage.types) {
1746
+ this.extractPackStructOfTypeReference(extendType, program);
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+ for (const member of narrowed.members) {
1752
+ this.extractPackStructOfType(member, program);
1753
+ }
1754
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.objectLiteral);
1755
+ if (isTypeLiteralNode(narrowed)) {
1756
+ descriptionNode = narrowed.parent;
1757
+ }
1758
+ this.extractDefaultValueReflection(program, descriptionNode);
1759
+ this.extractDescriptionReflection(program, descriptionNode);
1760
+ this.extractTagReflections(program, descriptionNode);
1761
+ if (isInterfaceDeclaration(narrowed)) {
1762
+ if (narrowed.name) this.resolveTypeName(getIdentifierName(narrowed.name), program);
1763
+ }
1764
+ program.popFrameImplicit();
1765
+ break;
1766
+ }
1767
+ case SyntaxKind2.TypeReference: {
1768
+ this.extractPackStructOfTypeReference(node, program);
1769
+ break;
1770
+ }
1771
+ case SyntaxKind2.ArrayType: {
1772
+ this.extractPackStructOfType(node.elementType, program);
1773
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.array);
1774
+ break;
1775
+ }
1776
+ case SyntaxKind2.RestType: {
1777
+ let type = node.type;
1778
+ if (isArrayTypeNode(type)) {
1779
+ type = type.elementType;
1780
+ }
1781
+ this.extractPackStructOfType(type, program);
1782
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.rest);
1783
+ break;
1784
+ }
1785
+ case SyntaxKind2.TupleType: {
1786
+ program.pushFrame();
1787
+ for (const element of node.elements) {
1788
+ if (isOptionalTypeNode(element)) {
1789
+ this.extractPackStructOfType(element.type, program);
1790
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.tupleMember);
1791
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.optional);
1792
+ } else if (isNamedTupleMember(element)) {
1793
+ if (element.dotDotDotToken) {
1794
+ let type = element.type;
1795
+ if (isArrayTypeNode(type)) {
1796
+ type = type.elementType;
1797
+ }
1798
+ this.extractPackStructOfType(type, program);
1799
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.rest);
1800
+ } else {
1801
+ this.extractPackStructOfType(element.type, program);
1802
+ }
1803
+ const index = program.findOrAddStackEntry(getIdentifierName(element.name));
1804
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.namedTupleMember, index);
1805
+ if (element.questionToken) {
1806
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.optional);
1807
+ }
1808
+ } else {
1809
+ this.extractPackStructOfType(element, program);
1810
+ }
1811
+ }
1812
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.tuple);
1813
+ program.popFrameImplicit();
1814
+ break;
1815
+ }
1816
+ case SyntaxKind2.PropertySignature: {
1817
+ const narrowed = node;
1818
+ if (narrowed.type) {
1819
+ this.extractPackStructOfType(narrowed.type, program);
1820
+ const name = getPropertyName(this.f, narrowed.name);
1821
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.propertySignature, program.findOrAddStackEntry(name));
1822
+ if (narrowed.questionToken) {
1823
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.optional);
1824
+ }
1825
+ if (hasModifier(narrowed, SyntaxKind2.ReadonlyKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1826
+ else {
1827
+ const readonly = extractJSDocBoolean(this.sourceFile, narrowed, "readonly");
1828
+ if (readonly) {
1829
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1830
+ }
1831
+ }
1832
+ this.extractDefaultValueReflection(program, narrowed);
1833
+ this.extractDescriptionReflection(program, narrowed);
1834
+ this.extractTagReflections(program, narrowed);
1835
+ } else {
1836
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.unknown);
1837
+ }
1838
+ break;
1839
+ }
1840
+ case SyntaxKind2.PropertyDeclaration: {
1841
+ const narrowed = node;
1842
+ if (false === this.getExplicitReflectionMode(program.sourceFile, narrowed)) return;
1843
+ if (narrowed.type) {
1844
+ this.extractPackStructOfType(narrowed.type, program);
1845
+ } else if (narrowed.initializer) {
1846
+ this.extractPackStructOfExpression(narrowed.initializer, program);
1847
+ } else {
1848
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.unknown);
1849
+ }
1850
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.property, program.findOrAddStackEntry(getPropertyName(this.f, narrowed.name)));
1851
+ if (narrowed.questionToken) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.optional);
1852
+ if (hasModifier(narrowed, SyntaxKind2.ReadonlyKeyword)) {
1853
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1854
+ } else {
1855
+ const readonly = extractJSDocBoolean(this.sourceFile, narrowed, "readonly");
1856
+ if (readonly) {
1857
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1858
+ }
1859
+ }
1860
+ if (hasModifier(narrowed, SyntaxKind2.PrivateKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.private);
1861
+ if (hasModifier(narrowed, SyntaxKind2.ProtectedKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.protected);
1862
+ if (hasModifier(narrowed, SyntaxKind2.AbstractKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.abstract);
1863
+ if (hasModifier(narrowed, SyntaxKind2.StaticKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.static);
1864
+ if (narrowed.initializer) {
1865
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.defaultValue, program.findOrAddStackEntry(this.f.createFunctionExpression(void 0, void 0, void 0, void 0, void 0, void 0, this.f.createBlock([
1866
+ this.f.createReturnStatement(narrowed.initializer)
1867
+ ]))));
1868
+ } else {
1869
+ this.extractDefaultValueReflection(program, narrowed);
1870
+ }
1871
+ this.extractDescriptionReflection(program, narrowed);
1872
+ this.extractTagReflections(program, narrowed);
1873
+ break;
1874
+ }
1875
+ case SyntaxKind2.ConditionalType: {
1876
+ const narrowed = node;
1877
+ const distributiveOverIdentifier = isTypeReferenceNode(narrowed.checkType) && isIdentifier2(narrowed.checkType.typeName) ? narrowed.checkType.typeName : void 0;
1878
+ if (distributiveOverIdentifier) {
1879
+ program.pushFrame();
1880
+ this.extractPackStructOfType(narrowed.checkType, program);
1881
+ program.pushVariable(getIdentifierName(distributiveOverIdentifier));
1882
+ program.pushCoRoutine();
1883
+ }
1884
+ program.pushConditionalFrame();
1885
+ this.extractPackStructOfType(narrowed.checkType, program);
1886
+ this.extractPackStructOfType(narrowed.extendsType, program);
1887
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.extends);
1888
+ program.pushCoRoutine();
1889
+ this.extractPackStructOfType(narrowed.trueType, program);
1890
+ const trueProgram = program.popCoRoutine();
1891
+ program.pushCoRoutine();
1892
+ this.extractPackStructOfType(narrowed.falseType, program);
1893
+ const falseProgram = program.popCoRoutine();
1894
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.jumpCondition, trueProgram, falseProgram);
1895
+ program.moveFrame();
1896
+ if (distributiveOverIdentifier) {
1897
+ const coRoutineIndex = program.popCoRoutine();
1898
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.distribute, coRoutineIndex);
1899
+ program.popFrameImplicit();
1900
+ }
1901
+ break;
1902
+ }
1903
+ case SyntaxKind2.InferType: {
1904
+ const narrowed = node;
1905
+ const frame = program.findConditionalFrame();
1906
+ if (frame) {
1907
+ const typeParameterName = getIdentifierName(narrowed.typeParameter.name);
1908
+ let variable = program.findVariable(typeParameterName);
1909
+ if (!variable) {
1910
+ program.pushVariable(typeParameterName, frame);
1911
+ variable = program.findVariable(typeParameterName);
1912
+ if (!variable) throw new Error("Could not find inserted infer variable");
1913
+ }
1914
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.infer, variable.frameOffset, variable.stackIndex);
1915
+ } else {
1916
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
1917
+ }
1918
+ break;
1919
+ }
1920
+ case SyntaxKind2.MethodSignature:
1921
+ case SyntaxKind2.MethodDeclaration:
1922
+ case SyntaxKind2.Constructor:
1923
+ case SyntaxKind2.ArrowFunction:
1924
+ case SyntaxKind2.FunctionExpression:
1925
+ case SyntaxKind2.ConstructSignature:
1926
+ case SyntaxKind2.ConstructorType:
1927
+ case SyntaxKind2.FunctionType:
1928
+ case SyntaxKind2.CallSignature:
1929
+ case SyntaxKind2.FunctionDeclaration: {
1930
+ const narrowed = node;
1931
+ if (false === this.getExplicitReflectionMode(program.sourceFile, narrowed)) {
1932
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
1933
+ return;
1934
+ }
1935
+ const name = isCallSignatureDeclaration(node) ? "" : isConstructorTypeNode(narrowed) || isConstructSignatureDeclaration(node) ? "new" : isConstructorDeclaration(narrowed) ? "constructor" : getPropertyName(this.f, narrowed.name);
1936
+ if (!narrowed.type && narrowed.parameters.length === 0 && !name) return;
1937
+ program.pushFrame();
1938
+ for (let i = 0; i < narrowed.parameters.length; i++) {
1939
+ const parameter = narrowed.parameters[i];
1940
+ const parameterName = isIdentifier2(parameter.name) ? getNameAsString(parameter.name) : "param" + i;
1941
+ const type = parameter.type ? parameter.dotDotDotToken && isArrayTypeNode(parameter.type) ? parameter.type.elementType : parameter.type : void 0;
1942
+ if (type) {
1943
+ this.extractPackStructOfType(type, program);
1944
+ } else {
1945
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
1946
+ }
1947
+ if (parameter.dotDotDotToken) {
1948
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.rest);
1949
+ }
1950
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.parameter, program.findOrAddStackEntry(parameterName));
1951
+ if (parameter.questionToken) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.optional);
1952
+ if (hasModifier(parameter, SyntaxKind2.PublicKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.public);
1953
+ if (hasModifier(parameter, SyntaxKind2.PrivateKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.private);
1954
+ if (hasModifier(parameter, SyntaxKind2.ProtectedKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.protected);
1955
+ if (hasModifier(parameter, SyntaxKind2.ReadonlyKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1956
+ else {
1957
+ let readonly = extractJSDocBoolean(this.sourceFile, parameter, "readonly");
1958
+ if (readonly) {
1959
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1960
+ } else {
1961
+ readonly = extractJSDocBoolean(this.sourceFile, narrowed, "readonly");
1962
+ if (readonly) {
1963
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
1964
+ }
1965
+ }
1966
+ }
1967
+ if (parameter.initializer && parameter.type && !getReceiveTypeParameter(parameter.type)) {
1968
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.defaultValue, program.findOrAddStackEntry(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, parameter.initializer)));
1969
+ } else {
1970
+ this.extractDefaultValueReflection(program, parameter);
1971
+ }
1972
+ this.extractDescriptionReflection(program, parameter);
1973
+ }
1974
+ if (narrowed.type) {
1975
+ this.extractPackStructOfType(narrowed.type, program);
1976
+ } else {
1977
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
1978
+ }
1979
+ program.pushOp(isCallSignatureDeclaration(node) ? chunk5NPGWGPO_cjs.ReflectionOp.callSignature : isMethodSignature(narrowed) || isConstructSignatureDeclaration(narrowed) ? chunk5NPGWGPO_cjs.ReflectionOp.methodSignature : isMethodDeclaration(narrowed) || isConstructorDeclaration(narrowed) ? chunk5NPGWGPO_cjs.ReflectionOp.method : chunk5NPGWGPO_cjs.ReflectionOp.function, program.findOrAddStackEntry(name));
1980
+ if (isMethodDeclaration(narrowed)) {
1981
+ if (hasModifier(narrowed, SyntaxKind2.PrivateKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.private);
1982
+ if (hasModifier(narrowed, SyntaxKind2.ProtectedKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.protected);
1983
+ if (hasModifier(narrowed, SyntaxKind2.AbstractKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.abstract);
1984
+ if (hasModifier(narrowed, SyntaxKind2.StaticKeyword)) program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.static);
1985
+ }
1986
+ this.extractDefaultValueReflection(program, narrowed);
1987
+ this.extractDescriptionReflection(program, narrowed);
1988
+ this.extractTagReflections(program, narrowed);
1989
+ program.popFrameImplicit();
1990
+ break;
1991
+ }
1992
+ case SyntaxKind2.LiteralType: {
1993
+ const narrowed = node;
1994
+ if (narrowed.literal.kind === SyntaxKind2.NullKeyword) {
1995
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.null);
1996
+ } else {
1997
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.literal, program.findOrAddStackEntry(narrowed.literal));
1998
+ }
1999
+ break;
2000
+ }
2001
+ case SyntaxKind2.TemplateLiteralType: {
2002
+ const narrowed = node;
2003
+ program.pushFrame();
2004
+ if (narrowed.head.rawText) {
2005
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.literal, program.findOrAddStackEntry(narrowed.head.rawText));
2006
+ }
2007
+ for (const span of narrowed.templateSpans) {
2008
+ this.extractPackStructOfType(span.type, program);
2009
+ if (span.literal.rawText) {
2010
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.literal, program.findOrAddStackEntry(span.literal.rawText));
2011
+ }
2012
+ }
2013
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.templateLiteral);
2014
+ program.popFrameImplicit();
2015
+ break;
2016
+ }
2017
+ case SyntaxKind2.UnionType: {
2018
+ const narrowed = node;
2019
+ if (narrowed.types.length === 0) ; else if (narrowed.types.length === 1) {
2020
+ this.extractPackStructOfType(narrowed.types[0], program);
2021
+ } else {
2022
+ program.pushFrame();
2023
+ for (const subType of narrowed.types) {
2024
+ this.extractPackStructOfType(subType, program);
2025
+ }
2026
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.union);
2027
+ program.popFrameImplicit();
2028
+ }
2029
+ break;
2030
+ }
2031
+ case SyntaxKind2.EnumDeclaration: {
2032
+ const narrowed = node;
2033
+ program.pushFrame();
2034
+ for (const type of narrowed.members) {
2035
+ const name = getPropertyName(this.f, type.name);
2036
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.enumMember, program.findOrAddStackEntry(name));
2037
+ this.extractDescriptionReflection(program, type);
2038
+ if (type.initializer) {
2039
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.defaultValue, program.findOrAddStackEntry(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, type.initializer)));
2040
+ }
2041
+ }
2042
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.enum);
2043
+ this.extractDefaultValueReflection(program, narrowed);
2044
+ this.extractDescriptionReflection(program, narrowed);
2045
+ this.extractTagReflections(program, narrowed);
2046
+ if (narrowed.name) this.resolveTypeName(getIdentifierName(narrowed.name), program);
2047
+ program.popFrameImplicit();
2048
+ break;
2049
+ }
2050
+ case SyntaxKind2.IndexSignature: {
2051
+ const narrowed = node;
2052
+ if (narrowed.parameters.length && narrowed.parameters[0].type) {
2053
+ this.extractPackStructOfType(narrowed.parameters[0].type, program);
2054
+ } else {
2055
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2056
+ }
2057
+ this.extractPackStructOfType(narrowed.type, program);
2058
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.indexSignature);
2059
+ break;
2060
+ }
2061
+ case SyntaxKind2.TypeQuery: {
2062
+ const narrowed = node;
2063
+ if (isIdentifier2(narrowed.exprName)) {
2064
+ const resolved = this.resolveDeclaration(narrowed.exprName);
2065
+ if (resolved && findSourceFile(resolved.declaration) !== this.sourceFile && resolved.importDeclaration) {
2066
+ ensureImportIsEmitted(resolved.importDeclaration, narrowed.exprName);
2067
+ }
2068
+ }
2069
+ const expression = serializeEntityNameAsExpression(this.f, narrowed.exprName);
2070
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.typeof, program.pushStack(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, expression)));
2071
+ break;
2072
+ }
2073
+ case SyntaxKind2.TypeOperator: {
2074
+ const narrowed = node;
2075
+ if (narrowed.type.kind === SyntaxKind2.ThisType) {
2076
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2077
+ break;
2078
+ }
2079
+ switch (narrowed.operator) {
2080
+ case SyntaxKind2.KeyOfKeyword: {
2081
+ this.extractPackStructOfType(narrowed.type, program);
2082
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.keyof);
2083
+ break;
2084
+ }
2085
+ case SyntaxKind2.ReadonlyKeyword: {
2086
+ this.extractPackStructOfType(narrowed.type, program);
2087
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.readonly);
2088
+ break;
2089
+ }
2090
+ default: {
2091
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
2092
+ }
2093
+ }
2094
+ break;
2095
+ }
2096
+ case SyntaxKind2.IndexedAccessType: {
2097
+ const narrowed = node;
2098
+ this.extractPackStructOfType(narrowed.objectType, program);
2099
+ this.extractPackStructOfType(narrowed.indexType, program);
2100
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.indexAccess);
2101
+ break;
2102
+ }
2103
+ case SyntaxKind2.Identifier: {
2104
+ const narrowed = node;
2105
+ const variable = program.findVariable(getIdentifierName(narrowed));
2106
+ if (variable) {
2107
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.loads, variable.frameOffset, variable.stackIndex);
2108
+ } else {
2109
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
2110
+ }
2111
+ break;
2112
+ }
2113
+ default: {
2114
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
2115
+ }
2116
+ }
2117
+ }
2118
+ getGlobalLibs() {
2119
+ if (this.cache.globalSourceFiles) return this.cache.globalSourceFiles;
2120
+ this.cache.globalSourceFiles = [];
2121
+ const options = {
2122
+ ...this.compilerOptions
2123
+ };
2124
+ if (options.target && options.target === ScriptTarget2.ESNext) {
2125
+ options.target = ScriptTarget2.ES2022;
2126
+ }
2127
+ const libs = vfs.knownLibFilesForCompilerOptions(options, ts4__default.default);
2128
+ for (const lib of libs) {
2129
+ if (this.isExcluded(lib)) continue;
2130
+ const sourceFile = this.resolver.resolveSourceFile(this.sourceFile, this.f.createStringLiteral("typescript/lib/" + lib.replace(".d.ts", "")));
2131
+ if (!sourceFile) continue;
2132
+ this.cache.globalSourceFiles.push(sourceFile);
2133
+ }
2134
+ return this.cache.globalSourceFiles;
2135
+ }
2136
+ /**
2137
+ * This is a custom resolver based on populated `locals` from the binder. It uses a custom resolution algorithm since
2138
+ * we have no access to the binder/TypeChecker directly and instantiating a TypeChecker per file/transformer is incredible slow.
2139
+ */
2140
+ resolveDeclaration(typeName) {
2141
+ let current = typeName.parent;
2142
+ if (typeName.kind === SyntaxKind2.QualifiedName) return;
2143
+ let declaration = void 0;
2144
+ while (current) {
2145
+ if (isNodeWithLocals(current) && current.locals) {
2146
+ const found = current.locals.get(typeName.escapedText);
2147
+ if (found && found.declarations && found.declarations[0]) {
2148
+ if (!isParameter(found.declarations[0])) {
2149
+ declaration = found.declarations[0];
2150
+ break;
2151
+ }
2152
+ }
2153
+ }
2154
+ if (current.kind === SyntaxKind2.SourceFile) break;
2155
+ current = current.parent;
2156
+ }
2157
+ if (!declaration) {
2158
+ for (const file of this.getGlobalLibs()) {
2159
+ const globals = getGlobalsOfSourceFile(file);
2160
+ if (!globals) continue;
2161
+ const symbol = globals.get(typeName.escapedText);
2162
+ if (symbol && symbol.declarations && symbol.declarations[0]) {
2163
+ declaration = symbol.declarations[0];
2164
+ break;
2165
+ }
2166
+ }
2167
+ }
2168
+ let importDeclaration = void 0;
2169
+ let typeOnly = false;
2170
+ if (declaration && isImportSpecifier(declaration)) {
2171
+ if (declaration.isTypeOnly) typeOnly = true;
2172
+ importDeclaration = declaration.parent.parent.parent;
2173
+ } else if (declaration && isImportDeclaration(declaration)) {
2174
+ importDeclaration = declaration;
2175
+ } else if (declaration && isImportClause(declaration)) {
2176
+ importDeclaration = declaration.parent;
2177
+ }
2178
+ if (importDeclaration) {
2179
+ if (importDeclaration.importClause && importDeclaration.importClause.isTypeOnly) typeOnly = true;
2180
+ declaration = this.resolveImportSpecifier(getEscapedText(typeName), importDeclaration, this.sourceFile);
2181
+ }
2182
+ if (declaration && declaration.kind === SyntaxKind2.TypeParameter && declaration.parent.kind === SyntaxKind2.TypeAliasDeclaration) {
2183
+ declaration = declaration.parent;
2184
+ }
2185
+ if (!declaration) return;
2186
+ return {
2187
+ declaration,
2188
+ importDeclaration,
2189
+ typeOnly
2190
+ };
2191
+ }
2192
+ getDeclarationVariableName(typeName) {
2193
+ if (isIdentifier2(typeName)) {
2194
+ return this.f.createIdentifier("__\u03A9" + getIdentifierName(typeName));
2195
+ }
2196
+ function joinQualifiedName2(name) {
2197
+ if (isIdentifier2(name)) return getIdentifierName(name);
2198
+ return joinQualifiedName2(name.left) + "_" + getIdentifierName(name.right);
2199
+ }
2200
+ chunkBGYQAVKQ_cjs.__name(joinQualifiedName2, "joinQualifiedName");
2201
+ return this.f.createIdentifier("__\u03A9" + joinQualifiedName2(typeName));
2202
+ }
2203
+ /**
2204
+ * The semantic of isExcluded is different from checking if the fileName is part
2205
+ * of reflection config option. isExcluded checks if the file should be excluded
2206
+ * via the exclude option. mainly used to exclude globals and external libraries.
2207
+ */
2208
+ isExcluded(fileName) {
2209
+ const resolver = this.overriddenConfigResolver || getConfigResolver(this.cache.resolver, this.parseConfigHost, this.compilerOptions, this.sourceFile);
2210
+ const res = reflectionModeMatcher({
2211
+ reflection: "default",
2212
+ exclude: resolver.config.exclude
2213
+ }, fileName);
2214
+ return res === "never";
2215
+ }
2216
+ extractPackStructOfTypeReference(type, program) {
2217
+ const typeName = isTypeReferenceNode(type) ? type.typeName : isIdentifier2(type.expression) ? type.expression : void 0;
2218
+ if (!typeName) {
2219
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2220
+ return;
2221
+ }
2222
+ if (isIdentifier2(typeName) && getIdentifierName(typeName) === "InlineRuntimeType" && type.typeArguments && type.typeArguments[0] && isTypeQueryNode(type.typeArguments[0])) {
2223
+ const expression = serializeEntityNameAsExpression(this.f, type.typeArguments[0].exprName);
2224
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.arg, program.pushStack(expression));
2225
+ return;
2226
+ }
2227
+ if (isIdentifier2(typeName) && getIdentifierName(typeName) !== "constructor" && this.knownClasses[getIdentifierName(typeName)]) {
2228
+ const name = getIdentifierName(typeName);
2229
+ const op = this.knownClasses[name];
2230
+ program.pushOp(op);
2231
+ } else if (isIdentifier2(typeName) && getIdentifierName(typeName) === "Promise") {
2232
+ if (type.typeArguments && type.typeArguments[0]) {
2233
+ this.extractPackStructOfType(type.typeArguments[0], program);
2234
+ } else {
2235
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2236
+ }
2237
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.promise);
2238
+ } else if (isIdentifier2(typeName) && getIdentifierName(typeName) === "integer") {
2239
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.numberBrand, chunk5NPGWGPO_cjs.TypeNumberBrand.integer);
2240
+ } else if (isIdentifier2(typeName) && getIdentifierName(typeName) !== "constructor" && chunk5NPGWGPO_cjs.TypeNumberBrand[getIdentifierName(typeName)] !== void 0) {
2241
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.numberBrand, chunk5NPGWGPO_cjs.TypeNumberBrand[getIdentifierName(typeName)]);
2242
+ } else {
2243
+ if (isIdentifier2(typeName)) {
2244
+ const variable = program.findVariable(getIdentifierName(typeName));
2245
+ if (variable) {
2246
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.loads, variable.frameOffset, variable.stackIndex);
2247
+ return;
2248
+ }
2249
+ } else if (isInferTypeNode(typeName)) {
2250
+ this.extractPackStructOfType(typeName, program);
2251
+ return;
2252
+ }
2253
+ const resolved = this.resolveDeclaration(typeName);
2254
+ if (!resolved) {
2255
+ if (isQualifiedName(typeName)) {
2256
+ if (isIdentifier2(typeName.left)) {
2257
+ const resolved2 = this.resolveDeclaration(typeName.left);
2258
+ if (resolved2 && isEnumDeclaration(resolved2.declaration)) {
2259
+ let lastExpression;
2260
+ let indexValue = 0;
2261
+ for (const member of resolved2.declaration.members) {
2262
+ if (getNameAsString(member.name) === getNameAsString(typeName.right)) {
2263
+ if (member.initializer) {
2264
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.arg, program.pushStack(this.nodeConverter.toExpression(member.initializer)));
2265
+ } else if (lastExpression) {
2266
+ const exp = this.nodeConverter.toExpression(lastExpression);
2267
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.arg, program.pushStack(this.f.createBinaryExpression(exp, SyntaxKind2.PlusToken, this.nodeConverter.toExpression(indexValue))));
2268
+ } else {
2269
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.arg, program.pushStack(this.nodeConverter.toExpression(indexValue)));
2270
+ }
2271
+ return;
2272
+ } else {
2273
+ indexValue++;
2274
+ if (member.initializer) {
2275
+ lastExpression = member.initializer;
2276
+ indexValue = 0;
2277
+ }
2278
+ }
2279
+ }
2280
+ }
2281
+ }
2282
+ }
2283
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
2284
+ debug2(`Could not resolve ${getNameAsString(typeName)} in ${program.sourceFile?.fileName || "intrinsic"}`);
2285
+ return;
2286
+ }
2287
+ let declaration = resolved.declaration;
2288
+ const declarationSourceFile = findSourceFile(declaration);
2289
+ const isGlobal = !declarationSourceFile || resolved.importDeclaration === void 0 && declarationSourceFile.fileName !== this.sourceFile.fileName;
2290
+ const isFromImport = resolved.importDeclaration !== void 0;
2291
+ if (isVariableDeclaration(declaration)) {
2292
+ if (declaration.type) {
2293
+ declaration = declaration.type;
2294
+ } else if (declaration.initializer) {
2295
+ declaration = declaration.initializer;
2296
+ }
2297
+ }
2298
+ if (isModuleDeclaration(declaration) && resolved.importDeclaration) {
2299
+ if (isIdentifier2(typeName)) ensureImportIsEmitted(resolved.importDeclaration, typeName);
2300
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.typeof, program.pushStack(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, serializeEntityNameAsExpression(this.f, typeName))));
2301
+ } else if (isTypeAliasDeclaration(declaration) || isInterfaceDeclaration(declaration) || isEnumDeclaration(declaration)) {
2302
+ const name = getNameAsString(typeName);
2303
+ if (name === "Array") {
2304
+ if (type.typeArguments && type.typeArguments[0]) {
2305
+ this.extractPackStructOfType(type.typeArguments[0], program);
2306
+ } else {
2307
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2308
+ }
2309
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.array);
2310
+ return;
2311
+ } else if (name === "Function") {
2312
+ program.pushFrame();
2313
+ const index2 = program.pushStack(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, this.f.createIdentifier("Function")));
2314
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.functionReference, index2);
2315
+ program.popFrameImplicit();
2316
+ return;
2317
+ } else if (name === "Set") {
2318
+ if (type.typeArguments && type.typeArguments[0]) {
2319
+ this.extractPackStructOfType(type.typeArguments[0], program);
2320
+ } else {
2321
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2322
+ }
2323
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.set);
2324
+ return;
2325
+ } else if (name === "Map") {
2326
+ if (type.typeArguments && type.typeArguments[0]) {
2327
+ this.extractPackStructOfType(type.typeArguments[0], program);
2328
+ } else {
2329
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2330
+ }
2331
+ if (type.typeArguments && type.typeArguments[1]) {
2332
+ this.extractPackStructOfType(type.typeArguments[1], program);
2333
+ } else {
2334
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2335
+ }
2336
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.map);
2337
+ return;
2338
+ }
2339
+ const runtimeTypeName = this.getDeclarationVariableName(typeName);
2340
+ if (!this.compiledDeclarations.has(declaration) && !this.compileDeclarations.has(declaration)) {
2341
+ if (declarationSourceFile && this.isExcluded(declarationSourceFile.fileName)) {
2342
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2343
+ return;
2344
+ }
2345
+ if (isGlobal) {
2346
+ this.embedDeclarations.set(declaration, {
2347
+ name: typeName,
2348
+ sourceFile: declarationSourceFile
2349
+ });
2350
+ } else if (isFromImport) {
2351
+ if (resolved.importDeclaration) {
2352
+ if (resolved.typeOnly) {
2353
+ this.resolveTypeOnlyImport(typeName, program);
2354
+ return;
2355
+ }
2356
+ if (declarationSourceFile.fileName.endsWith(".d.ts")) {
2357
+ const resolverDecVariable = this.resolveImportSpecifier(getEscapedText(runtimeTypeName), resolved.importDeclaration, this.sourceFile);
2358
+ if (!resolverDecVariable) {
2359
+ debug2(`Symbol ${runtimeTypeName.escapedText} not found in ${declarationSourceFile.fileName}`);
2360
+ this.resolveTypeOnlyImport(typeName, program);
2361
+ return;
2362
+ }
2363
+ this.addImports.push({
2364
+ identifier: runtimeTypeName,
2365
+ from: resolved.importDeclaration.moduleSpecifier
2366
+ });
2367
+ } else {
2368
+ const reflection = this.getReflectionConfig(declarationSourceFile);
2369
+ if (reflection.mode === "never") {
2370
+ this.resolveTypeOnlyImport(typeName, program);
2371
+ return;
2372
+ }
2373
+ const declarationReflection = this.isWithReflection(declarationSourceFile, declaration);
2374
+ if (!declarationReflection) {
2375
+ this.resolveTypeOnlyImport(typeName, program);
2376
+ return;
2377
+ }
2378
+ this.addImports.push({
2379
+ identifier: runtimeTypeName,
2380
+ from: resolved.importDeclaration.moduleSpecifier
2381
+ });
2382
+ }
2383
+ }
2384
+ } else {
2385
+ const reflection = this.isWithReflection(program.sourceFile, declaration);
2386
+ if (!reflection) {
2387
+ this.resolveTypeOnlyImport(typeName, program);
2388
+ return;
2389
+ }
2390
+ this.compileDeclarations.set(declaration, {
2391
+ name: typeName,
2392
+ sourceFile: declarationSourceFile
2393
+ });
2394
+ }
2395
+ }
2396
+ const index = program.pushStack(program.forNode === declaration ? 0 : this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, runtimeTypeName));
2397
+ if (type.typeArguments) {
2398
+ for (const argument of type.typeArguments) {
2399
+ this.extractPackStructOfType(argument, program);
2400
+ }
2401
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.inlineCall, index, type.typeArguments.length);
2402
+ } else {
2403
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.inline, index);
2404
+ }
2405
+ } else if (isClassDeclaration(declaration) || isFunctionDeclaration(declaration) || isFunctionExpression(declaration) || isArrowFunction2(declaration)) {
2406
+ if (resolved.typeOnly) {
2407
+ this.resolveTypeOnlyImport(typeName, program);
2408
+ return;
2409
+ }
2410
+ const reflection = declarationSourceFile?.fileName.endsWith(".d.ts") || this.isWithReflection(program.sourceFile, declaration);
2411
+ if (!reflection) {
2412
+ this.resolveTypeOnlyImport(typeName, program);
2413
+ return;
2414
+ }
2415
+ if (resolved.importDeclaration && isIdentifier2(typeName)) ensureImportIsEmitted(resolved.importDeclaration, typeName);
2416
+ program.pushFrame();
2417
+ if (type.typeArguments) {
2418
+ for (const typeArgument of type.typeArguments) {
2419
+ this.extractPackStructOfType(typeArgument, program);
2420
+ }
2421
+ }
2422
+ const body = isIdentifier2(typeName) ? typeName : this.createAccessorForEntityName(typeName);
2423
+ const index = program.pushStack(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, body));
2424
+ program.pushOp(isClassDeclaration(declaration) ? chunk5NPGWGPO_cjs.ReflectionOp.classReference : chunk5NPGWGPO_cjs.ReflectionOp.functionReference, index);
2425
+ program.popFrameImplicit();
2426
+ } else if (isTypeParameterDeclaration(declaration)) {
2427
+ this.resolveTypeParameter(declaration, type, program);
2428
+ } else {
2429
+ this.extractPackStructOfType(declaration, program);
2430
+ }
2431
+ }
2432
+ }
2433
+ /**
2434
+ * Returns the class declaration, function/arrow declaration, or block where type was used.
2435
+ */
2436
+ getTypeUser(type) {
2437
+ let current = type;
2438
+ while (current) {
2439
+ if (current.kind === SyntaxKind2.Block) return current;
2440
+ if (current.kind === SyntaxKind2.ClassDeclaration) return current;
2441
+ if (current.kind === SyntaxKind2.ClassExpression) return current;
2442
+ if (current.kind === SyntaxKind2.Constructor) return current.parent;
2443
+ if (current.kind === SyntaxKind2.MethodDeclaration) return current.parent;
2444
+ if (current.kind === SyntaxKind2.ArrowFunction || current.kind === SyntaxKind2.FunctionDeclaration || current.kind === SyntaxKind2.FunctionExpression) return current;
2445
+ current = current.parent;
2446
+ }
2447
+ return current;
2448
+ }
2449
+ /**
2450
+ * With this function we want to check if `type` is used in the signature itself from the parent of `declaration`.
2451
+ * If so, we do not try to infer the type from runtime values.
2452
+ *
2453
+ * Examples where we do not infer from runtime, `type` being `T` and `declaration` being `<T>` (return false):
2454
+ *
2455
+ * ```typescript
2456
+ * class User<T> {
2457
+ * config: T;
2458
+ * }
2459
+ *
2460
+ * class User<T> {
2461
+ * constructor(public config: T) {}
2462
+ * }
2463
+ *
2464
+ * function do<T>(item: T): void {}
2465
+ * function do<T>(item: T): T {}
2466
+ * ```
2467
+ *
2468
+ * Examples where we infer from runtime (return true):
2469
+ *
2470
+ * ```typescript
2471
+ * function do<T>(item: T) {
2472
+ * return typeOf<T>; //<-- because of that
2473
+ * }
2474
+ *
2475
+ * function do<T>(item: T) {
2476
+ * class A {
2477
+ * config: T; //<-- because of that
2478
+ * }
2479
+ * return A;
2480
+ * }
2481
+ *
2482
+ * function do<T>(item: T) {
2483
+ * class A {
2484
+ * doIt() {
2485
+ * class B {
2486
+ * config: T; //<-- because of that
2487
+ * }
2488
+ * return B;
2489
+ * }
2490
+ * }
2491
+ * return A;
2492
+ * }
2493
+ *
2494
+ * function do<T>(item: T) {
2495
+ * class A {
2496
+ * doIt(): T { //<-- because of that
2497
+ * }
2498
+ * }
2499
+ * return A;
2500
+ * }
2501
+ * ```
2502
+ */
2503
+ needsToBeInferred(declaration, type) {
2504
+ const declarationUser = this.getTypeUser(declaration);
2505
+ const typeUser = this.getTypeUser(type);
2506
+ return declarationUser !== typeUser;
2507
+ }
2508
+ resolveTypeOnlyImport(entityName, program) {
2509
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2510
+ const typeName = ts4__default.default.isIdentifier(entityName) ? getIdentifierName(entityName) : getIdentifierName(entityName.right);
2511
+ this.resolveTypeName(typeName, program);
2512
+ }
2513
+ resolveTypeName(typeName, program) {
2514
+ if (!typeName) return;
2515
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.typeName, program.findOrAddStackEntry(typeName));
2516
+ }
2517
+ resolveTypeParameter(declaration, type, program) {
2518
+ const isUsedInFunction = isFunctionLike(declaration.parent);
2519
+ const resolveRuntimeTypeParameter = isUsedInFunction && program.isResolveFunctionParameters(declaration.parent) || this.needsToBeInferred(declaration, type);
2520
+ if (resolveRuntimeTypeParameter) {
2521
+ const argumentName = declaration.name.escapedText;
2522
+ const foundUsers = [];
2523
+ if (isUsedInFunction) {
2524
+ for (const parameter of declaration.parent.parameters) {
2525
+ if (!parameter.type) continue;
2526
+ let found = false;
2527
+ const searchArgument = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((node) => {
2528
+ node = visitEachChild(node, searchArgument, this.context);
2529
+ if (isTypeReferenceNode(node) && isIdentifier2(node.typeName) && node.typeName.escapedText === argumentName) {
2530
+ found = true;
2531
+ node = this.f.createInferTypeNode(declaration);
2532
+ }
2533
+ return node;
2534
+ }, "searchArgument");
2535
+ if (isIdentifier2(parameter.name)) {
2536
+ const updatedParameterType = visitEachChild(parameter.type, searchArgument, this.context);
2537
+ if (found) {
2538
+ foundUsers.push({
2539
+ type: updatedParameterType,
2540
+ parameterName: parameter.name
2541
+ });
2542
+ }
2543
+ }
2544
+ }
2545
+ }
2546
+ if (foundUsers.length) {
2547
+ if (foundUsers.length > 1) ;
2548
+ const isReceiveType = foundUsers.find((v) => isTypeReferenceNode(v.type) && isIdentifier2(v.type.typeName) && getIdentifierName(v.type.typeName) === "ReceiveType");
2549
+ if (isReceiveType) {
2550
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.inline, program.pushStack(isReceiveType.parameterName));
2551
+ } else {
2552
+ for (const foundUser of foundUsers) {
2553
+ program.pushConditionalFrame();
2554
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.typeof, program.pushStack(this.f.createArrowFunction(void 0, void 0, [], void 0, void 0, foundUser.parameterName)));
2555
+ this.extractPackStructOfType(foundUser.type, program);
2556
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.extends);
2557
+ const found = program.findVariable(getIdentifierName(declaration.name));
2558
+ if (found) {
2559
+ this.extractPackStructOfType(declaration.name, program);
2560
+ } else {
2561
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2562
+ }
2563
+ this.extractPackStructOfType({
2564
+ kind: SyntaxKind2.NeverKeyword
2565
+ }, program);
2566
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.condition);
2567
+ program.popFrameImplicit();
2568
+ }
2569
+ }
2570
+ if (foundUsers.length > 1) ;
2571
+ } else if (declaration.constraint) {
2572
+ if (isUsedInFunction) program.resolveFunctionParametersIncrease(declaration.parent);
2573
+ const constraint = getEffectiveConstraintOfTypeParameter(declaration);
2574
+ if (constraint) {
2575
+ this.extractPackStructOfType(constraint, program);
2576
+ } else {
2577
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
2578
+ }
2579
+ if (isUsedInFunction) program.resolveFunctionParametersDecrease(declaration.parent);
2580
+ } else {
2581
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.never);
2582
+ }
2583
+ } else {
2584
+ program.pushOp(chunk5NPGWGPO_cjs.ReflectionOp.any);
2585
+ }
2586
+ }
2587
+ createAccessorForEntityName(e) {
2588
+ return this.f.createPropertyAccessExpression(isIdentifier2(e.left) ? e.left : this.createAccessorForEntityName(e.left), e.right);
2589
+ }
2590
+ findDeclarationInFile(sourceFile, declarationName) {
2591
+ if (isNodeWithLocals(sourceFile) && sourceFile.locals) {
2592
+ const declarationSymbol = sourceFile.locals.get(declarationName);
2593
+ if (declarationSymbol && declarationSymbol.declarations && declarationSymbol.declarations[0]) {
2594
+ return declarationSymbol.declarations[0];
2595
+ }
2596
+ }
2597
+ return;
2598
+ }
2599
+ resolveImportSpecifier(_declarationName, importOrExport, sourceFile) {
2600
+ const declarationName = "string" === typeof _declarationName ? _declarationName : getIdentifierName(_declarationName);
2601
+ if (!importOrExport.moduleSpecifier || !isStringLiteral3(importOrExport.moduleSpecifier)) {
2602
+ return;
2603
+ }
2604
+ const source = this.resolver.resolve(sourceFile, importOrExport);
2605
+ if (!source) {
2606
+ debug("module not found", importOrExport.moduleSpecifier.text, "Is transpileOnly enabled? It needs to be disabled.");
2607
+ return;
2608
+ }
2609
+ const declaration = this.findDeclarationInFile(source, declarationName);
2610
+ sourceFile = source;
2611
+ if (declaration && !isImportSpecifier(declaration)) {
2612
+ if (isExportDeclaration(declaration)) {
2613
+ return this.followExport(declarationName, declaration, sourceFile);
2614
+ }
2615
+ return declaration;
2616
+ }
2617
+ if (isSourceFile(sourceFile)) {
2618
+ for (const statement of sourceFile.statements) {
2619
+ if (!isExportDeclaration(statement)) continue;
2620
+ const found = this.followExport(declarationName, statement, sourceFile);
2621
+ if (found) return found;
2622
+ }
2623
+ }
2624
+ return;
2625
+ }
2626
+ followExport(declarationName, statement, sourceFile) {
2627
+ if (statement.exportClause) {
2628
+ if (isNamedExports(statement.exportClause)) {
2629
+ for (const element of statement.exportClause.elements) {
2630
+ if (getEscapedText(element.name) === declarationName) {
2631
+ if (!statement.moduleSpecifier || !isStringLiteral3(statement.moduleSpecifier)) {
2632
+ if (!statement.moduleSpecifier || !isStringLiteral3(statement.moduleSpecifier)) {
2633
+ if (isNodeWithLocals(sourceFile) && sourceFile.locals) {
2634
+ const found = sourceFile.locals.get(declarationName);
2635
+ if (found && found.declarations && found.declarations[0]) {
2636
+ const declaration = found.declarations[0];
2637
+ if (declaration && isImportSpecifier(declaration)) {
2638
+ const importOrExport = declaration.parent.parent.parent;
2639
+ const found2 = this.resolveImportSpecifier(element.propertyName ? getEscapedText(element.propertyName) : declarationName, importOrExport, sourceFile);
2640
+ if (found2) return found2;
2641
+ }
2642
+ return declaration;
2643
+ }
2644
+ }
2645
+ }
2646
+ } else {
2647
+ const found = this.resolveImportSpecifier(element.propertyName ? getEscapedText(element.propertyName) : declarationName, statement, sourceFile);
2648
+ if (found) return found;
2649
+ }
2650
+ }
2651
+ }
2652
+ }
2653
+ } else {
2654
+ const found = this.resolveImportSpecifier(declarationName, statement, sourceFile);
2655
+ if (found) {
2656
+ return found;
2657
+ }
2658
+ }
2659
+ return;
2660
+ }
2661
+ getTypeOfType(type) {
2662
+ const reflection = this.isWithReflection(this.sourceFile, type);
2663
+ if (!reflection) return;
2664
+ const program = new CompilerProgram(type, this.sourceFile);
2665
+ this.extractPackStructOfType(type, program);
2666
+ return this.packOpsAndStack(program);
2667
+ }
2668
+ packOpsAndStack(program) {
2669
+ const packStruct = program.buildPackStruct();
2670
+ if (packStruct.ops.length === 0) return;
2671
+ const packed = [
2672
+ ...packStruct.stack,
2673
+ encodeOps(packStruct.ops)
2674
+ ];
2675
+ return this.valueToExpression(packed);
2676
+ }
2677
+ /**
2678
+ * Note: We have to duplicate the expressions as it can be that incoming expression are from another file and contain wrong pos/end properties,
2679
+ * so the code generation is then broken when we simply reuse them. Wrong code like ``User.__type = [.toEqual({`` is then generated.
2680
+ * This function is probably not complete, but we add new copies when required.
2681
+ */
2682
+ valueToExpression(value) {
2683
+ return this.nodeConverter.toExpression(value);
2684
+ }
2685
+ /**
2686
+ * A class is decorated with type information by adding a static variable.
2687
+ *
2688
+ * class Model {
2689
+ * static __types = pack(ReflectionOp.string); //<-- encoded type information
2690
+ * title: string;
2691
+ * }
2692
+ */
2693
+ decorateClass(sourceFile, node) {
2694
+ const reflection = this.isWithReflection(sourceFile, node);
2695
+ if (!reflection) {
2696
+ return node;
2697
+ }
2698
+ const type = this.getTypeOfType(node);
2699
+ const __type = this.f.createPropertyDeclaration(this.f.createModifiersFromModifierFlags(ModifierFlags.Static), "__type", void 0, void 0, type);
2700
+ if (isClassDeclaration(node)) {
2701
+ return this.f.updateClassDeclaration(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, this.f.createNodeArray([
2702
+ ...node.members,
2703
+ __type
2704
+ ]));
2705
+ }
2706
+ return this.f.updateClassExpression(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, this.f.createNodeArray([
2707
+ ...node.members,
2708
+ __type
2709
+ ]));
2710
+ }
2711
+ /**
2712
+ * const fn = function() {}
2713
+ *
2714
+ * => const fn = __assignType(function() {}, [34])
2715
+ */
2716
+ decorateFunctionExpression(expression) {
2717
+ const encodedType = this.getTypeOfType(expression);
2718
+ if (!encodedType) return expression;
2719
+ return this.wrapWithAssignType(expression, encodedType);
2720
+ }
2721
+ /**
2722
+ * function name() {}
2723
+ *
2724
+ * => function name() {}; name.__type = 34;
2725
+ */
2726
+ decorateFunctionDeclaration(declaration) {
2727
+ const encodedType = this.getTypeOfType(declaration);
2728
+ if (!encodedType) return declaration;
2729
+ if (!declaration.name) {
2730
+ if (!declaration.body) return;
2731
+ const modifier = declaration.modifiers ? declaration.modifiers.filter((v) => v.kind !== SyntaxKind2.ExportKeyword && v.kind !== SyntaxKind2.DefaultKeyword && v.kind !== SyntaxKind2.Decorator) : [];
2732
+ return this.f.createExportAssignment(void 0, void 0, this.wrapWithAssignType(this.f.createFunctionExpression(modifier, declaration.asteriskToken, declaration.name, declaration.typeParameters, declaration.parameters, declaration.type, declaration.body), encodedType));
2733
+ }
2734
+ const statements = [
2735
+ declaration
2736
+ ];
2737
+ statements.push(this.f.createExpressionStatement(this.f.createAssignment(this.f.createPropertyAccessExpression(serializeEntityNameAsExpression(this.f, declaration.name), "__type"), encodedType)));
2738
+ return statements;
2739
+ }
2740
+ /**
2741
+ * const fn = () => {}
2742
+ * => const fn = __assignType(() => {}, [34])
2743
+ */
2744
+ decorateArrowFunction(expression) {
2745
+ const encodedType = this.getTypeOfType(expression);
2746
+ if (!encodedType) return expression;
2747
+ return this.wrapWithAssignType(expression, encodedType);
2748
+ }
2749
+ /**
2750
+ * Object.assign(fn, {__type: []}) is much slower than a custom implementation like
2751
+ *
2752
+ * assignType(fn, [])
2753
+ *
2754
+ * where we embed assignType() at the beginning of the type.
2755
+ */
2756
+ wrapWithAssignType(fn, type) {
2757
+ this.embedAssignType = true;
2758
+ return this.f.createCallExpression(this.f.createIdentifier("__assignType"), void 0, [
2759
+ fn,
2760
+ type
2761
+ ]);
2762
+ }
2763
+ /**
2764
+ * Checks if reflection was disabled/enabled in file via JSDoc attribute for a particular
2765
+ * Node, e.g `@reflection no`. If nothing is found, "reflection" config option needs to be used.
2766
+ */
2767
+ getExplicitReflectionMode(sourceFile, node) {
2768
+ let current = node;
2769
+ let reflectionComment = void 0;
2770
+ while ("undefined" === typeof reflectionComment && current) {
2771
+ const next = sourceFile && extractJSDocAttribute(sourceFile, current, "reflection");
2772
+ if ("undefined" !== typeof next) reflectionComment = next;
2773
+ current = current.parent;
2774
+ }
2775
+ if (reflectionComment === "" || reflectionComment === "true" || reflectionComment === "default" || reflectionComment === "enabled" || reflectionComment === "1") {
2776
+ return true;
2777
+ }
2778
+ if (reflectionComment === "false" || reflectionComment === "disabled" || reflectionComment === "never" || reflectionComment === "no" || reflectionComment === "0") {
2779
+ return false;
2780
+ }
2781
+ return;
2782
+ }
2783
+ };
2784
+ var DeclarationTransformer = class extends ReflectionTransformer {
2785
+ static {
2786
+ chunkBGYQAVKQ_cjs.__name(this, "DeclarationTransformer");
2787
+ }
2788
+ constructor() {
2789
+ super(...arguments);
2790
+ this.addExports = [];
2791
+ }
2792
+ transformSourceFile(sourceFile) {
2793
+ if (sourceFile.deepkitDeclarationTransformed) return sourceFile;
2794
+ this.sourceFile = sourceFile;
2795
+ this.addExports = [];
2796
+ const configResolver = this.getConfigResolver(sourceFile);
2797
+ const reflection = configResolver.match(sourceFile.fileName);
2798
+ Object.assign(this.compilerOptions, configResolver.config.compilerOptions);
2799
+ if (reflection.mode === "never") return sourceFile;
2800
+ const visitor = /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name((node) => {
2801
+ node = visitEachChild(node, visitor, this.context);
2802
+ if ((isTypeAliasDeclaration(node) || isInterfaceDeclaration(node) || isEnumDeclaration(node)) && hasModifier(node, SyntaxKind2.ExportKeyword)) {
2803
+ const reflection2 = this.isWithReflection(sourceFile, node);
2804
+ if (reflection2) {
2805
+ this.addExports.push({
2806
+ identifier: getIdentifierName(this.getDeclarationVariableName(node.name))
2807
+ });
2808
+ }
2809
+ }
2810
+ return node;
2811
+ }, "visitor");
2812
+ this.sourceFile = visitNode(this.sourceFile, visitor);
2813
+ if (this.addExports.length) {
2814
+ const exports$1 = [];
2815
+ const handledIdentifier = [];
2816
+ for (const imp of this.addExports) {
2817
+ if (handledIdentifier.includes(imp.identifier)) continue;
2818
+ handledIdentifier.push(imp.identifier);
2819
+ exports$1.push(this.f.createTypeAliasDeclaration([
2820
+ this.f.createModifier(SyntaxKind2.ExportKeyword),
2821
+ this.f.createModifier(SyntaxKind2.DeclareKeyword)
2822
+ ], this.f.createIdentifier(imp.identifier), void 0, this.f.createArrayTypeNode(this.f.createKeywordTypeNode(SyntaxKind2.AnyKeyword))));
2823
+ }
2824
+ this.sourceFile = this.f.updateSourceFile(this.sourceFile, [
2825
+ ...this.sourceFile.statements,
2826
+ ...exports$1
2827
+ ]);
2828
+ }
2829
+ this.sourceFile.deepkitDeclarationTransformed = true;
2830
+ return this.sourceFile;
2831
+ }
2832
+ };
2833
+ var cache2 = new Cache();
2834
+ function createTransformer(context, options = {}) {
2835
+ return /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name(function transformer2(ctx) {
2836
+ cache2.tick();
2837
+ return new ReflectionTransformer(ctx, cache2).withReflection(defu__default.default(options, {
2838
+ reflection: context.tsconfig.tsconfigJson.compilerOptions?.reflection || context.tsconfig.tsconfigJson.reflection,
2839
+ reflectionLevel: context.tsconfig.tsconfigJson.compilerOptions?.reflectionLevel || context.tsconfig.tsconfigJson.reflectionLevel
2840
+ }, {
2841
+ exclude: [],
2842
+ reflection: "default",
2843
+ reflectionLevel: "minimal"
2844
+ }));
2845
+ }, "transformer");
2846
+ }
2847
+ chunkBGYQAVKQ_cjs.__name(createTransformer, "createTransformer");
2848
+ function createDeclarationTransformer(context, options = {}) {
2849
+ return /* @__PURE__ */ chunkBGYQAVKQ_cjs.__name(function declarationTransformer2(ctx) {
2850
+ return new DeclarationTransformer(ctx, cache2).withReflection(defu__default.default(options, {
2851
+ reflection: context.tsconfig.tsconfigJson.compilerOptions?.reflection || context.tsconfig.tsconfigJson.reflection,
2852
+ reflectionLevel: context.tsconfig.tsconfigJson.compilerOptions?.reflectionLevel || context.tsconfig.tsconfigJson.reflectionLevel
2853
+ }, {
2854
+ exclude: [],
2855
+ reflection: "default",
2856
+ reflectionLevel: "minimal"
2857
+ }));
2858
+ }, "declarationTransformer");
2859
+ }
2860
+ chunkBGYQAVKQ_cjs.__name(createDeclarationTransformer, "createDeclarationTransformer");
2861
+
2862
+ exports.createDeclarationTransformer = createDeclarationTransformer;
2863
+ exports.createTransformer = createTransformer;