xml-model 1.3.3 → 2.0.0-beta.2
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 +39 -35
- package/dist/_virtual/_rolldown/runtime.js +8 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.js +7 -20
- package/dist/model.d.ts +53 -0
- package/dist/model.js +75 -0
- package/dist/node_modules/sax/lib/sax.js +1249 -0
- package/dist/node_modules/xml-js/lib/array-helper.js +13 -0
- package/dist/node_modules/xml-js/lib/index.js +19 -0
- package/dist/node_modules/xml-js/lib/js2xml.js +258 -0
- package/dist/node_modules/xml-js/lib/json2xml.js +22 -0
- package/dist/node_modules/xml-js/lib/options-helper.js +33 -0
- package/dist/node_modules/xml-js/lib/xml2js.js +246 -0
- package/dist/node_modules/xml-js/lib/xml2json.js +26 -0
- package/dist/util/kebab-case.js +24 -13
- package/dist/util/zod.d.ts +4 -0
- package/dist/util/zod.js +21 -0
- package/dist/xml/codec.d.ts +87 -0
- package/dist/xml/codec.js +339 -0
- package/dist/xml/examples.d.ts +188 -0
- package/dist/xml/index.d.ts +5 -79
- package/dist/xml/index.js +4 -57
- package/dist/xml/model.d.ts +18 -0
- package/dist/xml/model.js +33 -0
- package/dist/xml/schema-meta.d.ts +57 -0
- package/dist/xml/schema-meta.js +88 -0
- package/dist/xml/xml-js.d.ts +280 -3
- package/dist/xml/xml-js.js +121 -8
- package/package.json +27 -42
- package/dist/_virtual/Reflect.js +0 -8
- package/dist/_virtual/Reflect2.js +0 -5
- package/dist/_virtual/_commonjsHelpers.js +0 -47
- package/dist/defaults.d.ts +0 -28
- package/dist/defaults.js +0 -165
- package/dist/errors.d.ts +0 -40
- package/dist/errors.js +0 -45
- package/dist/middleware.d.ts +0 -10
- package/dist/middleware.js +0 -25
- package/dist/model/built-ins.d.ts +0 -3
- package/dist/model/built-ins.js +0 -43
- package/dist/model/index.d.ts +0 -69
- package/dist/model/index.js +0 -264
- package/dist/model/property.d.ts +0 -18
- package/dist/model/property.js +0 -67
- package/dist/model/registry.d.ts +0 -9
- package/dist/model/registry.js +0 -19
- package/dist/model/types.d.ts +0 -109
- package/dist/node_modules/reflect-metadata/Reflect.js +0 -806
- package/dist/types.d.ts +0 -25
- package/dist/util/is-regexp.d.ts +0 -12
- package/dist/util/is-regexp.js +0 -8
- package/dist/util/merge-maps.d.ts +0 -2
- package/dist/util/merge-maps.js +0 -23
- package/dist/vite/index.d.ts +0 -80
- package/dist/vite/index.js +0 -71
- package/dist/vite/node_modules/typescript-rtti/dist.esm/common/format.js +0 -105
- package/dist/vite/node_modules/typescript-rtti/dist.esm/common/index.js +0 -55
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/api-call-transformer.js +0 -152
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/class-analyzer.js +0 -83
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/compile-error.js +0 -8
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/import-analyzer.js +0 -89
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/interface-analyzer.js +0 -58
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/visitor-base.js +0 -93
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/declarations-emitter.js +0 -31
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/encode-parameter.js +0 -64
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/find-relative-path.js +0 -41
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/flags.js +0 -43
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/forward-ref.js +0 -20
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/get-exports-for-symbol.js +0 -64
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/index.js +0 -130
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/legacy-decorator.js +0 -10
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/legacy-type-encoder.js +0 -82
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/literal-node.js +0 -9
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-collector.js +0 -56
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-decorator.js +0 -80
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-emitter.js +0 -425
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-encoder.js +0 -212
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/rt-helper.js +0 -96
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/rtti-visitor-base.js +0 -28
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/serialize.js +0 -31
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/type-encoder.js +0 -76
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/type-literal.js +0 -499
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/utils.js +0 -906
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/workarounds.js +0 -7
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { F_INTERFACE, F_CLASS, F_PROPERTY, F_OPTIONAL, F_FUNCTION, F_ARROW_FUNCTION, F_METHOD, F_STATIC, F_INFERRED } from "../common/format.js";
|
|
3
|
-
import { encodeParameter } from "./encode-parameter.js";
|
|
4
|
-
import { getVisibility, isAbstract, isExported, isReadOnly, isAsync } from "./flags.js";
|
|
5
|
-
import { forwardRef } from "./forward-ref.js";
|
|
6
|
-
import { LegacyTypeEncoder } from "./legacy-type-encoder.js";
|
|
7
|
-
import { literalNode } from "./literal-node.js";
|
|
8
|
-
import { metadataDecorator, legacyMetadataDecorator } from "./metadata-decorator.js";
|
|
9
|
-
import { serialize } from "./serialize.js";
|
|
10
|
-
import { TypeEncoder } from "./type-encoder.js";
|
|
11
|
-
import { expressionForPropertyName, hasModifier, getModifiers, propertyNameToString } from "./utils.js";
|
|
12
|
-
import { createRequire } from "node:module";
|
|
13
|
-
const require$1 = createRequire(import.meta.url);
|
|
14
|
-
class MetadataEncoder {
|
|
15
|
-
constructor(ctx) {
|
|
16
|
-
this.ctx = ctx;
|
|
17
|
-
this.typeEncoder = new TypeEncoder(this.ctx);
|
|
18
|
-
this.legacyTypeEncoder = new LegacyTypeEncoder(this.ctx);
|
|
19
|
-
}
|
|
20
|
-
get emitStandardMetadata() {
|
|
21
|
-
return this.ctx.emitStandardMetadata;
|
|
22
|
-
}
|
|
23
|
-
get checker() {
|
|
24
|
-
return this.ctx.checker;
|
|
25
|
-
}
|
|
26
|
-
get importMap() {
|
|
27
|
-
return this.ctx.importMap;
|
|
28
|
-
}
|
|
29
|
-
typeNode(typeNode, standardName, allowStandardMetadata = true) {
|
|
30
|
-
return this.type(this.checker.getTypeAtLocation(typeNode), typeNode, standardName, allowStandardMetadata);
|
|
31
|
-
}
|
|
32
|
-
type(type, typeNode, standardName, allowStandardMetadata = true) {
|
|
33
|
-
let decs = [];
|
|
34
|
-
decs.push(metadataDecorator("rt:t", literalNode(forwardRef(this.typeEncoder.referToType(type, typeNode)))));
|
|
35
|
-
if (this.emitStandardMetadata && allowStandardMetadata)
|
|
36
|
-
decs.push(legacyMetadataDecorator(`design:${standardName}`, literalNode(this.legacyTypeEncoder.referToType(type, typeNode))));
|
|
37
|
-
return decs;
|
|
38
|
-
}
|
|
39
|
-
prepareElementNames(elementNames) {
|
|
40
|
-
return elementNames.map((elementName) => literalNode(expressionForPropertyName(elementName)));
|
|
41
|
-
}
|
|
42
|
-
class(klass, details) {
|
|
43
|
-
var _a;
|
|
44
|
-
let type = this.checker.getTypeAtLocation(klass);
|
|
45
|
-
let decs = [
|
|
46
|
-
ts.factory.createDecorator(ts.factory.createArrowFunction([], [], [
|
|
47
|
-
ts.factory.createParameterDeclaration([], void 0, "t")
|
|
48
|
-
], void 0, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createBinaryExpression(ts.factory.createElementAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("__RΦ"), "t"), type["id"]), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createIdentifier("t"))))
|
|
49
|
-
];
|
|
50
|
-
if (ts.isClassDeclaration(klass) || ts.isClassExpression(klass))
|
|
51
|
-
decs.push(metadataDecorator("rt:SP", this.prepareElementNames(details.staticPropertyNames)));
|
|
52
|
-
decs.push(metadataDecorator("rt:P", this.prepareElementNames(details.propertyNames)));
|
|
53
|
-
if (ts.isClassDeclaration(klass) || ts.isClassExpression(klass))
|
|
54
|
-
decs.push(metadataDecorator("rt:Sm", this.prepareElementNames(details.staticMethodNames)));
|
|
55
|
-
decs.push(metadataDecorator("rt:m", this.prepareElementNames(details.methodNames)));
|
|
56
|
-
if (ts.isClassDeclaration(klass) || ts.isClassExpression(klass)) {
|
|
57
|
-
let constructor = klass.members.find((x) => ts.isConstructorDeclaration(x));
|
|
58
|
-
if (constructor) {
|
|
59
|
-
decs.push(...this.params(constructor, klass));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
let impls = (_a = klass.heritageClauses) === null || _a === void 0 ? void 0 : _a.find((x) => x.token === (ts.isInterfaceDeclaration(klass) ? ts.SyntaxKind.ExtendsKeyword : ts.SyntaxKind.ImplementsKeyword));
|
|
63
|
-
if (impls) {
|
|
64
|
-
let typeRefs = [];
|
|
65
|
-
for (let heritageType of impls.types) {
|
|
66
|
-
let checker = this.checker;
|
|
67
|
-
let symbol = checker.getSymbolAtLocation(heritageType.expression);
|
|
68
|
-
let type2 = checker.getTypeAtLocation(heritageType.expression);
|
|
69
|
-
if (symbol) {
|
|
70
|
-
let localName = heritageType.expression.getText();
|
|
71
|
-
typeRefs.push(this.typeEncoder.referToType(type2, heritageType));
|
|
72
|
-
} else {
|
|
73
|
-
console.error(`RTTI: Cannot identify type ${heritageType.getText()} on implements clause for class ${klass.name.text} [please report]`);
|
|
74
|
-
typeRefs.push(void 0);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
decs.push(metadataDecorator("rt:i", typeRefs.map((tr) => tr ? literalNode(forwardRef(tr)) : void 0)));
|
|
78
|
-
}
|
|
79
|
-
let klassModifiers = ts.canHaveModifiers(klass) ? ts.getModifiers(klass) : [];
|
|
80
|
-
let fType = ts.isInterfaceDeclaration(klass) ? F_INTERFACE : F_CLASS;
|
|
81
|
-
decs.push(metadataDecorator("rt:f", `${fType}${getVisibility(klassModifiers)}${isAbstract(klassModifiers)}${isExported(klassModifiers)}`));
|
|
82
|
-
return decs;
|
|
83
|
-
}
|
|
84
|
-
getClassName(node) {
|
|
85
|
-
if (!node.parent)
|
|
86
|
-
return `unknown class/interface`;
|
|
87
|
-
if (ts.isClassDeclaration(node.parent)) {
|
|
88
|
-
if (node.parent.name)
|
|
89
|
-
return `class ${node.parent.name.text}`;
|
|
90
|
-
else if (hasModifier(ts.canHaveModifiers(node.parent) ? ts.getModifiers(node.parent) : [], ts.SyntaxKind.DefaultKeyword))
|
|
91
|
-
return `default class`;
|
|
92
|
-
else
|
|
93
|
-
return `unknown class`;
|
|
94
|
-
} else if (ts.isClassExpression(node.parent)) {
|
|
95
|
-
if (node.parent.name)
|
|
96
|
-
return `class ${node.parent.name.text}`;
|
|
97
|
-
else
|
|
98
|
-
return `unnamed class expression`;
|
|
99
|
-
} else if (ts.isInterfaceDeclaration(node.parent)) {
|
|
100
|
-
if (node.parent.name)
|
|
101
|
-
return `interface ${node.parent.name.text}`;
|
|
102
|
-
else if (hasModifier(getModifiers(node.parent), ts.SyntaxKind.DefaultKeyword))
|
|
103
|
-
return `default interface`;
|
|
104
|
-
else
|
|
105
|
-
return `unknown interface`;
|
|
106
|
-
}
|
|
107
|
-
return `unknown class`;
|
|
108
|
-
}
|
|
109
|
-
property(node) {
|
|
110
|
-
var _a;
|
|
111
|
-
let typeNode = node.type;
|
|
112
|
-
let type;
|
|
113
|
-
if (!typeNode && ts.isSetAccessor(node) && node.parameters.length > 0) {
|
|
114
|
-
typeNode = node.parameters[0].type;
|
|
115
|
-
}
|
|
116
|
-
this.ctx.locationHint = `Property '${propertyNameToString(node.name)}' of ${this.getClassName(node)}`;
|
|
117
|
-
if (typeNode) {
|
|
118
|
-
type = this.checker.getTypeAtLocation(typeNode);
|
|
119
|
-
} else {
|
|
120
|
-
type = this.checker.getTypeAtLocation(node);
|
|
121
|
-
}
|
|
122
|
-
const nodeModifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : [];
|
|
123
|
-
return [
|
|
124
|
-
...this.type(type, typeNode, "type", (ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node)) && ts.canHaveDecorators(node) && ((_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) > 0),
|
|
125
|
-
metadataDecorator("rt:f", `${F_PROPERTY}${getVisibility(nodeModifiers)}${isReadOnly(nodeModifiers)}${node.questionToken ? F_OPTIONAL : ""}`)
|
|
126
|
-
];
|
|
127
|
-
}
|
|
128
|
-
methodFlags(node) {
|
|
129
|
-
if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node)) {
|
|
130
|
-
let type2 = F_FUNCTION;
|
|
131
|
-
return `${type2}${isAsync(getModifiers(node))}${ts.isArrowFunction(node) ? F_ARROW_FUNCTION : ""}`;
|
|
132
|
-
}
|
|
133
|
-
const nodeModifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : [];
|
|
134
|
-
let type = F_METHOD;
|
|
135
|
-
let flags = `${type}${getVisibility(nodeModifiers)}${isAbstract(nodeModifiers)}${isAsync(nodeModifiers)}`;
|
|
136
|
-
if (ts.isMethodDeclaration(node) && getModifiers(node).some((x) => x.kind === ts.SyntaxKind.StaticKeyword))
|
|
137
|
-
flags += F_STATIC;
|
|
138
|
-
if (node.questionToken)
|
|
139
|
-
flags += F_OPTIONAL;
|
|
140
|
-
if (!node.type)
|
|
141
|
-
flags += F_INFERRED;
|
|
142
|
-
return flags;
|
|
143
|
-
}
|
|
144
|
-
method(node) {
|
|
145
|
-
let propNameStr = propertyNameToString(node.name);
|
|
146
|
-
if (ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) {
|
|
147
|
-
this.ctx.locationHint = `Method ${propNameStr !== null && propNameStr !== void 0 ? propNameStr : "<unknown>"}() of ${this.getClassName(node)}`;
|
|
148
|
-
} else if (ts.isFunctionDeclaration(node)) {
|
|
149
|
-
this.ctx.locationHint = `Function ${propNameStr !== null && propNameStr !== void 0 ? propNameStr : "<unknown>"}()`;
|
|
150
|
-
} else if (ts.isFunctionExpression(node)) {
|
|
151
|
-
if (node.name)
|
|
152
|
-
this.ctx.locationHint = `Function ${propNameStr}()`;
|
|
153
|
-
else
|
|
154
|
-
this.ctx.locationHint = `Unnamed function expression`;
|
|
155
|
-
} else if (ts.isArrowFunction(node)) {
|
|
156
|
-
this.ctx.locationHint = `Arrow function`;
|
|
157
|
-
}
|
|
158
|
-
let methodHint = this.ctx.locationHint;
|
|
159
|
-
let decs = [];
|
|
160
|
-
let nodeDecorators = [];
|
|
161
|
-
if (ts.canHaveDecorators(node))
|
|
162
|
-
nodeDecorators = ts.getDecorators(node);
|
|
163
|
-
if (this.emitStandardMetadata && ts.isMethodDeclaration(node) && (nodeDecorators === null || nodeDecorators === void 0 ? void 0 : nodeDecorators.length) > 0)
|
|
164
|
-
decs.push(legacyMetadataDecorator("design:type", literalNode(ts.factory.createIdentifier("Function"))));
|
|
165
|
-
decs.push(...this.params(node));
|
|
166
|
-
decs.push(metadataDecorator("rt:f", this.methodFlags(node)));
|
|
167
|
-
let allowStandardMetadata = ts.isMethodDeclaration(node) && (nodeDecorators === null || nodeDecorators === void 0 ? void 0 : nodeDecorators.length) > 0;
|
|
168
|
-
if (node.type) {
|
|
169
|
-
decs.push(...this.typeNode(node.type, "returntype", allowStandardMetadata));
|
|
170
|
-
} else {
|
|
171
|
-
let signature = this.checker.getSignatureFromDeclaration(node);
|
|
172
|
-
if (signature) {
|
|
173
|
-
this.ctx.locationHint = `[Return type of] ${methodHint}`;
|
|
174
|
-
decs.push(...this.type(signature.getReturnType(), void 0, "returntype", allowStandardMetadata));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return decs;
|
|
178
|
-
}
|
|
179
|
-
params(node, containingNode) {
|
|
180
|
-
var _a, _b;
|
|
181
|
-
let decs = [];
|
|
182
|
-
let standardParamTypes = [];
|
|
183
|
-
let serializedParamMeta = [];
|
|
184
|
-
for (let param of node.parameters) {
|
|
185
|
-
let name;
|
|
186
|
-
if (ts.isIdentifier(param.name))
|
|
187
|
-
name = param.name.text;
|
|
188
|
-
if (name === "this")
|
|
189
|
-
continue;
|
|
190
|
-
let expr = this.legacyTypeEncoder.referToTypeNode(param.type);
|
|
191
|
-
standardParamTypes.push(expr);
|
|
192
|
-
serializedParamMeta.push(literalNode(serialize(encodeParameter(this.typeEncoder, param))));
|
|
193
|
-
}
|
|
194
|
-
decs.push(metadataDecorator("rt:p", serializedParamMeta));
|
|
195
|
-
let eligibleForLegacyDecorators = ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node);
|
|
196
|
-
if (this.emitStandardMetadata && eligibleForLegacyDecorators) {
|
|
197
|
-
let parent = containingNode !== null && containingNode !== void 0 ? containingNode : node.parent;
|
|
198
|
-
let isDecorated = false;
|
|
199
|
-
if (ts.canHaveDecorators(node))
|
|
200
|
-
isDecorated = ((_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
201
|
-
if (ts.isConstructorDeclaration(node) && parent && ts.canHaveDecorators(parent))
|
|
202
|
-
isDecorated = ((_b = ts.getDecorators(parent)) === null || _b === void 0 ? void 0 : _b.length) > 0;
|
|
203
|
-
if (isDecorated)
|
|
204
|
-
decs.push(metadataDecorator("design:paramtypes", standardParamTypes.map((t) => literalNode(t))));
|
|
205
|
-
}
|
|
206
|
-
return decs;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
export {
|
|
210
|
-
MetadataEncoder
|
|
211
|
-
};
|
|
212
|
-
//# sourceMappingURL=metadata-encoder.js.map
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { literalNode } from "./literal-node.js";
|
|
3
|
-
import { serialize } from "./serialize.js";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
const require$1 = createRequire(import.meta.url);
|
|
6
|
-
function rtStore(typeMap) {
|
|
7
|
-
const factory = ts.factory;
|
|
8
|
-
let typeEntries = Array.from(typeMap.entries()).map(([i, t]) => factory.createPropertyAssignment(factory.createComputedPropertyName(ts.factory.createNumericLiteral(i)), t));
|
|
9
|
-
let typeStore = factory.createObjectLiteralExpression(typeEntries);
|
|
10
|
-
return factory.createVariableStatement(void 0, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("__RΦ"), void 0, void 0, serialize({
|
|
11
|
-
m: literalNode(factory.createArrowFunction(void 0, void 0, [
|
|
12
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("k"), void 0, void 0, void 0),
|
|
13
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("v"), void 0, void 0, void 0)
|
|
14
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createArrowFunction(void 0, void 0, [
|
|
15
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("t"), void 0, void 0, void 0),
|
|
16
|
-
factory.createParameterDeclaration(void 0, factory.createToken(ts.SyntaxKind.DotDotDotToken), factory.createIdentifier("a"), void 0, void 0, void 0)
|
|
17
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createConditionalExpression(factory.createBinaryExpression(factory.createIdentifier("t"), factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken), factory.createPropertyAccessExpression(factory.createIdentifier("Reflect"), factory.createIdentifier("metadata"))), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createCallExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Reflect"), factory.createIdentifier("metadata")), void 0, [
|
|
18
|
-
factory.createIdentifier("k"),
|
|
19
|
-
factory.createIdentifier("v")
|
|
20
|
-
]), void 0, [
|
|
21
|
-
factory.createIdentifier("t"),
|
|
22
|
-
factory.createSpreadElement(factory.createIdentifier("a"))
|
|
23
|
-
]), factory.createToken(ts.SyntaxKind.ColonToken), factory.createVoidExpression(factory.createNumericLiteral("0")))))),
|
|
24
|
-
f: literalNode(factory.createArrowFunction(void 0, void 0, [
|
|
25
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("f"), void 0, void 0, void 0),
|
|
26
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("d"), void 0, void 0, void 0),
|
|
27
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("n"), void 0, void 0, void 0)
|
|
28
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createParenthesizedExpression(factory.createBinaryExpression(factory.createBinaryExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("d"), factory.createIdentifier("forEach")), void 0, [factory.createArrowFunction(void 0, void 0, [factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("d"), void 0, void 0, void 0)], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [factory.createIdentifier("f")]))]), factory.createToken(ts.SyntaxKind.CommaToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("defineProperty")), void 0, [
|
|
29
|
-
factory.createIdentifier("f"),
|
|
30
|
-
factory.createStringLiteral("name"),
|
|
31
|
-
factory.createObjectLiteralExpression([
|
|
32
|
-
factory.createPropertyAssignment(factory.createIdentifier("value"), factory.createIdentifier("n")),
|
|
33
|
-
factory.createPropertyAssignment(factory.createIdentifier("writable"), factory.createFalse())
|
|
34
|
-
], false)
|
|
35
|
-
])), factory.createToken(ts.SyntaxKind.CommaToken), factory.createIdentifier("f"))))),
|
|
36
|
-
c: literalNode(factory.createArrowFunction(void 0, void 0, [
|
|
37
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("c"), void 0, void 0, void 0),
|
|
38
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("d"), void 0, void 0, void 0),
|
|
39
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("dp"), void 0, void 0, void 0),
|
|
40
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("dsp"), void 0, void 0, void 0),
|
|
41
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("n"), void 0, void 0, void 0)
|
|
42
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createParenthesizedExpression(factory.createBinaryExpression(factory.createBinaryExpression(factory.createBinaryExpression(factory.createBinaryExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("d"), factory.createIdentifier("forEach")), void 0, [factory.createArrowFunction(void 0, void 0, [factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("d"), void 0, void 0, void 0)], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [factory.createIdentifier("c")]))]), factory.createToken(ts.SyntaxKind.CommaToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("dp"), factory.createIdentifier("forEach")), void 0, [factory.createArrowFunction(void 0, void 0, [factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern([
|
|
43
|
-
factory.createBindingElement(void 0, void 0, factory.createIdentifier("p"), void 0),
|
|
44
|
-
factory.createBindingElement(void 0, void 0, factory.createIdentifier("d"), void 0)
|
|
45
|
-
]), void 0, void 0, void 0)], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [
|
|
46
|
-
factory.createPropertyAccessExpression(factory.createIdentifier("c"), factory.createIdentifier("prototype")),
|
|
47
|
-
factory.createIdentifier("p")
|
|
48
|
-
]))])), factory.createToken(ts.SyntaxKind.CommaToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("dsp"), factory.createIdentifier("forEach")), void 0, [factory.createArrowFunction(void 0, void 0, [factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern([
|
|
49
|
-
factory.createBindingElement(void 0, void 0, factory.createIdentifier("p"), void 0),
|
|
50
|
-
factory.createBindingElement(void 0, void 0, factory.createIdentifier("d"), void 0)
|
|
51
|
-
]), void 0, void 0, void 0)], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [
|
|
52
|
-
factory.createIdentifier("c"),
|
|
53
|
-
factory.createIdentifier("p")
|
|
54
|
-
]))])), factory.createToken(ts.SyntaxKind.CommaToken), factory.createConditionalExpression(factory.createIdentifier("n"), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("defineProperty")), void 0, [
|
|
55
|
-
factory.createIdentifier("c"),
|
|
56
|
-
factory.createStringLiteral("name"),
|
|
57
|
-
factory.createObjectLiteralExpression([
|
|
58
|
-
factory.createPropertyAssignment(factory.createIdentifier("value"), factory.createIdentifier("n")),
|
|
59
|
-
factory.createPropertyAssignment(factory.createIdentifier("writable"), factory.createFalse())
|
|
60
|
-
], false)
|
|
61
|
-
]), factory.createToken(ts.SyntaxKind.ColonToken), factory.createIdentifier("undefined"))), factory.createToken(ts.SyntaxKind.CommaToken), factory.createIdentifier("c"))))),
|
|
62
|
-
r: literalNode(factory.createArrowFunction(void 0, void 0, [
|
|
63
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("o"), void 0, void 0, void 0),
|
|
64
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("a"), void 0, void 0, void 0)
|
|
65
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createParenthesizedExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("assign")), void 0, [
|
|
66
|
-
factory.createIdentifier("o"),
|
|
67
|
-
factory.createIdentifier("a")
|
|
68
|
-
])))),
|
|
69
|
-
a: literalNode(factory.createArrowFunction(void 0, void 0, [factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("id"), void 0, void 0, void 0)], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createBlock([
|
|
70
|
-
factory.createVariableStatement(void 0, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("t"), void 0, void 0, factory.createElementAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__RΦ"), factory.createIdentifier("t")), factory.createIdentifier("id")))], ts.NodeFlags.Let)),
|
|
71
|
-
factory.createIfStatement(factory.createBinaryExpression(factory.createIdentifier("t"), factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), factory.createVoidExpression(factory.createNumericLiteral("0"))), factory.createReturnStatement(factory.createVoidExpression(factory.createNumericLiteral("0"))), void 0),
|
|
72
|
-
factory.createIfStatement(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("RΦ")), factory.createBlock([
|
|
73
|
-
factory.createVariableStatement(void 0, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("r"), void 0, void 0, factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("RΦ")))], ts.NodeFlags.Let)),
|
|
74
|
-
factory.createExpressionStatement(factory.createDeleteExpression(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("RΦ")))),
|
|
75
|
-
factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__RΦ"), factory.createIdentifier("r")), void 0, [
|
|
76
|
-
factory.createIdentifier("t"),
|
|
77
|
-
factory.createCallExpression(factory.createIdentifier("r"), void 0, [factory.createIdentifier("t")])
|
|
78
|
-
]))
|
|
79
|
-
], true), factory.createIfStatement(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("LΦ")), factory.createBlock([
|
|
80
|
-
factory.createVariableStatement(void 0, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("l"), void 0, void 0, factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("LΦ")), void 0, []))], ts.NodeFlags.Let)),
|
|
81
|
-
factory.createExpressionStatement(factory.createDeleteExpression(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("LΦ")))),
|
|
82
|
-
factory.createExpressionStatement(factory.createBinaryExpression(factory.createElementAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__RΦ"), factory.createIdentifier("t")), factory.createIdentifier("id")), factory.createToken(ts.SyntaxKind.EqualsToken), factory.createBinaryExpression(factory.createIdentifier("t"), factory.createToken(ts.SyntaxKind.EqualsToken), factory.createIdentifier("l"))))
|
|
83
|
-
], true), void 0)),
|
|
84
|
-
factory.createReturnStatement(factory.createIdentifier("t"))
|
|
85
|
-
], true))),
|
|
86
|
-
oe: literalNode(factory.createArrowFunction(void 0, void 0, [
|
|
87
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("o"), void 0, void 0, void 0),
|
|
88
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("k"), void 0, void 0, void 0)
|
|
89
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createBlock([factory.createTryStatement(factory.createBlock([factory.createReturnStatement(factory.createElementAccessExpression(factory.createIdentifier("o"), factory.createIdentifier("k")))], true), factory.createCatchClause(factory.createVariableDeclaration(factory.createIdentifier("e"), void 0, void 0, void 0), factory.createBlock([factory.createReturnStatement(factory.createIdentifier("undefined"))], true)), void 0)], true))),
|
|
90
|
-
t: literalNode(typeStore)
|
|
91
|
-
}))], ts.NodeFlags.Const));
|
|
92
|
-
}
|
|
93
|
-
export {
|
|
94
|
-
rtStore
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=rt-helper.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { VisitorBase } from "./common/visitor-base.js";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
const require$1 = createRequire(import.meta.url);
|
|
4
|
-
class RttiVisitor extends VisitorBase {
|
|
5
|
-
constructor(ctx) {
|
|
6
|
-
super(ctx.transformationContext);
|
|
7
|
-
this.ctx = ctx;
|
|
8
|
-
}
|
|
9
|
-
get program() {
|
|
10
|
-
return this.ctx.program;
|
|
11
|
-
}
|
|
12
|
-
get checker() {
|
|
13
|
-
return this.ctx.checker;
|
|
14
|
-
}
|
|
15
|
-
get trace() {
|
|
16
|
-
return this.ctx.trace;
|
|
17
|
-
}
|
|
18
|
-
get sourceFile() {
|
|
19
|
-
return this.ctx.sourceFile;
|
|
20
|
-
}
|
|
21
|
-
get importMap() {
|
|
22
|
-
return this.ctx.importMap;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
RttiVisitor
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=rtti-visitor-base.js.map
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import "../common/index.js";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import { isLiteralNode } from "../common/format.js";
|
|
5
|
-
const require$1 = createRequire(import.meta.url);
|
|
6
|
-
function serialize(object) {
|
|
7
|
-
if (object === null)
|
|
8
|
-
return ts.factory.createNull();
|
|
9
|
-
if (object === void 0)
|
|
10
|
-
return ts.factory.createVoidZero();
|
|
11
|
-
if (object instanceof Array)
|
|
12
|
-
return ts.factory.createArrayLiteralExpression(object.map((x) => serialize(x)));
|
|
13
|
-
if (typeof object === "string")
|
|
14
|
-
return ts.factory.createStringLiteral(object);
|
|
15
|
-
if (typeof object === "number")
|
|
16
|
-
return ts.factory.createNumericLiteral(object);
|
|
17
|
-
if (typeof object === "boolean")
|
|
18
|
-
return object ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
19
|
-
if (typeof object === "function")
|
|
20
|
-
throw new Error(`Cannot serialize a function`);
|
|
21
|
-
if (isLiteralNode(object))
|
|
22
|
-
return object.node;
|
|
23
|
-
let props = [];
|
|
24
|
-
for (let key of Object.keys(object))
|
|
25
|
-
props.push(ts.factory.createPropertyAssignment(key, serialize(object[key])));
|
|
26
|
-
return ts.factory.createObjectLiteralExpression(props, false);
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
serialize
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=serialize.js.map
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { T_STAND_IN } from "../common/format.js";
|
|
3
|
-
import { literalNode } from "./literal-node.js";
|
|
4
|
-
import { serialize } from "./serialize.js";
|
|
5
|
-
import { structuredTypeLiteral, typeLiteral } from "./type-literal.js";
|
|
6
|
-
import { hasFlag } from "./utils.js";
|
|
7
|
-
import { createRequire } from "node:module";
|
|
8
|
-
const require$1 = createRequire(import.meta.url);
|
|
9
|
-
class TypeEncoder {
|
|
10
|
-
constructor(ctx) {
|
|
11
|
-
this.ctx = ctx;
|
|
12
|
-
}
|
|
13
|
-
get typeMap() {
|
|
14
|
-
return this.ctx.typeMap;
|
|
15
|
-
}
|
|
16
|
-
get program() {
|
|
17
|
-
return this.ctx.program;
|
|
18
|
-
}
|
|
19
|
-
get sourceFile() {
|
|
20
|
-
return this.ctx.sourceFile;
|
|
21
|
-
}
|
|
22
|
-
get importMap() {
|
|
23
|
-
return this.ctx.importMap;
|
|
24
|
-
}
|
|
25
|
-
get checker() {
|
|
26
|
-
return this.ctx.checker;
|
|
27
|
-
}
|
|
28
|
-
referToTypeNode(typeNode) {
|
|
29
|
-
return this.referToType(this.checker.getTypeFromTypeNode(typeNode), typeNode);
|
|
30
|
-
}
|
|
31
|
-
referToType(type, typeNode) {
|
|
32
|
-
var _a, _b, _c;
|
|
33
|
-
if (!type["id"])
|
|
34
|
-
throw new Error(`Type does not have an ID!`);
|
|
35
|
-
if (!this.typeMap.has(type["id"])) {
|
|
36
|
-
this.typeMap.set(type["id"], null);
|
|
37
|
-
let isEnum = hasFlag(type.flags, ts.TypeFlags.Enum) || hasFlag(type.flags, ts.TypeFlags.EnumLiteral) && hasFlag((_a = type.aliasSymbol) === null || _a === void 0 ? void 0 : _a.flags, ts.SymbolFlags.Enum);
|
|
38
|
-
let declarations = (_b = type.symbol) === null || _b === void 0 ? void 0 : _b.getDeclarations();
|
|
39
|
-
let declaration = declarations === null || declarations === void 0 ? void 0 : declarations[0];
|
|
40
|
-
let sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
41
|
-
let isLocal = sourceFile === this.ctx.sourceFile;
|
|
42
|
-
let isAmbient = hasFlag(
|
|
43
|
-
declaration === null || declaration === void 0 ? void 0 : declaration.flags,
|
|
44
|
-
16777216
|
|
45
|
-
/* InternalNodeFlags.Ambient */
|
|
46
|
-
);
|
|
47
|
-
let useStandIn = false;
|
|
48
|
-
if (isEnum) {
|
|
49
|
-
useStandIn = isLocal && !hasFlag(type.symbol.flags, ts.SymbolFlags.ConstEnum);
|
|
50
|
-
} else if (type.isClassOrInterface()) {
|
|
51
|
-
useStandIn = isLocal && !isAmbient;
|
|
52
|
-
}
|
|
53
|
-
if (useStandIn) {
|
|
54
|
-
this.typeMap.set(type["id"], serialize({
|
|
55
|
-
TΦ: T_STAND_IN,
|
|
56
|
-
name: `${type.symbol.name}`
|
|
57
|
-
}));
|
|
58
|
-
} else {
|
|
59
|
-
let expr = isLocal && isAmbient ? structuredTypeLiteral(this, type, typeNode, (_c = type.symbol) === null || _c === void 0 ? void 0 : _c.name) : typeLiteral(this, type, typeNode);
|
|
60
|
-
let propName = ts.isObjectLiteralExpression(expr) ? "RΦ" : "LΦ";
|
|
61
|
-
this.typeMap.set(type["id"], serialize({
|
|
62
|
-
[propName]: literalNode(ts.factory.createArrowFunction([], [], [
|
|
63
|
-
ts.factory.createParameterDeclaration([], void 0, "t", void 0, void 0, void 0)
|
|
64
|
-
], void 0, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), expr))
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(`__RΦ`), "a"), [], [
|
|
69
|
-
ts.factory.createNumericLiteral(type["id"])
|
|
70
|
-
]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
TypeEncoder
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=type-encoder.js.map
|