@runtyped/type-compiler 1.0.20-alpha.1

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 (84) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +4 -0
  3. package/compiler-debug.ts +38 -0
  4. package/deepkit-compiler-debug.js +5 -0
  5. package/deepkit-type-install.js +5 -0
  6. package/dist/cjs/compiler-debug.d.ts +1 -0
  7. package/dist/cjs/compiler-debug.js +28 -0
  8. package/dist/cjs/compiler-debug.js.map +1 -0
  9. package/dist/cjs/index.d.ts +7 -0
  10. package/dist/cjs/index.js +36 -0
  11. package/dist/cjs/index.js.map +1 -0
  12. package/dist/cjs/install-transformer.d.ts +7 -0
  13. package/dist/cjs/install-transformer.js +77 -0
  14. package/dist/cjs/install-transformer.js.map +1 -0
  15. package/dist/cjs/src/compiler.d.ts +313 -0
  16. package/dist/cjs/src/compiler.js +2506 -0
  17. package/dist/cjs/src/compiler.js.map +1 -0
  18. package/dist/cjs/src/config.d.ts +83 -0
  19. package/dist/cjs/src/config.js +248 -0
  20. package/dist/cjs/src/config.js.map +1 -0
  21. package/dist/cjs/src/debug.d.ts +9 -0
  22. package/dist/cjs/src/debug.js +26 -0
  23. package/dist/cjs/src/debug.js.map +1 -0
  24. package/dist/cjs/src/loader.d.ts +18 -0
  25. package/dist/cjs/src/loader.js +55 -0
  26. package/dist/cjs/src/loader.js.map +1 -0
  27. package/dist/cjs/src/plugin.d.ts +14 -0
  28. package/dist/cjs/src/plugin.js +46 -0
  29. package/dist/cjs/src/plugin.js.map +1 -0
  30. package/dist/cjs/src/reflection-ast.d.ts +46 -0
  31. package/dist/cjs/src/reflection-ast.js +335 -0
  32. package/dist/cjs/src/reflection-ast.js.map +1 -0
  33. package/dist/cjs/src/resolver.d.ts +27 -0
  34. package/dist/cjs/src/resolver.js +88 -0
  35. package/dist/cjs/src/resolver.js.map +1 -0
  36. package/dist/cjs/src/ts-types.d.ts +17 -0
  37. package/dist/cjs/src/ts-types.js +6 -0
  38. package/dist/cjs/src/ts-types.js.map +1 -0
  39. package/dist/esm/compiler-debug.d.ts +1 -0
  40. package/dist/esm/compiler-debug.js +26 -0
  41. package/dist/esm/compiler-debug.js.map +1 -0
  42. package/dist/esm/index.d.ts +7 -0
  43. package/dist/esm/index.js +19 -0
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/install-transformer.d.ts +7 -0
  46. package/dist/esm/install-transformer.js +75 -0
  47. package/dist/esm/install-transformer.js.map +1 -0
  48. package/dist/esm/src/compiler.d.ts +313 -0
  49. package/dist/esm/src/compiler.js +2463 -0
  50. package/dist/esm/src/compiler.js.map +1 -0
  51. package/dist/esm/src/config.d.ts +83 -0
  52. package/dist/esm/src/config.js +238 -0
  53. package/dist/esm/src/config.js.map +1 -0
  54. package/dist/esm/src/debug.d.ts +9 -0
  55. package/dist/esm/src/debug.js +21 -0
  56. package/dist/esm/src/debug.js.map +1 -0
  57. package/dist/esm/src/loader.d.ts +18 -0
  58. package/dist/esm/src/loader.js +48 -0
  59. package/dist/esm/src/loader.js.map +1 -0
  60. package/dist/esm/src/plugin.d.ts +14 -0
  61. package/dist/esm/src/plugin.js +40 -0
  62. package/dist/esm/src/plugin.js.map +1 -0
  63. package/dist/esm/src/reflection-ast.d.ts +46 -0
  64. package/dist/esm/src/reflection-ast.js +284 -0
  65. package/dist/esm/src/reflection-ast.js.map +1 -0
  66. package/dist/esm/src/resolver.d.ts +27 -0
  67. package/dist/esm/src/resolver.js +80 -0
  68. package/dist/esm/src/resolver.js.map +1 -0
  69. package/dist/esm/src/ts-types.d.ts +17 -0
  70. package/dist/esm/src/ts-types.js +5 -0
  71. package/dist/esm/src/ts-types.js.map +1 -0
  72. package/index.ts +22 -0
  73. package/install-transformer.ts +84 -0
  74. package/package.json +59 -0
  75. package/src/compiler.ts +3003 -0
  76. package/src/config.ts +331 -0
  77. package/src/debug.ts +22 -0
  78. package/src/loader.ts +58 -0
  79. package/src/plugin.ts +58 -0
  80. package/src/reflection-ast.ts +335 -0
  81. package/src/resolver.ts +113 -0
  82. package/src/ts-types.ts +28 -0
  83. package/tsconfig.esm.json +16 -0
  84. package/tsconfig.json +27 -0
