@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,335 @@
1
+ /*
2
+ * Runtyped Framework
3
+ * Copyright (c) Deepkit UG, Marc J. Schmidt
4
+ * Copyright (c) Jacopo Scazzosi
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the MIT License.
8
+ *
9
+ * You should have received a copy of the MIT License along with this program.
10
+ */
11
+
12
+ import ts, {
13
+ __String,
14
+ ArrowFunction,
15
+ BigIntLiteral,
16
+ BinaryExpression,
17
+ EntityName,
18
+ Expression,
19
+ Identifier,
20
+ ImportDeclaration,
21
+ isBigIntLiteral,
22
+ JSDoc,
23
+ JSDocImportTag,
24
+ ModifierLike,
25
+ Node,
26
+ NodeArray,
27
+ NodeFactory,
28
+ NumericLiteral,
29
+ PrivateIdentifier,
30
+ PropertyAccessExpression,
31
+ PropertyName,
32
+ QualifiedName,
33
+ StringLiteral,
34
+ StringLiteralLike,
35
+ SymbolTable,
36
+ } from 'typescript';
37
+ import { cloneNode as tsNodeClone, CloneNodeHook } from '@marcj/ts-clone-node';
38
+ import { SourceFile } from './ts-types.js';
39
+
40
+ const {
41
+ isArrowFunction,
42
+ isComputedPropertyName,
43
+ isIdentifier,
44
+ isNamedImports,
45
+ isNumericLiteral,
46
+ isPrivateIdentifier,
47
+ isStringLiteral,
48
+ isStringLiteralLike,
49
+ setOriginalNode,
50
+ getLeadingCommentRanges,
51
+ isNoSubstitutionTemplateLiteral,
52
+ NodeFlags,
53
+ SyntaxKind,
54
+ } = ts;
55
+
56
+ export type PackExpression = Expression | string | number | boolean | bigint;
57
+
58
+ function is__String(value: any): value is __String {
59
+ return typeof value === 'string';
60
+ }
61
+
62
+ export function getIdentifierName(node: Identifier | PrivateIdentifier | StringLiteral | __String): string {
63
+ if (is__String(node)) return node as string;
64
+ if (isIdentifier(node) || isPrivateIdentifier(node)) {
65
+ return ts.unescapeLeadingUnderscores(node.escapedText);
66
+ }
67
+ if (isStringLiteral(node)) return node.text;
68
+ return '';
69
+ }
70
+
71
+ export function getEscapedText(node: Identifier | PrivateIdentifier | StringLiteral | __String): string {
72
+ if (is__String(node)) return node as string;
73
+ if (isIdentifier(node) || isPrivateIdentifier(node)) return node.escapedText as string;
74
+ return getIdentifierName(node);
75
+ }
76
+
77
+ export function findSourceFile(node: Node): SourceFile | undefined {
78
+ if (node.kind === SyntaxKind.SourceFile) return node as SourceFile;
79
+ let current = node.parent;
80
+ while (current && current.kind !== SyntaxKind.SourceFile) {
81
+ current = current.parent;
82
+ }
83
+ return current as SourceFile;
84
+ }
85
+
86
+ export function joinQualifiedName(name: EntityName): string {
87
+ if (isIdentifier(name)) return getIdentifierName(name);
88
+ return joinQualifiedName(name.left) + '_' + getIdentifierName(name.right);
89
+ }
90
+
91
+ export function getCommentOfNode(sourceFile: SourceFile, node: Node): string | undefined {
92
+ const comment = getLeadingCommentRanges(sourceFile.text, node.pos);
93
+ if (!comment) return;
94
+
95
+ return comment.map(v => sourceFile.text.substring(v.pos, v.end)).join('\n');
96
+ }
97
+
98
+ export function parseJSDocAttributeFromText(comment: string, attribute: string): string | undefined {
99
+ // no regex
100
+ const index = comment.indexOf('@' + attribute + ' ');
101
+ if (index === -1) {
102
+ let start = 0;
103
+ while (true) {
104
+ const withoutContent = comment.indexOf('@' + attribute, start);
105
+ if (withoutContent === -1) return undefined;
106
+ //make sure next character is space or end of comment
107
+ const nextCharacter = comment[withoutContent + attribute.length + 1];
108
+ if (!nextCharacter || nextCharacter === ' ' || nextCharacter === '\n' || nextCharacter === '\r' || nextCharacter === '\t') {
109
+ return '';
110
+ }
111
+ start = withoutContent + attribute.length + 1;
112
+ }
113
+ return undefined;
114
+ }
115
+
116
+ const start = index + attribute.length + 2;
117
+ // end is either next attribute @ or end of comment.
118
+ const nextAttribute = comment.indexOf('@', start);
119
+ const endOfComment = comment.indexOf('*/', start);
120
+ const end = nextAttribute === -1 ? endOfComment : Math.min(nextAttribute, endOfComment);
121
+ const content = comment.substring(start, end).trim();
122
+
123
+ // make sure multiline comments are supported, and each line is trimmed and `\s\s\s\*` removed
124
+ return content.split('\n').map(v => {
125
+ const indexOfStar = v.indexOf('*');
126
+ if (indexOfStar === -1) return v.trim();
127
+ return v.substring(indexOfStar + 1).trim();
128
+ }).join('\n');
129
+ }
130
+
131
+ export function extractJSDocAttribute(sourceFile: SourceFile, node: Node | undefined, attribute: string): string | undefined {
132
+ // in TypeScript 5.3 they made JSDoc parsing optional and disabled by default.
133
+ // we need to read the comments manually and then parse @{attribute} {value} manually.
134
+ // we need reference to SourceFile, since Node.getSourceFile() although available in types,
135
+ // is not available at runtime sometimes (works in tests, but fails with tsc).
136
+ if (!node) return undefined;
137
+ const comment = getCommentOfNode(sourceFile, node);
138
+ if (!comment) return undefined;
139
+
140
+ return parseJSDocAttributeFromText(comment, attribute);
141
+ }
142
+
143
+ export function getPropertyName(f: NodeFactory, node?: PropertyName): string | symbol | number | ArrowFunction {
144
+ if (!node) return '';
145
+
146
+ if (isIdentifier(node)) return getIdentifierName(node);
147
+ if (isStringLiteral(node)) return node.text;
148
+ if (isNumericLiteral(node)) return +node.text;
149
+ if (isNoSubstitutionTemplateLiteral(node)) return node.text;
150
+ if (isComputedPropertyName(node)) {
151
+ return f.createArrowFunction(undefined, undefined, [], undefined, undefined, node.expression);
152
+ }
153
+ if (isPrivateIdentifier(node)) return getIdentifierName(node);
154
+
155
+ return '';
156
+ }
157
+
158
+ export function getNameAsString(node?: PropertyName | QualifiedName): string {
159
+ if (!node) return '';
160
+ if (isIdentifier(node)) return getIdentifierName(node);
161
+ if (isStringLiteral(node)) return node.text;
162
+ if (isNumericLiteral(node)) return node.text;
163
+ if (isBigIntLiteral(node)) return node.text;
164
+ if (isNoSubstitutionTemplateLiteral(node)) return node.text;
165
+ if (isComputedPropertyName(node)) {
166
+ if (isStringLiteralLike(node) || isNumericLiteral(node)) return (node as StringLiteralLike | NumericLiteral).text;
167
+ return '';
168
+ }
169
+ if (isPrivateIdentifier(node)) return getIdentifierName(node);
170
+
171
+ return joinQualifiedName(node);
172
+ }
173
+
174
+ export function hasModifier(node: Node & { modifiers?: NodeArray<ModifierLike> }, modifier: ts.SyntaxKind): boolean {
175
+ if (!node.modifiers) return false;
176
+ return node.modifiers.some(v => v.kind === modifier);
177
+ }
178
+
179
+ const cloneHook = <T extends Node>(node: T, payload: { depth: number }): CloneNodeHook<T> | undefined => {
180
+ if (isIdentifier(node)) {
181
+ //ts-clone-node wants to read `node.text` which does not exist. we hook into it and provide the correct value.
182
+ return {
183
+ text: () => {
184
+ return getIdentifierName(node);
185
+ },
186
+ } as any;
187
+ }
188
+ return;
189
+ };
190
+
191
+ export class NodeConverter {
192
+ constructor(protected f: NodeFactory) {
193
+ }
194
+
195
+ toExpression<T extends PackExpression | PackExpression[]>(node?: T): Expression {
196
+ if (node === undefined) return this.f.createIdentifier('undefined');
197
+
198
+ if (Array.isArray(node)) {
199
+ return this.f.createArrayLiteralExpression(this.f.createNodeArray(node.map(v => this.toExpression(v))) as NodeArray<Expression>);
200
+ }
201
+
202
+ if ('string' === typeof node) return this.f.createStringLiteral(node, true);
203
+ if ('number' === typeof node) return this.f.createNumericLiteral(node);
204
+ if ('bigint' === typeof node) return this.f.createBigIntLiteral(String(node));
205
+ if ('boolean' === typeof node) return node ? this.f.createTrue() : this.f.createFalse();
206
+
207
+ if (node.pos === -1 && node.end === -1 && node.parent === undefined) {
208
+ if (isArrowFunction(node)) {
209
+ if (node.body.pos === -1 && node.body.end === -1 && node.body.parent === undefined) return node;
210
+ return this.f.createArrowFunction(node.modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, this.toExpression(node.body as Expression));
211
+ }
212
+ return node;
213
+ }
214
+ switch (node.kind) {
215
+ case SyntaxKind.Identifier:
216
+ return finish(node, this.f.createIdentifier(getIdentifierName(node as Identifier)));
217
+ case SyntaxKind.StringLiteral:
218
+ return finish(node, this.f.createStringLiteral((node as StringLiteral).text));
219
+ case SyntaxKind.NumericLiteral:
220
+ return finish(node, this.f.createNumericLiteral((node as NumericLiteral).text));
221
+ case SyntaxKind.BigIntLiteral:
222
+ return finish(node, this.f.createBigIntLiteral((node as BigIntLiteral).text));
223
+ case SyntaxKind.TrueKeyword:
224
+ return finish(node, this.f.createTrue());
225
+ case SyntaxKind.FalseKeyword:
226
+ return finish(node, this.f.createFalse());
227
+ }
228
+
229
+ //todo: ts-node-clone broke with ts 4.8,
230
+ // => TypeError: Cannot read properties of undefined (reading 'emitNode')
231
+ // which is probably due a broken node clone. We need to figure out which node it is
232
+ // and see what the issue is. since ts-node-clone is not really maintained anymore,
233
+ // we need to fork it
234
+ try {
235
+ return tsNodeClone(node, {
236
+ preserveComments: false,
237
+ factory: this.f,
238
+ setOriginalNodes: true,
239
+ preserveSymbols: true,
240
+ setParents: true,
241
+ hook: cloneHook,
242
+ }) as Expression;
243
+ } catch (error) {
244
+ console.error('could not clone node', node);
245
+ throw error;
246
+ }
247
+
248
+ }
249
+ }
250
+
251
+ function isExternalOrCommonJsModule(file: SourceFile): boolean {
252
+ //both attributes are internal and not yet public
253
+ return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== undefined;
254
+ }
255
+
256
+ export function isNodeWithLocals(node: Node): node is (Node & { locals: SymbolTable | undefined }) {
257
+ return 'locals' in node;
258
+ }
259
+
260
+ //logic copied from typescript
261
+ export function getGlobalsOfSourceFile(file: SourceFile): SymbolTable | void {
262
+ if (file.redirectInfo) return;
263
+ if (!isNodeWithLocals(file)) return;
264
+ if (!isExternalOrCommonJsModule(file)) return file.locals;
265
+ if (file.jsGlobalAugmentations) return file.jsGlobalAugmentations;
266
+ if (file.symbol && file.symbol.globalExports) return file.symbol.globalExports;
267
+ }
268
+
269
+ /**
270
+ * For imports that can removed (like a class import only used as type only, like `p: Model[]`) we have
271
+ * to modify the import so TS does not remove it.
272
+ */
273
+ export function ensureImportIsEmitted(importDeclaration: ImportDeclaration | JSDocImportTag, specifierName?: Identifier) {
274
+ if (specifierName && importDeclaration.importClause && importDeclaration.importClause.namedBindings) {
275
+ // const binding = importDeclaration.importClause.namedBindings;
276
+ if (isNamedImports(importDeclaration.importClause.namedBindings)) {
277
+ for (const element of importDeclaration.importClause.namedBindings.elements) {
278
+ if (element.name.escapedText === specifierName.escapedText) {
279
+ (element.flags as any) |= NodeFlags.Synthesized;
280
+ return;
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ (importDeclaration.flags as any) |= NodeFlags.Synthesized;
287
+ }
288
+
289
+
290
+ /**
291
+ * Serializes an entity name as an expression for decorator type metadata.
292
+ *
293
+ * @param node The entity name to serialize.
294
+ */
295
+ export function serializeEntityNameAsExpression(f: NodeFactory, node: EntityName): SerializedEntityNameAsExpression {
296
+ switch (node.kind) {
297
+ case SyntaxKind.Identifier:
298
+ return finish(node, f.createIdentifier(getIdentifierName(node)));
299
+ case SyntaxKind.QualifiedName:
300
+ return finish(node, serializeQualifiedNameAsExpression(f, node));
301
+ }
302
+ return node;
303
+ }
304
+
305
+ type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression;
306
+
307
+ /**
308
+ * Serializes an qualified name as an expression for decorator type metadata.
309
+ *
310
+ * @param node The qualified name to serialize.
311
+ * @param useFallback A value indicating whether to use logical operators to test for the
312
+ * qualified name at runtime.
313
+ */
314
+ function serializeQualifiedNameAsExpression(f: NodeFactory, node: QualifiedName): SerializedEntityNameAsExpression {
315
+ return f.createPropertyAccessExpression(serializeEntityNameAsExpression(f, node.left), node.right);
316
+ }
317
+
318
+ export type MetaNode = Node & {
319
+ jsDoc?: JSDoc[];
320
+ _original?: MetaNode;
321
+ original?: MetaNode;
322
+ _symbol?: Symbol;
323
+ symbol?: Symbol;
324
+ _parent?: MetaNode;
325
+ localSymbol?: Symbol;
326
+ };
327
+
328
+ function finish<T extends MetaNode>(oldNode: MetaNode, newNode: T): T {
329
+ setOriginalNode(newNode, oldNode);
330
+ newNode._original = newNode.original;
331
+
332
+ newNode._symbol = oldNode._symbol ?? oldNode.symbol;
333
+ newNode.symbol = newNode._symbol;
334
+ return newNode;
335
+ }
@@ -0,0 +1,113 @@
1
+ import micromatch from 'micromatch';
2
+ import {
3
+ CompilerHost,
4
+ CompilerOptions,
5
+ ExportDeclaration,
6
+ Expression,
7
+ ImportDeclaration, JSDocImportTag,
8
+ ResolvedModule,
9
+ SourceFile,
10
+ StringLiteral,
11
+ } from 'typescript';
12
+ import ts from 'typescript';
13
+
14
+ const { createSourceFile, resolveModuleName, isStringLiteral, JSDocParsingMode, ScriptTarget } = ts;
15
+
16
+ export function patternMatch(path: string, patterns: string[], base?: string): boolean {
17
+ const include = patterns.filter(pattern => pattern[0] !== '!');
18
+
19
+ const exclude = patterns.filter(pattern => pattern[0] === '!').map(pattern => pattern.substring(1));
20
+
21
+ return micromatch.isMatch(path, include, {
22
+ ignore: exclude,
23
+ });
24
+ }
25
+
26
+ /**
27
+ * A utility to resolve a module path and its declaration.
28
+ *
29
+ * It automatically reads a SourceFile, binds and caches it.
30
+ */
31
+ export class Resolver {
32
+ constructor(
33
+ public compilerOptions: CompilerOptions,
34
+ public host: CompilerHost,
35
+ protected sourceFiles: { [fileName: string]: SourceFile },
36
+ ) {}
37
+
38
+ resolve(from: SourceFile, importOrExportNode: ExportDeclaration | ImportDeclaration | JSDocImportTag): SourceFile | undefined {
39
+ const moduleSpecifier: Expression | undefined = importOrExportNode.moduleSpecifier;
40
+ if (!moduleSpecifier) return;
41
+ if (!isStringLiteral(moduleSpecifier)) return;
42
+
43
+ return this.resolveSourceFile(from, moduleSpecifier);
44
+ }
45
+
46
+ protected resolveImpl(modulePath: StringLiteral, sourceFile: SourceFile): ResolvedModule | undefined {
47
+ if (this.host.resolveModuleNameLiterals !== undefined) {
48
+ const results = this.host.resolveModuleNameLiterals(
49
+ [modulePath],
50
+ sourceFile.fileName,
51
+ /*reusedNames*/ undefined,
52
+ this.compilerOptions,
53
+ sourceFile,
54
+ undefined,
55
+ );
56
+ if (results[0]) return results[0].resolvedModule;
57
+ return;
58
+ }
59
+ if (this.host.resolveModuleNames !== undefined) {
60
+ return this.host.resolveModuleNames(
61
+ [modulePath.text],
62
+ sourceFile.fileName,
63
+ /*reusedNames*/ undefined,
64
+ /*redirectedReference*/ undefined,
65
+ this.compilerOptions,
66
+ )[0];
67
+ }
68
+ const result = resolveModuleName(modulePath.text, sourceFile.fileName, this.compilerOptions, this.host);
69
+ return result.resolvedModule;
70
+ }
71
+
72
+ /**
73
+ * Tries to resolve the .ts/d.ts file path for a given module path.
74
+ * Scans relative paths. Looks into package.json "types" and "exports" (with new 4.7 support)
75
+ *
76
+ * @param sourceFile the SourceFile of the file that contains the import. modulePath is relative to that.
77
+ * @param modulePath the x in 'from x'.
78
+ */
79
+ resolveSourceFile(sourceFile: SourceFile, modulePath: StringLiteral): SourceFile | undefined {
80
+ const result = this.resolveImpl(modulePath, sourceFile);
81
+ if (!result) return;
82
+
83
+ // only .ts, .tsx and .d.ts files are supported
84
+ if (!result.resolvedFileName.endsWith('.ts')
85
+ && !result.resolvedFileName.endsWith('.tsx')
86
+ && !result.resolvedFileName.endsWith('.d.ts')) {
87
+ return;
88
+ }
89
+
90
+ const fileName = result.resolvedFileName;
91
+ if (this.sourceFiles[fileName]) return this.sourceFiles[fileName];
92
+
93
+ const source = this.host.readFile(result.resolvedFileName);
94
+ if (!source) return;
95
+ const moduleSourceFile = (this.sourceFiles[fileName] = createSourceFile(
96
+ fileName,
97
+ source,
98
+ {
99
+ languageVersion: this.compilerOptions.target || ScriptTarget.ES2018,
100
+ // JSDocParsingMode is not available in TS < 5.3
101
+ jsDocParsingMode: JSDocParsingMode ? JSDocParsingMode.ParseNone : undefined,
102
+ },
103
+ true,
104
+ ));
105
+
106
+ this.sourceFiles[fileName] = moduleSourceFile;
107
+
108
+ //@ts-ignore
109
+ ts.bindSourceFile(moduleSourceFile, this.compilerOptions);
110
+
111
+ return moduleSourceFile;
112
+ }
113
+ }
@@ -0,0 +1,28 @@
1
+ //Contains types and makes certain properties available that are currently marked as @internal and thus not part of the public TS API.
2
+ //Certain interfaces do not contain all properties/methods from all internal TS types, because we add only those we actually use.
3
+ //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.
4
+
5
+ import type { SourceFile as TSSourceFile, ScriptKind, Symbol, SymbolTable, Node } from 'typescript';
6
+
7
+ /**
8
+ * Contains @internal properties that are not yet in the public API of TS.
9
+ */
10
+ export interface SourceFile extends TSSourceFile {
11
+ /**
12
+ * If two source files are for the same version of the same package, one will redirect to the other.
13
+ * (See `createRedirectSourceFile` in program.ts.)
14
+ * The redirect will have this set. The redirected-to source file will be in `redirectTargetsMap`.
15
+ */
16
+ redirectInfo?: any;
17
+
18
+ scriptKind?: ScriptKind;
19
+
20
+ externalModuleIndicator?: Node;
21
+ // The first node that causes this file to be a CommonJS module
22
+ commonJsModuleIndicator?: Node;
23
+ // JS identifier-declarations that are intended to merge with globals
24
+ jsGlobalAugmentations?: SymbolTable;
25
+
26
+ //part of Node
27
+ symbol?: Symbol; // Symbol declared by node (initialized by binding)
28
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "module": "ES2020",
6
+ "tsBuildInfoFile": ".esm.tsbuildinfo"
7
+ },
8
+ "references": [
9
+ {
10
+ "path": "../type-spec/tsconfig.esm.json"
11
+ },
12
+ {
13
+ "path": "../expect/tsconfig.esm.json"
14
+ }
15
+ ]
16
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs",
5
+ "types": [
6
+ "lz-string",
7
+ "micromatch",
8
+ "node"
9
+ ],
10
+ "tsBuildInfoFile": ".cjs.tsbuildinfo"
11
+ },
12
+ "include": [
13
+ "src",
14
+ "tests",
15
+ "install-transformer.ts",
16
+ "compiler-debug.ts",
17
+ "index.ts"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../type-spec/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../expect/tsconfig.json"
25
+ }
26
+ ]
27
+ }