xml-model 1.2.0 → 1.3.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/README.md +0 -1
- package/dist/_virtual/Reflect.js +8 -0
- package/dist/_virtual/Reflect2.js +5 -0
- package/{vite/dist → dist}/_virtual/_commonjsHelpers.js +10 -4
- package/dist/defaults.d.ts +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/middleware.d.ts +1 -0
- package/dist/model/built-ins.d.ts +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/property.d.ts +1 -0
- package/dist/model/registry.d.ts +1 -0
- package/dist/model/types.d.ts +1 -0
- package/dist/node_modules/reflect-metadata/Reflect.js +867 -0
- package/dist/types.d.ts +1 -0
- package/dist/util/is-regexp.d.ts +1 -0
- package/dist/util/kebab-case.d.ts +1 -0
- package/dist/util/merge-maps.d.ts +1 -0
- package/dist/xml/index.d.ts +1 -0
- package/dist/xml/xml-js.d.ts +1 -0
- package/package.json +4 -4
- package/vite/dist/index.js +2 -3
- package/vite/dist/node_modules/typescript-rtti/dist.esm/common/format.js +105 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/common/index.js +55 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/api-call-transformer.js +152 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/class-analyzer.js +83 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/compile-error.js +8 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/import-analyzer.js +89 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/interface-analyzer.js +58 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/visitor-base.js +93 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/declarations-emitter.js +31 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/encode-parameter.js +64 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/find-relative-path.js +41 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/flags.js +43 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/forward-ref.js +20 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/get-exports-for-symbol.js +64 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/index.js +130 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/legacy-decorator.js +10 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/legacy-type-encoder.js +82 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/literal-node.js +9 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-collector.js +56 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-decorator.js +80 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-emitter.js +425 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-encoder.js +212 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/rt-helper.js +96 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/rtti-visitor-base.js +28 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/serialize.js +31 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/type-encoder.js +76 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/type-literal.js +499 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/utils.js +906 -0
- package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/workarounds.js +7 -0
- package/vite/dist/src/class-names.test.d.ts +9 -0
- package/vite/dist/src/defaults.d.ts +15 -0
- package/vite/dist/src/errors.d.ts +24 -0
- package/vite/dist/src/index.d.ts +8 -0
- package/vite/dist/src/middleware.d.ts +10 -0
- package/vite/dist/src/model/built-ins.d.ts +3 -0
- package/vite/dist/src/model/index.d.ts +21 -0
- package/vite/dist/src/model/property.d.ts +6 -0
- package/vite/dist/src/model/registry.d.ts +9 -0
- package/vite/dist/src/model/types.d.ts +74 -0
- package/vite/dist/src/model.test.d.ts +2 -0
- package/vite/dist/src/types.d.ts +17 -0
- package/vite/dist/src/util/is-regexp.d.ts +12 -0
- package/vite/dist/src/util/kebab-case.d.ts +16 -0
- package/vite/dist/src/util/merge-maps.d.ts +2 -0
- package/vite/dist/src/xml/index.d.ts +33 -0
- package/vite/dist/src/xml/xml-js.d.ts +7 -0
- package/vite/dist/_virtual/_commonjs-dynamic-modules.js +0 -7
- package/vite/dist/_virtual/_typescript.js +0 -5
- package/vite/dist/_virtual/api-call-transformer.js +0 -5
- package/vite/dist/_virtual/class-analyzer.js +0 -5
- package/vite/dist/_virtual/compile-error.js +0 -5
- package/vite/dist/_virtual/declarations-emitter.js +0 -5
- package/vite/dist/_virtual/encode-parameter.js +0 -5
- package/vite/dist/_virtual/find-relative-path.js +0 -5
- package/vite/dist/_virtual/flags.js +0 -5
- package/vite/dist/_virtual/format.js +0 -5
- package/vite/dist/_virtual/forward-ref.js +0 -5
- package/vite/dist/_virtual/get-exports-for-symbol.js +0 -5
- package/vite/dist/_virtual/import-analyzer.js +0 -5
- package/vite/dist/_virtual/index.js +0 -8
- package/vite/dist/_virtual/index2.js +0 -5
- package/vite/dist/_virtual/index3.js +0 -5
- package/vite/dist/_virtual/interface-analyzer.js +0 -5
- package/vite/dist/_virtual/legacy-decorator.js +0 -5
- package/vite/dist/_virtual/legacy-type-encoder.js +0 -5
- package/vite/dist/_virtual/literal-node.js +0 -5
- package/vite/dist/_virtual/metadata-collector.js +0 -5
- package/vite/dist/_virtual/metadata-decorator.js +0 -5
- package/vite/dist/_virtual/metadata-emitter.js +0 -5
- package/vite/dist/_virtual/metadata-encoder.js +0 -5
- package/vite/dist/_virtual/rt-helper.js +0 -5
- package/vite/dist/_virtual/rtti-visitor-base.js +0 -5
- package/vite/dist/_virtual/serialize.js +0 -5
- package/vite/dist/_virtual/type-encoder.js +0 -5
- package/vite/dist/_virtual/type-literal.js +0 -5
- package/vite/dist/_virtual/utils.js +0 -5
- package/vite/dist/_virtual/visitor-base.js +0 -5
- package/vite/dist/_virtual/workarounds.js +0 -5
- package/vite/dist/index.d.ts +0 -28
- package/vite/dist/node_modules/typescript-rtti/dist/common/format.js +0 -69
- package/vite/dist/node_modules/typescript-rtti/dist/common/index.js +0 -34
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/api-call-transformer.js +0 -197
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/class-analyzer.js +0 -124
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/compile-error.js +0 -18
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/import-analyzer.js +0 -130
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/interface-analyzer.js +0 -98
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/visitor-base.js +0 -132
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/declarations-emitter.js +0 -72
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/encode-parameter.js +0 -110
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/find-relative-path.js +0 -51
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/flags.js +0 -59
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/forward-ref.js +0 -35
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/get-exports-for-symbol.js +0 -75
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/index.js +0 -174
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/legacy-decorator.js +0 -20
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/legacy-type-encoder.js +0 -123
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/literal-node.js +0 -19
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-collector.js +0 -96
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-decorator.js +0 -99
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-emitter.js +0 -475
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-encoder.js +0 -261
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/rt-helper.js +0 -113
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/rtti-visitor-base.js +0 -39
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/serialize.js +0 -46
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/type-encoder.js +0 -96
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/type-literal.js +0 -546
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/utils.js +0 -922
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/workarounds.js +0 -16
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
6
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
9
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
10
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
11
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
12
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
13
|
+
};
|
|
14
|
+
var _VisitorBase_instances, _VisitorBase_visitationMap, _VisitorBase_buildMap, _VisitorBase_visitor;
|
|
15
|
+
const require$1 = createRequire(import.meta.url);
|
|
16
|
+
function Visit(kind) {
|
|
17
|
+
if (!Array.isArray(kind))
|
|
18
|
+
kind = [kind];
|
|
19
|
+
let kinds = kind;
|
|
20
|
+
return (target, propertyKey) => {
|
|
21
|
+
target[propertyKey].kinds = kinds;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
class VisitorBase {
|
|
25
|
+
constructor(context) {
|
|
26
|
+
this.context = context;
|
|
27
|
+
_VisitorBase_instances.add(this);
|
|
28
|
+
_VisitorBase_visitationMap.set(this, void 0);
|
|
29
|
+
this.traceVisits = false;
|
|
30
|
+
_VisitorBase_visitor.set(this, void 0);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Runs for every node, regardless of what receivers are defined.
|
|
34
|
+
* If `false` is returned, the node (and all its children) are not visited.
|
|
35
|
+
* Note that if you return nothing (ie `undefined`) the node is visited.
|
|
36
|
+
* @param node
|
|
37
|
+
*/
|
|
38
|
+
everyNode(node) {
|
|
39
|
+
}
|
|
40
|
+
visitNode(node) {
|
|
41
|
+
__classPrivateFieldGet(this, _VisitorBase_instances, "m", _VisitorBase_buildMap).call(this);
|
|
42
|
+
return ts.visitNode(node, __classPrivateFieldGet(this, _VisitorBase_visitor, "f"));
|
|
43
|
+
}
|
|
44
|
+
visitEachChild(node) {
|
|
45
|
+
__classPrivateFieldGet(this, _VisitorBase_instances, "m", _VisitorBase_buildMap).call(this);
|
|
46
|
+
return ts.visitEachChild(node, __classPrivateFieldGet(this, _VisitorBase_visitor, "f"), this.context);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
_VisitorBase_visitationMap = /* @__PURE__ */ new WeakMap(), _VisitorBase_visitor = /* @__PURE__ */ new WeakMap(), _VisitorBase_instances = /* @__PURE__ */ new WeakSet(), _VisitorBase_buildMap = function _VisitorBase_buildMap2() {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
if (__classPrivateFieldGet(this, _VisitorBase_visitationMap, "f"))
|
|
52
|
+
return;
|
|
53
|
+
__classPrivateFieldSet(this, _VisitorBase_visitationMap, /* @__PURE__ */ new Map(), "f");
|
|
54
|
+
let methodNames = Object.getOwnPropertyNames(this.constructor.prototype).filter((x) => !["constructor", "visitEachChild"].includes(x)).filter((x) => typeof this.constructor.prototype[x] === "function");
|
|
55
|
+
for (let methodName of methodNames) {
|
|
56
|
+
let kinds = (_a = this.constructor.prototype[methodName].kinds) !== null && _a !== void 0 ? _a : [];
|
|
57
|
+
for (let kind of kinds) {
|
|
58
|
+
let receivers = (_b = __classPrivateFieldGet(this, _VisitorBase_visitationMap, "f").get(kind)) !== null && _b !== void 0 ? _b : [];
|
|
59
|
+
receivers.push(methodName);
|
|
60
|
+
__classPrivateFieldGet(this, _VisitorBase_visitationMap, "f").set(kind, receivers);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
__classPrivateFieldSet(this, _VisitorBase_visitor, (node) => {
|
|
64
|
+
var _a2;
|
|
65
|
+
if (!node)
|
|
66
|
+
return;
|
|
67
|
+
let continueProcessing = this.everyNode(node);
|
|
68
|
+
if (continueProcessing === false)
|
|
69
|
+
return node;
|
|
70
|
+
let receivers = (_a2 = __classPrivateFieldGet(this, _VisitorBase_visitationMap, "f").get(node.kind)) !== null && _a2 !== void 0 ? _a2 : [];
|
|
71
|
+
if (receivers.length === 0) {
|
|
72
|
+
if (this.traceVisits)
|
|
73
|
+
console.log(`${this.constructor.name}: [Auto] Visiting ${ts.SyntaxKind[node.kind]}`);
|
|
74
|
+
return ts.visitEachChild(node, __classPrivateFieldGet(this, _VisitorBase_visitor, "f"), this.context);
|
|
75
|
+
}
|
|
76
|
+
if (this.traceVisits)
|
|
77
|
+
console.log(`${this.constructor.name}: Visiting ${ts.SyntaxKind[node.kind]}`);
|
|
78
|
+
for (let receiver of receivers) {
|
|
79
|
+
let result = this[receiver](node);
|
|
80
|
+
if (result === null)
|
|
81
|
+
return void 0;
|
|
82
|
+
if (result === void 0)
|
|
83
|
+
continue;
|
|
84
|
+
node = result;
|
|
85
|
+
}
|
|
86
|
+
return node;
|
|
87
|
+
}, "f");
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
Visit,
|
|
91
|
+
VisitorBase
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=visitor-base.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Visit } from "./common/visitor-base.js";
|
|
2
|
+
import { RttiVisitor } from "./rtti-visitor-base.js";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __metadata = function(k, v) {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
13
|
+
};
|
|
14
|
+
const require$1 = createRequire(import.meta.url);
|
|
15
|
+
class DeclarationsEmitter extends RttiVisitor {
|
|
16
|
+
static emit(sourceFile, ctx) {
|
|
17
|
+
return new DeclarationsEmitter(ctx).visitNode(sourceFile);
|
|
18
|
+
}
|
|
19
|
+
functionDecl(decl) {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
__decorate([
|
|
23
|
+
Visit(ts.SyntaxKind.FunctionDeclaration),
|
|
24
|
+
__metadata("design:type", Function),
|
|
25
|
+
__metadata("design:paramtypes", [Object]),
|
|
26
|
+
__metadata("design:returntype", void 0)
|
|
27
|
+
], DeclarationsEmitter.prototype, "functionDecl", null);
|
|
28
|
+
export {
|
|
29
|
+
DeclarationsEmitter
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=declarations-emitter.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { F_ARRAY_BINDING, F_OBJECT_BINDING, F_OPTIONAL, F_REST, F_READONLY, F_PRIVATE, F_PUBLIC, F_PROTECTED } from "../common/format.js";
|
|
3
|
+
import { functionForwardRef, forwardRef } from "./forward-ref.js";
|
|
4
|
+
import { literalNode } from "./literal-node.js";
|
|
5
|
+
import { getModifiers } from "./utils.js";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
const require$1 = createRequire(import.meta.url);
|
|
8
|
+
function encodeParameter(encoder, param) {
|
|
9
|
+
if (ts.isOmittedExpression(param))
|
|
10
|
+
return { f: "," };
|
|
11
|
+
let nameNode = param.name;
|
|
12
|
+
let bindings;
|
|
13
|
+
let name;
|
|
14
|
+
let f = [];
|
|
15
|
+
let typeExpr;
|
|
16
|
+
let checker = encoder.ctx.checker;
|
|
17
|
+
if (ts.isArrayBindingPattern(nameNode)) {
|
|
18
|
+
f.push(F_ARRAY_BINDING);
|
|
19
|
+
bindings = [];
|
|
20
|
+
for (let element of nameNode.elements) {
|
|
21
|
+
bindings.push(encodeParameter(encoder, element));
|
|
22
|
+
}
|
|
23
|
+
} else if (ts.isObjectBindingPattern(nameNode)) {
|
|
24
|
+
f.push(F_OBJECT_BINDING);
|
|
25
|
+
bindings = [];
|
|
26
|
+
for (let element of nameNode.elements) {
|
|
27
|
+
bindings.push(encodeParameter(encoder, element));
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
name = nameNode.text;
|
|
31
|
+
}
|
|
32
|
+
if (ts.isParameter(param)) {
|
|
33
|
+
if (param.questionToken)
|
|
34
|
+
f.push(F_OPTIONAL);
|
|
35
|
+
if (param.dotDotDotToken)
|
|
36
|
+
f.push(F_REST);
|
|
37
|
+
typeExpr = param.type ? encoder.referToTypeNode(param.type) : encoder.referToType(checker.getTypeAtLocation(param.initializer), param.type);
|
|
38
|
+
} else {
|
|
39
|
+
typeExpr = encoder.referToType(checker.getTypeAtLocation(param));
|
|
40
|
+
}
|
|
41
|
+
for (let modifier of getModifiers(param)) {
|
|
42
|
+
if (modifier.kind === ts.SyntaxKind.ReadonlyKeyword)
|
|
43
|
+
f.push(F_READONLY);
|
|
44
|
+
if (modifier.kind === ts.SyntaxKind.PrivateKeyword)
|
|
45
|
+
f.push(F_PRIVATE);
|
|
46
|
+
if (modifier.kind === ts.SyntaxKind.PublicKeyword)
|
|
47
|
+
f.push(F_PUBLIC);
|
|
48
|
+
if (modifier.kind === ts.SyntaxKind.ProtectedKeyword)
|
|
49
|
+
f.push(F_PROTECTED);
|
|
50
|
+
}
|
|
51
|
+
let meta = {
|
|
52
|
+
n: name,
|
|
53
|
+
t: literalNode(forwardRef(typeExpr)),
|
|
54
|
+
b: bindings,
|
|
55
|
+
v: param.initializer ? literalNode(functionForwardRef(param.initializer)) : null
|
|
56
|
+
};
|
|
57
|
+
if (f.length > 0)
|
|
58
|
+
meta.f = f.join("");
|
|
59
|
+
return meta;
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
encodeParameter
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=encode-parameter.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
const require$1 = createRequire(import.meta.url);
|
|
3
|
+
function findRelativePathToFile(fromFile, toFile) {
|
|
4
|
+
fromFile = fromFile.replace(/\\/g, "/");
|
|
5
|
+
toFile = toFile.replace(/\\/g, "/");
|
|
6
|
+
if (fromFile.startsWith("./"))
|
|
7
|
+
fromFile = fromFile.slice(2);
|
|
8
|
+
if (toFile.startsWith("./"))
|
|
9
|
+
toFile = toFile.slice(2);
|
|
10
|
+
let fromAbsolute = /^[A-Za-z]:/.test(fromFile) || /^\//.test(fromFile);
|
|
11
|
+
let toAbsolute = /^[A-Za-z]:/.test(toFile) || /^\//.test(toFile);
|
|
12
|
+
if (fromAbsolute !== toAbsolute)
|
|
13
|
+
throw new Error(`Cannot determine relationship between an absolute and a relative path!`);
|
|
14
|
+
if (!fromAbsolute && !toAbsolute) {
|
|
15
|
+
fromFile = `/${fromFile}`;
|
|
16
|
+
toFile = `/${toFile}`;
|
|
17
|
+
}
|
|
18
|
+
let from = fromFile.split("/");
|
|
19
|
+
let to = toFile.split("/");
|
|
20
|
+
let parents = 0;
|
|
21
|
+
let toFileName = to.pop();
|
|
22
|
+
while (from.length > 0 && !(to.join("/") + "/").startsWith(from.join("/") + "/")) {
|
|
23
|
+
parents += 1;
|
|
24
|
+
from.pop();
|
|
25
|
+
}
|
|
26
|
+
let result;
|
|
27
|
+
if (from.length === 0) {
|
|
28
|
+
return void 0;
|
|
29
|
+
} else {
|
|
30
|
+
if (parents > 1) {
|
|
31
|
+
result = [...Array(parents - 1).fill(".."), ...to.slice(from.length), toFileName].join("/");
|
|
32
|
+
} else {
|
|
33
|
+
result = [".", ...to.slice(from.length), toFileName].join("/");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
findRelativePathToFile
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=find-relative-path.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { F_PUBLIC, F_PRIVATE, F_PROTECTED, F_READONLY, F_ABSTRACT, F_ASYNC, F_EXPORTED } from "../common/format.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
const require$1 = createRequire(import.meta.url);
|
|
5
|
+
function getVisibility(modifiers) {
|
|
6
|
+
if (modifiers) {
|
|
7
|
+
if (modifiers.some((x) => x.kind === ts.SyntaxKind.PublicKeyword))
|
|
8
|
+
return F_PUBLIC;
|
|
9
|
+
if (modifiers.some((x) => x.kind === ts.SyntaxKind.PrivateKeyword))
|
|
10
|
+
return F_PRIVATE;
|
|
11
|
+
if (modifiers.some((x) => x.kind === ts.SyntaxKind.ProtectedKeyword))
|
|
12
|
+
return F_PROTECTED;
|
|
13
|
+
}
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
function isReadOnly(modifiers) {
|
|
17
|
+
if (!modifiers)
|
|
18
|
+
return "";
|
|
19
|
+
return modifiers.some((x) => x.kind === ts.SyntaxKind.ReadonlyKeyword) ? F_READONLY : "";
|
|
20
|
+
}
|
|
21
|
+
function isAbstract(modifiers) {
|
|
22
|
+
if (!modifiers)
|
|
23
|
+
return "";
|
|
24
|
+
return modifiers.some((x) => x.kind === ts.SyntaxKind.AbstractKeyword) ? F_ABSTRACT : "";
|
|
25
|
+
}
|
|
26
|
+
function isAsync(modifiers) {
|
|
27
|
+
if (!modifiers)
|
|
28
|
+
return "";
|
|
29
|
+
return modifiers.some((x) => x.kind === ts.SyntaxKind.AsyncKeyword) ? F_ASYNC : "";
|
|
30
|
+
}
|
|
31
|
+
function isExported(modifiers) {
|
|
32
|
+
if (!modifiers)
|
|
33
|
+
return "";
|
|
34
|
+
return modifiers.some((x) => x.kind === ts.SyntaxKind.ExportKeyword) ? F_EXPORTED : "";
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
getVisibility,
|
|
38
|
+
isAbstract,
|
|
39
|
+
isAsync,
|
|
40
|
+
isExported,
|
|
41
|
+
isReadOnly
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
const require$1 = createRequire(import.meta.url);
|
|
4
|
+
function forwardRef(expr) {
|
|
5
|
+
if (!expr)
|
|
6
|
+
throw new Error(`Cannot make forwardRef without an expression`);
|
|
7
|
+
return ts.factory.createArrowFunction([], [], [], void 0, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), expr);
|
|
8
|
+
}
|
|
9
|
+
function functionForwardRef(expr) {
|
|
10
|
+
if (!expr)
|
|
11
|
+
throw new Error(`Cannot make forwardRef without an expression`);
|
|
12
|
+
return ts.factory.createFunctionExpression([], void 0, "", [], [], void 0, ts.factory.createBlock([
|
|
13
|
+
ts.factory.createReturnStatement(expr)
|
|
14
|
+
]));
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
forwardRef,
|
|
18
|
+
functionForwardRef
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=forward-ref.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { externalModules, getDirectoryPath, getDefaultLikeExportInfo, skipAlias, isTypeOnlySymbol, hasFilesystemAccess, fileExists } from "./utils.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
const require$1 = createRequire(import.meta.url);
|
|
4
|
+
function getExportsForSymbol(program, importingFile, symbol) {
|
|
5
|
+
const checker = program.getTypeChecker();
|
|
6
|
+
const compilerOptions = program.getCompilerOptions();
|
|
7
|
+
const result = [];
|
|
8
|
+
let exportingModuleSymbol = symbol["parent"];
|
|
9
|
+
for (let [moduleSymbol, moduleFile] of externalModules(program)) {
|
|
10
|
+
let isRootDeclaration = moduleSymbol === exportingModuleSymbol;
|
|
11
|
+
if (moduleFile === importingFile)
|
|
12
|
+
continue;
|
|
13
|
+
if (moduleFile && !isRootDeclaration && importingFile.fileName.startsWith(getDirectoryPath(moduleFile.fileName)))
|
|
14
|
+
continue;
|
|
15
|
+
const defaultInfo = getDefaultLikeExportInfo(importingFile, moduleSymbol, checker, compilerOptions);
|
|
16
|
+
if (defaultInfo && skipAlias(defaultInfo.symbol, checker) === symbol) {
|
|
17
|
+
result.push({
|
|
18
|
+
moduleSymbol,
|
|
19
|
+
importKind: defaultInfo.kind,
|
|
20
|
+
exportedSymbolIsTypeOnly: isTypeOnlySymbol(defaultInfo.symbol, checker),
|
|
21
|
+
symbol: void 0,
|
|
22
|
+
sourceFile: moduleFile
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
for (const exported of getExportsAndPropertiesOfModule(checker, moduleSymbol)) {
|
|
26
|
+
if (skipAlias(exported, checker) === symbol) {
|
|
27
|
+
result.push({
|
|
28
|
+
moduleSymbol,
|
|
29
|
+
importKind: 0,
|
|
30
|
+
exportedSymbolIsTypeOnly: isTypeOnlySymbol(exported, checker),
|
|
31
|
+
symbol: exported,
|
|
32
|
+
sourceFile: moduleFile
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function getPreferredExportForImport(program, importingFile, symbol) {
|
|
40
|
+
let exports$1 = getExportsForSymbol(program, importingFile, symbol).slice();
|
|
41
|
+
exports$1 = exports$1.filter((x) => x.sourceFile);
|
|
42
|
+
exports$1.sort((a, b) => {
|
|
43
|
+
return a.sourceFile.fileName.length - b.sourceFile.fileName.length;
|
|
44
|
+
});
|
|
45
|
+
if (hasFilesystemAccess()) {
|
|
46
|
+
exports$1 = exports$1.filter((exp) => {
|
|
47
|
+
if (exp.sourceFile.fileName.endsWith(".d.ts")) {
|
|
48
|
+
let jsFile = exp.sourceFile.fileName.replace(/\.d\.ts$/, ".js");
|
|
49
|
+
if (!fileExists(jsFile))
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return exports$1[0];
|
|
56
|
+
}
|
|
57
|
+
function getExportsAndPropertiesOfModule(checker, moduleSymbol) {
|
|
58
|
+
return checker["getExportsAndPropertiesOfModule"](moduleSymbol);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
getExportsForSymbol,
|
|
62
|
+
getPreferredExportForImport
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=get-exports-for-symbol.js.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { rtStore } from "./rt-helper.js";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { ImportAnalyzer } from "./common/import-analyzer.js";
|
|
4
|
+
import { CompileError } from "./common/compile-error.js";
|
|
5
|
+
import { ApiCallTransformer } from "./api-call-transformer.js";
|
|
6
|
+
import { MetadataEmitter } from "./metadata-emitter.js";
|
|
7
|
+
import { DeclarationsEmitter } from "./declarations-emitter.js";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
const require$1 = createRequire(import.meta.url);
|
|
10
|
+
const transformer = (program) => {
|
|
11
|
+
let compilerOptions = program.getCompilerOptions();
|
|
12
|
+
if (typeof compilerOptions["rtti$emitStandardMetadata"] === "undefined") {
|
|
13
|
+
let emitDecoratorMetadata = compilerOptions.emitDecoratorMetadata;
|
|
14
|
+
compilerOptions["rtti$emitStandardMetadata"] = emitDecoratorMetadata;
|
|
15
|
+
compilerOptions.emitDecoratorMetadata = false;
|
|
16
|
+
}
|
|
17
|
+
let emitStandardMetadata = compilerOptions["rtti$emitStandardMetadata"];
|
|
18
|
+
if (globalThis.RTTI_TRACE)
|
|
19
|
+
console.log(`RTTI: Entering program [emitDecoratorMetadata=${emitStandardMetadata}]`);
|
|
20
|
+
let pkgJsonMap = /* @__PURE__ */ new Map();
|
|
21
|
+
const rttiTransformer = (context) => {
|
|
22
|
+
let settings = context.getCompilerOptions().rtti;
|
|
23
|
+
if (globalThis.RTTI_TRACE)
|
|
24
|
+
console.log(`RTTI: Transformer setup`);
|
|
25
|
+
return (sourceFile) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if (globalThis.RTTI_TRACE)
|
|
28
|
+
console.log(`RTTI: Transforming '${sourceFile.fileName}'`);
|
|
29
|
+
let ctx = {
|
|
30
|
+
program,
|
|
31
|
+
checker: program.getTypeChecker(),
|
|
32
|
+
currentNameScope: void 0,
|
|
33
|
+
freeImportReference: 0,
|
|
34
|
+
importMap: /* @__PURE__ */ new Map(),
|
|
35
|
+
sourceFile,
|
|
36
|
+
trace: (_a = settings === null || settings === void 0 ? void 0 : settings.trace) !== null && _a !== void 0 ? _a : false,
|
|
37
|
+
throwOnFailure: (_b = settings === null || settings === void 0 ? void 0 : settings.throwOnFailure) !== null && _b !== void 0 ? _b : false,
|
|
38
|
+
transformationContext: context,
|
|
39
|
+
typeMap: /* @__PURE__ */ new Map(),
|
|
40
|
+
pkgJsonMap,
|
|
41
|
+
emitStandardMetadata,
|
|
42
|
+
currentTopStatement: void 0,
|
|
43
|
+
interfaceSymbols: []
|
|
44
|
+
};
|
|
45
|
+
ImportAnalyzer.analyze(sourceFile, ctx);
|
|
46
|
+
if (sourceFile.isDeclarationFile || sourceFile.fileName.endsWith(".d.ts")) {
|
|
47
|
+
if (ctx.trace)
|
|
48
|
+
console.log(`#### Processing declaration ${sourceFile.fileName}`);
|
|
49
|
+
return DeclarationsEmitter.emit(sourceFile, ctx);
|
|
50
|
+
}
|
|
51
|
+
if (ctx.trace)
|
|
52
|
+
console.log(`#### Processing ${sourceFile.fileName}`);
|
|
53
|
+
globalThis.RTTI_TRACE = ctx.trace;
|
|
54
|
+
globalThis.RTTI_THROW_ON_FAILURE = ctx.throwOnFailure;
|
|
55
|
+
sourceFile = ApiCallTransformer.transform(sourceFile, ctx);
|
|
56
|
+
function generateInterfaceSymbols(statements) {
|
|
57
|
+
for (let iface of ctx.interfaceSymbols) {
|
|
58
|
+
let impoIndex = statements.indexOf(iface.interfaceDecl);
|
|
59
|
+
if (impoIndex >= 0) {
|
|
60
|
+
statements.splice(impoIndex, 0, ...iface.symbolDecl);
|
|
61
|
+
} else {
|
|
62
|
+
statements.push(...iface.symbolDecl);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return statements;
|
|
66
|
+
}
|
|
67
|
+
function generateImports(statements) {
|
|
68
|
+
var _a2;
|
|
69
|
+
let imports = [];
|
|
70
|
+
let isCommonJS = context.getCompilerOptions().module === ts.ModuleKind.CommonJS;
|
|
71
|
+
let statementTransforms = /* @__PURE__ */ new Map();
|
|
72
|
+
for (let statement of statements)
|
|
73
|
+
statementTransforms.set(ts.getOriginalNode(statement), statement);
|
|
74
|
+
for (let impo of ctx.importMap.values()) {
|
|
75
|
+
if (!impo.referenced)
|
|
76
|
+
continue;
|
|
77
|
+
if (ctx.trace)
|
|
78
|
+
console.log(`RTTI: Generating owned import for '${impo.modulePath}'`);
|
|
79
|
+
let ownedImpo;
|
|
80
|
+
if (impo.isDefault) {
|
|
81
|
+
if (isCommonJS) {
|
|
82
|
+
ownedImpo = ts.factory.createVariableStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(ts.factory.createIdentifier(impo.localName), void 0, void 0, ts.factory.createPropertyAccessExpression(ts.factory.createCallExpression(ts.factory.createIdentifier("require"), void 0, [ts.factory.createStringLiteral(impo.modulePath)]), ts.factory.createIdentifier("default")))], ts.NodeFlags.None));
|
|
83
|
+
} else {
|
|
84
|
+
ownedImpo = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, ts.factory.createIdentifier(impo.localName), void 0), ts.factory.createStringLiteral(impo.modulePath), void 0);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
ownedImpo = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, impo.isNamespace ? ts.factory.createNamespaceImport(ts.factory.createIdentifier(impo.localName)) : ts.factory.createNamedImports([
|
|
88
|
+
ts.factory.createImportSpecifier(false, ts.factory.createIdentifier(impo.refName), ts.factory.createIdentifier(impo.localName))
|
|
89
|
+
])), ts.factory.createStringLiteral(impo.modulePath));
|
|
90
|
+
}
|
|
91
|
+
let impoIndex = -1;
|
|
92
|
+
if (impo.importDeclaration) {
|
|
93
|
+
let original = (_a2 = statementTransforms.get(impo.importDeclaration)) !== null && _a2 !== void 0 ? _a2 : impo.importDeclaration;
|
|
94
|
+
impoIndex = statements.indexOf(original);
|
|
95
|
+
if (impoIndex < 0)
|
|
96
|
+
impoIndex = statements.indexOf(impo.importDeclaration);
|
|
97
|
+
}
|
|
98
|
+
if (impoIndex >= 0) {
|
|
99
|
+
statements.splice(impoIndex, 0, ownedImpo);
|
|
100
|
+
} else {
|
|
101
|
+
statements.splice(0, 0, ownedImpo);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return statements;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
sourceFile = MetadataEmitter.emit(sourceFile, ctx);
|
|
108
|
+
sourceFile = ts.factory.updateSourceFile(sourceFile, [
|
|
109
|
+
...generateInterfaceSymbols(generateImports(Array.from(sourceFile.statements)))
|
|
110
|
+
], sourceFile.isDeclarationFile, sourceFile.referencedFiles, sourceFile.typeReferenceDirectives, sourceFile.hasNoDefaultLib, sourceFile.libReferenceDirectives);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
if (e instanceof CompileError)
|
|
113
|
+
throw e;
|
|
114
|
+
console.error(`RTTI: Failed to build source file ${sourceFile.fileName}: ${e.message} [please report]`);
|
|
115
|
+
console.error(e);
|
|
116
|
+
if (globalThis.RTTI_THROW_ON_FAILURE)
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
sourceFile = ts.factory.updateSourceFile(sourceFile, [rtStore(ctx.typeMap), ...sourceFile.statements], sourceFile.isDeclarationFile, sourceFile.referencedFiles, sourceFile.typeReferenceDirectives, sourceFile.hasNoDefaultLib, sourceFile.libReferenceDirectives);
|
|
120
|
+
if (globalThis.RTTI_TRACE)
|
|
121
|
+
console.log(`RTTI: Finished transforming '${sourceFile.fileName}'`);
|
|
122
|
+
return sourceFile;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
return rttiTransformer;
|
|
126
|
+
};
|
|
127
|
+
export {
|
|
128
|
+
transformer as default
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
const require$1 = createRequire(import.meta.url);
|
|
3
|
+
function legacyDecorator(decorator) {
|
|
4
|
+
decorator["__Φlegacy"] = true;
|
|
5
|
+
return decorator;
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
legacyDecorator
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=legacy-decorator.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { typeLiteral } from "./type-literal.js";
|
|
3
|
+
import { hasFlag, hasAnyFlag, isFlagType } from "./utils.js";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
const require$1 = createRequire(import.meta.url);
|
|
6
|
+
class LegacyTypeEncoder {
|
|
7
|
+
constructor(ctx) {
|
|
8
|
+
this.ctx = ctx;
|
|
9
|
+
}
|
|
10
|
+
get typeMap() {
|
|
11
|
+
return this.ctx.typeMap;
|
|
12
|
+
}
|
|
13
|
+
get program() {
|
|
14
|
+
return this.ctx.program;
|
|
15
|
+
}
|
|
16
|
+
get sourceFile() {
|
|
17
|
+
return this.ctx.sourceFile;
|
|
18
|
+
}
|
|
19
|
+
get importMap() {
|
|
20
|
+
return this.ctx.importMap;
|
|
21
|
+
}
|
|
22
|
+
get checker() {
|
|
23
|
+
return this.ctx.checker;
|
|
24
|
+
}
|
|
25
|
+
referToTypeNode(typeNode) {
|
|
26
|
+
return this.referToType(this.checker.getTypeFromTypeNode(typeNode), typeNode);
|
|
27
|
+
}
|
|
28
|
+
referToType(type, typeNode) {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!type)
|
|
31
|
+
return ts.factory.createIdentifier("Object");
|
|
32
|
+
if (hasFlag(type.flags, ts.TypeFlags.StringLike)) {
|
|
33
|
+
return ts.factory.createIdentifier("String");
|
|
34
|
+
} else if (hasFlag(type.flags, ts.TypeFlags.NumberLike)) {
|
|
35
|
+
return ts.factory.createIdentifier("Number");
|
|
36
|
+
} else if (hasFlag(type.flags, ts.TypeFlags.BooleanLike)) {
|
|
37
|
+
return ts.factory.createIdentifier("Boolean");
|
|
38
|
+
} else if (hasAnyFlag(type.flags, [ts.TypeFlags.Void, ts.TypeFlags.Undefined, ts.TypeFlags.Null])) {
|
|
39
|
+
return ts.factory.createVoidZero();
|
|
40
|
+
} else if (hasFlag(type.flags, ts.TypeFlags.BigIntLike)) {
|
|
41
|
+
return ts.factory.createIdentifier("BigInt");
|
|
42
|
+
} else if (isFlagType(type, ts.TypeFlags.Object)) {
|
|
43
|
+
if (hasFlag(type.objectFlags, ts.ObjectFlags.Reference)) {
|
|
44
|
+
let typeRef = type;
|
|
45
|
+
if (typeRef.target !== typeRef) {
|
|
46
|
+
if ((typeRef.target.objectFlags & ts.ObjectFlags.Tuple) !== 0)
|
|
47
|
+
return ts.factory.createIdentifier("Array");
|
|
48
|
+
if (typeRef.target.symbol.name === "Array" && typeRef.typeArguments.length === 1)
|
|
49
|
+
return ts.factory.createIdentifier("Array");
|
|
50
|
+
return this.referToType(typeRef.target, typeNode);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (hasFlag(type.objectFlags, ts.ObjectFlags.Anonymous)) {
|
|
54
|
+
let anonymousType = type;
|
|
55
|
+
if (anonymousType.getCallSignatures().length > 0)
|
|
56
|
+
return ts.factory.createIdentifier(`Function`);
|
|
57
|
+
return ts.factory.createIdentifier("Object");
|
|
58
|
+
} else if (type.isClassOrInterface()) {
|
|
59
|
+
let reifiedType = type.isClass() || ((_a = type.symbol) === null || _a === void 0 ? void 0 : _a.name) === "Promise" || !!type.symbol.valueDeclaration;
|
|
60
|
+
if (reifiedType) {
|
|
61
|
+
return typeLiteral(this, type, typeNode, { hoistImportsInCommonJS: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return ts.factory.createIdentifier("Object");
|
|
65
|
+
} else if (isFlagType(type, ts.TypeFlags.EnumLike)) {
|
|
66
|
+
let types = type["types"];
|
|
67
|
+
if (types && types.length > 0) {
|
|
68
|
+
if (types.every((x) => hasFlag(x.flags, ts.TypeFlags.StringLike)))
|
|
69
|
+
return ts.factory.createIdentifier("String");
|
|
70
|
+
else if (types.every((x) => hasFlag(x.flags, ts.TypeFlags.NumberLike)))
|
|
71
|
+
return ts.factory.createIdentifier("Number");
|
|
72
|
+
else if (types.every((x) => hasFlag(x.flags, ts.TypeFlags.BigIntLike)))
|
|
73
|
+
return ts.factory.createIdentifier("BigInt");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return ts.factory.createIdentifier("Object");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
LegacyTypeEncoder
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=legacy-type-encoder.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { getDecorators, getModifiers } from "./utils.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
const require$1 = createRequire(import.meta.url);
|
|
5
|
+
class InlineMetadataCollector {
|
|
6
|
+
collect(node, decorators) {
|
|
7
|
+
if (decorators.length === 0)
|
|
8
|
+
return node;
|
|
9
|
+
if (ts.isPropertyDeclaration(node)) {
|
|
10
|
+
return ts.factory.updatePropertyDeclaration(node, [...getDecorators(node), ...decorators, ...getModifiers(node)], node.name, node.questionToken || node.exclamationToken, node.type, node.initializer);
|
|
11
|
+
} else if (ts.isGetAccessor(node)) {
|
|
12
|
+
return ts.factory.updateGetAccessorDeclaration(node, [...getDecorators(node), ...decorators, ...getModifiers(node)], node.name, node.parameters, node.type, node.body);
|
|
13
|
+
} else if (ts.isSetAccessor(node)) {
|
|
14
|
+
return ts.factory.updateSetAccessorDeclaration(node, [...getDecorators(node), ...decorators, ...getModifiers(node)], node.name, node.parameters, node.body);
|
|
15
|
+
} else if (ts.isMethodDeclaration(node)) {
|
|
16
|
+
return ts.factory.updateMethodDeclaration(node, [...getDecorators(node), ...decorators, ...getModifiers(node)], node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
|
|
17
|
+
} else if (ts.isClassDeclaration(node)) {
|
|
18
|
+
return ts.factory.updateClassDeclaration(node, [...getDecorators(node), ...decorators, ...getModifiers(node)], node.name, node.typeParameters, node.heritageClauses, node.members);
|
|
19
|
+
} else {
|
|
20
|
+
throw new TypeError(`Not sure how to collect metadata onto ${node}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class ExternalMetadataCollector {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.inlineCollector = new InlineMetadataCollector();
|
|
27
|
+
this.decorators = [];
|
|
28
|
+
}
|
|
29
|
+
collect(node, addedDecorators) {
|
|
30
|
+
var _a;
|
|
31
|
+
let property;
|
|
32
|
+
if (ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node)) {
|
|
33
|
+
property = node.name;
|
|
34
|
+
}
|
|
35
|
+
let legacyDecorators = addedDecorators.filter((decorator) => decorator["__Φlegacy"]);
|
|
36
|
+
let nonLegacyDecorators = addedDecorators.filter((decorator) => !decorator["__Φlegacy"]);
|
|
37
|
+
this.decorators.push(...nonLegacyDecorators.map((decorator) => {
|
|
38
|
+
var _a2;
|
|
39
|
+
return {
|
|
40
|
+
property,
|
|
41
|
+
node,
|
|
42
|
+
decorator,
|
|
43
|
+
direct: (_a2 = decorator["__Φdirect"]) !== null && _a2 !== void 0 ? _a2 : false
|
|
44
|
+
};
|
|
45
|
+
}));
|
|
46
|
+
if (((_a = getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) > 0 && legacyDecorators.length > 0) {
|
|
47
|
+
node = this.inlineCollector.collect(node, legacyDecorators);
|
|
48
|
+
}
|
|
49
|
+
return node;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
ExternalMetadataCollector,
|
|
54
|
+
InlineMetadataCollector
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=metadata-collector.js.map
|