@@ -0,0 +1,17 @@
1
+ import type { SourceFile as TSSourceFile, ScriptKind, Symbol, SymbolTable, Node } from 'typescript';
2
+ /**
3
+ * Contains @internal properties that are not yet in the public API of TS.
4
+ */
5
+ export interface SourceFile extends TSSourceFile {
6
+ /**
7
+ * If two source files are for the same version of the same package, one will redirect to the other.
8
+ * (See `createRedirectSourceFile` in program.ts.)
9
+ * The redirect will have this set. The redirected-to source file will be in `redirectTargetsMap`.
10
+ */
11
+ redirectInfo?: any;
12
+ scriptKind?: ScriptKind;
13
+ externalModuleIndicator?: Node;
14
+ commonJsModuleIndicator?: Node;
15
+ jsGlobalAugmentations?: SymbolTable;
16
+ symbol?: Symbol;
17
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ //Contains types and makes certain properties available that are currently marked as @internal and thus not part of the public TS API.
3
+ //Certain interfaces do not contain all properties/methods from all internal TS types, because we add only those we actually use.
4
+ //This helps to identity which types are actually needed and maybe can be brought up to the TS team as candidates to make them public.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=ts-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-types.js","sourceRoot":"","sources":["../../../src/ts-types.ts"],"names":[],"mappings":";AAAA,sIAAsI;AACtI,iIAAiI;AACjI,sIAAsI"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { deepkitType } from './src/plugin.js';
2
+ import { readFileSync } from 'fs';
3
+ function parseArguments(args) {
4
+ const result = {
5
+ file: '',
6
+ };
7
+ for (let i = 0; i < args.length; i++) {
8
+ const arg = args[i];
9
+ if (arg === '--config') {
10
+ result.config = args[i + 1];
11
+ i++;
12
+ }
13
+ else {
14
+ result.file = arg;
15
+ }
16
+ }
17
+ return result;
18
+ }
19
+ const args = parseArguments(process.argv.slice(2));
20
+ const transformer = deepkitType({
21
+ tsConfig: args.config,
22
+ });
23
+ const code = readFileSync(args.file, 'utf8');
24
+ const transformed = transformer(code, args.file);
25
+ console.log(transformed?.code);
26
+ //# sourceMappingURL=compiler-debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler-debug.js","sourceRoot":"","sources":["../../compiler-debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAOlC,SAAS,cAAc,CAAC,IAAc;IAClC,MAAM,MAAM,GAAc;QACtB,IAAI,EAAE,EAAE;KACX,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACrB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,CAAC,EAAE,CAAC;QACR,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;QACtB,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAInD,MAAM,WAAW,GAAG,WAAW,CAAC;IAC5B,QAAQ,EAAE,IAAI,CAAC,MAAM;CACxB,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7C,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAEjD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Program } from 'typescript';
2
+ export * from './src/compiler.js';
3
+ export * from './src/loader.js';
4
+ export default function myTransformerPlugin(program: Program, opts: {}): {
5
+ before: import("typescript").CustomTransformerFactory;
6
+ afterDeclarations: import("typescript").CustomTransformerFactory;
7
+ };
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Runtyped Framework
3
+ * Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the MIT License.
7
+ *
8
+ * You should have received a copy of the MIT License along with this program.
9
+ */
10
+ import { declarationTransformer, transformer } from './src/compiler.js';
11
+ export * from './src/compiler.js';
12
+ export * from './src/loader.js';
13
+ export default function myTransformerPlugin(program, opts) {
14
+ return {
15
+ before: transformer,
16
+ afterDeclarations: declarationTransformer,
17
+ };
18
+ }
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGxE,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAEhC,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,OAAgB,EAAE,IAAQ;IAClE,OAAO;QACH,MAAM,EAAE,WAAW;QACnB,iBAAiB,EAAE,sBAAsB;KAC5C,CAAC;AACN,CAAC"}
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * This script installs the deepkit/type transformer (that extracts automatically types and adds the correct @t decorator) to the typescript node_modules.
4
+ *
5
+ * The critical section that needs adjustment is in the `function getScriptTransformers` in `node_modules/typescript/lib/tsc.js`.
6
+ */
7
+ export {};
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * This script installs the deepkit/type transformer (that extracts automatically types and adds the correct @t decorator) to the typescript node_modules.
4
+ *
5
+ * The critical section that needs adjustment is in the `function getScriptTransformers` in `node_modules/typescript/lib/tsc.js`.
6
+ */
7
+ import { dirname, join, relative } from 'path';
8
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
9
+ let to = process.argv[2] || process.cwd();
10
+ function getPatchId(id) {
11
+ return 'deepkit_type_patch_' + id;
12
+ }
13
+ function getCode(deepkitDistPath, varName, id) {
14
+ return `
15
+ //${getPatchId(id)}
16
+ try {
17
+ var typeTransformer;
18
+ try {
19
+ typeTransformer = require('@runtyped/type-compiler');
20
+ } catch (error) {
21
+ typeTransformer = require(${JSON.stringify(deepkitDistPath)});
22
+ }
23
+ if (typeTransformer) {
24
+ if (!customTransformers) ${varName} = {};
25
+ if (!${varName}.before) ${varName}.before = [];
26
+ let alreadyPatched = false;
27
+ for (let fn of ${varName}.before) {
28
+ if (fn && fn.name === 'deepkitTransformer') alreadyPatched = true;
29
+ }
30
+ if (!alreadyPatched) {
31
+ if (!${varName}.before.includes(typeTransformer.transformer)) ${varName}.before.push(typeTransformer.transformer);
32
+
33
+ if (!${varName}.afterDeclarations) ${varName}.afterDeclarations = [];
34
+ if (!${varName}.afterDeclarations.includes(typeTransformer.declarationTransformer)) {
35
+ ${varName}.afterDeclarations.push(typeTransformer.declarationTransformer);
36
+ }
37
+ }
38
+ }
39
+ } catch (e) {
40
+ }
41
+ //${getPatchId(id)}-end
42
+ `;
43
+ }
44
+ function isPatched(code, id) {
45
+ return code.includes(getPatchId(id));
46
+ }
47
+ function patchGetTransformers(deepkitDistPath, code) {
48
+ const id = 'patchGetTransformers';
49
+ if (isPatched(code, id))
50
+ return '';
51
+ const find = /function getTransformers\([^)]+\)\s*{/;
52
+ if (!code.match(find))
53
+ return '';
54
+ code = code.replace(find, function (a) {
55
+ return a + '\n ' + getCode(deepkitDistPath, 'customTransformers', id);
56
+ });
57
+ return code;
58
+ }
59
+ if (to + '/dist/cjs' === __dirname) {
60
+ to = join(to, '..'); //we exclude type-compiler/node_modules
61
+ }
62
+ const typeScriptPath = dirname(require.resolve('typescript', { paths: [to] }));
63
+ const deepkitDistPath = relative(typeScriptPath, __dirname);
64
+ const paths = ['tsc.js', '_tsc.js', 'typescript.js'];
65
+ for (const fileName of paths) {
66
+ const file = join(typeScriptPath, fileName);
67
+ if (!existsSync(file))
68
+ continue;
69
+ const content = patchGetTransformers(deepkitDistPath, readFileSync(file, 'utf8'));
70
+ if (!content)
71
+ continue;
72
+ writeFileSync(file, content);
73
+ console.log('Deepkit Type: Injected TypeScript transformer at', file);
74
+ }
75
+ //# sourceMappingURL=install-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-transformer.js","sourceRoot":"","sources":["../../install-transformer.ts"],"names":[],"mappings":";AAEA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAE7D,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAE1C,SAAS,UAAU,CAAC,EAAU;IAC1B,OAAO,qBAAqB,GAAG,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,OAAO,CAAC,eAAuB,EAAE,OAAe,EAAE,EAAU;IACjE,OAAO;YACC,UAAU,CAAC,EAAE,CAAC;;;;;;4CAMkB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC;;;2CAGhC,OAAO;uBAC3B,OAAO,YAAY,OAAO;;iCAEhB,OAAO;;;;2BAIb,OAAO,kDAAkD,OAAO;;2BAEhE,OAAO,uBAAuB,OAAO;2BACrC,OAAO;0BACR,OAAO;;;;;;YAMrB,UAAU,CAAC,EAAE,CAAC;KACrB,CAAC;AACN,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,EAAU;IACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,oBAAoB,CAAC,eAAuB,EAAE,IAAY;IAC/D,MAAM,EAAE,GAAG,sBAAsB,CAAC;IAClC,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,MAAM,IAAI,GAAG,uCAAuC,CAAC;IACrD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC;QACjC,OAAO,CAAC,GAAG,QAAQ,GAAG,OAAO,CAAC,eAAe,EAAE,oBAAoB,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,IAAI,EAAE,GAAG,WAAW,KAAK,SAAS,EAAE,CAAC;IACjC,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,uCAAuC;AAChE,CAAC;AAED,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/E,MAAM,eAAe,GAAG,QAAQ,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAE5D,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;AAErD,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,SAAS;IAChC,MAAM,OAAO,GAAG,oBAAoB,CAAC,eAAe,EAAE,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAClF,IAAI,CAAC,OAAO;QAAE,SAAS;IACvB,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,kDAAkD,EAAE,IAAI,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,313 @@
1
+ import ts, { ArrowFunction, Bundle, ClassDeclaration, ClassExpression, CompilerHost, CompilerOptions, ConstructorDeclaration, CustomTransformer, CustomTransformerFactory, Declaration, EntityName, ExportDeclaration, Expression, ExpressionWithTypeArguments, FunctionDeclaration, FunctionExpression, Identifier, ImportDeclaration, JSDocImportTag, MethodDeclaration, ModuleDeclaration, ModuleExportName, Node, NodeArray, NodeFactory, ParseConfigHost, PropertyAccessExpression, QualifiedName, Statement, TransformationContext, TypeAliasDeclaration, TypeChecker, TypeParameterDeclaration, TypeReferenceNode } from 'typescript';
2
+ import { NodeConverter, PackExpression } from './reflection-ast.js';
3
+ import { SourceFile } from './ts-types.js';
4
+ import { ReflectionOp } from '@runtyped/type-spec';
5
+ import { Resolver } from './resolver.js';
6
+ import { ConfigResolver, MatchResult, ReflectionConfig, ReflectionConfigCache } from './config.js';
7
+ export declare function encodeOps(ops: ReflectionOp[]): string;
8
+ export declare const packSizeByte: number;
9
+ /**
10
+ * It can't be more ops than this given number
11
+ */
12
+ export declare const packSize: number;
13
+ export declare function debugPackStruct(sourceFile: SourceFile, forType: Node, pack: {
14
+ ops: ReflectionOp[];
15
+ stack: PackExpression[];
16
+ }): void;
17
+ interface Frame {
18
+ variables: {
19
+ name: string;
20
+ index: number;
21
+ }[];
22
+ opIndex: number;
23
+ conditional?: true;
24
+ previous?: Frame;
25
+ }
26
+ type StackEntry = Expression | string | number | boolean;
27
+ declare class CompilerProgram {
28
+ forNode: Node;
29
+ sourceFile?: SourceFile | undefined;
30
+ protected ops: ReflectionOp[];
31
+ protected stack: StackEntry[];
32
+ protected mainOffset: number;
33
+ protected stackPosition: number;
34
+ protected frame: Frame;
35
+ protected activeCoRoutines: {
36
+ ops: ReflectionOp[];
37
+ }[];
38
+ protected coRoutines: {
39
+ ops: ReflectionOp[];
40
+ }[];
41
+ constructor(forNode: Node, sourceFile?: SourceFile | undefined);
42
+ buildPackStruct(): {
43
+ ops: ReflectionOp[];
44
+ stack: StackEntry[];
45
+ };
46
+ isEmpty(): boolean;
47
+ pushConditionalFrame(): void;
48
+ pushStack(item: StackEntry): number;
49
+ pushCoRoutine(): void;
50
+ popCoRoutine(): number;
51
+ pushOp(...ops: ReflectionOp[]): void;
52
+ pushOpAtFrame(frame: Frame, ...ops: ReflectionOp[]): void;
53
+ /**
54
+ * Returns the index of the `entry` in the stack, if already exists. If not, add it, and return that new index.
55
+ */
56
+ findOrAddStackEntry(entry: any): number;
57
+ /**
58
+ * To make room for a stack entry expected on the stack as input for example.
59
+ */
60
+ increaseStackPosition(): number;
61
+ protected resolveFunctionParameters: Map<ts.Node, number>;
62
+ resolveFunctionParametersIncrease(fn: Node): void;
63
+ resolveFunctionParametersDecrease(fn: Node): void;
64
+ isResolveFunctionParameters(fn: Node): boolean;
65
+ /**
66
+ *
67
+ * Each pushFrame() call needs a popFrame() call.
68
+ */
69
+ pushFrame(implicit?: boolean): Frame;
70
+ findConditionalFrame(): Frame | undefined;
71
+ /**
72
+ * Remove stack without doing it as OP in the processor. Some other command calls popFrame() already, which makes popFrameImplicit() an implicit popFrame.
73
+ * e.g. union, class, etc. all call popFrame(). the current CompilerProgram needs to be aware of that, which this function is for.
74
+ */
75
+ popFrameImplicit(): void;
76
+ moveFrame(): void;
77
+ pushVariable(name: string, frame?: Frame): number;
78
+ pushTemplateParameter(name: string, withDefault?: boolean): number;
79
+ findVariable(name: string, frame?: Frame): {
80
+ frameOffset: number;
81
+ stackIndex: number;
82
+ } | undefined;
83
+ }
84
+ export declare class Cache {
85
+ resolver: ReflectionConfigCache;
86
+ sourceFiles: {
87
+ [fileName: string]: SourceFile;
88
+ };
89
+ globalSourceFiles?: SourceFile[];
90
+ /**
91
+ * Signals the cache to check if it needs to be cleared.
92
+ */
93
+ tick(): void;
94
+ }
95
+ /**
96
+ * Read the TypeScript AST and generate pack struct (instructions + pre-defined stack).
97
+ *
98
+ * This transformer extracts type and add the encoded (so its small and low overhead) at classes and functions as property.
99
+ *
100
+ * runtyped/type can then extract and decode them on-demand.
101
+ */
102
+ export declare class ReflectionTransformer implements CustomTransformer {
103
+ protected context: TransformationContext;
104
+ protected cache: Cache;
105
+ sourceFile: SourceFile;
106
+ protected f: NodeFactory;
107
+ protected embedAssignType: boolean;
108
+ /**
109
+ * Types added to this map will get a type program directly under it.
110
+ * This is for types used in the very same file.
111
+ */
112
+ protected compileDeclarations: Map<ts.EnumDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration, {
113
+ name: EntityName;
114
+ sourceFile: SourceFile;
115
+ compiled?: Statement[];
116
+ }>;
117
+ /**
118
+ * Types added to this map will get a type program at the top root level of the program.
119
+ * This is for imported types, which need to be inlined into the current file, as we do not emit type imports (TS will omit them).
120
+ */
121
+ protected embedDeclarations: Map<ts.Node, {
122
+ name: EntityName;
123
+ sourceFile?: SourceFile;
124
+ }>;
125
+ /**
126
+ * When a node was embedded or compiled (from the maps above), we store it here to know to not add it again.
127
+ */
128
+ protected compiledDeclarations: Set<ts.Node>;
129
+ protected addImports: {
130
+ importDeclaration: ImportDeclaration | JSDocImportTag;
131
+ identifier: Identifier;
132
+ }[];
133
+ protected additionalImports: Map<ts.ImportDeclaration | ts.JSDocImportTag, ts.Statement>;
134
+ protected nodeConverter: NodeConverter;
135
+ protected typeChecker?: TypeChecker;
136
+ protected resolver: Resolver;
137
+ protected host: CompilerHost;
138
+ protected overriddenHost: boolean;
139
+ protected overriddenConfigResolver?: ConfigResolver;
140
+ protected compilerOptions: CompilerOptions;
141
+ /**
142
+ * When a deep call expression was found a script-wide variable is necessary
143
+ * as temporary storage.
144
+ */
145
+ protected tempResultIdentifier?: Identifier;
146
+ protected parseConfigHost: ParseConfigHost;
147
+ protected intrinsicMetaDeclaration: TypeAliasDeclaration;
148
+ constructor(context: TransformationContext, cache?: Cache);
149
+ forHost(host: CompilerHost): this;
150
+ withReflection(config: ReflectionConfig): this;
151
+ transformBundle(node: Bundle): Bundle;
152
+ getTempResultIdentifier(): Identifier;
153
+ protected getConfigResolver(sourceFile: {
154
+ fileName: string;
155
+ }): ConfigResolver;
156
+ protected getReflectionConfig(sourceFile: {
157
+ fileName: string;
158
+ }): MatchResult;
159
+ protected isWithReflection(sourceFile: SourceFile | undefined, node: Node & {
160
+ __deepkitConfig?: ReflectionConfig;
161
+ }): boolean;
162
+ transformSourceFile(sourceFile: SourceFile): SourceFile;
163
+ attachAdditionalStatements(statements: NodeArray<Statement> | Statement[]): Statement[];
164
+ protected getModuleType(): 'cjs' | 'esm';
165
+ protected getArrowFunctionΩPropertyAccessIdentifier(node: ArrowFunction): Identifier | undefined;
166
+ protected injectResetΩ<T extends FunctionDeclaration | FunctionExpression | MethodDeclaration | ConstructorDeclaration | ArrowFunction>(node: T): T;
167
+ protected createProgramVarFromNode(node: Node, name: EntityName, sourceFile?: SourceFile): Statement[];
168
+ protected extractPackStructOfExpression(node: Expression, program: CompilerProgram): void;
169
+ protected extractPackStructOfType(node: Node | Declaration | ClassDeclaration | ClassExpression, program: CompilerProgram): void;
170
+ protected knownClasses: {
171
+ [name: string]: ReflectionOp;
172
+ };
173
+ protected getGlobalLibs(): SourceFile[];
174
+ /**
175
+ * This is a custom resolver based on populated `locals` from the binder. It uses a custom resolution algorithm since
176
+ * we have no access to the binder/TypeChecker directly and instantiating a TypeChecker per file/transformer is incredible slow.
177
+ */
178
+ protected resolveDeclaration(typeName: EntityName): {
179
+ declaration: Node;
180
+ importDeclaration?: ImportDeclaration | JSDocImportTag;
181
+ typeOnly?: boolean;
182
+ } | void;
183
+ protected getDeclarationVariableName(typeName: EntityName): Identifier;
184
+ /**
185
+ * The semantic of isExcluded is different from checking if the fileName is part
186
+ * of reflection config option. isExcluded checks if the file should be excluded
187
+ * via the exclude option. mainly used to exclude globals and external libraries.
188
+ */
189
+ protected isExcluded(fileName: string): boolean;
190
+ protected extractPackStructOfTypeReference(type: Identifier | TypeReferenceNode | ExpressionWithTypeArguments, program: CompilerProgram): void;
191
+ /**
192
+ * Returns the class declaration, function/arrow declaration, or block where type was used.
193
+ */
194
+ protected getTypeUser(type: Node): Node;
195
+ /**
196
+ * With this function we want to check if `type` is used in the signature itself from the parent of `declaration`.
197
+ * If so, we do not try to infer the type from runtime values.
198
+ *
199
+ * Examples where we do not infer from runtime, `type` being `T` and `declaration` being `<T>` (return false):
200
+ *
201
+ * ```typescript
202
+ * class User<T> {
203
+ * config: T;
204
+ * }
205
+ *
206
+ * class User<T> {
207
+ * constructor(public config: T) {}
208
+ * }
209
+ *
210
+ * function do<T>(item: T): void {}
211
+ * function do<T>(item: T): T {}
212
+ * ```
213
+ *
214
+ * Examples where we infer from runtime (return true):
215
+ *
216
+ * ```typescript
217
+ * function do<T>(item: T) {
218
+ * return typeOf<T>; //<-- because of that
219
+ * }
220
+ *
221
+ * function do<T>(item: T) {
222
+ * class A {
223
+ * config: T; //<-- because of that
224
+ * }
225
+ * return A;
226
+ * }
227
+ *
228
+ * function do<T>(item: T) {
229
+ * class A {
230
+ * doIt() {
231
+ * class B {
232
+ * config: T; //<-- because of that
233
+ * }
234
+ * return B;
235
+ * }
236
+ * }
237
+ * return A;
238
+ * }
239
+ *
240
+ * function do<T>(item: T) {
241
+ * class A {
242
+ * doIt(): T { //<-- because of that
243
+ * }
244
+ * }
245
+ * return A;
246
+ * }
247
+ * ```
248
+ */
249
+ protected needsToBeInferred(declaration: TypeParameterDeclaration, type: Identifier | TypeReferenceNode | ExpressionWithTypeArguments): boolean;
250
+ protected resolveTypeOnlyImport(entityName: EntityName, program: CompilerProgram): void;
251
+ protected resolveTypeName(typeName: string, program: CompilerProgram): void;
252
+ protected resolveTypeParameter(declaration: TypeParameterDeclaration, type: Identifier | TypeReferenceNode | ExpressionWithTypeArguments, program: CompilerProgram): void;
253
+ protected createAccessorForEntityName(e: QualifiedName): PropertyAccessExpression;
254
+ protected findDeclarationInFile(sourceFile: SourceFile | ModuleDeclaration, declarationName: string): Declaration | undefined;
255
+ protected resolveImportSpecifier(_declarationName: string | ModuleExportName, importOrExport: ExportDeclaration | ImportDeclaration | JSDocImportTag, sourceFile: SourceFile): Declaration | undefined;
256
+ protected followExport(declarationName: string, statement: ExportDeclaration, sourceFile: SourceFile): Declaration | undefined;
257
+ protected getTypeOfType(type: Node | Declaration): Expression | undefined;
258
+ protected packOpsAndStack(program: CompilerProgram): ts.Expression | undefined;
259
+ /**
260
+ * Note: We have to duplicate the expressions as it can be that incoming expression are from another file and contain wrong pos/end properties,
261
+ * so the code generation is then broken when we simply reuse them. Wrong code like ``User.__type = [.toEqual({`` is then generated.
262
+ * This function is probably not complete, but we add new copies when required.
263
+ */
264
+ protected valueToExpression(value: undefined | PackExpression | PackExpression[]): Expression;
265
+ /**
266
+ * A class is decorated with type information by adding a static variable.
267
+ *
268
+ * class Model {
269
+ * static __types = pack(ReflectionOp.string); //<-- encoded type information
270
+ * title: string;
271
+ * }
272
+ */
273
+ protected decorateClass(sourceFile: SourceFile, node: ClassDeclaration | ClassExpression): Node;
274
+ /**
275
+ * const fn = function() {}
276
+ *
277
+ * => const fn = __assignType(function() {}, [34])
278
+ */
279
+ protected decorateFunctionExpression(expression: FunctionExpression): ts.FunctionExpression | ts.CallExpression;
280
+ /**
281
+ * function name() {}
282
+ *
283
+ * => function name() {}; name.__type = 34;
284
+ */
285
+ protected decorateFunctionDeclaration(declaration: FunctionDeclaration): ts.ExportAssignment | ts.FunctionDeclaration | ts.Statement[] | undefined;
286
+ /**
287
+ * const fn = () => {}
288
+ * => const fn = __assignType(() => {}, [34])
289
+ */
290
+ protected decorateArrowFunction(expression: ArrowFunction): ts.ArrowFunction | ts.CallExpression;
291
+ /**
292
+ * Object.assign(fn, {__type: []}) is much slower than a custom implementation like
293
+ *
294
+ * assignType(fn, [])
295
+ *
296
+ * where we embed assignType() at the beginning of the type.
297
+ */
298
+ protected wrapWithAssignType(fn: Expression, type: Expression): ts.CallExpression;
299
+ /**
300
+ * Checks if reflection was disabled/enabled in file via JSDoc attribute for a particular
301
+ * Node, e.g `@reflection no`. If nothing is found, "reflection" config option needs to be used.
302
+ */
303
+ protected getExplicitReflectionMode(sourceFile: SourceFile | undefined, node: Node): boolean | undefined;
304
+ }
305
+ export declare class DeclarationTransformer extends ReflectionTransformer {
306
+ protected addExports: {
307
+ identifier: string;
308
+ }[];
309
+ transformSourceFile(sourceFile: SourceFile): SourceFile;
310
+ }
311
+ export declare const transformer: CustomTransformerFactory;
312
+ export declare const declarationTransformer: CustomTransformerFactory;
313
+ export {};