xml-model 0.3.0 → 1.0.0
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 +46 -1
- package/dist/defaults.d.ts +14 -0
- package/dist/defaults.js +129 -0
- package/{build/main → dist}/errors.d.ts +1 -1
- package/dist/errors.js +51 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/{build/main → dist}/middleware.d.ts +2 -2
- package/dist/middleware.js +31 -0
- package/dist/model/built-ins.d.ts +2 -0
- package/dist/model/built-ins.js +46 -0
- package/{build/module → dist}/model/index.d.ts +7 -11
- package/dist/model/index.js +242 -0
- package/{build/main → dist}/model/property.d.ts +2 -2
- package/dist/model/property.js +71 -0
- package/dist/model/registry.d.ts +8 -0
- package/dist/model/registry.js +26 -0
- package/{build/module → dist}/model/types.d.ts +7 -7
- package/dist/model/types.js +2 -0
- package/{build/module → dist}/types.d.ts +4 -4
- package/dist/types.js +2 -0
- package/dist/util/is-regexp.d.ts +11 -0
- package/dist/util/is-regexp.js +11 -0
- package/dist/util/kebab-case.d.ts +15 -0
- package/dist/util/kebab-case.js +18 -0
- package/dist/util/merge-maps.js +27 -0
- package/{build/main → dist}/xml/index.d.ts +4 -4
- package/dist/xml/index.js +73 -0
- package/{build/main → dist}/xml/xml-js.d.ts +1 -4
- package/dist/xml/xml-js.js +9 -0
- package/package.json +56 -39
- package/vite/dist/_virtual/_commonjs-dynamic-modules.js +7 -0
- package/vite/dist/_virtual/_commonjsHelpers.js +47 -0
- package/vite/dist/_virtual/_typescript.js +5 -0
- package/vite/dist/_virtual/api-call-transformer.js +5 -0
- package/vite/dist/_virtual/class-analyzer.js +5 -0
- package/vite/dist/_virtual/compile-error.js +5 -0
- package/vite/dist/_virtual/declarations-emitter.js +5 -0
- package/vite/dist/_virtual/encode-parameter.js +5 -0
- package/vite/dist/_virtual/find-relative-path.js +5 -0
- package/vite/dist/_virtual/flags.js +5 -0
- package/vite/dist/_virtual/format.js +5 -0
- package/vite/dist/_virtual/forward-ref.js +5 -0
- package/vite/dist/_virtual/get-exports-for-symbol.js +5 -0
- package/vite/dist/_virtual/import-analyzer.js +5 -0
- package/vite/dist/_virtual/index.js +8 -0
- package/vite/dist/_virtual/index2.js +5 -0
- package/vite/dist/_virtual/index3.js +5 -0
- package/vite/dist/_virtual/interface-analyzer.js +5 -0
- package/vite/dist/_virtual/legacy-decorator.js +5 -0
- package/vite/dist/_virtual/legacy-type-encoder.js +5 -0
- package/vite/dist/_virtual/literal-node.js +5 -0
- package/vite/dist/_virtual/metadata-collector.js +5 -0
- package/vite/dist/_virtual/metadata-decorator.js +5 -0
- package/vite/dist/_virtual/metadata-emitter.js +5 -0
- package/vite/dist/_virtual/metadata-encoder.js +5 -0
- package/vite/dist/_virtual/rt-helper.js +5 -0
- package/vite/dist/_virtual/rtti-visitor-base.js +5 -0
- package/vite/dist/_virtual/serialize.js +5 -0
- package/vite/dist/_virtual/type-encoder.js +5 -0
- package/vite/dist/_virtual/type-literal.js +5 -0
- package/vite/dist/_virtual/utils.js +5 -0
- package/vite/dist/_virtual/visitor-base.js +5 -0
- package/vite/dist/_virtual/workarounds.js +5 -0
- package/vite/dist/index.d.ts +21 -0
- package/vite/dist/index.js +62 -0
- package/vite/dist/node_modules/typescript-rtti/dist/common/format.js +69 -0
- package/vite/dist/node_modules/typescript-rtti/dist/common/index.js +34 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/api-call-transformer.js +197 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/class-analyzer.js +124 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/compile-error.js +18 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/import-analyzer.js +130 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/interface-analyzer.js +98 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/visitor-base.js +132 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/declarations-emitter.js +72 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/encode-parameter.js +110 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/find-relative-path.js +51 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/flags.js +59 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/forward-ref.js +35 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/get-exports-for-symbol.js +75 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/index.js +174 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/legacy-decorator.js +20 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/legacy-type-encoder.js +123 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/literal-node.js +19 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-collector.js +96 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-decorator.js +99 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-emitter.js +475 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-encoder.js +261 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/rt-helper.js +113 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/rtti-visitor-base.js +39 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/serialize.js +46 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/type-encoder.js +96 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/type-literal.js +546 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/utils.js +922 -0
- package/vite/dist/node_modules/typescript-rtti/dist/transformer/workarounds.js +16 -0
- package/build/main/defaults/index.d.ts +0 -14
- package/build/main/defaults/index.js +0 -170
- package/build/main/defaults/models.d.ts +0 -1
- package/build/main/defaults/models.js +0 -55
- package/build/main/errors.js +0 -93
- package/build/main/helper/merge-maps.js +0 -42
- package/build/main/index.d.ts +0 -6
- package/build/main/index.js +0 -46
- package/build/main/middleware.js +0 -61
- package/build/main/model/index.d.ts +0 -23
- package/build/main/model/index.js +0 -342
- package/build/main/model/property.js +0 -100
- package/build/main/model/types.d.ts +0 -73
- package/build/main/model/types.js +0 -152
- package/build/main/types.d.ts +0 -16
- package/build/main/types.js +0 -41
- package/build/main/xml/index.js +0 -105
- package/build/main/xml/xml-js.js +0 -26
- package/build/module/defaults/index.d.ts +0 -14
- package/build/module/defaults/index.js +0 -164
- package/build/module/defaults/models.d.ts +0 -1
- package/build/module/defaults/models.js +0 -54
- package/build/module/errors.d.ts +0 -23
- package/build/module/errors.js +0 -89
- package/build/module/helper/merge-maps.d.ts +0 -1
- package/build/module/helper/merge-maps.js +0 -39
- package/build/module/index.d.ts +0 -6
- package/build/module/index.js +0 -21
- package/build/module/middleware.d.ts +0 -9
- package/build/module/middleware.js +0 -56
- package/build/module/model/index.js +0 -334
- package/build/module/model/property.d.ts +0 -5
- package/build/module/model/property.js +0 -99
- package/build/module/model/types.js +0 -152
- package/build/module/types.js +0 -38
- package/build/module/xml/index.d.ts +0 -32
- package/build/module/xml/index.js +0 -94
- package/build/module/xml/xml-js.d.ts +0 -9
- package/build/module/xml/xml-js.js +0 -24
- /package/{build/main/helper → dist/util}/merge-maps.d.ts +0 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import "../../../../_virtual/_commonjsHelpers.js";
|
|
2
|
+
import { __exports as metadataEncoder } from "../../../../_virtual/metadata-encoder.js";
|
|
3
|
+
import "../../../../_virtual/_typescript.js";
|
|
4
|
+
import { __require as requireFormat } from "../common/format.js";
|
|
5
|
+
import { __require as requireEncodeParameter } from "./encode-parameter.js";
|
|
6
|
+
import { __require as requireFlags } from "./flags.js";
|
|
7
|
+
import { __require as requireForwardRef } from "./forward-ref.js";
|
|
8
|
+
import { __require as requireLegacyTypeEncoder } from "./legacy-type-encoder.js";
|
|
9
|
+
import { __require as requireLiteralNode } from "./literal-node.js";
|
|
10
|
+
import { __require as requireMetadataDecorator } from "./metadata-decorator.js";
|
|
11
|
+
import { __require as requireSerialize } from "./serialize.js";
|
|
12
|
+
import { __require as requireTypeEncoder } from "./type-encoder.js";
|
|
13
|
+
import { __require as requireUtils } from "./utils.js";
|
|
14
|
+
import require$$0 from "typescript";
|
|
15
|
+
var hasRequiredMetadataEncoder;
|
|
16
|
+
function requireMetadataEncoder() {
|
|
17
|
+
if (hasRequiredMetadataEncoder) return metadataEncoder;
|
|
18
|
+
hasRequiredMetadataEncoder = 1;
|
|
19
|
+
"use strict";
|
|
20
|
+
var __createBinding = metadataEncoder && metadataEncoder.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === void 0) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() {
|
|
25
|
+
return m[k];
|
|
26
|
+
} };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === void 0) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = metadataEncoder && metadataEncoder.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = metadataEncoder && metadataEncoder.__importStar || function(mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) {
|
|
42
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
|
+
}
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(metadataEncoder, "__esModule", { value: true });
|
|
48
|
+
metadataEncoder.MetadataEncoder = void 0;
|
|
49
|
+
const ts = __importStar(require$$0);
|
|
50
|
+
const format_1 = requireFormat();
|
|
51
|
+
const encode_parameter_1 = requireEncodeParameter();
|
|
52
|
+
const flags_1 = requireFlags();
|
|
53
|
+
const forward_ref_1 = requireForwardRef();
|
|
54
|
+
const legacy_type_encoder_1 = requireLegacyTypeEncoder();
|
|
55
|
+
const literal_node_1 = requireLiteralNode();
|
|
56
|
+
const metadata_decorator_1 = requireMetadataDecorator();
|
|
57
|
+
const serialize_1 = requireSerialize();
|
|
58
|
+
const type_encoder_1 = requireTypeEncoder();
|
|
59
|
+
const utils_1 = requireUtils();
|
|
60
|
+
class MetadataEncoder {
|
|
61
|
+
constructor(ctx) {
|
|
62
|
+
this.ctx = ctx;
|
|
63
|
+
this.typeEncoder = new type_encoder_1.TypeEncoder(this.ctx);
|
|
64
|
+
this.legacyTypeEncoder = new legacy_type_encoder_1.LegacyTypeEncoder(this.ctx);
|
|
65
|
+
}
|
|
66
|
+
get emitStandardMetadata() {
|
|
67
|
+
return this.ctx.emitStandardMetadata;
|
|
68
|
+
}
|
|
69
|
+
get checker() {
|
|
70
|
+
return this.ctx.checker;
|
|
71
|
+
}
|
|
72
|
+
get importMap() {
|
|
73
|
+
return this.ctx.importMap;
|
|
74
|
+
}
|
|
75
|
+
typeNode(typeNode, standardName, allowStandardMetadata = true) {
|
|
76
|
+
return this.type(this.checker.getTypeAtLocation(typeNode), typeNode, standardName, allowStandardMetadata);
|
|
77
|
+
}
|
|
78
|
+
type(type, typeNode, standardName, allowStandardMetadata = true) {
|
|
79
|
+
let decs = [];
|
|
80
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:t", (0, literal_node_1.literalNode)((0, forward_ref_1.forwardRef)(this.typeEncoder.referToType(type, typeNode)))));
|
|
81
|
+
if (this.emitStandardMetadata && allowStandardMetadata)
|
|
82
|
+
decs.push((0, metadata_decorator_1.legacyMetadataDecorator)(`design:${standardName}`, (0, literal_node_1.literalNode)(this.legacyTypeEncoder.referToType(type, typeNode))));
|
|
83
|
+
return decs;
|
|
84
|
+
}
|
|
85
|
+
prepareElementNames(elementNames) {
|
|
86
|
+
return elementNames.map((elementName) => (0, literal_node_1.literalNode)((0, utils_1.expressionForPropertyName)(elementName)));
|
|
87
|
+
}
|
|
88
|
+
class(klass, details) {
|
|
89
|
+
var _a;
|
|
90
|
+
let type = this.checker.getTypeAtLocation(klass);
|
|
91
|
+
let decs = [
|
|
92
|
+
ts.factory.createDecorator(ts.factory.createArrowFunction([], [], [
|
|
93
|
+
ts.factory.createParameterDeclaration([], void 0, "t")
|
|
94
|
+
], 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"))))
|
|
95
|
+
];
|
|
96
|
+
if (ts.isClassDeclaration(klass) || ts.isClassExpression(klass))
|
|
97
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:SP", this.prepareElementNames(details.staticPropertyNames)));
|
|
98
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:P", this.prepareElementNames(details.propertyNames)));
|
|
99
|
+
if (ts.isClassDeclaration(klass) || ts.isClassExpression(klass))
|
|
100
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:Sm", this.prepareElementNames(details.staticMethodNames)));
|
|
101
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:m", this.prepareElementNames(details.methodNames)));
|
|
102
|
+
if (ts.isClassDeclaration(klass) || ts.isClassExpression(klass)) {
|
|
103
|
+
let constructor = klass.members.find((x) => ts.isConstructorDeclaration(x));
|
|
104
|
+
if (constructor) {
|
|
105
|
+
decs.push(...this.params(constructor, klass));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
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));
|
|
109
|
+
if (impls) {
|
|
110
|
+
let typeRefs = [];
|
|
111
|
+
for (let heritageType of impls.types) {
|
|
112
|
+
let checker = this.checker;
|
|
113
|
+
let symbol = checker.getSymbolAtLocation(heritageType.expression);
|
|
114
|
+
let type2 = checker.getTypeAtLocation(heritageType.expression);
|
|
115
|
+
if (symbol) {
|
|
116
|
+
let localName = heritageType.expression.getText();
|
|
117
|
+
typeRefs.push(this.typeEncoder.referToType(type2, heritageType));
|
|
118
|
+
} else {
|
|
119
|
+
console.error(`RTTI: Cannot identify type ${heritageType.getText()} on implements clause for class ${klass.name.text} [please report]`);
|
|
120
|
+
typeRefs.push(void 0);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:i", typeRefs.map((tr) => tr ? (0, literal_node_1.literalNode)((0, forward_ref_1.forwardRef)(tr)) : void 0)));
|
|
124
|
+
}
|
|
125
|
+
let klassModifiers = ts.canHaveModifiers(klass) ? ts.getModifiers(klass) : [];
|
|
126
|
+
let fType = ts.isInterfaceDeclaration(klass) ? format_1.F_INTERFACE : format_1.F_CLASS;
|
|
127
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:f", `${fType}${(0, flags_1.getVisibility)(klassModifiers)}${(0, flags_1.isAbstract)(klassModifiers)}${(0, flags_1.isExported)(klassModifiers)}`));
|
|
128
|
+
return decs;
|
|
129
|
+
}
|
|
130
|
+
getClassName(node) {
|
|
131
|
+
if (!node.parent)
|
|
132
|
+
return `unknown class/interface`;
|
|
133
|
+
if (ts.isClassDeclaration(node.parent)) {
|
|
134
|
+
if (node.parent.name)
|
|
135
|
+
return `class ${node.parent.name.text}`;
|
|
136
|
+
else if ((0, utils_1.hasModifier)(ts.canHaveModifiers(node.parent) ? ts.getModifiers(node.parent) : [], ts.SyntaxKind.DefaultKeyword))
|
|
137
|
+
return `default class`;
|
|
138
|
+
else
|
|
139
|
+
return `unknown class`;
|
|
140
|
+
} else if (ts.isClassExpression(node.parent)) {
|
|
141
|
+
if (node.parent.name)
|
|
142
|
+
return `class ${node.parent.name.text}`;
|
|
143
|
+
else
|
|
144
|
+
return `unnamed class expression`;
|
|
145
|
+
} else if (ts.isInterfaceDeclaration(node.parent)) {
|
|
146
|
+
if (node.parent.name)
|
|
147
|
+
return `interface ${node.parent.name.text}`;
|
|
148
|
+
else if ((0, utils_1.hasModifier)((0, utils_1.getModifiers)(node.parent), ts.SyntaxKind.DefaultKeyword))
|
|
149
|
+
return `default interface`;
|
|
150
|
+
else
|
|
151
|
+
return `unknown interface`;
|
|
152
|
+
}
|
|
153
|
+
return `unknown class`;
|
|
154
|
+
}
|
|
155
|
+
property(node) {
|
|
156
|
+
var _a;
|
|
157
|
+
let typeNode = node.type;
|
|
158
|
+
let type;
|
|
159
|
+
if (!typeNode && ts.isSetAccessor(node) && node.parameters.length > 0) {
|
|
160
|
+
typeNode = node.parameters[0].type;
|
|
161
|
+
}
|
|
162
|
+
this.ctx.locationHint = `Property '${(0, utils_1.propertyNameToString)(node.name)}' of ${this.getClassName(node)}`;
|
|
163
|
+
if (typeNode) {
|
|
164
|
+
type = this.checker.getTypeAtLocation(typeNode);
|
|
165
|
+
} else {
|
|
166
|
+
type = this.checker.getTypeAtLocation(node);
|
|
167
|
+
}
|
|
168
|
+
const nodeModifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : [];
|
|
169
|
+
return [
|
|
170
|
+
...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),
|
|
171
|
+
(0, metadata_decorator_1.metadataDecorator)("rt:f", `${format_1.F_PROPERTY}${(0, flags_1.getVisibility)(nodeModifiers)}${(0, flags_1.isReadOnly)(nodeModifiers)}${node.questionToken ? format_1.F_OPTIONAL : ""}`)
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
methodFlags(node) {
|
|
175
|
+
if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node)) {
|
|
176
|
+
let type2 = format_1.F_FUNCTION;
|
|
177
|
+
return `${type2}${(0, flags_1.isAsync)((0, utils_1.getModifiers)(node))}${ts.isArrowFunction(node) ? format_1.F_ARROW_FUNCTION : ""}`;
|
|
178
|
+
}
|
|
179
|
+
const nodeModifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : [];
|
|
180
|
+
let type = format_1.F_METHOD;
|
|
181
|
+
let flags = `${type}${(0, flags_1.getVisibility)(nodeModifiers)}${(0, flags_1.isAbstract)(nodeModifiers)}${(0, flags_1.isAsync)(nodeModifiers)}`;
|
|
182
|
+
if (ts.isMethodDeclaration(node) && (0, utils_1.getModifiers)(node).some((x) => x.kind === ts.SyntaxKind.StaticKeyword))
|
|
183
|
+
flags += format_1.F_STATIC;
|
|
184
|
+
if (node.questionToken)
|
|
185
|
+
flags += format_1.F_OPTIONAL;
|
|
186
|
+
if (!node.type)
|
|
187
|
+
flags += format_1.F_INFERRED;
|
|
188
|
+
return flags;
|
|
189
|
+
}
|
|
190
|
+
method(node) {
|
|
191
|
+
let propNameStr = (0, utils_1.propertyNameToString)(node.name);
|
|
192
|
+
if (ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) {
|
|
193
|
+
this.ctx.locationHint = `Method ${propNameStr !== null && propNameStr !== void 0 ? propNameStr : "<unknown>"}() of ${this.getClassName(node)}`;
|
|
194
|
+
} else if (ts.isFunctionDeclaration(node)) {
|
|
195
|
+
this.ctx.locationHint = `Function ${propNameStr !== null && propNameStr !== void 0 ? propNameStr : "<unknown>"}()`;
|
|
196
|
+
} else if (ts.isFunctionExpression(node)) {
|
|
197
|
+
if (node.name)
|
|
198
|
+
this.ctx.locationHint = `Function ${propNameStr}()`;
|
|
199
|
+
else
|
|
200
|
+
this.ctx.locationHint = `Unnamed function expression`;
|
|
201
|
+
} else if (ts.isArrowFunction(node)) {
|
|
202
|
+
this.ctx.locationHint = `Arrow function`;
|
|
203
|
+
}
|
|
204
|
+
let methodHint = this.ctx.locationHint;
|
|
205
|
+
let decs = [];
|
|
206
|
+
let nodeDecorators = [];
|
|
207
|
+
if (ts.canHaveDecorators(node))
|
|
208
|
+
nodeDecorators = ts.getDecorators(node);
|
|
209
|
+
if (this.emitStandardMetadata && ts.isMethodDeclaration(node) && (nodeDecorators === null || nodeDecorators === void 0 ? void 0 : nodeDecorators.length) > 0)
|
|
210
|
+
decs.push((0, metadata_decorator_1.legacyMetadataDecorator)("design:type", (0, literal_node_1.literalNode)(ts.factory.createIdentifier("Function"))));
|
|
211
|
+
decs.push(...this.params(node));
|
|
212
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:f", this.methodFlags(node)));
|
|
213
|
+
let allowStandardMetadata = ts.isMethodDeclaration(node) && (nodeDecorators === null || nodeDecorators === void 0 ? void 0 : nodeDecorators.length) > 0;
|
|
214
|
+
if (node.type) {
|
|
215
|
+
decs.push(...this.typeNode(node.type, "returntype", allowStandardMetadata));
|
|
216
|
+
} else {
|
|
217
|
+
let signature = this.checker.getSignatureFromDeclaration(node);
|
|
218
|
+
if (signature) {
|
|
219
|
+
this.ctx.locationHint = `[Return type of] ${methodHint}`;
|
|
220
|
+
decs.push(...this.type(signature.getReturnType(), void 0, "returntype", allowStandardMetadata));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return decs;
|
|
224
|
+
}
|
|
225
|
+
params(node, containingNode) {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
let decs = [];
|
|
228
|
+
let standardParamTypes = [];
|
|
229
|
+
let serializedParamMeta = [];
|
|
230
|
+
for (let param of node.parameters) {
|
|
231
|
+
let name;
|
|
232
|
+
if (ts.isIdentifier(param.name))
|
|
233
|
+
name = param.name.text;
|
|
234
|
+
if (name === "this")
|
|
235
|
+
continue;
|
|
236
|
+
let expr = this.legacyTypeEncoder.referToTypeNode(param.type);
|
|
237
|
+
standardParamTypes.push(expr);
|
|
238
|
+
serializedParamMeta.push((0, literal_node_1.literalNode)((0, serialize_1.serialize)((0, encode_parameter_1.encodeParameter)(this.typeEncoder, param))));
|
|
239
|
+
}
|
|
240
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("rt:p", serializedParamMeta));
|
|
241
|
+
let eligibleForLegacyDecorators = ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node);
|
|
242
|
+
if (this.emitStandardMetadata && eligibleForLegacyDecorators) {
|
|
243
|
+
let parent = containingNode !== null && containingNode !== void 0 ? containingNode : node.parent;
|
|
244
|
+
let isDecorated = false;
|
|
245
|
+
if (ts.canHaveDecorators(node))
|
|
246
|
+
isDecorated = ((_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
247
|
+
if (ts.isConstructorDeclaration(node) && parent && ts.canHaveDecorators(parent))
|
|
248
|
+
isDecorated = ((_b = ts.getDecorators(parent)) === null || _b === void 0 ? void 0 : _b.length) > 0;
|
|
249
|
+
if (isDecorated)
|
|
250
|
+
decs.push((0, metadata_decorator_1.metadataDecorator)("design:paramtypes", standardParamTypes.map((t) => (0, literal_node_1.literalNode)(t))));
|
|
251
|
+
}
|
|
252
|
+
return decs;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
metadataEncoder.MetadataEncoder = MetadataEncoder;
|
|
256
|
+
return metadataEncoder;
|
|
257
|
+
}
|
|
258
|
+
export {
|
|
259
|
+
requireMetadataEncoder as __require
|
|
260
|
+
};
|
|
261
|
+
//# sourceMappingURL=metadata-encoder.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import "../../../../_virtual/_commonjsHelpers.js";
|
|
2
|
+
import { __exports as rtHelper } from "../../../../_virtual/rt-helper.js";
|
|
3
|
+
import "../../../../_virtual/_typescript.js";
|
|
4
|
+
import { __require as requireLiteralNode } from "./literal-node.js";
|
|
5
|
+
import { __require as requireSerialize } from "./serialize.js";
|
|
6
|
+
import require$$0 from "typescript";
|
|
7
|
+
var hasRequiredRtHelper;
|
|
8
|
+
function requireRtHelper() {
|
|
9
|
+
if (hasRequiredRtHelper) return rtHelper;
|
|
10
|
+
hasRequiredRtHelper = 1;
|
|
11
|
+
"use strict";
|
|
12
|
+
var __importDefault = rtHelper && rtHelper.__importDefault || function(mod) {
|
|
13
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(rtHelper, "__esModule", { value: true });
|
|
16
|
+
rtHelper.rtStore = void 0;
|
|
17
|
+
const typescript_1 = __importDefault(require$$0);
|
|
18
|
+
const literal_node_1 = requireLiteralNode();
|
|
19
|
+
const serialize_1 = requireSerialize();
|
|
20
|
+
function rtStore(typeMap) {
|
|
21
|
+
const factory = typescript_1.default.factory;
|
|
22
|
+
let typeEntries = Array.from(typeMap.entries()).map(([i, t]) => factory.createPropertyAssignment(factory.createComputedPropertyName(typescript_1.default.factory.createNumericLiteral(i)), t));
|
|
23
|
+
let typeStore = factory.createObjectLiteralExpression(typeEntries);
|
|
24
|
+
return factory.createVariableStatement(void 0, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("__RΦ"), void 0, void 0, (0, serialize_1.serialize)({
|
|
25
|
+
m: (0, literal_node_1.literalNode)(factory.createArrowFunction(void 0, void 0, [
|
|
26
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("k"), void 0, void 0, void 0),
|
|
27
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("v"), void 0, void 0, void 0)
|
|
28
|
+
], void 0, factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createArrowFunction(void 0, void 0, [
|
|
29
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("t"), void 0, void 0, void 0),
|
|
30
|
+
factory.createParameterDeclaration(void 0, factory.createToken(typescript_1.default.SyntaxKind.DotDotDotToken), factory.createIdentifier("a"), void 0, void 0, void 0)
|
|
31
|
+
], void 0, factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createConditionalExpression(factory.createBinaryExpression(factory.createIdentifier("t"), factory.createToken(typescript_1.default.SyntaxKind.AmpersandAmpersandToken), factory.createPropertyAccessExpression(factory.createIdentifier("Reflect"), factory.createIdentifier("metadata"))), factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), factory.createCallExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Reflect"), factory.createIdentifier("metadata")), void 0, [
|
|
32
|
+
factory.createIdentifier("k"),
|
|
33
|
+
factory.createIdentifier("v")
|
|
34
|
+
]), void 0, [
|
|
35
|
+
factory.createIdentifier("t"),
|
|
36
|
+
factory.createSpreadElement(factory.createIdentifier("a"))
|
|
37
|
+
]), factory.createToken(typescript_1.default.SyntaxKind.ColonToken), factory.createVoidExpression(factory.createNumericLiteral("0")))))),
|
|
38
|
+
f: (0, literal_node_1.literalNode)(factory.createArrowFunction(void 0, void 0, [
|
|
39
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("f"), void 0, void 0, void 0),
|
|
40
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("d"), 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(typescript_1.default.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(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [factory.createIdentifier("f")]))]), factory.createToken(typescript_1.default.SyntaxKind.CommaToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("defineProperty")), void 0, [
|
|
43
|
+
factory.createIdentifier("f"),
|
|
44
|
+
factory.createStringLiteral("name"),
|
|
45
|
+
factory.createObjectLiteralExpression([
|
|
46
|
+
factory.createPropertyAssignment(factory.createIdentifier("value"), factory.createIdentifier("n")),
|
|
47
|
+
factory.createPropertyAssignment(factory.createIdentifier("writable"), factory.createFalse())
|
|
48
|
+
], false)
|
|
49
|
+
])), factory.createToken(typescript_1.default.SyntaxKind.CommaToken), factory.createIdentifier("f"))))),
|
|
50
|
+
c: (0, literal_node_1.literalNode)(factory.createArrowFunction(void 0, void 0, [
|
|
51
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("c"), void 0, void 0, void 0),
|
|
52
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("d"), void 0, void 0, void 0),
|
|
53
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("dp"), void 0, void 0, void 0),
|
|
54
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("dsp"), void 0, void 0, void 0),
|
|
55
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("n"), void 0, void 0, void 0)
|
|
56
|
+
], void 0, factory.createToken(typescript_1.default.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(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [factory.createIdentifier("c")]))]), factory.createToken(typescript_1.default.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([
|
|
57
|
+
factory.createBindingElement(void 0, void 0, factory.createIdentifier("p"), void 0),
|
|
58
|
+
factory.createBindingElement(void 0, void 0, factory.createIdentifier("d"), void 0)
|
|
59
|
+
]), void 0, void 0, void 0)], void 0, factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [
|
|
60
|
+
factory.createPropertyAccessExpression(factory.createIdentifier("c"), factory.createIdentifier("prototype")),
|
|
61
|
+
factory.createIdentifier("p")
|
|
62
|
+
]))])), factory.createToken(typescript_1.default.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([
|
|
63
|
+
factory.createBindingElement(void 0, void 0, factory.createIdentifier("p"), void 0),
|
|
64
|
+
factory.createBindingElement(void 0, void 0, factory.createIdentifier("d"), void 0)
|
|
65
|
+
]), void 0, void 0, void 0)], void 0, factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createIdentifier("d"), void 0, [
|
|
66
|
+
factory.createIdentifier("c"),
|
|
67
|
+
factory.createIdentifier("p")
|
|
68
|
+
]))])), factory.createToken(typescript_1.default.SyntaxKind.CommaToken), factory.createConditionalExpression(factory.createIdentifier("n"), factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("defineProperty")), void 0, [
|
|
69
|
+
factory.createIdentifier("c"),
|
|
70
|
+
factory.createStringLiteral("name"),
|
|
71
|
+
factory.createObjectLiteralExpression([
|
|
72
|
+
factory.createPropertyAssignment(factory.createIdentifier("value"), factory.createIdentifier("n")),
|
|
73
|
+
factory.createPropertyAssignment(factory.createIdentifier("writable"), factory.createFalse())
|
|
74
|
+
], false)
|
|
75
|
+
]), factory.createToken(typescript_1.default.SyntaxKind.ColonToken), factory.createIdentifier("undefined"))), factory.createToken(typescript_1.default.SyntaxKind.CommaToken), factory.createIdentifier("c"))))),
|
|
76
|
+
r: (0, literal_node_1.literalNode)(factory.createArrowFunction(void 0, void 0, [
|
|
77
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("o"), void 0, void 0, void 0),
|
|
78
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("a"), void 0, void 0, void 0)
|
|
79
|
+
], void 0, factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createParenthesizedExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("assign")), void 0, [
|
|
80
|
+
factory.createIdentifier("o"),
|
|
81
|
+
factory.createIdentifier("a")
|
|
82
|
+
])))),
|
|
83
|
+
a: (0, literal_node_1.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(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), factory.createBlock([
|
|
84
|
+
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")))], typescript_1.default.NodeFlags.Let)),
|
|
85
|
+
factory.createIfStatement(factory.createBinaryExpression(factory.createIdentifier("t"), factory.createToken(typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken), factory.createVoidExpression(factory.createNumericLiteral("0"))), factory.createReturnStatement(factory.createVoidExpression(factory.createNumericLiteral("0"))), void 0),
|
|
86
|
+
factory.createIfStatement(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("RΦ")), factory.createBlock([
|
|
87
|
+
factory.createVariableStatement(void 0, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("r"), void 0, void 0, factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("RΦ")))], typescript_1.default.NodeFlags.Let)),
|
|
88
|
+
factory.createExpressionStatement(factory.createDeleteExpression(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("RΦ")))),
|
|
89
|
+
factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__RΦ"), factory.createIdentifier("r")), void 0, [
|
|
90
|
+
factory.createIdentifier("t"),
|
|
91
|
+
factory.createCallExpression(factory.createIdentifier("r"), void 0, [factory.createIdentifier("t")])
|
|
92
|
+
]))
|
|
93
|
+
], true), factory.createIfStatement(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("LΦ")), factory.createBlock([
|
|
94
|
+
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, []))], typescript_1.default.NodeFlags.Let)),
|
|
95
|
+
factory.createExpressionStatement(factory.createDeleteExpression(factory.createPropertyAccessExpression(factory.createIdentifier("t"), factory.createIdentifier("LΦ")))),
|
|
96
|
+
factory.createExpressionStatement(factory.createBinaryExpression(factory.createElementAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__RΦ"), factory.createIdentifier("t")), factory.createIdentifier("id")), factory.createToken(typescript_1.default.SyntaxKind.EqualsToken), factory.createBinaryExpression(factory.createIdentifier("t"), factory.createToken(typescript_1.default.SyntaxKind.EqualsToken), factory.createIdentifier("l"))))
|
|
97
|
+
], true), void 0)),
|
|
98
|
+
factory.createReturnStatement(factory.createIdentifier("t"))
|
|
99
|
+
], true))),
|
|
100
|
+
oe: (0, literal_node_1.literalNode)(factory.createArrowFunction(void 0, void 0, [
|
|
101
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("o"), void 0, void 0, void 0),
|
|
102
|
+
factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("k"), void 0, void 0, void 0)
|
|
103
|
+
], void 0, factory.createToken(typescript_1.default.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))),
|
|
104
|
+
t: (0, literal_node_1.literalNode)(typeStore)
|
|
105
|
+
}))], typescript_1.default.NodeFlags.Const));
|
|
106
|
+
}
|
|
107
|
+
rtHelper.rtStore = rtStore;
|
|
108
|
+
return rtHelper;
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
requireRtHelper as __require
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=rt-helper.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "../../../../_virtual/_commonjsHelpers.js";
|
|
2
|
+
import { __exports as rttiVisitorBase } from "../../../../_virtual/rtti-visitor-base.js";
|
|
3
|
+
import { __require as requireVisitorBase } from "./common/visitor-base.js";
|
|
4
|
+
var hasRequiredRttiVisitorBase;
|
|
5
|
+
function requireRttiVisitorBase() {
|
|
6
|
+
if (hasRequiredRttiVisitorBase) return rttiVisitorBase;
|
|
7
|
+
hasRequiredRttiVisitorBase = 1;
|
|
8
|
+
"use strict";
|
|
9
|
+
Object.defineProperty(rttiVisitorBase, "__esModule", { value: true });
|
|
10
|
+
rttiVisitorBase.RttiVisitor = void 0;
|
|
11
|
+
const visitor_base_1 = requireVisitorBase();
|
|
12
|
+
class RttiVisitor extends visitor_base_1.VisitorBase {
|
|
13
|
+
constructor(ctx) {
|
|
14
|
+
super(ctx.transformationContext);
|
|
15
|
+
this.ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
get program() {
|
|
18
|
+
return this.ctx.program;
|
|
19
|
+
}
|
|
20
|
+
get checker() {
|
|
21
|
+
return this.ctx.checker;
|
|
22
|
+
}
|
|
23
|
+
get trace() {
|
|
24
|
+
return this.ctx.trace;
|
|
25
|
+
}
|
|
26
|
+
get sourceFile() {
|
|
27
|
+
return this.ctx.sourceFile;
|
|
28
|
+
}
|
|
29
|
+
get importMap() {
|
|
30
|
+
return this.ctx.importMap;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
rttiVisitorBase.RttiVisitor = RttiVisitor;
|
|
34
|
+
return rttiVisitorBase;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
requireRttiVisitorBase as __require
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=rtti-visitor-base.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "../../../../_virtual/_commonjsHelpers.js";
|
|
2
|
+
import { __exports as serialize } from "../../../../_virtual/serialize.js";
|
|
3
|
+
import "../../../../_virtual/_typescript.js";
|
|
4
|
+
import { __require as requireCommon } from "../common/index.js";
|
|
5
|
+
import require$$0 from "typescript";
|
|
6
|
+
var hasRequiredSerialize;
|
|
7
|
+
function requireSerialize() {
|
|
8
|
+
if (hasRequiredSerialize) return serialize;
|
|
9
|
+
hasRequiredSerialize = 1;
|
|
10
|
+
"use strict";
|
|
11
|
+
var __importDefault = serialize && serialize.__importDefault || function(mod) {
|
|
12
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(serialize, "__esModule", { value: true });
|
|
15
|
+
serialize.serialize = void 0;
|
|
16
|
+
const typescript_1 = __importDefault(require$$0);
|
|
17
|
+
const common_1 = requireCommon();
|
|
18
|
+
function serialize$1(object) {
|
|
19
|
+
if (object === null)
|
|
20
|
+
return typescript_1.default.factory.createNull();
|
|
21
|
+
if (object === void 0)
|
|
22
|
+
return typescript_1.default.factory.createVoidZero();
|
|
23
|
+
if (object instanceof Array)
|
|
24
|
+
return typescript_1.default.factory.createArrayLiteralExpression(object.map((x) => serialize$1(x)));
|
|
25
|
+
if (typeof object === "string")
|
|
26
|
+
return typescript_1.default.factory.createStringLiteral(object);
|
|
27
|
+
if (typeof object === "number")
|
|
28
|
+
return typescript_1.default.factory.createNumericLiteral(object);
|
|
29
|
+
if (typeof object === "boolean")
|
|
30
|
+
return object ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse();
|
|
31
|
+
if (typeof object === "function")
|
|
32
|
+
throw new Error(`Cannot serialize a function`);
|
|
33
|
+
if ((0, common_1.isLiteralNode)(object))
|
|
34
|
+
return object.node;
|
|
35
|
+
let props = [];
|
|
36
|
+
for (let key of Object.keys(object))
|
|
37
|
+
props.push(typescript_1.default.factory.createPropertyAssignment(key, serialize$1(object[key])));
|
|
38
|
+
return typescript_1.default.factory.createObjectLiteralExpression(props, false);
|
|
39
|
+
}
|
|
40
|
+
serialize.serialize = serialize$1;
|
|
41
|
+
return serialize;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
requireSerialize as __require
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import "../../../../_virtual/_commonjsHelpers.js";
|
|
2
|
+
import { __exports as typeEncoder } from "../../../../_virtual/type-encoder.js";
|
|
3
|
+
import "../../../../_virtual/_typescript.js";
|
|
4
|
+
import { __require as requireFormat } from "../common/format.js";
|
|
5
|
+
import { __require as requireLiteralNode } from "./literal-node.js";
|
|
6
|
+
import { __require as requireSerialize } from "./serialize.js";
|
|
7
|
+
import { __require as requireTypeLiteral } from "./type-literal.js";
|
|
8
|
+
import { __require as requireUtils } from "./utils.js";
|
|
9
|
+
import require$$0 from "typescript";
|
|
10
|
+
var hasRequiredTypeEncoder;
|
|
11
|
+
function requireTypeEncoder() {
|
|
12
|
+
if (hasRequiredTypeEncoder) return typeEncoder;
|
|
13
|
+
hasRequiredTypeEncoder = 1;
|
|
14
|
+
"use strict";
|
|
15
|
+
var __importDefault = typeEncoder && typeEncoder.__importDefault || function(mod) {
|
|
16
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(typeEncoder, "__esModule", { value: true });
|
|
19
|
+
typeEncoder.TypeEncoder = void 0;
|
|
20
|
+
const typescript_1 = __importDefault(require$$0);
|
|
21
|
+
const format_1 = requireFormat();
|
|
22
|
+
const literal_node_1 = requireLiteralNode();
|
|
23
|
+
const serialize_1 = requireSerialize();
|
|
24
|
+
const type_literal_1 = requireTypeLiteral();
|
|
25
|
+
const utils_1 = requireUtils();
|
|
26
|
+
class TypeEncoder {
|
|
27
|
+
constructor(ctx) {
|
|
28
|
+
this.ctx = ctx;
|
|
29
|
+
}
|
|
30
|
+
get typeMap() {
|
|
31
|
+
return this.ctx.typeMap;
|
|
32
|
+
}
|
|
33
|
+
get program() {
|
|
34
|
+
return this.ctx.program;
|
|
35
|
+
}
|
|
36
|
+
get sourceFile() {
|
|
37
|
+
return this.ctx.sourceFile;
|
|
38
|
+
}
|
|
39
|
+
get importMap() {
|
|
40
|
+
return this.ctx.importMap;
|
|
41
|
+
}
|
|
42
|
+
get checker() {
|
|
43
|
+
return this.ctx.checker;
|
|
44
|
+
}
|
|
45
|
+
referToTypeNode(typeNode) {
|
|
46
|
+
return this.referToType(this.checker.getTypeFromTypeNode(typeNode), typeNode);
|
|
47
|
+
}
|
|
48
|
+
referToType(type, typeNode) {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
if (!type["id"])
|
|
51
|
+
throw new Error(`Type does not have an ID!`);
|
|
52
|
+
if (!this.typeMap.has(type["id"])) {
|
|
53
|
+
this.typeMap.set(type["id"], null);
|
|
54
|
+
let isEnum = (0, utils_1.hasFlag)(type.flags, typescript_1.default.TypeFlags.Enum) || (0, utils_1.hasFlag)(type.flags, typescript_1.default.TypeFlags.EnumLiteral) && (0, utils_1.hasFlag)((_a = type.aliasSymbol) === null || _a === void 0 ? void 0 : _a.flags, typescript_1.default.SymbolFlags.Enum);
|
|
55
|
+
let declarations = (_b = type.symbol) === null || _b === void 0 ? void 0 : _b.getDeclarations();
|
|
56
|
+
let declaration = declarations === null || declarations === void 0 ? void 0 : declarations[0];
|
|
57
|
+
let sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
58
|
+
let isLocal = sourceFile === this.ctx.sourceFile;
|
|
59
|
+
let isAmbient = (0, utils_1.hasFlag)(
|
|
60
|
+
declaration === null || declaration === void 0 ? void 0 : declaration.flags,
|
|
61
|
+
16777216
|
|
62
|
+
/* InternalNodeFlags.Ambient */
|
|
63
|
+
);
|
|
64
|
+
let useStandIn = false;
|
|
65
|
+
if (isEnum) {
|
|
66
|
+
useStandIn = isLocal && !(0, utils_1.hasFlag)(type.symbol.flags, typescript_1.default.SymbolFlags.ConstEnum);
|
|
67
|
+
} else if (type.isClassOrInterface()) {
|
|
68
|
+
useStandIn = isLocal && !isAmbient;
|
|
69
|
+
}
|
|
70
|
+
if (useStandIn) {
|
|
71
|
+
this.typeMap.set(type["id"], (0, serialize_1.serialize)({
|
|
72
|
+
TΦ: format_1.T_STAND_IN,
|
|
73
|
+
name: `${type.symbol.name}`
|
|
74
|
+
}));
|
|
75
|
+
} else {
|
|
76
|
+
let expr = isLocal && isAmbient ? (0, type_literal_1.structuredTypeLiteral)(this, type, typeNode, (_c = type.symbol) === null || _c === void 0 ? void 0 : _c.name) : (0, type_literal_1.typeLiteral)(this, type, typeNode);
|
|
77
|
+
let propName = typescript_1.default.isObjectLiteralExpression(expr) ? "RΦ" : "LΦ";
|
|
78
|
+
this.typeMap.set(type["id"], (0, serialize_1.serialize)({
|
|
79
|
+
[propName]: (0, literal_node_1.literalNode)(typescript_1.default.factory.createArrowFunction([], [], [
|
|
80
|
+
typescript_1.default.factory.createParameterDeclaration([], void 0, "t", void 0, void 0, void 0)
|
|
81
|
+
], void 0, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), expr))
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(`__RΦ`), "a"), [], [
|
|
86
|
+
typescript_1.default.factory.createNumericLiteral(type["id"])
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
typeEncoder.TypeEncoder = TypeEncoder;
|
|
91
|
+
return typeEncoder;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
requireTypeEncoder as __require
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=type-encoder.js.map
|