xml-model 1.3.2 → 2.0.0-beta.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 +39 -35
- package/dist/index.d.ts +3 -7
- package/dist/index.js +18 -17
- package/dist/model.d.ts +53 -0
- package/dist/model.js +69 -0
- 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 +385 -0
- package/dist/xml/examples.d.ts +188 -0
- package/dist/xml/index.d.ts +5 -32
- package/dist/xml/index.js +14 -54
- package/dist/xml/model.d.ts +18 -0
- package/dist/xml/model.js +37 -0
- package/dist/xml/schema-meta.d.ts +57 -0
- package/dist/xml/schema-meta.js +96 -0
- package/dist/xml/xml-js.d.ts +138 -3
- package/dist/xml/xml-js.js +89 -5
- package/package.json +10 -23
- 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 -15
- package/dist/defaults.js +0 -130
- package/dist/errors.d.ts +0 -24
- 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 -21
- package/dist/model/index.js +0 -236
- package/dist/model/property.d.ts +0 -6
- 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 -74
- package/dist/node_modules/reflect-metadata/Reflect.js +0 -806
- package/dist/types.d.ts +0 -17
- 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 -53
- package/dist/vite/index.js +0 -63
- 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,56 +0,0 @@
|
|
|
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
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { legacyDecorator } from "./legacy-decorator.js";
|
|
3
|
-
import { literalNode } from "./literal-node.js";
|
|
4
|
-
import { serialize } from "./serialize.js";
|
|
5
|
-
import { hasModifier, getModifiers, expressionForPropertyName } from "./utils.js";
|
|
6
|
-
import { createRequire } from "node:module";
|
|
7
|
-
const require$1 = createRequire(import.meta.url);
|
|
8
|
-
function metadataDecorator(key, object) {
|
|
9
|
-
return ts.factory.createDecorator(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("__RΦ"), "m"), [], [
|
|
10
|
-
ts.factory.createStringLiteral(key),
|
|
11
|
-
serialize(object)
|
|
12
|
-
]));
|
|
13
|
-
}
|
|
14
|
-
function hostMetadataDecorator() {
|
|
15
|
-
let factory = ts.factory;
|
|
16
|
-
let dec = ts.factory.createDecorator(factory.createArrowFunction(void 0, void 0, [
|
|
17
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("t"), void 0, void 0, void 0),
|
|
18
|
-
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("p"), void 0, void 0, void 0)
|
|
19
|
-
], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__RΦ"), factory.createIdentifier("m")), void 0, [
|
|
20
|
-
factory.createStringLiteral("rt:h"),
|
|
21
|
-
factory.createArrowFunction(void 0, void 0, [], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createConditionalExpression(factory.createBinaryExpression(factory.createTypeOfExpression(factory.createIdentifier("t")), factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), factory.createStringLiteral("object")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("constructor")), factory.createToken(ts.SyntaxKind.ColonToken), factory.createIdentifier("t")))
|
|
22
|
-
]), void 0, [factory.createElementAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("p"))])));
|
|
23
|
-
return dec;
|
|
24
|
-
}
|
|
25
|
-
function legacyMetadataDecorator(key, object) {
|
|
26
|
-
return legacyDecorator(metadataDecorator(key, object));
|
|
27
|
-
}
|
|
28
|
-
function directMetadataDecorator(key, object) {
|
|
29
|
-
let dec = metadataDecorator(key, object);
|
|
30
|
-
dec["__Φdirect"] = true;
|
|
31
|
-
return dec;
|
|
32
|
-
}
|
|
33
|
-
function decorateFunctionExpression(func, decorators) {
|
|
34
|
-
let name = "";
|
|
35
|
-
if (func.parent) {
|
|
36
|
-
if (ts.isPropertyAssignment(func.parent) || ts.isVariableDeclaration(func.parent)) {
|
|
37
|
-
name = func.parent.name.getText();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("__RΦ"), "f"), [], [
|
|
41
|
-
func,
|
|
42
|
-
ts.factory.createArrayLiteralExpression(decorators.map((d) => d.expression)),
|
|
43
|
-
ts.factory.createStringLiteral(name)
|
|
44
|
-
]);
|
|
45
|
-
}
|
|
46
|
-
function decorateClassExpression(classExpr, decorators, externalDecorators) {
|
|
47
|
-
let name = "";
|
|
48
|
-
if (classExpr.name) {
|
|
49
|
-
name = classExpr.name.text;
|
|
50
|
-
} else if (classExpr.parent) {
|
|
51
|
-
if (ts.isPropertyAssignment(classExpr.parent) || ts.isVariableDeclaration(classExpr.parent)) {
|
|
52
|
-
name = classExpr.parent.name.getText();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
let propDecorators = externalDecorators.filter((x) => x.property);
|
|
56
|
-
let staticPropDecorators = propDecorators.filter((x) => hasModifier(getModifiers(x.node), ts.SyntaxKind.StaticKeyword));
|
|
57
|
-
let instancePropDecorators = propDecorators.filter((x) => !hasModifier(getModifiers(x.node), ts.SyntaxKind.StaticKeyword));
|
|
58
|
-
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("__RΦ"), "c"), [], [
|
|
59
|
-
classExpr,
|
|
60
|
-
serialize(decorators.map((d) => literalNode(d.expression))),
|
|
61
|
-
serialize(instancePropDecorators.map((x) => [
|
|
62
|
-
literalNode(expressionForPropertyName(x.property)),
|
|
63
|
-
literalNode(x.decorator.expression)
|
|
64
|
-
])),
|
|
65
|
-
serialize(staticPropDecorators.map((x) => [
|
|
66
|
-
literalNode(expressionForPropertyName(x.property)),
|
|
67
|
-
literalNode(x.decorator.expression)
|
|
68
|
-
])),
|
|
69
|
-
name ? ts.factory.createStringLiteral(name) : ts.factory.createVoidZero()
|
|
70
|
-
]);
|
|
71
|
-
}
|
|
72
|
-
export {
|
|
73
|
-
decorateClassExpression,
|
|
74
|
-
decorateFunctionExpression,
|
|
75
|
-
directMetadataDecorator,
|
|
76
|
-
hostMetadataDecorator,
|
|
77
|
-
legacyMetadataDecorator,
|
|
78
|
-
metadataDecorator
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=metadata-decorator.js.map
|
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { RttiVisitor } from "./rtti-visitor-base.js";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { Visit } from "./common/visitor-base.js";
|
|
4
|
-
import { ClassAnalyzer } from "./common/class-analyzer.js";
|
|
5
|
-
import { InterfaceAnalyzer } from "./common/interface-analyzer.js";
|
|
6
|
-
import { decorateFunctionExpression, decorateClassExpression, directMetadataDecorator, hostMetadataDecorator } from "./metadata-decorator.js";
|
|
7
|
-
import { MetadataEncoder } from "./metadata-encoder.js";
|
|
8
|
-
import { InlineMetadataCollector, ExternalMetadataCollector } from "./metadata-collector.js";
|
|
9
|
-
import { getRttiDocTagFromNode, isStatement, hasModifier, getModifiers, hasModifiers, expressionForPropertyName } from "./utils.js";
|
|
10
|
-
import { serialize } from "./serialize.js";
|
|
11
|
-
import { literalNode } from "./literal-node.js";
|
|
12
|
-
import "../common/index.js";
|
|
13
|
-
import { WORKAROUND_TYPESCRIPT_49794 } from "./workarounds.js";
|
|
14
|
-
import { createRequire } from "node:module";
|
|
15
|
-
import { T_ENUM } from "../common/format.js";
|
|
16
|
-
var __decorate = function(decorators, target, key, desc) {
|
|
17
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
19
|
-
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;
|
|
20
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
-
};
|
|
22
|
-
var __metadata = function(k, v) {
|
|
23
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
24
|
-
};
|
|
25
|
-
const require$1 = createRequire(import.meta.url);
|
|
26
|
-
class MetadataEmitter extends RttiVisitor {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(...arguments);
|
|
29
|
-
this.metadataEncoder = new MetadataEncoder(this.ctx);
|
|
30
|
-
this.collector = new InlineMetadataCollector();
|
|
31
|
-
}
|
|
32
|
-
static emit(sourceFile, ctx) {
|
|
33
|
-
return new MetadataEmitter(ctx).visitNode(sourceFile);
|
|
34
|
-
}
|
|
35
|
-
collectMetadata(callback) {
|
|
36
|
-
let originalCollector = this.collector;
|
|
37
|
-
let originalOutboardCollector = this.outboardCollector;
|
|
38
|
-
let collector = new ExternalMetadataCollector();
|
|
39
|
-
if (WORKAROUND_TYPESCRIPT_49794) {
|
|
40
|
-
this.collector = this.outboardCollector = collector;
|
|
41
|
-
} else {
|
|
42
|
-
this.outboardCollector = collector;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
return {
|
|
46
|
-
node: callback(),
|
|
47
|
-
decorators: collector.decorators
|
|
48
|
-
};
|
|
49
|
-
} finally {
|
|
50
|
-
this.collector = originalCollector;
|
|
51
|
-
this.outboardCollector = originalOutboardCollector;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* In some cases we need to collect all metadata under an entire node subtree. An example is for class expressions
|
|
56
|
-
* which are not valid decorator targets, but we still support emitting for them.
|
|
57
|
-
* @param callback
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
collectAllMetadata(callback) {
|
|
61
|
-
let originalCollector = this.collector;
|
|
62
|
-
let originalOutboardCollector = this.outboardCollector;
|
|
63
|
-
let collector = new ExternalMetadataCollector();
|
|
64
|
-
this.collector = collector;
|
|
65
|
-
this.outboardCollector = collector;
|
|
66
|
-
try {
|
|
67
|
-
return {
|
|
68
|
-
node: callback(),
|
|
69
|
-
decorators: collector.decorators
|
|
70
|
-
};
|
|
71
|
-
} finally {
|
|
72
|
-
this.collector = originalCollector;
|
|
73
|
-
this.outboardCollector = originalOutboardCollector;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
scope(nameScope, callback) {
|
|
77
|
-
let originalScope = this.ctx.currentNameScope;
|
|
78
|
-
this.ctx.currentNameScope = nameScope;
|
|
79
|
-
try {
|
|
80
|
-
return callback();
|
|
81
|
-
} finally {
|
|
82
|
-
this.ctx.currentNameScope = originalScope;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
everyNode(node) {
|
|
86
|
-
if (getRttiDocTagFromNode(node, "skip") === "")
|
|
87
|
-
return false;
|
|
88
|
-
if (isStatement(node) && node.parent && ts.isSourceFile(node.parent)) {
|
|
89
|
-
this.ctx.currentTopStatement = node;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
property(decl) {
|
|
93
|
-
return this.collector.collect(decl, this.metadataEncoder.property(decl));
|
|
94
|
-
}
|
|
95
|
-
propertySignature(signature) {
|
|
96
|
-
if (ts.isInterfaceDeclaration(signature.parent))
|
|
97
|
-
signature = this.outboardCollector.collect(signature, this.metadataEncoder.property(signature));
|
|
98
|
-
return signature;
|
|
99
|
-
}
|
|
100
|
-
class(decl) {
|
|
101
|
-
let details = ClassAnalyzer.analyze(decl, this.context);
|
|
102
|
-
let className = decl.name.getText();
|
|
103
|
-
if (hasModifier(ts.canHaveModifiers(decl) ? ts.getModifiers(decl) : [], ts.SyntaxKind.DeclareKeyword))
|
|
104
|
-
return decl;
|
|
105
|
-
return this.scope(decl, () => {
|
|
106
|
-
let outboardMetadata = this.collectMetadata(() => {
|
|
107
|
-
try {
|
|
108
|
-
decl = this.collector.collect(decl, this.metadataEncoder.class(decl, details));
|
|
109
|
-
decl = this.visitEachChild(decl);
|
|
110
|
-
return decl;
|
|
111
|
-
} catch (e) {
|
|
112
|
-
console.error(`RTTI: During outboard metadata collection for class ${className}: ${e.message}`);
|
|
113
|
-
throw e;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
if (this.trace)
|
|
117
|
-
console.log(` - ${outboardMetadata.decorators.length} outboard decorators`);
|
|
118
|
-
return [
|
|
119
|
-
decl,
|
|
120
|
-
...this.emitOutboardMetadata(decl, outboardMetadata)
|
|
121
|
-
];
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
export(decl) {
|
|
125
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
126
|
-
if (!decl.exportClause)
|
|
127
|
-
return this.visitEachChild(decl);
|
|
128
|
-
if (ts.isNamedExports(decl.exportClause)) {
|
|
129
|
-
let statements = [];
|
|
130
|
-
for (let expo of decl.exportClause.elements) {
|
|
131
|
-
let ident = expo.name;
|
|
132
|
-
let localSymbol = this.checker.getSymbolAtLocation(ident);
|
|
133
|
-
let rootSymbol = this.checker.getAliasedSymbol(localSymbol);
|
|
134
|
-
let type = this.checker.getTypeAtLocation((_a = rootSymbol === null || rootSymbol === void 0 ? void 0 : rootSymbol.declarations) === null || _a === void 0 ? void 0 : _a[0]);
|
|
135
|
-
let reifiedType = type.isClass() || ((_b = type.symbol) === null || _b === void 0 ? void 0 : _b.name) === "Promise" || !!((_c = type.symbol) === null || _c === void 0 ? void 0 : _c.valueDeclaration);
|
|
136
|
-
let sourceFile = (_f = (_e = (_d = type.symbol) === null || _d === void 0 ? void 0 : _d.declarations) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.getSourceFile();
|
|
137
|
-
let isLocal = sourceFile === this.ctx.sourceFile;
|
|
138
|
-
if (!reifiedType && !isLocal) {
|
|
139
|
-
let parents = [];
|
|
140
|
-
let parent = (_g = type.symbol) === null || _g === void 0 ? void 0 : _g["parent"];
|
|
141
|
-
while (parent) {
|
|
142
|
-
parents.push(parent);
|
|
143
|
-
parent = parent["parent"];
|
|
144
|
-
}
|
|
145
|
-
let importName;
|
|
146
|
-
if (parents.length > 1) {
|
|
147
|
-
importName = parents[1].name;
|
|
148
|
-
} else {
|
|
149
|
-
importName = (_h = type.symbol) === null || _h === void 0 ? void 0 : _h.name;
|
|
150
|
-
}
|
|
151
|
-
let modulePath = parents[0] ? JSON.parse(parents[0].name) : void 0;
|
|
152
|
-
if (localSymbol) {
|
|
153
|
-
let localDecl = localSymbol.declarations[0];
|
|
154
|
-
if (localDecl) {
|
|
155
|
-
if (ts.isExportSpecifier(localDecl)) {
|
|
156
|
-
localSymbol = this.checker.getImmediateAliasedSymbol(localSymbol);
|
|
157
|
-
localDecl = localSymbol === null || localSymbol === void 0 ? void 0 : localSymbol.declarations[0];
|
|
158
|
-
}
|
|
159
|
-
if (localDecl) {
|
|
160
|
-
if (ts.isImportSpecifier(localDecl)) {
|
|
161
|
-
let specifier = (_l = (_k = (_j = localDecl.parent) === null || _j === void 0 ? void 0 : _j.parent) === null || _k === void 0 ? void 0 : _k.parent) === null || _l === void 0 ? void 0 : _l.moduleSpecifier;
|
|
162
|
-
let detectedImportPath = specifier.text;
|
|
163
|
-
if (detectedImportPath)
|
|
164
|
-
modulePath = detectedImportPath;
|
|
165
|
-
} else {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (parents.length === 1 && ((_m = type.symbol) === null || _m === void 0 ? void 0 : _m.name) === "default") {
|
|
172
|
-
statements.push(this.exportInterfaceToken(ident.text, `default`, modulePath));
|
|
173
|
-
} else {
|
|
174
|
-
statements.push(this.exportInterfaceToken(ident.text, void 0, modulePath));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return [
|
|
179
|
-
this.visitEachChild(decl),
|
|
180
|
-
...statements
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
exportInterfaceToken(name, propertyName, from) {
|
|
185
|
-
return ts.factory.createExportDeclaration(void 0, false, ts.factory.createNamedExports([
|
|
186
|
-
ts.factory.createExportSpecifier(false, propertyName ? ts.factory.createIdentifier(propertyName) : void 0, ts.factory.createIdentifier(`IΦ${name}`))
|
|
187
|
-
]), from ? ts.factory.createStringLiteral(from) : void 0);
|
|
188
|
-
}
|
|
189
|
-
enum(decl) {
|
|
190
|
-
if (hasModifier(getModifiers(decl), ts.SyntaxKind.ConstKeyword)) {
|
|
191
|
-
return decl;
|
|
192
|
-
}
|
|
193
|
-
let type = this.checker.getTypeAtLocation(decl);
|
|
194
|
-
return [
|
|
195
|
-
decl,
|
|
196
|
-
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createArrowFunction([], [], [
|
|
197
|
-
ts.factory.createParameterDeclaration([], void 0, "t")
|
|
198
|
-
], 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), serialize({ TΦ: T_ENUM, e: literalNode(ts.factory.createIdentifier("t")) }))), [], [
|
|
199
|
-
ts.factory.createIdentifier(decl.name.text)
|
|
200
|
-
]))
|
|
201
|
-
];
|
|
202
|
-
}
|
|
203
|
-
interface(decl) {
|
|
204
|
-
let emitName = decl.name.text;
|
|
205
|
-
if (hasModifiers(getModifiers(decl), [ts.SyntaxKind.ExportKeyword, ts.SyntaxKind.DefaultKeyword]))
|
|
206
|
-
emitName = "default";
|
|
207
|
-
let tokenDecl = ts.factory.createVariableStatement([], ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(ts.factory.createIdentifier(`IΦ${emitName}`), void 0, void 0, serialize({
|
|
208
|
-
name: decl.name.text,
|
|
209
|
-
prototype: {},
|
|
210
|
-
identity: literalNode(ts.factory.createCallExpression(ts.factory.createIdentifier("Symbol"), void 0, [ts.factory.createStringLiteral(`${decl.name.text} (interface)`)]))
|
|
211
|
-
}))], ts.NodeFlags.None));
|
|
212
|
-
this.ctx.interfaceSymbols.push({
|
|
213
|
-
interfaceDecl: decl,
|
|
214
|
-
symbolDecl: []
|
|
215
|
-
});
|
|
216
|
-
if (this.trace)
|
|
217
|
-
console.log(`Decorating interface ${decl.name.text}`);
|
|
218
|
-
let details = Object.assign(Object.assign({}, InterfaceAnalyzer.analyze(decl, this.context)), { staticPropertyNames: [], staticMethodNames: [] });
|
|
219
|
-
let interfaceName = decl.name.getText();
|
|
220
|
-
let interfaceDecl = decl;
|
|
221
|
-
return this.scope(decl, () => {
|
|
222
|
-
let result = this.collectMetadata(() => {
|
|
223
|
-
try {
|
|
224
|
-
return this.visitEachChild(decl);
|
|
225
|
-
} catch (e) {
|
|
226
|
-
console.error(`RTTI: During metadata collection for interface ${interfaceName}: ${e.message}`);
|
|
227
|
-
throw e;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
return [
|
|
231
|
-
result.node,
|
|
232
|
-
tokenDecl,
|
|
233
|
-
...hasModifier(getModifiers(decl), ts.SyntaxKind.ExportKeyword) ? [this.exportInterfaceToken(emitName)] : [],
|
|
234
|
-
...this.metadataEncoder.class(decl, details).map((decorator) => ts.factory.createExpressionStatement(ts.factory.createCallExpression(decorator.expression, void 0, [
|
|
235
|
-
ts.factory.createIdentifier(`IΦ${emitName}`)
|
|
236
|
-
]))),
|
|
237
|
-
...this.emitOutboardMetadata(interfaceDecl, result)
|
|
238
|
-
];
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
functionDecl(decl) {
|
|
242
|
-
if (!decl.body)
|
|
243
|
-
return;
|
|
244
|
-
let metadata = this.metadataEncoder.method(decl);
|
|
245
|
-
let functionName = decl.name.getText();
|
|
246
|
-
if (decl.parent && !ts.isBlock(decl.parent) && !ts.isSourceFile(decl.parent)) {
|
|
247
|
-
let expr = ts.factory.createFunctionExpression(getModifiers(decl), decl.asteriskToken, decl.name, decl.typeParameters, decl.parameters, decl.type, decl.body);
|
|
248
|
-
try {
|
|
249
|
-
expr = this.visitEachChild(expr);
|
|
250
|
-
} catch (e) {
|
|
251
|
-
console.error(`RTTI: During non-block function declaration ${functionName}: ${e.message}`);
|
|
252
|
-
throw e;
|
|
253
|
-
}
|
|
254
|
-
return ts.factory.createVariableStatement([], [
|
|
255
|
-
ts.factory.createVariableDeclaration(decl.name.getText(), void 0, void 0, decorateFunctionExpression(expr, metadata))
|
|
256
|
-
]);
|
|
257
|
-
}
|
|
258
|
-
try {
|
|
259
|
-
decl = this.visitEachChild(decl);
|
|
260
|
-
} catch (e) {
|
|
261
|
-
console.error(`RTTI: During function declaration ${functionName}: ${e.message}`);
|
|
262
|
-
throw e;
|
|
263
|
-
}
|
|
264
|
-
return [
|
|
265
|
-
decl,
|
|
266
|
-
...metadata.map((dec) => ts.factory.createExpressionStatement(ts.factory.createCallExpression(dec.expression, void 0, [
|
|
267
|
-
ts.factory.createIdentifier(`${decl.name.text}`)
|
|
268
|
-
])))
|
|
269
|
-
];
|
|
270
|
-
}
|
|
271
|
-
functionExpr(decl) {
|
|
272
|
-
return decorateFunctionExpression(this.visitEachChild(decl), this.metadataEncoder.method(decl));
|
|
273
|
-
}
|
|
274
|
-
classExpr(decl) {
|
|
275
|
-
let details = ClassAnalyzer.analyze(decl, this.context);
|
|
276
|
-
return this.scope(decl, () => {
|
|
277
|
-
let result = this.collectAllMetadata(() => {
|
|
278
|
-
try {
|
|
279
|
-
decl = this.visitEachChild(decl);
|
|
280
|
-
} catch (e) {
|
|
281
|
-
console.error(`RTTI: During metadata collection for class expression: ${e.message}`);
|
|
282
|
-
throw e;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
return decorateClassExpression(decl, this.metadataEncoder.class(decl, details), result.decorators);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
method(decl) {
|
|
289
|
-
var _a, _b;
|
|
290
|
-
if (!decl.parent || !(ts.isClassDeclaration(decl.parent) || ts.isClassExpression(decl.parent)))
|
|
291
|
-
return;
|
|
292
|
-
if (this.trace)
|
|
293
|
-
console.log(`Decorating class method ${(_b = (_a = decl.parent.name) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : "<anonymous>"}#${decl.name.getText()}`);
|
|
294
|
-
let metadata = this.metadataEncoder.method(decl);
|
|
295
|
-
let isAbstract = hasModifier(getModifiers(decl), ts.SyntaxKind.AbstractKeyword);
|
|
296
|
-
if (isAbstract) {
|
|
297
|
-
this.outboardCollector.collect(decl, metadata);
|
|
298
|
-
} else {
|
|
299
|
-
this.outboardCollector.collect(decl, [
|
|
300
|
-
directMetadataDecorator("rt:f", this.metadataEncoder.methodFlags(decl)),
|
|
301
|
-
hostMetadataDecorator()
|
|
302
|
-
]);
|
|
303
|
-
decl = this.collector.collect(decl, metadata);
|
|
304
|
-
}
|
|
305
|
-
return this.visitEachChild(decl);
|
|
306
|
-
}
|
|
307
|
-
methodSignature(node) {
|
|
308
|
-
if (!ts.isInterfaceDeclaration(node.parent))
|
|
309
|
-
return;
|
|
310
|
-
if (this.trace)
|
|
311
|
-
console.log(`Decorating interface method ${node.parent.name.text}#${node.name.getText()}`);
|
|
312
|
-
return this.outboardCollector.collect(node, this.metadataEncoder.method(node));
|
|
313
|
-
}
|
|
314
|
-
emitOutboardMetadataExpressions(node, outboardMetadata) {
|
|
315
|
-
let nodes = [];
|
|
316
|
-
let elementName = node.name.text;
|
|
317
|
-
for (let dec of outboardMetadata.decorators) {
|
|
318
|
-
let host = ts.factory.createIdentifier(elementName);
|
|
319
|
-
if (ts.isInterfaceDeclaration(node)) {
|
|
320
|
-
let interfaceName = `IΦ${node.name.text}`;
|
|
321
|
-
if (hasModifiers(getModifiers(node), [ts.SyntaxKind.ExportKeyword, ts.SyntaxKind.DefaultKeyword]))
|
|
322
|
-
interfaceName = `IΦdefault`;
|
|
323
|
-
host = ts.factory.createIdentifier(interfaceName);
|
|
324
|
-
}
|
|
325
|
-
let isStatic = false;
|
|
326
|
-
if (ts.isPropertyDeclaration(dec.node) || ts.isMethodDeclaration(dec.node) || ts.isGetAccessor(dec.node) || ts.isSetAccessor(dec.node))
|
|
327
|
-
isStatic = hasModifier(getModifiers(dec.node), ts.SyntaxKind.StaticKeyword);
|
|
328
|
-
if (ts.isClassDeclaration(dec.node))
|
|
329
|
-
isStatic = true;
|
|
330
|
-
if (!isStatic)
|
|
331
|
-
host = ts.factory.createPropertyAccessExpression(host, "prototype");
|
|
332
|
-
if (dec.property) {
|
|
333
|
-
if (dec.direct) {
|
|
334
|
-
host = ts.factory.createElementAccessExpression(host, expressionForPropertyName(dec.property));
|
|
335
|
-
nodes.push(ts.factory.createCallExpression(dec.decorator.expression, void 0, [
|
|
336
|
-
host
|
|
337
|
-
]));
|
|
338
|
-
} else {
|
|
339
|
-
nodes.push(ts.factory.createCallExpression(dec.decorator.expression, void 0, [
|
|
340
|
-
host,
|
|
341
|
-
expressionForPropertyName(dec.property)
|
|
342
|
-
]));
|
|
343
|
-
}
|
|
344
|
-
} else {
|
|
345
|
-
nodes.push(ts.factory.createCallExpression(dec.decorator.expression, void 0, [
|
|
346
|
-
host
|
|
347
|
-
]));
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return nodes;
|
|
351
|
-
}
|
|
352
|
-
emitOutboardMetadata(node, outboardMetadata) {
|
|
353
|
-
return this.emitOutboardMetadataExpressions(node, outboardMetadata).map((x) => ts.factory.createExpressionStatement(x));
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
__decorate([
|
|
357
|
-
Visit([ts.SyntaxKind.PropertyDeclaration, ts.SyntaxKind.GetAccessor, ts.SyntaxKind.SetAccessor]),
|
|
358
|
-
__metadata("design:type", Function),
|
|
359
|
-
__metadata("design:paramtypes", [Object]),
|
|
360
|
-
__metadata("design:returntype", void 0)
|
|
361
|
-
], MetadataEmitter.prototype, "property", null);
|
|
362
|
-
__decorate([
|
|
363
|
-
Visit(ts.SyntaxKind.PropertySignature),
|
|
364
|
-
__metadata("design:type", Function),
|
|
365
|
-
__metadata("design:paramtypes", [Object]),
|
|
366
|
-
__metadata("design:returntype", void 0)
|
|
367
|
-
], MetadataEmitter.prototype, "propertySignature", null);
|
|
368
|
-
__decorate([
|
|
369
|
-
Visit(ts.SyntaxKind.ClassDeclaration),
|
|
370
|
-
__metadata("design:type", Function),
|
|
371
|
-
__metadata("design:paramtypes", [Object]),
|
|
372
|
-
__metadata("design:returntype", void 0)
|
|
373
|
-
], MetadataEmitter.prototype, "class", null);
|
|
374
|
-
__decorate([
|
|
375
|
-
Visit(ts.SyntaxKind.ExportDeclaration),
|
|
376
|
-
__metadata("design:type", Function),
|
|
377
|
-
__metadata("design:paramtypes", [Object]),
|
|
378
|
-
__metadata("design:returntype", void 0)
|
|
379
|
-
], MetadataEmitter.prototype, "export", null);
|
|
380
|
-
__decorate([
|
|
381
|
-
Visit(ts.SyntaxKind.EnumDeclaration),
|
|
382
|
-
__metadata("design:type", Function),
|
|
383
|
-
__metadata("design:paramtypes", [Object]),
|
|
384
|
-
__metadata("design:returntype", void 0)
|
|
385
|
-
], MetadataEmitter.prototype, "enum", null);
|
|
386
|
-
__decorate([
|
|
387
|
-
Visit(ts.SyntaxKind.InterfaceDeclaration),
|
|
388
|
-
__metadata("design:type", Function),
|
|
389
|
-
__metadata("design:paramtypes", [Object]),
|
|
390
|
-
__metadata("design:returntype", void 0)
|
|
391
|
-
], MetadataEmitter.prototype, "interface", null);
|
|
392
|
-
__decorate([
|
|
393
|
-
Visit(ts.SyntaxKind.FunctionDeclaration),
|
|
394
|
-
__metadata("design:type", Function),
|
|
395
|
-
__metadata("design:paramtypes", [Object]),
|
|
396
|
-
__metadata("design:returntype", void 0)
|
|
397
|
-
], MetadataEmitter.prototype, "functionDecl", null);
|
|
398
|
-
__decorate([
|
|
399
|
-
Visit([ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction]),
|
|
400
|
-
__metadata("design:type", Function),
|
|
401
|
-
__metadata("design:paramtypes", [Object]),
|
|
402
|
-
__metadata("design:returntype", void 0)
|
|
403
|
-
], MetadataEmitter.prototype, "functionExpr", null);
|
|
404
|
-
__decorate([
|
|
405
|
-
Visit(ts.SyntaxKind.ClassExpression),
|
|
406
|
-
__metadata("design:type", Function),
|
|
407
|
-
__metadata("design:paramtypes", [Object]),
|
|
408
|
-
__metadata("design:returntype", void 0)
|
|
409
|
-
], MetadataEmitter.prototype, "classExpr", null);
|
|
410
|
-
__decorate([
|
|
411
|
-
Visit(ts.SyntaxKind.MethodDeclaration),
|
|
412
|
-
__metadata("design:type", Function),
|
|
413
|
-
__metadata("design:paramtypes", [Object]),
|
|
414
|
-
__metadata("design:returntype", void 0)
|
|
415
|
-
], MetadataEmitter.prototype, "method", null);
|
|
416
|
-
__decorate([
|
|
417
|
-
Visit(ts.SyntaxKind.MethodSignature),
|
|
418
|
-
__metadata("design:type", Function),
|
|
419
|
-
__metadata("design:paramtypes", [Object]),
|
|
420
|
-
__metadata("design:returntype", void 0)
|
|
421
|
-
], MetadataEmitter.prototype, "methodSignature", null);
|
|
422
|
-
export {
|
|
423
|
-
MetadataEmitter
|
|
424
|
-
};
|
|
425
|
-
//# sourceMappingURL=metadata-emitter.js.map
|