@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.
- package/LICENSE +22 -0
- package/README.md +4 -0
- package/compiler-debug.ts +38 -0
- package/deepkit-compiler-debug.js +5 -0
- package/deepkit-type-install.js +5 -0
- package/dist/cjs/compiler-debug.d.ts +1 -0
- package/dist/cjs/compiler-debug.js +28 -0
- package/dist/cjs/compiler-debug.js.map +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/install-transformer.d.ts +7 -0
- package/dist/cjs/install-transformer.js +77 -0
- package/dist/cjs/install-transformer.js.map +1 -0
- package/dist/cjs/src/compiler.d.ts +313 -0
- package/dist/cjs/src/compiler.js +2506 -0
- package/dist/cjs/src/compiler.js.map +1 -0
- package/dist/cjs/src/config.d.ts +83 -0
- package/dist/cjs/src/config.js +248 -0
- package/dist/cjs/src/config.js.map +1 -0
- package/dist/cjs/src/debug.d.ts +9 -0
- package/dist/cjs/src/debug.js +26 -0
- package/dist/cjs/src/debug.js.map +1 -0
- package/dist/cjs/src/loader.d.ts +18 -0
- package/dist/cjs/src/loader.js +55 -0
- package/dist/cjs/src/loader.js.map +1 -0
- package/dist/cjs/src/plugin.d.ts +14 -0
- package/dist/cjs/src/plugin.js +46 -0
- package/dist/cjs/src/plugin.js.map +1 -0
- package/dist/cjs/src/reflection-ast.d.ts +46 -0
- package/dist/cjs/src/reflection-ast.js +335 -0
- package/dist/cjs/src/reflection-ast.js.map +1 -0
- package/dist/cjs/src/resolver.d.ts +27 -0
- package/dist/cjs/src/resolver.js +88 -0
- package/dist/cjs/src/resolver.js.map +1 -0
- package/dist/cjs/src/ts-types.d.ts +17 -0
- package/dist/cjs/src/ts-types.js +6 -0
- package/dist/cjs/src/ts-types.js.map +1 -0
- package/dist/esm/compiler-debug.d.ts +1 -0
- package/dist/esm/compiler-debug.js +26 -0
- package/dist/esm/compiler-debug.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/install-transformer.d.ts +7 -0
- package/dist/esm/install-transformer.js +75 -0
- package/dist/esm/install-transformer.js.map +1 -0
- package/dist/esm/src/compiler.d.ts +313 -0
- package/dist/esm/src/compiler.js +2463 -0
- package/dist/esm/src/compiler.js.map +1 -0
- package/dist/esm/src/config.d.ts +83 -0
- package/dist/esm/src/config.js +238 -0
- package/dist/esm/src/config.js.map +1 -0
- package/dist/esm/src/debug.d.ts +9 -0
- package/dist/esm/src/debug.js +21 -0
- package/dist/esm/src/debug.js.map +1 -0
- package/dist/esm/src/loader.d.ts +18 -0
- package/dist/esm/src/loader.js +48 -0
- package/dist/esm/src/loader.js.map +1 -0
- package/dist/esm/src/plugin.d.ts +14 -0
- package/dist/esm/src/plugin.js +40 -0
- package/dist/esm/src/plugin.js.map +1 -0
- package/dist/esm/src/reflection-ast.d.ts +46 -0
- package/dist/esm/src/reflection-ast.js +284 -0
- package/dist/esm/src/reflection-ast.js.map +1 -0
- package/dist/esm/src/resolver.d.ts +27 -0
- package/dist/esm/src/resolver.js +80 -0
- package/dist/esm/src/resolver.js.map +1 -0
- package/dist/esm/src/ts-types.d.ts +17 -0
- package/dist/esm/src/ts-types.js +5 -0
- package/dist/esm/src/ts-types.js.map +1 -0
- package/index.ts +22 -0
- package/install-transformer.ts +84 -0
- package/package.json +59 -0
- package/src/compiler.ts +3003 -0
- package/src/config.ts +331 -0
- package/src/debug.ts +22 -0
- package/src/loader.ts +58 -0
- package/src/plugin.ts +58 -0
- package/src/reflection-ast.ts +335 -0
- package/src/resolver.ts +113 -0
- package/src/ts-types.ts +28 -0
- package/tsconfig.esm.json +16 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { Cache, ReflectionTransformer } from './compiler.js';
|
|
3
|
+
export class DeepkitLoader {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.options = {
|
|
6
|
+
allowJs: true,
|
|
7
|
+
declaration: false,
|
|
8
|
+
};
|
|
9
|
+
this.host = ts.createCompilerHost(this.options);
|
|
10
|
+
this.program = ts.createProgram([], this.options, this.host);
|
|
11
|
+
this.printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
12
|
+
this.cache = new Cache;
|
|
13
|
+
this.knownFiles = {};
|
|
14
|
+
this.sourceFiles = {};
|
|
15
|
+
const originReadFile = this.host.readFile;
|
|
16
|
+
this.host.readFile = (fileName) => {
|
|
17
|
+
if (this.knownFiles[fileName])
|
|
18
|
+
return this.knownFiles[fileName];
|
|
19
|
+
return originReadFile.call(this.host, fileName);
|
|
20
|
+
};
|
|
21
|
+
//the program should not write any files
|
|
22
|
+
this.host.writeFile = () => {
|
|
23
|
+
};
|
|
24
|
+
const originalGetSourceFile = this.host.getSourceFile;
|
|
25
|
+
this.host.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
26
|
+
if (this.sourceFiles[fileName])
|
|
27
|
+
return this.sourceFiles[fileName];
|
|
28
|
+
return originalGetSourceFile.call(this.host, fileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
transform(source, path) {
|
|
32
|
+
this.knownFiles[path] = source;
|
|
33
|
+
const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.ESNext, true, path.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
34
|
+
let newSource = source;
|
|
35
|
+
ts.transform(sourceFile, [
|
|
36
|
+
(context) => {
|
|
37
|
+
const transformer = new ReflectionTransformer(context, this.cache).forHost(this.host).withReflection({ reflection: 'default' });
|
|
38
|
+
return (node) => {
|
|
39
|
+
const sourceFile = transformer.transformSourceFile(node);
|
|
40
|
+
newSource = this.printer.printNode(ts.EmitHint.SourceFile, sourceFile, sourceFile);
|
|
41
|
+
return sourceFile;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
], this.options);
|
|
45
|
+
return newSource;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/loader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE7D,MAAM,OAAO,aAAa;IAgBtB;QAfU,YAAO,GAAoB;YACjC,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,KAAK;SACrB,CAAC;QAEQ,SAAI,GAAG,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE3C,YAAO,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAExD,YAAO,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjE,UAAK,GAAG,IAAI,KAAK,CAAC;QAElB,eAAU,GAA+B,EAAE,CAAC;QAC5C,gBAAW,GAAmC,EAAE,CAAC;QAGvD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,QAAgB,EAAE,EAAE;YACtC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAChE,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC;QAEF,wCAAwC;QACxC,IAAI,CAAC,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AC,IAAI,CAAC,CAAC;oBAEzD,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;oBACnF,OAAO,UAAU,CAAC;gBACtB,CAAC,CAAC;YACN,CAAC;SACJ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjB,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export interface Options {
|
|
3
|
+
include?: string;
|
|
4
|
+
exclude?: string;
|
|
5
|
+
tsConfig?: string;
|
|
6
|
+
transformers?: ts.CustomTransformers;
|
|
7
|
+
compilerOptions?: ts.CompilerOptions;
|
|
8
|
+
readFile?: (path: string) => string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export type Transform = (code: string, fileName: string) => {
|
|
11
|
+
code: string;
|
|
12
|
+
map?: string;
|
|
13
|
+
} | undefined;
|
|
14
|
+
export declare function deepkitType(options?: Options): Transform;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { cwd } from 'process';
|
|
3
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
4
|
+
import { declarationTransformer, transformer } from './compiler.js';
|
|
5
|
+
export function deepkitType(options = {}) {
|
|
6
|
+
const filter = createFilter(options.include ?? ['**/*.tsx', '**/*.ts'], options.exclude ?? 'node_modules/**');
|
|
7
|
+
const transformers = options.transformers || {
|
|
8
|
+
before: [transformer],
|
|
9
|
+
after: [declarationTransformer],
|
|
10
|
+
};
|
|
11
|
+
const configFilePath = options.tsConfig || cwd() + '/tsconfig.json';
|
|
12
|
+
const tsConfig = ts.readConfigFile(configFilePath, options.readFile || ts.sys.readFile);
|
|
13
|
+
if (tsConfig.error) {
|
|
14
|
+
throw new Error(ts.formatDiagnostic(tsConfig.error, {
|
|
15
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
16
|
+
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
17
|
+
getNewLine: () => ts.sys.newLine,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
const compilerOptions = Object.assign({
|
|
21
|
+
'target': ts.ScriptTarget.ESNext,
|
|
22
|
+
'module': ts.ModuleKind.ESNext,
|
|
23
|
+
configFilePath,
|
|
24
|
+
}, tsConfig.config, options.compilerOptions || {});
|
|
25
|
+
return function transform(code, fileName) {
|
|
26
|
+
if (!filter(fileName))
|
|
27
|
+
return;
|
|
28
|
+
const transformed = ts.transpileModule(code, {
|
|
29
|
+
compilerOptions,
|
|
30
|
+
fileName,
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
transformers
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
code: transformed.outputText,
|
|
36
|
+
map: transformed.sourceMapText,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAapE,MAAM,UAAU,WAAW,CAAC,UAAmB,EAAE;IAC7C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,IAAI,iBAAiB,CAAC,CAAC;IAE9G,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI;QACzC,MAAM,EAAE,CAAC,WAAW,CAAC;QACrB,KAAK,EAAE,CAAC,sBAAsB,CAAC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Name, Expression, Identifier, ImportDeclaration, JSDoc, JSDocImportTag, ModifierLike, Node, NodeArray, NodeFactory, PrivateIdentifier, PropertyAccessExpression, PropertyName, QualifiedName, StringLiteral, SymbolTable } from 'typescript';
|
|
2
|
+
import { SourceFile } from './ts-types.js';
|
|
3
|
+
export type PackExpression = Expression | string | number | boolean | bigint;
|
|
4
|
+
export declare function getIdentifierName(node: Identifier | PrivateIdentifier | StringLiteral | __String): string;
|
|
5
|
+
export declare function getEscapedText(node: Identifier | PrivateIdentifier | StringLiteral | __String): string;
|
|
6
|
+
export declare function findSourceFile(node: Node): SourceFile | undefined;
|
|
7
|
+
export declare function joinQualifiedName(name: EntityName): string;
|
|
8
|
+
export declare function getCommentOfNode(sourceFile: SourceFile, node: Node): string | undefined;
|
|
9
|
+
export declare function parseJSDocAttributeFromText(comment: string, attribute: string): string | undefined;
|
|
10
|
+
export declare function extractJSDocAttribute(sourceFile: SourceFile, node: Node | undefined, attribute: string): string | undefined;
|
|
11
|
+
export declare function getPropertyName(f: NodeFactory, node?: PropertyName): string | symbol | number | ArrowFunction;
|
|
12
|
+
export declare function getNameAsString(node?: PropertyName | QualifiedName): string;
|
|
13
|
+
export declare function hasModifier(node: Node & {
|
|
14
|
+
modifiers?: NodeArray<ModifierLike>;
|
|
15
|
+
}, modifier: ts.SyntaxKind): boolean;
|
|
16
|
+
export declare class NodeConverter {
|
|
17
|
+
protected f: NodeFactory;
|
|
18
|
+
constructor(f: NodeFactory);
|
|
19
|
+
toExpression<T extends PackExpression | PackExpression[]>(node?: T): Expression;
|
|
20
|
+
}
|
|
21
|
+
export declare function isNodeWithLocals(node: Node): node is (Node & {
|
|
22
|
+
locals: SymbolTable | undefined;
|
|
23
|
+
});
|
|
24
|
+
export declare function getGlobalsOfSourceFile(file: SourceFile): SymbolTable | void;
|
|
25
|
+
/**
|
|
26
|
+
* For imports that can removed (like a class import only used as type only, like `p: Model[]`) we have
|
|
27
|
+
* to modify the import so TS does not remove it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ensureImportIsEmitted(importDeclaration: ImportDeclaration | JSDocImportTag, specifierName?: Identifier): void;
|
|
30
|
+
/**
|
|
31
|
+
* Serializes an entity name as an expression for decorator type metadata.
|
|
32
|
+
*
|
|
33
|
+
* @param node The entity name to serialize.
|
|
34
|
+
*/
|
|
35
|
+
export declare function serializeEntityNameAsExpression(f: NodeFactory, node: EntityName): SerializedEntityNameAsExpression;
|
|
36
|
+
type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression;
|
|
37
|
+
export type MetaNode = Node & {
|
|
38
|
+
jsDoc?: JSDoc[];
|
|
39
|
+
_original?: MetaNode;
|
|
40
|
+
original?: MetaNode;
|
|
41
|
+
_symbol?: Symbol;
|
|
42
|
+
symbol?: Symbol;
|
|
43
|
+
_parent?: MetaNode;
|
|
44
|
+
localSymbol?: Symbol;
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,284 @@
|
|
|
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
|
+
import ts, { isBigIntLiteral, } from 'typescript';
|
|
12
|
+
import { cloneNode as tsNodeClone } from '@marcj/ts-clone-node';
|
|
13
|
+
const { isArrowFunction, isComputedPropertyName, isIdentifier, isNamedImports, isNumericLiteral, isPrivateIdentifier, isStringLiteral, isStringLiteralLike, setOriginalNode, getLeadingCommentRanges, isNoSubstitutionTemplateLiteral, NodeFlags, SyntaxKind, } = ts;
|
|
14
|
+
function is__String(value) {
|
|
15
|
+
return typeof value === 'string';
|
|
16
|
+
}
|
|
17
|
+
export function getIdentifierName(node) {
|
|
18
|
+
if (is__String(node))
|
|
19
|
+
return node;
|
|
20
|
+
if (isIdentifier(node) || isPrivateIdentifier(node)) {
|
|
21
|
+
return ts.unescapeLeadingUnderscores(node.escapedText);
|
|
22
|
+
}
|
|
23
|
+
if (isStringLiteral(node))
|
|
24
|
+
return node.text;
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
export function getEscapedText(node) {
|
|
28
|
+
if (is__String(node))
|
|
29
|
+
return node;
|
|
30
|
+
if (isIdentifier(node) || isPrivateIdentifier(node))
|
|
31
|
+
return node.escapedText;
|
|
32
|
+
return getIdentifierName(node);
|
|
33
|
+
}
|
|
34
|
+
export function findSourceFile(node) {
|
|
35
|
+
if (node.kind === SyntaxKind.SourceFile)
|
|
36
|
+
return node;
|
|
37
|
+
let current = node.parent;
|
|
38
|
+
while (current && current.kind !== SyntaxKind.SourceFile) {
|
|
39
|
+
current = current.parent;
|
|
40
|
+
}
|
|
41
|
+
return current;
|
|
42
|
+
}
|
|
43
|
+
export function joinQualifiedName(name) {
|
|
44
|
+
if (isIdentifier(name))
|
|
45
|
+
return getIdentifierName(name);
|
|
46
|
+
return joinQualifiedName(name.left) + '_' + getIdentifierName(name.right);
|
|
47
|
+
}
|
|
48
|
+
export function getCommentOfNode(sourceFile, node) {
|
|
49
|
+
const comment = getLeadingCommentRanges(sourceFile.text, node.pos);
|
|
50
|
+
if (!comment)
|
|
51
|
+
return;
|
|
52
|
+
return comment.map(v => sourceFile.text.substring(v.pos, v.end)).join('\n');
|
|
53
|
+
}
|
|
54
|
+
export function parseJSDocAttributeFromText(comment, attribute) {
|
|
55
|
+
// no regex
|
|
56
|
+
const index = comment.indexOf('@' + attribute + ' ');
|
|
57
|
+
if (index === -1) {
|
|
58
|
+
let start = 0;
|
|
59
|
+
while (true) {
|
|
60
|
+
const withoutContent = comment.indexOf('@' + attribute, start);
|
|
61
|
+
if (withoutContent === -1)
|
|
62
|
+
return undefined;
|
|
63
|
+
//make sure next character is space or end of comment
|
|
64
|
+
const nextCharacter = comment[withoutContent + attribute.length + 1];
|
|
65
|
+
if (!nextCharacter || nextCharacter === ' ' || nextCharacter === '\n' || nextCharacter === '\r' || nextCharacter === '\t') {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
start = withoutContent + attribute.length + 1;
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const start = index + attribute.length + 2;
|
|
73
|
+
// end is either next attribute @ or end of comment.
|
|
74
|
+
const nextAttribute = comment.indexOf('@', start);
|
|
75
|
+
const endOfComment = comment.indexOf('*/', start);
|
|
76
|
+
const end = nextAttribute === -1 ? endOfComment : Math.min(nextAttribute, endOfComment);
|
|
77
|
+
const content = comment.substring(start, end).trim();
|
|
78
|
+
// make sure multiline comments are supported, and each line is trimmed and `\s\s\s\*` removed
|
|
79
|
+
return content.split('\n').map(v => {
|
|
80
|
+
const indexOfStar = v.indexOf('*');
|
|
81
|
+
if (indexOfStar === -1)
|
|
82
|
+
return v.trim();
|
|
83
|
+
return v.substring(indexOfStar + 1).trim();
|
|
84
|
+
}).join('\n');
|
|
85
|
+
}
|
|
86
|
+
export function extractJSDocAttribute(sourceFile, node, attribute) {
|
|
87
|
+
// in TypeScript 5.3 they made JSDoc parsing optional and disabled by default.
|
|
88
|
+
// we need to read the comments manually and then parse @{attribute} {value} manually.
|
|
89
|
+
// we need reference to SourceFile, since Node.getSourceFile() although available in types,
|
|
90
|
+
// is not available at runtime sometimes (works in tests, but fails with tsc).
|
|
91
|
+
if (!node)
|
|
92
|
+
return undefined;
|
|
93
|
+
const comment = getCommentOfNode(sourceFile, node);
|
|
94
|
+
if (!comment)
|
|
95
|
+
return undefined;
|
|
96
|
+
return parseJSDocAttributeFromText(comment, attribute);
|
|
97
|
+
}
|
|
98
|
+
export function getPropertyName(f, node) {
|
|
99
|
+
if (!node)
|
|
100
|
+
return '';
|
|
101
|
+
if (isIdentifier(node))
|
|
102
|
+
return getIdentifierName(node);
|
|
103
|
+
if (isStringLiteral(node))
|
|
104
|
+
return node.text;
|
|
105
|
+
if (isNumericLiteral(node))
|
|
106
|
+
return +node.text;
|
|
107
|
+
if (isNoSubstitutionTemplateLiteral(node))
|
|
108
|
+
return node.text;
|
|
109
|
+
if (isComputedPropertyName(node)) {
|
|
110
|
+
return f.createArrowFunction(undefined, undefined, [], undefined, undefined, node.expression);
|
|
111
|
+
}
|
|
112
|
+
if (isPrivateIdentifier(node))
|
|
113
|
+
return getIdentifierName(node);
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
export function getNameAsString(node) {
|
|
117
|
+
if (!node)
|
|
118
|
+
return '';
|
|
119
|
+
if (isIdentifier(node))
|
|
120
|
+
return getIdentifierName(node);
|
|
121
|
+
if (isStringLiteral(node))
|
|
122
|
+
return node.text;
|
|
123
|
+
if (isNumericLiteral(node))
|
|
124
|
+
return node.text;
|
|
125
|
+
if (isBigIntLiteral(node))
|
|
126
|
+
return node.text;
|
|
127
|
+
if (isNoSubstitutionTemplateLiteral(node))
|
|
128
|
+
return node.text;
|
|
129
|
+
if (isComputedPropertyName(node)) {
|
|
130
|
+
if (isStringLiteralLike(node) || isNumericLiteral(node))
|
|
131
|
+
return node.text;
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
if (isPrivateIdentifier(node))
|
|
135
|
+
return getIdentifierName(node);
|
|
136
|
+
return joinQualifiedName(node);
|
|
137
|
+
}
|
|
138
|
+
export function hasModifier(node, modifier) {
|
|
139
|
+
if (!node.modifiers)
|
|
140
|
+
return false;
|
|
141
|
+
return node.modifiers.some(v => v.kind === modifier);
|
|
142
|
+
}
|
|
143
|
+
const cloneHook = (node, payload) => {
|
|
144
|
+
if (isIdentifier(node)) {
|
|
145
|
+
//ts-clone-node wants to read `node.text` which does not exist. we hook into it and provide the correct value.
|
|
146
|
+
return {
|
|
147
|
+
text: () => {
|
|
148
|
+
return getIdentifierName(node);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
};
|
|
154
|
+
export class NodeConverter {
|
|
155
|
+
constructor(f) {
|
|
156
|
+
this.f = f;
|
|
157
|
+
}
|
|
158
|
+
toExpression(node) {
|
|
159
|
+
if (node === undefined)
|
|
160
|
+
return this.f.createIdentifier('undefined');
|
|
161
|
+
if (Array.isArray(node)) {
|
|
162
|
+
return this.f.createArrayLiteralExpression(this.f.createNodeArray(node.map(v => this.toExpression(v))));
|
|
163
|
+
}
|
|
164
|
+
if ('string' === typeof node)
|
|
165
|
+
return this.f.createStringLiteral(node, true);
|
|
166
|
+
if ('number' === typeof node)
|
|
167
|
+
return this.f.createNumericLiteral(node);
|
|
168
|
+
if ('bigint' === typeof node)
|
|
169
|
+
return this.f.createBigIntLiteral(String(node));
|
|
170
|
+
if ('boolean' === typeof node)
|
|
171
|
+
return node ? this.f.createTrue() : this.f.createFalse();
|
|
172
|
+
if (node.pos === -1 && node.end === -1 && node.parent === undefined) {
|
|
173
|
+
if (isArrowFunction(node)) {
|
|
174
|
+
if (node.body.pos === -1 && node.body.end === -1 && node.body.parent === undefined)
|
|
175
|
+
return node;
|
|
176
|
+
return this.f.createArrowFunction(node.modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, this.toExpression(node.body));
|
|
177
|
+
}
|
|
178
|
+
return node;
|
|
179
|
+
}
|
|
180
|
+
switch (node.kind) {
|
|
181
|
+
case SyntaxKind.Identifier:
|
|
182
|
+
return finish(node, this.f.createIdentifier(getIdentifierName(node)));
|
|
183
|
+
case SyntaxKind.StringLiteral:
|
|
184
|
+
return finish(node, this.f.createStringLiteral(node.text));
|
|
185
|
+
case SyntaxKind.NumericLiteral:
|
|
186
|
+
return finish(node, this.f.createNumericLiteral(node.text));
|
|
187
|
+
case SyntaxKind.BigIntLiteral:
|
|
188
|
+
return finish(node, this.f.createBigIntLiteral(node.text));
|
|
189
|
+
case SyntaxKind.TrueKeyword:
|
|
190
|
+
return finish(node, this.f.createTrue());
|
|
191
|
+
case SyntaxKind.FalseKeyword:
|
|
192
|
+
return finish(node, this.f.createFalse());
|
|
193
|
+
}
|
|
194
|
+
//todo: ts-node-clone broke with ts 4.8,
|
|
195
|
+
// => TypeError: Cannot read properties of undefined (reading 'emitNode')
|
|
196
|
+
// which is probably due a broken node clone. We need to figure out which node it is
|
|
197
|
+
// and see what the issue is. since ts-node-clone is not really maintained anymore,
|
|
198
|
+
// we need to fork it
|
|
199
|
+
try {
|
|
200
|
+
return tsNodeClone(node, {
|
|
201
|
+
preserveComments: false,
|
|
202
|
+
factory: this.f,
|
|
203
|
+
setOriginalNodes: true,
|
|
204
|
+
preserveSymbols: true,
|
|
205
|
+
setParents: true,
|
|
206
|
+
hook: cloneHook,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
console.error('could not clone node', node);
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function isExternalOrCommonJsModule(file) {
|
|
216
|
+
//both attributes are internal and not yet public
|
|
217
|
+
return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== undefined;
|
|
218
|
+
}
|
|
219
|
+
export function isNodeWithLocals(node) {
|
|
220
|
+
return 'locals' in node;
|
|
221
|
+
}
|
|
222
|
+
//logic copied from typescript
|
|
223
|
+
export function getGlobalsOfSourceFile(file) {
|
|
224
|
+
if (file.redirectInfo)
|
|
225
|
+
return;
|
|
226
|
+
if (!isNodeWithLocals(file))
|
|
227
|
+
return;
|
|
228
|
+
if (!isExternalOrCommonJsModule(file))
|
|
229
|
+
return file.locals;
|
|
230
|
+
if (file.jsGlobalAugmentations)
|
|
231
|
+
return file.jsGlobalAugmentations;
|
|
232
|
+
if (file.symbol && file.symbol.globalExports)
|
|
233
|
+
return file.symbol.globalExports;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* For imports that can removed (like a class import only used as type only, like `p: Model[]`) we have
|
|
237
|
+
* to modify the import so TS does not remove it.
|
|
238
|
+
*/
|
|
239
|
+
export function ensureImportIsEmitted(importDeclaration, specifierName) {
|
|
240
|
+
if (specifierName && importDeclaration.importClause && importDeclaration.importClause.namedBindings) {
|
|
241
|
+
// const binding = importDeclaration.importClause.namedBindings;
|
|
242
|
+
if (isNamedImports(importDeclaration.importClause.namedBindings)) {
|
|
243
|
+
for (const element of importDeclaration.importClause.namedBindings.elements) {
|
|
244
|
+
if (element.name.escapedText === specifierName.escapedText) {
|
|
245
|
+
element.flags |= NodeFlags.Synthesized;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
importDeclaration.flags |= NodeFlags.Synthesized;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Serializes an entity name as an expression for decorator type metadata.
|
|
255
|
+
*
|
|
256
|
+
* @param node The entity name to serialize.
|
|
257
|
+
*/
|
|
258
|
+
export function serializeEntityNameAsExpression(f, node) {
|
|
259
|
+
switch (node.kind) {
|
|
260
|
+
case SyntaxKind.Identifier:
|
|
261
|
+
return finish(node, f.createIdentifier(getIdentifierName(node)));
|
|
262
|
+
case SyntaxKind.QualifiedName:
|
|
263
|
+
return finish(node, serializeQualifiedNameAsExpression(f, node));
|
|
264
|
+
}
|
|
265
|
+
return node;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Serializes an qualified name as an expression for decorator type metadata.
|
|
269
|
+
*
|
|
270
|
+
* @param node The qualified name to serialize.
|
|
271
|
+
* @param useFallback A value indicating whether to use logical operators to test for the
|
|
272
|
+
* qualified name at runtime.
|
|
273
|
+
*/
|
|
274
|
+
function serializeQualifiedNameAsExpression(f, node) {
|
|
275
|
+
return f.createPropertyAccessExpression(serializeEntityNameAsExpression(f, node.left), node.right);
|
|
276
|
+
}
|
|
277
|
+
function finish(oldNode, newNode) {
|
|
278
|
+
setOriginalNode(newNode, oldNode);
|
|
279
|
+
newNode._original = newNode.original;
|
|
280
|
+
newNode._symbol = oldNode._symbol ?? oldNode.symbol;
|
|
281
|
+
newNode.symbol = newNode._symbol;
|
|
282
|
+
return newNode;
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=reflection-ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflection-ast.js","sourceRoot":"","sources":["../../../src/reflection-ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,EAAE,EASP,eAAe,GAelB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,IAAI,WAAW,EAAiB,MAAM,sBAAsB,CAAC;AAG/E,MAAM,EACF,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,+BAA+B,EAC/B,SAAS,EACT,UAAU,GACb,GAAG,EAAE,CAAC;AAIP,SAAS,UAAU,CAAC,KAAU;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAA+D;IAC7F,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAc,CAAC;IAC5C,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,OAAO,EAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,eAAe,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC;IAC5C,OAAO,EAAE,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAA+D;IAC1F,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAc,CAAC;IAC5C,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,WA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C,CAAC,8BAA8B,CAAC,+BAA+B,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AACvG,CAAC;AAYD,SAAS,MAAM,CAAqB,OAAiB,EAAE,OAAU;IAC7D,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAErC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IACpD,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CompilerHost, CompilerOptions, ExportDeclaration, ImportDeclaration, JSDocImportTag, ResolvedModule, SourceFile, StringLiteral } from 'typescript';
|
|
2
|
+
export declare function patternMatch(path: string, patterns: string[], base?: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* A utility to resolve a module path and its declaration.
|
|
5
|
+
*
|
|
6
|
+
* It automatically reads a SourceFile, binds and caches it.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Resolver {
|
|
9
|
+
compilerOptions: CompilerOptions;
|
|
10
|
+
host: CompilerHost;
|
|
11
|
+
protected sourceFiles: {
|
|
12
|
+
[fileName: string]: SourceFile;
|
|
13
|
+
};
|
|
14
|
+
constructor(compilerOptions: CompilerOptions, host: CompilerHost, sourceFiles: {
|
|
15
|
+
[fileName: string]: SourceFile;
|
|
16
|
+
});
|
|
17
|
+
resolve(from: SourceFile, importOrExportNode: ExportDeclaration | ImportDeclaration | JSDocImportTag): SourceFile | undefined;
|
|
18
|
+
protected resolveImpl(modulePath: StringLiteral, sourceFile: SourceFile): ResolvedModule | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Tries to resolve the .ts/d.ts file path for a given module path.
|
|
21
|
+
* Scans relative paths. Looks into package.json "types" and "exports" (with new 4.7 support)
|
|
22
|
+
*
|
|
23
|
+
* @param sourceFile the SourceFile of the file that contains the import. modulePath is relative to that.
|
|
24
|
+
* @param modulePath the x in 'from x'.
|
|
25
|
+
*/
|
|
26
|
+
resolveSourceFile(sourceFile: SourceFile, modulePath: StringLiteral): SourceFile | undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import micromatch from 'micromatch';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
const { createSourceFile, resolveModuleName, isStringLiteral, JSDocParsingMode, ScriptTarget } = ts;
|
|
4
|
+
export function patternMatch(path, patterns, base) {
|
|
5
|
+
const include = patterns.filter(pattern => pattern[0] !== '!');
|
|
6
|
+
const exclude = patterns.filter(pattern => pattern[0] === '!').map(pattern => pattern.substring(1));
|
|
7
|
+
return micromatch.isMatch(path, include, {
|
|
8
|
+
ignore: exclude,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A utility to resolve a module path and its declaration.
|
|
13
|
+
*
|
|
14
|
+
* It automatically reads a SourceFile, binds and caches it.
|
|
15
|
+
*/
|
|
16
|
+
export class Resolver {
|
|
17
|
+
constructor(compilerOptions, host, sourceFiles) {
|
|
18
|
+
this.compilerOptions = compilerOptions;
|
|
19
|
+
this.host = host;
|
|
20
|
+
this.sourceFiles = sourceFiles;
|
|
21
|
+
}
|
|
22
|
+
resolve(from, importOrExportNode) {
|
|
23
|
+
const moduleSpecifier = importOrExportNode.moduleSpecifier;
|
|
24
|
+
if (!moduleSpecifier)
|
|
25
|
+
return;
|
|
26
|
+
if (!isStringLiteral(moduleSpecifier))
|
|
27
|
+
return;
|
|
28
|
+
return this.resolveSourceFile(from, moduleSpecifier);
|
|
29
|
+
}
|
|
30
|
+
resolveImpl(modulePath, sourceFile) {
|
|
31
|
+
if (this.host.resolveModuleNameLiterals !== undefined) {
|
|
32
|
+
const results = this.host.resolveModuleNameLiterals([modulePath], sourceFile.fileName,
|
|
33
|
+
/*reusedNames*/ undefined, this.compilerOptions, sourceFile, undefined);
|
|
34
|
+
if (results[0])
|
|
35
|
+
return results[0].resolvedModule;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (this.host.resolveModuleNames !== undefined) {
|
|
39
|
+
return this.host.resolveModuleNames([modulePath.text], sourceFile.fileName,
|
|
40
|
+
/*reusedNames*/ undefined,
|
|
41
|
+
/*redirectedReference*/ undefined, this.compilerOptions)[0];
|
|
42
|
+
}
|
|
43
|
+
const result = resolveModuleName(modulePath.text, sourceFile.fileName, this.compilerOptions, this.host);
|
|
44
|
+
return result.resolvedModule;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Tries to resolve the .ts/d.ts file path for a given module path.
|
|
48
|
+
* Scans relative paths. Looks into package.json "types" and "exports" (with new 4.7 support)
|
|
49
|
+
*
|
|
50
|
+
* @param sourceFile the SourceFile of the file that contains the import. modulePath is relative to that.
|
|
51
|
+
* @param modulePath the x in 'from x'.
|
|
52
|
+
*/
|
|
53
|
+
resolveSourceFile(sourceFile, modulePath) {
|
|
54
|
+
const result = this.resolveImpl(modulePath, sourceFile);
|
|
55
|
+
if (!result)
|
|
56
|
+
return;
|
|
57
|
+
// only .ts, .tsx and .d.ts files are supported
|
|
58
|
+
if (!result.resolvedFileName.endsWith('.ts')
|
|
59
|
+
&& !result.resolvedFileName.endsWith('.tsx')
|
|
60
|
+
&& !result.resolvedFileName.endsWith('.d.ts')) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const fileName = result.resolvedFileName;
|
|
64
|
+
if (this.sourceFiles[fileName])
|
|
65
|
+
return this.sourceFiles[fileName];
|
|
66
|
+
const source = this.host.readFile(result.resolvedFileName);
|
|
67
|
+
if (!source)
|
|
68
|
+
return;
|
|
69
|
+
const moduleSourceFile = (this.sourceFiles[fileName] = createSourceFile(fileName, source, {
|
|
70
|
+
languageVersion: this.compilerOptions.target || ScriptTarget.ES2018,
|
|
71
|
+
// JSDocParsingMode is not available in TS < 5.3
|
|
72
|
+
jsDocParsingMode: JSDocParsingMode ? JSDocParsingMode.ParseNone : undefined,
|
|
73
|
+
}, true));
|
|
74
|
+
this.sourceFiles[fileName] = moduleSourceFile;
|
|
75
|
+
//@ts-ignore
|
|
76
|
+
ts.bindSourceFile(moduleSourceFile, this.compilerOptions);
|
|
77
|
+
return moduleSourceFile;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAWpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;AAEpG,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,QAAkB,EAAE,IAAa;IACxE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IAE/D,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpG,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE;QACrC,MAAM,EAAE,OAAO;KAClB,CAAC,CAAC;AACP,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACjB,YACW,eAAgC,EAChC,IAAkB,EACf,WAA+C;QAFlD,oBAAe,GAAf,eAAe,CAAiB;QAChC,SAAI,GAAJ,IAAI,CA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
|
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,5 @@
|
|
|
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
|
+
export {};
|
|
5
|
+
//# 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"}
|
package/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
|
|
11
|
+
import { declarationTransformer, transformer } from './src/compiler.js';
|
|
12
|
+
import type { Program } from 'typescript';
|
|
13
|
+
|
|
14
|
+
export * from './src/compiler.js';
|
|
15
|
+
export * from './src/loader.js';
|
|
16
|
+
|
|
17
|
+
export default function myTransformerPlugin(program: Program, opts: {}) {
|
|
18
|
+
return {
|
|
19
|
+
before: transformer,
|
|
20
|
+
afterDeclarations: declarationTransformer,
|
|
21
|
+
};
|
|
22
|
+
}
|