@hodfords/turbo-transformer 1.0.0 → 1.1.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/bundles/class-transformer.umd.js +202 -14
- package/bundles/class-transformer.umd.js.map +1 -1
- package/bundles/class-transformer.umd.min.js +1 -1
- package/bundles/class-transformer.umd.min.js.map +1 -1
- package/cjs/TransformCompiler.js +143 -11
- package/cjs/TransformCompiler.js.map +1 -1
- package/cjs/TransformOperationExecutor.js +50 -1
- package/cjs/TransformOperationExecutor.js.map +1 -1
- package/esm2015/TransformCompiler.js +141 -10
- package/esm2015/TransformCompiler.js.map +1 -1
- package/esm2015/TransformOperationExecutor.js +50 -1
- package/esm2015/TransformOperationExecutor.js.map +1 -1
- package/esm5/TransformCompiler.js +153 -13
- package/esm5/TransformCompiler.js.map +1 -1
- package/esm5/TransformOperationExecutor.js +50 -1
- package/esm5/TransformOperationExecutor.js.map +1 -1
- package/package.json +1 -1
- package/types/TransformCompiler.d.ts +16 -0
- package/types/TransformOperationExecutor.d.ts +10 -0
package/cjs/TransformCompiler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JitCache = exports.getJitCache = exports.setJitEnabled = void 0;
|
|
3
|
+
exports.DirectTransformer = exports.JitCache = exports.getJitCache = exports.setJitEnabled = void 0;
|
|
4
4
|
const storage_1 = require("./storage");
|
|
5
5
|
const enums_1 = require("./enums");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
@@ -71,8 +71,25 @@ class JitCache {
|
|
|
71
71
|
constructor() {
|
|
72
72
|
this.version = -1;
|
|
73
73
|
this.classes = new WeakMap();
|
|
74
|
+
this.directs = new WeakMap();
|
|
74
75
|
this.anonymous = undefined;
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the compiled transformer to call directly for elements of arrays of given type, or null.
|
|
79
|
+
*/
|
|
80
|
+
direct(targetType, executor) {
|
|
81
|
+
// get() first: it drops everything when metadata changed
|
|
82
|
+
const transformer = this.get(targetType, executor);
|
|
83
|
+
if (!transformer)
|
|
84
|
+
return null;
|
|
85
|
+
let direct = this.directs.get(targetType);
|
|
86
|
+
if (direct === undefined || direct.transformer !== transformer) {
|
|
87
|
+
const resolved = helpers.resolveChild(executor, targetType);
|
|
88
|
+
direct = resolved ? new DirectTransformer(resolved, helpers.directPrototype(targetType)) : null;
|
|
89
|
+
this.directs.set(targetType, direct);
|
|
90
|
+
}
|
|
91
|
+
return direct;
|
|
92
|
+
}
|
|
76
93
|
/**
|
|
77
94
|
* Returns the compiled transformer for given target type (undefined when it can not be compiled).
|
|
78
95
|
*/
|
|
@@ -82,6 +99,7 @@ class JitCache {
|
|
|
82
99
|
if (version !== this.version) {
|
|
83
100
|
this.version = version;
|
|
84
101
|
this.classes = new WeakMap();
|
|
102
|
+
this.directs = new WeakMap();
|
|
85
103
|
this.anonymous = undefined;
|
|
86
104
|
}
|
|
87
105
|
if (targetType === undefined || targetType === null) {
|
|
@@ -100,6 +118,24 @@ class JitCache {
|
|
|
100
118
|
}
|
|
101
119
|
}
|
|
102
120
|
exports.JitCache = JitCache;
|
|
121
|
+
/**
|
|
122
|
+
* Compiled transformer of a type, with the check of the values TransformOperationExecutor#transform would
|
|
123
|
+
* transform with it: plain objects and instances of the type which are not arrays, sets, dates, maps, buffers or
|
|
124
|
+
* promises.
|
|
125
|
+
*/
|
|
126
|
+
class DirectTransformer {
|
|
127
|
+
constructor(transformer, prototype) {
|
|
128
|
+
this.transformer = transformer;
|
|
129
|
+
this.prototype = prototype;
|
|
130
|
+
}
|
|
131
|
+
accepts(value) {
|
|
132
|
+
if (value === null || typeof value !== 'object')
|
|
133
|
+
return false;
|
|
134
|
+
const prototype = Object.getPrototypeOf(value);
|
|
135
|
+
return (prototype === Object.prototype || prototype === this.prototype) && typeof value.then !== 'function';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.DirectTransformer = DirectTransformer;
|
|
103
139
|
// ---------------------------------------------------------------------------
|
|
104
140
|
// Runtime helpers used by the generated code
|
|
105
141
|
// ---------------------------------------------------------------------------
|
|
@@ -137,6 +173,46 @@ const helpers = {
|
|
|
137
173
|
const descriptor = getPropertyDescriptor(prototype, key);
|
|
138
174
|
return !!(descriptor && !descriptor.set);
|
|
139
175
|
},
|
|
176
|
+
/**
|
|
177
|
+
* Returns the compiled transformer to call directly for objects of given (resolved) type, or null when
|
|
178
|
+
* TransformOperationExecutor#transform would not take its object branch with this type as target.
|
|
179
|
+
*/
|
|
180
|
+
resolveChild(executor, type) {
|
|
181
|
+
if (typeof type !== 'function' || type === String || type === Number || type === Boolean || type === Date) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
if (!!(0, utils_1.getGlobal)().Buffer && type === Buffer)
|
|
185
|
+
return null;
|
|
186
|
+
const jit = executor.jit;
|
|
187
|
+
return (jit && jit.get(type, executor)) || null;
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* Prototype of the instances that can be passed directly to the compiled transformer of given type, besides plain
|
|
191
|
+
* objects: null when instances of the type are arrays, sets, dates, maps or buffers (handled by other branches).
|
|
192
|
+
*/
|
|
193
|
+
directPrototype(type) {
|
|
194
|
+
const prototype = type.prototype;
|
|
195
|
+
if (!prototype)
|
|
196
|
+
return null;
|
|
197
|
+
const excluded = [Array, Set, Date, Map];
|
|
198
|
+
if ((0, utils_1.getGlobal)().Buffer)
|
|
199
|
+
excluded.push(Buffer);
|
|
200
|
+
for (const cls of excluded) {
|
|
201
|
+
if (prototype === cls.prototype || prototype instanceof cls)
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return prototype;
|
|
205
|
+
},
|
|
206
|
+
/** Same as instantiateArrayType in TransformOperationExecutor. */
|
|
207
|
+
newArray(arrayType) {
|
|
208
|
+
if (!arrayType)
|
|
209
|
+
return [];
|
|
210
|
+
const array = new arrayType();
|
|
211
|
+
if (!(array instanceof Set) && !('push' in array)) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
return array;
|
|
215
|
+
},
|
|
140
216
|
prefixBlocked(key, prefixes) {
|
|
141
217
|
return !prefixes.every(prefix => key.substr(0, prefix.length) !== prefix);
|
|
142
218
|
},
|
|
@@ -239,6 +315,9 @@ function compile(target, executor) {
|
|
|
239
315
|
};
|
|
240
316
|
const str = (value) => JSON.stringify(value);
|
|
241
317
|
let labelCounter = 0;
|
|
318
|
+
// per call site caches of the last resolved child type => compiled transformer
|
|
319
|
+
const siteDeclarations = [];
|
|
320
|
+
const circularCheck = !!options.enableCircularCheck;
|
|
242
321
|
// custom @Transform() functions applied to a key, filtered exactly like applyCustomTransformations
|
|
243
322
|
const getTransforms = (key) => {
|
|
244
323
|
let metadatas = storage.findTransformMetadatas(target, key, transformationType);
|
|
@@ -261,8 +340,11 @@ function compile(target, executor) {
|
|
|
261
340
|
return options.exposeUnsetFields ? assign : `if (fv !== undefined) { ${assign} }\n`;
|
|
262
341
|
};
|
|
263
342
|
/**
|
|
264
|
-
* Transformation of `fv` (sub value) into `fv
|
|
265
|
-
*
|
|
343
|
+
* Transformation of `fv` (sub value) into `fv`, same as TransformOperationExecutor#transform:
|
|
344
|
+
* - primitives are converted inline,
|
|
345
|
+
* - plain objects (or instances of the target type) and arrays of them, when the type has a compiled transformer,
|
|
346
|
+
* are passed directly to that compiled transformer,
|
|
347
|
+
* - everything else goes through TransformOperationExecutor#transform.
|
|
266
348
|
*/
|
|
267
349
|
const emitChild = (typeExpr, kind, arrayTypeExpr, isMapExpr, valueKeyExpr) => {
|
|
268
350
|
let primitive;
|
|
@@ -286,8 +368,46 @@ function compile(target, executor) {
|
|
|
286
368
|
default:
|
|
287
369
|
primitive = isMapExpr === 'true' ? 'fv' : `(${isMapExpr} ? fv : H.conv(fv, ${typeExpr}))`;
|
|
288
370
|
}
|
|
371
|
+
const slow = `fv = ex.transform(source ? source[${valueKeyExpr}] : undefined, fv, ${typeExpr}, ${arrayTypeExpr}, ${isMapExpr}, level + 1);`;
|
|
372
|
+
// types which can never have a compiled transformer: no direct call
|
|
373
|
+
if (kind !== 'none' && kind !== 'dynamic') {
|
|
374
|
+
return `if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\nelse { ${slow} }\n`;
|
|
375
|
+
}
|
|
376
|
+
if (typeExpr === 'undefined') {
|
|
377
|
+
return `if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\nelse { ${slow} }\n`;
|
|
378
|
+
}
|
|
379
|
+
const site = String(siteDeclarations.length);
|
|
380
|
+
const sT = 'sT' + site; // last type seen at this call site
|
|
381
|
+
const sF = 'sF' + site; // its compiled transformer (null: not directly callable)
|
|
382
|
+
const sP = 'sP' + site; // prototype of instances which can be passed directly
|
|
383
|
+
siteDeclarations.push(`let ${sT} = UNSET, ${sF} = null, ${sP} = null;\n`);
|
|
384
|
+
const callDirect = (valueExpr, levelExpr) => circularCheck
|
|
385
|
+
? `(ex.recursionStack.add(${valueExpr}), r = ${sF}(ex, undefined, ${valueExpr}, ${levelExpr}), ex.recursionStack.delete(${valueExpr}), r)`
|
|
386
|
+
: `${sF}(ex, undefined, ${valueExpr}, ${levelExpr})`;
|
|
387
|
+
const isDirect = (valueExpr) => `((pp = Object.getPrototypeOf(${valueExpr})) === OP || pp === ${sP}) && typeof ${valueExpr}.then !== 'function'`;
|
|
388
|
+
// array branch of TransformOperationExecutor#transform, with forEach and the element type checks unrolled
|
|
389
|
+
const newArray = isPlainToClass && arrayTypeExpr !== 'undefined' ? `H.newArray(${arrayTypeExpr})` : '[]';
|
|
390
|
+
const add = (valueExpr) => newArray === '[]' ? `arr.push(${valueExpr});` : `if (isSet) arr.add(${valueExpr}); else arr.push(${valueExpr});`;
|
|
391
|
+
let arrayCode = `const n = fv.length;\nconst arr = ${newArray};\n` +
|
|
392
|
+
(newArray === '[]' ? '' : 'const isSet = arr instanceof Set;\n') +
|
|
393
|
+
`for (let j = 0; j < n; j++) {\nif (!(j in fv)) continue;\nconst el = fv[j];\n`;
|
|
394
|
+
if (circularCheck) {
|
|
395
|
+
arrayCode += `if (ex.recursionStack.has(el)) { ${isClassToClass ? add('el') : ''} continue; }\n`;
|
|
396
|
+
}
|
|
397
|
+
arrayCode +=
|
|
398
|
+
`let r;\n` +
|
|
399
|
+
`if (typeof el !== 'object' || el === null) r = el;\n` +
|
|
400
|
+
`else if (${isDirect('el')}) r = ${callDirect('el', 'level + 2')};\n` +
|
|
401
|
+
`else r = ex.transform(undefined, el, t, undefined, el instanceof Map, level + 2);\n` +
|
|
402
|
+
`${add('r')}\n}\nfv = arr;\n`;
|
|
289
403
|
return (`if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\n` +
|
|
290
|
-
`else {
|
|
404
|
+
`else {\nconst t = ${typeExpr};\n` +
|
|
405
|
+
`if (t !== ${sT}) { ${sT} = t; ${sF} = H.resolveChild(ex, t); ${sP} = ${sF} === null ? null : H.directPrototype(t); }\n` +
|
|
406
|
+
`let pp, r;\n` +
|
|
407
|
+
`if (${sF} === null || source) { ${slow} }\n` +
|
|
408
|
+
`else if (Array.isArray(fv) && fv.forEach === AFE) {\n${arrayCode}}\n` +
|
|
409
|
+
`else if (!${isMapExpr} && ${isDirect('fv')}) { fv = ${callDirect('fv', 'level + 1')}; }\n` +
|
|
410
|
+
`else { ${slow} }\n}\n`);
|
|
291
411
|
};
|
|
292
412
|
/**
|
|
293
413
|
* Generates the transformation of a single key. `key` is the static key, or undefined for the
|
|
@@ -376,10 +496,15 @@ function compile(target, executor) {
|
|
|
376
496
|
// skip keys matching a getter / method of the new value
|
|
377
497
|
if (createsInstance) {
|
|
378
498
|
const staticSkip = key === undefined ? `H.descSkip(proto, key)` : String(helpers.descSkip(targetPrototype, newValueKey));
|
|
499
|
+
const descriptorSkip = staticSkip === 'false'
|
|
500
|
+
? `(!protoIsTarget && H.descSkip(proto, ${newKeyExpr}))`
|
|
501
|
+
: staticSkip === 'true'
|
|
502
|
+
? `(protoIsTarget || H.descSkip(proto, ${newKeyExpr}))`
|
|
503
|
+
: `(protoIsTarget ? ${staticSkip} : H.descSkip(proto, ${newKeyExpr}))`;
|
|
504
|
+
// `newValue.constructor.prototype` is read once per object, but must throw here like the interpreter
|
|
379
505
|
code +=
|
|
380
|
-
`
|
|
381
|
-
`if (proto && (
|
|
382
|
-
`|| newValue[${newKeyExpr}] instanceof Function)) break ${label};\n`;
|
|
506
|
+
`if (nvc == null) newValue.constructor.prototype;\n` +
|
|
507
|
+
`if (proto && (${descriptorSkip} || newValue[${newKeyExpr}] instanceof Function)) break ${label};\n`;
|
|
383
508
|
}
|
|
384
509
|
const transforms = key === undefined ? [] : getTransforms(transformKey);
|
|
385
510
|
let main = 'let fv;\n';
|
|
@@ -421,6 +546,11 @@ function compile(target, executor) {
|
|
|
421
546
|
// keys always transformed (exposed properties), or all keys when they are not dynamic
|
|
422
547
|
const staticKeys = ex.getKeys(target, {}, false);
|
|
423
548
|
let body = `const newValue = source ? source : ${createsInstance && target ? `new ${ref(target)}()` : '{}'};\nconst nvm = newValue instanceof Map;\n`;
|
|
549
|
+
if (createsInstance) {
|
|
550
|
+
body +=
|
|
551
|
+
`const nvc = newValue.constructor;\nconst proto = nvc == null ? undefined : nvc.prototype;\n` +
|
|
552
|
+
`const protoIsTarget = proto === ${ref(targetPrototype)};\n`;
|
|
553
|
+
}
|
|
424
554
|
if (!dynamicKeys) {
|
|
425
555
|
for (const key of staticKeys)
|
|
426
556
|
body += emitKey(key);
|
|
@@ -439,15 +569,18 @@ function compile(target, executor) {
|
|
|
439
569
|
knownKeys.delete('constructor');
|
|
440
570
|
const extraKeys = staticKeys.filter(key => key !== '__proto__' && key !== 'constructor');
|
|
441
571
|
// exposed keys missing from the object are transformed after the object keys
|
|
572
|
+
// set when the key is found in the object keys
|
|
442
573
|
extraKeys.forEach((key, index) => {
|
|
443
|
-
body += `
|
|
574
|
+
body += `let has${String(index)} = false;\n`;
|
|
444
575
|
});
|
|
445
576
|
let cases = `case "__proto__": case "constructor": continue;\n`;
|
|
446
577
|
knownKeys.forEach(key => {
|
|
447
578
|
const probe = {};
|
|
448
579
|
probe[key] = true;
|
|
449
580
|
const blocked = !ex.getKeys(target, probe, false).includes(key);
|
|
450
|
-
|
|
581
|
+
const extraIndex = extraKeys.indexOf(key);
|
|
582
|
+
const seen = extraIndex === -1 ? '' : `has${String(extraIndex)} = true;\n`;
|
|
583
|
+
cases += blocked ? `case ${str(key)}: continue;\n` : `case ${str(key)}: ${seen}${emitKey(key)}continue;\n`;
|
|
451
584
|
});
|
|
452
585
|
body += `const keys = Object.keys(value);\n`;
|
|
453
586
|
body += `for (let i = 0; i < keys.length; i++) {\nconst key = keys[i];\nswitch (key) {\n${cases}}\n`;
|
|
@@ -462,8 +595,7 @@ function compile(target, executor) {
|
|
|
462
595
|
}
|
|
463
596
|
body += 'return newValue;\n';
|
|
464
597
|
const declarations = constants.map((_, index) => `const k${index} = K[${index}];\n`).join('');
|
|
465
|
-
const source = `'use strict';\n${declarations}const
|
|
466
|
-
`return function compiledTransform(ex, source, value, level) {\n${body}};`;
|
|
598
|
+
const source = `'use strict';\n${declarations}const OP = Object.prototype;\nconst AFE = Array.prototype.forEach;\nconst UNSET = {};\n${siteDeclarations.join('')}` + `return function compiledTransform(ex, source, value, level) {\n${body}};`;
|
|
467
599
|
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
468
600
|
const factory = new Function('K', 'H', source);
|
|
469
601
|
return factory(constants, helpers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransformCompiler.js","sourceRoot":"","sources":["../../src/TransformCompiler.ts"],"names":[],"mappings":";;;AAAA,uCAAmD;AACnD,mCAA6C;AAE7C,mCAAoC;AAmBpC,iEAAiE;AACjE,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,yFAAyF;AACzF,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,IAAI,UAAU,GAAG,IAAI,CAAC;AACtB,MAAM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,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { defaultMetadataStorage } from './storage';\nimport { TransformationType } from './enums';\nimport { ClassTransformOptions, TransformMetadata, TypeHelpOptions, TypeMetadata, TypeOptions } from './interfaces';\nimport { getGlobal } from './utils';\nimport type { TransformOperationExecutor } from './TransformOperationExecutor';\n\n/**\n * JIT compiler for object transformations.\n *\n * The interpreted transformation (TransformOperationExecutor#transformObject) looks up the metadata storage for\n * every key of every object it transforms: exposed / excluded keys, renamed keys, @Type and @Transform metadata,\n * version and group filters, property descriptors... All of these only depend on the target class and on the\n * transformation options, so for every (transformation type, options, class) combination we resolve them once and\n * generate (with `new Function`) a specialized function that transforms objects of that class.\n *\n * The generated code mirrors the interpreted algorithm step by step, so the result is the same. Whenever a case\n * cannot be compiled (Map values, target maps, a failing metadata lookup, CSP forbidding `new Function`...) the\n * executor falls back to the interpreted transformation.\n */\n\nexport type CompiledTransformer = (executor: TransformOperationExecutor, source: any, value: any, level: number) => any;\n\n/** Max number of different option combinations kept in cache. */\nconst MAX_CACHES = 256;\n/** Max number of unknown keys for which implicit types are cached per compiled class. */\nconst MAX_IMPLICIT_CACHE = 1000;\n\nlet jitEnabled = true;\nconst caches = new Map<string, JitCache>();\n\n/**\n * Enables or disables the compiled (JIT) transformation. Enabled by default.\n * @internal mainly used for testing the compiled and interpreted transformations against each other.\n */\nexport function setJitEnabled(enabled: boolean): void {\n jitEnabled = enabled;\n caches.clear();\n}\n\n/**\n * Returns the cache of compiled transformers for given transformation type and options,\n * or undefined when the options cannot be compiled.\n */\nexport function getJitCache(transformationType: TransformationType, options: ClassTransformOptions): JitCache {\n if (!jitEnabled || !options || options.targetMaps) return undefined;\n\n // the global storage may have been created by another (older) copy of the library\n const storage: any = defaultMetadataStorage;\n if (typeof storage.version !== 'number' || typeof storage.getMetadataPropertyNames !== 'function') return undefined;\n\n const fingerprint = getFingerprint(transformationType, options);\n let cache = caches.get(fingerprint);\n if (!cache) {\n if (caches.size >= MAX_CACHES) caches.clear();\n cache = new JitCache();\n caches.set(fingerprint, cache);\n }\n return cache;\n}\n\n/**\n * Builds a key from everything in the options that influences the generated code.\n */\nfunction getFingerprint(transformationType: TransformationType, o: ClassTransformOptions): string {\n return (\n String(transformationType) +\n '|' +\n String(o.strategy || '') +\n '|' +\n (o.excludeExtraneousValues ? '1' : '0') +\n (o.ignoreDecorators ? '1' : '0') +\n (o.enableCircularCheck ? '1' : '0') +\n (o.enableImplicitConversion ? '1' : '0') +\n (o.exposeDefaultValues ? '1' : '0') +\n (o.exposeUnsetFields ? '1' : '0') +\n '|' +\n typeof o.version +\n ':' +\n String(o.version) +\n '|' +\n (o.groups && o.groups.length ? JSON.stringify(o.groups) : '') +\n '|' +\n (o.excludePrefixes && o.excludePrefixes.length ? JSON.stringify(o.excludePrefixes) : '')\n );\n}\n\n/**\n * Compiled transformers of each class for one transformation type and set of options.\n */\nexport class JitCache {\n private version = -1;\n private classes = new WeakMap<Function, CompiledTransformer | null>();\n private anonymous: CompiledTransformer | null | undefined = undefined;\n\n /**\n * Returns the compiled transformer for given target type (undefined when it can not be compiled).\n */\n get(targetType: any, executor: TransformOperationExecutor): CompiledTransformer | undefined {\n // metadata changed since the transformers were compiled: drop them all\n const version = defaultMetadataStorage.version;\n if (version !== this.version) {\n this.version = version;\n this.classes = new WeakMap();\n this.anonymous = undefined;\n }\n\n if (targetType === undefined || targetType === null) {\n if (this.anonymous === undefined) this.anonymous = compileSafe(undefined, executor);\n return this.anonymous || undefined;\n }\n if (typeof targetType !== 'function') return undefined;\n\n let compiled = this.classes.get(targetType);\n if (compiled === undefined) {\n compiled = compileSafe(targetType, executor);\n this.classes.set(targetType, compiled);\n }\n return compiled || undefined;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Runtime helpers used by the generated code\n// ---------------------------------------------------------------------------\n\nfunction getPropertyDescriptor(obj: any, key: PropertyKey): PropertyDescriptor | undefined {\n const descriptor = Object.getOwnPropertyDescriptor(obj, key);\n if (descriptor) return descriptor;\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype ? getPropertyDescriptor(prototype, key) : undefined;\n}\n\nconst helpers = {\n /**\n * Same as the primitive branches of TransformOperationExecutor#transform (value is not an object).\n */\n conv(value: any, targetType: any): any {\n if (targetType === String) return value === null || value === undefined ? value : String(value);\n if (targetType === Number) return value === null || value === undefined ? value : Number(value);\n if (targetType === Boolean) return value === null || value === undefined ? value : Boolean(value);\n if (targetType === Date) return value === null || value === undefined ? value : new Date(value);\n if (!!getGlobal().Buffer && targetType === Buffer) {\n return value === null || value === undefined ? value : Buffer.from(value);\n }\n return value;\n },\n\n /**\n * True when the prototype has a property without setter (getter / method) for given key.\n */\n descSkip(prototype: any, key: string): boolean {\n if (!(key in prototype)) return false;\n const descriptor = getPropertyDescriptor(prototype, key);\n return !!(descriptor && !descriptor.set);\n },\n\n prefixBlocked(key: string, prefixes: string[]): boolean {\n return !prefixes.every(prefix => key.substr(0, prefix.length) !== prefix);\n },\n\n implicitType(cache: Map<string, any>, target: Function, key: string): any {\n let type = cache.get(key);\n if (type === undefined && !cache.has(key)) {\n type = (Reflect as any).getMetadata('design:type', target.prototype, key) || undefined;\n if (cache.size < MAX_IMPLICIT_CACHE) cache.set(key, type);\n }\n return type;\n },\n\n /**\n * Resolves the type of a property having a @Type() with discriminator, exactly like the interpreted version.\n */\n discType(\n executor: TransformOperationExecutor,\n metadata: TypeMetadata,\n value: any,\n valueKey: string,\n subValue: any,\n newValue: any,\n propertyName: string\n ): any {\n const options: TypeHelpOptions = { newObject: newValue, object: value, property: propertyName };\n const newType = metadata.typeFunction ? metadata.typeFunction(options) : metadata.reflectedType;\n const transformationType: TransformationType = (executor as any).transformationType;\n let type: any = undefined;\n if (!(value[valueKey] instanceof Array)) {\n if (transformationType === TransformationType.PLAIN_TO_CLASS) {\n type = metadata.options.discriminator.subTypes.find(subType => {\n if (subValue && subValue instanceof Object && metadata.options.discriminator.property in subValue) {\n return subType.name === subValue[metadata.options.discriminator.property];\n }\n });\n type === undefined ? (type = newType) : (type = type.value);\n if (!metadata.options.keepDiscriminatorProperty) {\n if (subValue && subValue instanceof Object && metadata.options.discriminator.property in subValue) {\n delete subValue[metadata.options.discriminator.property];\n }\n }\n }\n if (transformationType === TransformationType.CLASS_TO_CLASS) {\n type = subValue.constructor;\n }\n if (transformationType === TransformationType.CLASS_TO_PLAIN) {\n if (subValue) {\n subValue[metadata.options.discriminator.property] = metadata.options.discriminator.subTypes.find(\n subType => subType.value === subValue.constructor\n ).name;\n }\n }\n } else {\n type = metadata;\n }\n return type;\n },\n};\n\n// ---------------------------------------------------------------------------\n// Compiler\n// ---------------------------------------------------------------------------\n\nfunction compileSafe(target: Function | undefined, executor: TransformOperationExecutor): CompiledTransformer | null {\n try {\n // objects extending Map are filled using `set`, leave them to the interpreter\n if (target && (target === Map || target.prototype instanceof Map)) return null;\n return compile(target, executor);\n } catch (error) {\n // any failure (CSP forbidding `new Function`, a throwing metadata lookup...) => use the interpreter,\n // which reproduces the error when it applies\n return null;\n }\n}\n\ntype TypeKind = 'none' | 'string' | 'number' | 'boolean' | 'date' | 'dynamic';\n\nfunction kindOfStaticType(type: any): TypeKind {\n if (type === undefined) return 'none';\n if (type === String) return 'string';\n if (type === Number) return 'number';\n if (type === Boolean) return 'boolean';\n if (type === Date) return 'date';\n if (typeof Buffer !== 'undefined' && type === Buffer) return 'dynamic';\n // any other class: primitives are returned as they are\n return 'none';\n}\n\nfunction compile(target: Function | undefined, executor: TransformOperationExecutor): CompiledTransformer {\n // the compiler reuses private members of the executor (options, key resolution, version & group checks)\n const ex: any = executor;\n const storage = defaultMetadataStorage;\n const options: ClassTransformOptions = ex.options;\n const transformationType: TransformationType = ex.transformationType;\n const isPlainToClass = transformationType === TransformationType.PLAIN_TO_CLASS;\n const isClassToClass = transformationType === TransformationType.CLASS_TO_CLASS;\n const isClassToPlain = transformationType === TransformationType.CLASS_TO_PLAIN;\n const createsInstance = isPlainToClass || isClassToClass;\n const targetPrototype = target ? target.prototype : Object.prototype;\n\n // constants made available to the generated code\n const constants: any[] = [];\n const ref = (value: any): string => {\n let index = constants.indexOf(value);\n if (index === -1) index = constants.push(value) - 1;\n return 'k' + String(index);\n };\n const str = (value: string): string => JSON.stringify(value);\n let labelCounter = 0;\n\n // custom @Transform() functions applied to a key, filtered exactly like applyCustomTransformations\n const getTransforms = (key: string): TransformMetadata[] => {\n let metadatas = storage.findTransformMetadatas(target, key, transformationType);\n if (options.version !== undefined) {\n metadatas = metadatas.filter(\n metadata => !metadata.options || ex.checkVersion(metadata.options.since, metadata.options.until)\n );\n }\n if (options.groups && options.groups.length) {\n metadatas = metadatas.filter(metadata => !metadata.options || ex.checkGroups(metadata.options.groups));\n } else {\n metadatas = metadatas.filter(\n metadata => !metadata.options || !metadata.options.groups || !metadata.options.groups.length\n );\n }\n return metadatas;\n };\n\n const emitTransforms = (metadatas: TransformMetadata[], keyExpr: string): string =>\n metadatas\n .map(\n metadata =>\n `fv = ${ref(metadata)}.transformFn({ value: fv, key: ${keyExpr}, obj: value, type: ${String(\n transformationType\n )}, options: ex.options });\\n`\n )\n .join('');\n\n const emitAssign = (newKeyExpr: string): string => {\n const assign = `if (nvm) newValue.set(${newKeyExpr}, fv); else newValue[${newKeyExpr}] = fv;\\n`;\n return options.exposeUnsetFields ? assign : `if (fv !== undefined) { ${assign} }\\n`;\n };\n\n /**\n * Transformation of `fv` (sub value) into `fv`: primitives are converted inline,\n * everything else goes through TransformOperationExecutor#transform.\n */\n const emitChild = (\n typeExpr: string,\n kind: TypeKind,\n arrayTypeExpr: string,\n isMapExpr: string,\n valueKeyExpr: string\n ): string => {\n let primitive: string;\n const convert = (expr: string) => (isMapExpr === 'true' ? 'fv' : `(${isMapExpr} || fv == null ? fv : ${expr})`);\n switch (kind) {\n case 'none':\n primitive = 'fv';\n break;\n case 'string':\n primitive = convert('String(fv)');\n break;\n case 'number':\n primitive = convert('Number(fv)');\n break;\n case 'boolean':\n primitive = convert('Boolean(fv)');\n break;\n case 'date':\n primitive = convert('new Date(fv)');\n break;\n default:\n primitive = isMapExpr === 'true' ? 'fv' : `(${isMapExpr} ? fv : H.conv(fv, ${typeExpr}))`;\n }\n return (\n `if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\\n` +\n `else { fv = ex.transform(source ? source[${valueKeyExpr}] : undefined, fv, ${typeExpr}, ${arrayTypeExpr}, ${isMapExpr}, level + 1); }\\n`\n );\n };\n\n /**\n * Generates the transformation of a single key. `key` is the static key, or undefined for the\n * generic code handling (at runtime) keys without any metadata, stored in the `key` variable.\n */\n const emitKey = (key: string | undefined): string => {\n if (key === '__proto__' || key === 'constructor') return '';\n const label = 'p' + String(labelCounter++);\n const keyExpr = key === undefined ? 'key' : str(key);\n\n // key renaming\n let newValueKey = key;\n let propertyName = key;\n if (key !== undefined && !options.ignoreDecorators && target) {\n if (isPlainToClass) {\n const exposeMetadata = storage.findExposeMetadataByCustomName(target, key);\n if (exposeMetadata) {\n propertyName = exposeMetadata.propertyName;\n newValueKey = exposeMetadata.propertyName;\n }\n } else {\n const exposeMetadata = storage.findExposeMetadata(target, key);\n if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {\n newValueKey = exposeMetadata.options.name;\n }\n }\n }\n const newKeyExpr = key === undefined ? 'key' : str(newValueKey);\n const propertyExpr = key === undefined ? 'key' : str(propertyName);\n const transformKey = isPlainToClass ? newValueKey : key;\n const transformKeyExpr = isPlainToClass ? newKeyExpr : keyExpr;\n\n let code = `${label}: {\\n`;\n\n // sub value\n code += isPlainToClass\n ? `const sv = value[${keyExpr}];\\n`\n : `const sv = value[${keyExpr}] instanceof Function ? value[${keyExpr}]() : value[${keyExpr}];\\n`;\n\n // type\n let typeExpr = 'undefined';\n let kind: TypeKind = 'none';\n let isMapExpr = 'sv instanceof Map';\n let arrayTypeExpr = 'undefined';\n const typeMetadata = key !== undefined && target ? storage.findTypeMetadata(target, propertyName) : undefined;\n if (typeMetadata) {\n const typeOptions: TypeOptions = typeMetadata.options;\n if (\n typeOptions &&\n typeOptions.discriminator &&\n typeOptions.discriminator.property &&\n typeOptions.discriminator.subTypes\n ) {\n code += `const type = H.discType(ex, ${ref(\n typeMetadata\n )}, value, ${keyExpr}, sv, newValue, ${propertyExpr});\\n`;\n typeExpr = 'type';\n kind = 'dynamic';\n } else if (typeMetadata.typeFunction) {\n code += `const type = ${ref(\n typeMetadata\n )}.typeFunction({ newObject: newValue, object: value, property: ${propertyExpr} });\\n`;\n typeExpr = 'type';\n kind = 'dynamic';\n } else {\n typeExpr = ref(typeMetadata.reflectedType);\n kind = kindOfStaticType(typeMetadata.reflectedType);\n }\n if (typeMetadata.reflectedType === Map) isMapExpr = 'true';\n if (typeMetadata.reflectedType !== undefined) {\n arrayTypeExpr = `(Array.isArray(value[${keyExpr}]) ? ${ref(typeMetadata.reflectedType)} : undefined)`;\n }\n } else if (target && options.enableImplicitConversion && isPlainToClass) {\n if (key === undefined) {\n code += `const type = H.implicitType(${ref(new Map())}, ${ref(target)}, key);\\n`;\n typeExpr = 'type';\n kind = 'dynamic';\n } else {\n const reflectedType = (Reflect as any).getMetadata('design:type', target.prototype, propertyName);\n if (reflectedType) {\n typeExpr = ref(reflectedType);\n kind = kindOfStaticType(reflectedType);\n }\n }\n }\n if (isMapExpr !== 'true') code += `const ism = ${isMapExpr};\\n`;\n const isMapVar = isMapExpr === 'true' ? 'true' : 'ism';\n\n // skip keys matching a getter / method of the new value\n if (createsInstance) {\n const staticSkip =\n key === undefined ? `H.descSkip(proto, key)` : String(helpers.descSkip(targetPrototype, newValueKey));\n code +=\n `const proto = newValue.constructor.prototype;\\n` +\n `if (proto && ((proto === ${ref(targetPrototype)} ? ${staticSkip} : H.descSkip(proto, ${newKeyExpr})) ` +\n `|| newValue[${newKeyExpr}] instanceof Function)) break ${label};\\n`;\n }\n\n const transforms = key === undefined ? [] : getTransforms(transformKey);\n\n let main = 'let fv;\\n';\n if (isClassToPlain) {\n main += `fv = value[${transformKeyExpr}];\\n`;\n main += emitTransforms(transforms, transformKeyExpr);\n main += `fv = value[${transformKeyExpr}] === fv ? sv : fv;\\n`;\n main += emitChild(typeExpr, kind, arrayTypeExpr, isMapVar, keyExpr);\n } else {\n const transformSub =\n 'fv = sv;\\n' +\n emitChild(typeExpr, kind, arrayTypeExpr, isMapVar, keyExpr) +\n emitTransforms(transforms, transformKeyExpr);\n main += options.exposeDefaultValues\n ? `if (sv === undefined) { fv = newValue[${newKeyExpr}]; } else {\\n${transformSub}}\\n`\n : transformSub;\n }\n main += emitAssign(newKeyExpr);\n\n if (options.enableCircularCheck) {\n code += `if (!ex.recursionStack.has(sv)) {\\n${main}}\\n`;\n if (isClassToClass) {\n const circularTransforms = key === undefined ? [] : getTransforms(key);\n code += `else {\\nlet fv = sv;\\n${emitTransforms(circularTransforms, keyExpr)}${emitAssign(newKeyExpr)}}\\n`;\n }\n } else {\n code += main;\n }\n\n return code + '}\\n';\n };\n\n // -------------------------------------------------------------------------\n // keys to transform\n // -------------------------------------------------------------------------\n\n let strategy = storage.getStrategy(target);\n if (strategy === 'none') strategy = options.strategy || 'exposeAll';\n // with exposeAll, keys of the transformed object are used (see TransformOperationExecutor#getKeys)\n const dynamicKeys = strategy === 'exposeAll' && !(target && options.excludeExtraneousValues);\n // keys always transformed (exposed properties), or all keys when they are not dynamic\n const staticKeys: string[] = ex.getKeys(target, {}, false);\n\n let body = `const newValue = source ? source : ${\n createsInstance && target ? `new ${ref(target)}()` : '{}'\n };\\nconst nvm = newValue instanceof Map;\\n`;\n\n if (!dynamicKeys) {\n for (const key of staticKeys) body += emitKey(key);\n } else {\n // keys having metadata get their own compiled code, other keys use the generic code\n const knownKeys = new Set<string>(staticKeys);\n if (target) {\n storage.getMetadataPropertyNames(target).forEach(name => knownKeys.add(name));\n storage.getExposedMetadatas(target).forEach(metadata => {\n if (metadata.options && typeof metadata.options.name === 'string') knownKeys.add(metadata.options.name);\n });\n }\n knownKeys.delete('__proto__');\n knownKeys.delete('constructor');\n\n const extraKeys = staticKeys.filter(key => key !== '__proto__' && key !== 'constructor');\n // exposed keys missing from the object are transformed after the object keys\n extraKeys.forEach((key, index) => {\n body += `const has${String(index)} = PIE.call(value, ${str(key)});\\n`;\n });\n\n let cases = `case \"__proto__\": case \"constructor\": continue;\\n`;\n knownKeys.forEach(key => {\n const probe: Record<string, any> = {};\n probe[key] = true;\n const blocked = !ex.getKeys(target, probe, false).includes(key);\n cases += blocked ? `case ${str(key)}: continue;\\n` : `case ${str(key)}: ${emitKey(key)}continue;\\n`;\n });\n\n body += `const keys = Object.keys(value);\\n`;\n body += `for (let i = 0; i < keys.length; i++) {\\nconst key = keys[i];\\nswitch (key) {\\n${cases}}\\n`;\n if (options.excludePrefixes && options.excludePrefixes.length) {\n body += `if (H.prefixBlocked(key, ${ref(options.excludePrefixes.slice())})) continue;\\n`;\n }\n body += emitKey(undefined);\n body += '}\\n';\n\n extraKeys.forEach((key, index) => {\n body += `if (!has${String(index)}) {\\n${emitKey(key)}}\\n`;\n });\n }\n body += 'return newValue;\\n';\n\n const declarations = constants.map((_, index) => `const k${index} = K[${index}];\\n`).join('');\n const source =\n `'use strict';\\n${declarations}const PIE = Object.prototype.propertyIsEnumerable;\\n` +\n `return function compiledTransform(ex, source, value, level) {\\n${body}};`;\n\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n const factory = new Function('K', 'H', source) as (constants: any[], h: typeof helpers) => CompiledTransformer;\n return factory(constants, helpers);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TransformCompiler.js","sourceRoot":"","sources":["../../src/TransformCompiler.ts"],"names":[],"mappings":";;;AAAA,uCAAmD;AACnD,mCAA6C;AAE7C,mCAAoC;AAmBpC,iEAAiE;AACjE,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,yFAAyF;AACzF,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,IAAI,UAAU,GAAG,IAAI,CAAC;AACtB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;AAE3C;;;GAGG;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AI,CAAC,EAAE,CAAC,CAAC;IAC9F,MAAM,MAAM,GACV,kBAAkB,YAAY,0FAA0F,gBAAgB,CAAC,IAAI,CAC3I,EAAE,CACH,EAAE,GAAG,kEAAkE,IAAI,IAAI,CAAC;IAEnF,8DAA8D;IAC9D,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAiE,CAAC;IAC/G,OAAO,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { defaultMetadataStorage } from './storage';\nimport { TransformationType } from './enums';\nimport { ClassTransformOptions, TransformMetadata, TypeHelpOptions, TypeMetadata, TypeOptions } from './interfaces';\nimport { getGlobal } from './utils';\nimport type { TransformOperationExecutor } from './TransformOperationExecutor';\n\n/**\n * JIT compiler for object transformations.\n *\n * The interpreted transformation (TransformOperationExecutor#transformObject) looks up the metadata storage for\n * every key of every object it transforms: exposed / excluded keys, renamed keys, @Type and @Transform metadata,\n * version and group filters, property descriptors... All of these only depend on the target class and on the\n * transformation options, so for every (transformation type, options, class) combination we resolve them once and\n * generate (with `new Function`) a specialized function that transforms objects of that class.\n *\n * The generated code mirrors the interpreted algorithm step by step, so the result is the same. Whenever a case\n * cannot be compiled (Map values, target maps, a failing metadata lookup, CSP forbidding `new Function`...) the\n * executor falls back to the interpreted transformation.\n */\n\nexport type CompiledTransformer = (executor: TransformOperationExecutor, source: any, value: any, level: number) => any;\n\n/** Max number of different option combinations kept in cache. */\nconst MAX_CACHES = 256;\n/** Max number of unknown keys for which implicit types are cached per compiled class. */\nconst MAX_IMPLICIT_CACHE = 1000;\n\nlet jitEnabled = true;\nconst caches = new Map<string, JitCache>();\n\n/**\n * Enables or disables the compiled (JIT) transformation. Enabled by default.\n * @internal mainly used for testing the compiled and interpreted transformations against each other.\n */\nexport function setJitEnabled(enabled: boolean): void {\n jitEnabled = enabled;\n caches.clear();\n}\n\n/**\n * Returns the cache of compiled transformers for given transformation type and options,\n * or undefined when the options cannot be compiled.\n */\nexport function getJitCache(transformationType: TransformationType, options: ClassTransformOptions): JitCache {\n if (!jitEnabled || !options || options.targetMaps) return undefined;\n\n // the global storage may have been created by another (older) copy of the library\n const storage: any = defaultMetadataStorage;\n if (typeof storage.version !== 'number' || typeof storage.getMetadataPropertyNames !== 'function') return undefined;\n\n const fingerprint = getFingerprint(transformationType, options);\n let cache = caches.get(fingerprint);\n if (!cache) {\n if (caches.size >= MAX_CACHES) caches.clear();\n cache = new JitCache();\n caches.set(fingerprint, cache);\n }\n return cache;\n}\n\n/**\n * Builds a key from everything in the options that influences the generated code.\n */\nfunction getFingerprint(transformationType: TransformationType, o: ClassTransformOptions): string {\n return (\n String(transformationType) +\n '|' +\n String(o.strategy || '') +\n '|' +\n (o.excludeExtraneousValues ? '1' : '0') +\n (o.ignoreDecorators ? '1' : '0') +\n (o.enableCircularCheck ? '1' : '0') +\n (o.enableImplicitConversion ? '1' : '0') +\n (o.exposeDefaultValues ? '1' : '0') +\n (o.exposeUnsetFields ? '1' : '0') +\n '|' +\n typeof o.version +\n ':' +\n String(o.version) +\n '|' +\n (o.groups && o.groups.length ? JSON.stringify(o.groups) : '') +\n '|' +\n (o.excludePrefixes && o.excludePrefixes.length ? JSON.stringify(o.excludePrefixes) : '')\n );\n}\n\n/**\n * Compiled transformers of each class for one transformation type and set of options.\n */\nexport class JitCache {\n private version = -1;\n private classes = new WeakMap<Function, CompiledTransformer | null>();\n private directs = new WeakMap<Function, DirectTransformer | null>();\n private anonymous: CompiledTransformer | null | undefined = undefined;\n\n /**\n * Returns the compiled transformer to call directly for elements of arrays of given type, or null.\n */\n direct(targetType: Function, executor: TransformOperationExecutor): DirectTransformer | null {\n // get() first: it drops everything when metadata changed\n const transformer = this.get(targetType, executor);\n if (!transformer) return null;\n let direct = this.directs.get(targetType);\n if (direct === undefined || direct.transformer !== transformer) {\n const resolved = helpers.resolveChild(executor, targetType);\n direct = resolved ? new DirectTransformer(resolved, helpers.directPrototype(targetType)) : null;\n this.directs.set(targetType, direct);\n }\n return direct;\n }\n\n /**\n * Returns the compiled transformer for given target type (undefined when it can not be compiled).\n */\n get(targetType: any, executor: TransformOperationExecutor): CompiledTransformer | undefined {\n // metadata changed since the transformers were compiled: drop them all\n const version = defaultMetadataStorage.version;\n if (version !== this.version) {\n this.version = version;\n this.classes = new WeakMap();\n this.directs = new WeakMap();\n this.anonymous = undefined;\n }\n\n if (targetType === undefined || targetType === null) {\n if (this.anonymous === undefined) this.anonymous = compileSafe(undefined, executor);\n return this.anonymous || undefined;\n }\n if (typeof targetType !== 'function') return undefined;\n\n let compiled = this.classes.get(targetType);\n if (compiled === undefined) {\n compiled = compileSafe(targetType, executor);\n this.classes.set(targetType, compiled);\n }\n return compiled || undefined;\n }\n}\n\n/**\n * Compiled transformer of a type, with the check of the values TransformOperationExecutor#transform would\n * transform with it: plain objects and instances of the type which are not arrays, sets, dates, maps, buffers or\n * promises.\n */\nexport class DirectTransformer {\n constructor(readonly transformer: CompiledTransformer, private readonly prototype: any) {}\n\n accepts(value: any): boolean {\n if (value === null || typeof value !== 'object') return false;\n const prototype = Object.getPrototypeOf(value);\n return (prototype === Object.prototype || prototype === this.prototype) && typeof value.then !== 'function';\n }\n}\n\n// ---------------------------------------------------------------------------\n// Runtime helpers used by the generated code\n// ---------------------------------------------------------------------------\n\nfunction getPropertyDescriptor(obj: any, key: PropertyKey): PropertyDescriptor | undefined {\n const descriptor = Object.getOwnPropertyDescriptor(obj, key);\n if (descriptor) return descriptor;\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype ? getPropertyDescriptor(prototype, key) : undefined;\n}\n\nconst helpers = {\n /**\n * Same as the primitive branches of TransformOperationExecutor#transform (value is not an object).\n */\n conv(value: any, targetType: any): any {\n if (targetType === String) return value === null || value === undefined ? value : String(value);\n if (targetType === Number) return value === null || value === undefined ? value : Number(value);\n if (targetType === Boolean) return value === null || value === undefined ? value : Boolean(value);\n if (targetType === Date) return value === null || value === undefined ? value : new Date(value);\n if (!!getGlobal().Buffer && targetType === Buffer) {\n return value === null || value === undefined ? value : Buffer.from(value);\n }\n return value;\n },\n\n /**\n * True when the prototype has a property without setter (getter / method) for given key.\n */\n descSkip(prototype: any, key: string): boolean {\n if (!(key in prototype)) return false;\n const descriptor = getPropertyDescriptor(prototype, key);\n return !!(descriptor && !descriptor.set);\n },\n\n /**\n * Returns the compiled transformer to call directly for objects of given (resolved) type, or null when\n * TransformOperationExecutor#transform would not take its object branch with this type as target.\n */\n resolveChild(executor: TransformOperationExecutor, type: any): CompiledTransformer | null {\n if (typeof type !== 'function' || type === String || type === Number || type === Boolean || type === Date) {\n return null;\n }\n if (!!getGlobal().Buffer && type === Buffer) return null;\n const jit: JitCache = (executor as any).jit;\n return (jit && jit.get(type, executor)) || null;\n },\n\n /**\n * Prototype of the instances that can be passed directly to the compiled transformer of given type, besides plain\n * objects: null when instances of the type are arrays, sets, dates, maps or buffers (handled by other branches).\n */\n directPrototype(type: Function): any {\n const prototype = type.prototype;\n if (!prototype) return null;\n const excluded: Function[] = [Array, Set, Date, Map];\n if (getGlobal().Buffer) excluded.push(Buffer);\n for (const cls of excluded) {\n if (prototype === cls.prototype || prototype instanceof cls) return null;\n }\n return prototype;\n },\n\n /** Same as instantiateArrayType in TransformOperationExecutor. */\n newArray(arrayType: any): any {\n if (!arrayType) return [];\n const array = new arrayType();\n if (!(array instanceof Set) && !('push' in array)) {\n return [];\n }\n return array;\n },\n\n prefixBlocked(key: string, prefixes: string[]): boolean {\n return !prefixes.every(prefix => key.substr(0, prefix.length) !== prefix);\n },\n\n implicitType(cache: Map<string, any>, target: Function, key: string): any {\n let type = cache.get(key);\n if (type === undefined && !cache.has(key)) {\n type = (Reflect as any).getMetadata('design:type', target.prototype, key) || undefined;\n if (cache.size < MAX_IMPLICIT_CACHE) cache.set(key, type);\n }\n return type;\n },\n\n /**\n * Resolves the type of a property having a @Type() with discriminator, exactly like the interpreted version.\n */\n discType(\n executor: TransformOperationExecutor,\n metadata: TypeMetadata,\n value: any,\n valueKey: string,\n subValue: any,\n newValue: any,\n propertyName: string\n ): any {\n const options: TypeHelpOptions = { newObject: newValue, object: value, property: propertyName };\n const newType = metadata.typeFunction ? metadata.typeFunction(options) : metadata.reflectedType;\n const transformationType: TransformationType = (executor as any).transformationType;\n let type: any = undefined;\n if (!(value[valueKey] instanceof Array)) {\n if (transformationType === TransformationType.PLAIN_TO_CLASS) {\n type = metadata.options.discriminator.subTypes.find(subType => {\n if (subValue && subValue instanceof Object && metadata.options.discriminator.property in subValue) {\n return subType.name === subValue[metadata.options.discriminator.property];\n }\n });\n type === undefined ? (type = newType) : (type = type.value);\n if (!metadata.options.keepDiscriminatorProperty) {\n if (subValue && subValue instanceof Object && metadata.options.discriminator.property in subValue) {\n delete subValue[metadata.options.discriminator.property];\n }\n }\n }\n if (transformationType === TransformationType.CLASS_TO_CLASS) {\n type = subValue.constructor;\n }\n if (transformationType === TransformationType.CLASS_TO_PLAIN) {\n if (subValue) {\n subValue[metadata.options.discriminator.property] = metadata.options.discriminator.subTypes.find(\n subType => subType.value === subValue.constructor\n ).name;\n }\n }\n } else {\n type = metadata;\n }\n return type;\n },\n};\n\n// ---------------------------------------------------------------------------\n// Compiler\n// ---------------------------------------------------------------------------\n\nfunction compileSafe(target: Function | undefined, executor: TransformOperationExecutor): CompiledTransformer | null {\n try {\n // objects extending Map are filled using `set`, leave them to the interpreter\n if (target && (target === Map || target.prototype instanceof Map)) return null;\n return compile(target, executor);\n } catch (error) {\n // any failure (CSP forbidding `new Function`, a throwing metadata lookup...) => use the interpreter,\n // which reproduces the error when it applies\n return null;\n }\n}\n\ntype TypeKind = 'none' | 'string' | 'number' | 'boolean' | 'date' | 'dynamic';\n\nfunction kindOfStaticType(type: any): TypeKind {\n if (type === undefined) return 'none';\n if (type === String) return 'string';\n if (type === Number) return 'number';\n if (type === Boolean) return 'boolean';\n if (type === Date) return 'date';\n if (typeof Buffer !== 'undefined' && type === Buffer) return 'dynamic';\n // any other class: primitives are returned as they are\n return 'none';\n}\n\nfunction compile(target: Function | undefined, executor: TransformOperationExecutor): CompiledTransformer {\n // the compiler reuses private members of the executor (options, key resolution, version & group checks)\n const ex: any = executor;\n const storage = defaultMetadataStorage;\n const options: ClassTransformOptions = ex.options;\n const transformationType: TransformationType = ex.transformationType;\n const isPlainToClass = transformationType === TransformationType.PLAIN_TO_CLASS;\n const isClassToClass = transformationType === TransformationType.CLASS_TO_CLASS;\n const isClassToPlain = transformationType === TransformationType.CLASS_TO_PLAIN;\n const createsInstance = isPlainToClass || isClassToClass;\n const targetPrototype = target ? target.prototype : Object.prototype;\n\n // constants made available to the generated code\n const constants: any[] = [];\n const ref = (value: any): string => {\n let index = constants.indexOf(value);\n if (index === -1) index = constants.push(value) - 1;\n return 'k' + String(index);\n };\n const str = (value: string): string => JSON.stringify(value);\n let labelCounter = 0;\n // per call site caches of the last resolved child type => compiled transformer\n const siteDeclarations: string[] = [];\n const circularCheck = !!options.enableCircularCheck;\n\n // custom @Transform() functions applied to a key, filtered exactly like applyCustomTransformations\n const getTransforms = (key: string): TransformMetadata[] => {\n let metadatas = storage.findTransformMetadatas(target, key, transformationType);\n if (options.version !== undefined) {\n metadatas = metadatas.filter(\n metadata => !metadata.options || ex.checkVersion(metadata.options.since, metadata.options.until)\n );\n }\n if (options.groups && options.groups.length) {\n metadatas = metadatas.filter(metadata => !metadata.options || ex.checkGroups(metadata.options.groups));\n } else {\n metadatas = metadatas.filter(\n metadata => !metadata.options || !metadata.options.groups || !metadata.options.groups.length\n );\n }\n return metadatas;\n };\n\n const emitTransforms = (metadatas: TransformMetadata[], keyExpr: string): string =>\n metadatas\n .map(\n metadata =>\n `fv = ${ref(metadata)}.transformFn({ value: fv, key: ${keyExpr}, obj: value, type: ${String(\n transformationType\n )}, options: ex.options });\\n`\n )\n .join('');\n\n const emitAssign = (newKeyExpr: string): string => {\n const assign = `if (nvm) newValue.set(${newKeyExpr}, fv); else newValue[${newKeyExpr}] = fv;\\n`;\n return options.exposeUnsetFields ? assign : `if (fv !== undefined) { ${assign} }\\n`;\n };\n\n /**\n * Transformation of `fv` (sub value) into `fv`, same as TransformOperationExecutor#transform:\n * - primitives are converted inline,\n * - plain objects (or instances of the target type) and arrays of them, when the type has a compiled transformer,\n * are passed directly to that compiled transformer,\n * - everything else goes through TransformOperationExecutor#transform.\n */\n const emitChild = (\n typeExpr: string,\n kind: TypeKind,\n arrayTypeExpr: string,\n isMapExpr: string,\n valueKeyExpr: string\n ): string => {\n let primitive: string;\n const convert = (expr: string) => (isMapExpr === 'true' ? 'fv' : `(${isMapExpr} || fv == null ? fv : ${expr})`);\n switch (kind) {\n case 'none':\n primitive = 'fv';\n break;\n case 'string':\n primitive = convert('String(fv)');\n break;\n case 'number':\n primitive = convert('Number(fv)');\n break;\n case 'boolean':\n primitive = convert('Boolean(fv)');\n break;\n case 'date':\n primitive = convert('new Date(fv)');\n break;\n default:\n primitive = isMapExpr === 'true' ? 'fv' : `(${isMapExpr} ? fv : H.conv(fv, ${typeExpr}))`;\n }\n const slow = `fv = ex.transform(source ? source[${valueKeyExpr}] : undefined, fv, ${typeExpr}, ${arrayTypeExpr}, ${isMapExpr}, level + 1);`;\n\n // types which can never have a compiled transformer: no direct call\n if (kind !== 'none' && kind !== 'dynamic') {\n return `if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\\nelse { ${slow} }\\n`;\n }\n if (typeExpr === 'undefined') {\n return `if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\\nelse { ${slow} }\\n`;\n }\n\n const site = String(siteDeclarations.length);\n const sT = 'sT' + site; // last type seen at this call site\n const sF = 'sF' + site; // its compiled transformer (null: not directly callable)\n const sP = 'sP' + site; // prototype of instances which can be passed directly\n siteDeclarations.push(`let ${sT} = UNSET, ${sF} = null, ${sP} = null;\\n`);\n\n const callDirect = (valueExpr: string, levelExpr: string) =>\n circularCheck\n ? `(ex.recursionStack.add(${valueExpr}), r = ${sF}(ex, undefined, ${valueExpr}, ${levelExpr}), ex.recursionStack.delete(${valueExpr}), r)`\n : `${sF}(ex, undefined, ${valueExpr}, ${levelExpr})`;\n const isDirect = (valueExpr: string) =>\n `((pp = Object.getPrototypeOf(${valueExpr})) === OP || pp === ${sP}) && typeof ${valueExpr}.then !== 'function'`;\n\n // array branch of TransformOperationExecutor#transform, with forEach and the element type checks unrolled\n const newArray = isPlainToClass && arrayTypeExpr !== 'undefined' ? `H.newArray(${arrayTypeExpr})` : '[]';\n const add = (valueExpr: string) =>\n newArray === '[]' ? `arr.push(${valueExpr});` : `if (isSet) arr.add(${valueExpr}); else arr.push(${valueExpr});`;\n let arrayCode =\n `const n = fv.length;\\nconst arr = ${newArray};\\n` +\n (newArray === '[]' ? '' : 'const isSet = arr instanceof Set;\\n') +\n `for (let j = 0; j < n; j++) {\\nif (!(j in fv)) continue;\\nconst el = fv[j];\\n`;\n if (circularCheck) {\n arrayCode += `if (ex.recursionStack.has(el)) { ${isClassToClass ? add('el') : ''} continue; }\\n`;\n }\n arrayCode +=\n `let r;\\n` +\n `if (typeof el !== 'object' || el === null) r = el;\\n` +\n `else if (${isDirect('el')}) r = ${callDirect('el', 'level + 2')};\\n` +\n `else r = ex.transform(undefined, el, t, undefined, el instanceof Map, level + 2);\\n` +\n `${add('r')}\\n}\\nfv = arr;\\n`;\n\n return (\n `if (typeof fv !== 'object' || fv === null) { fv = ${primitive}; }\\n` +\n `else {\\nconst t = ${typeExpr};\\n` +\n `if (t !== ${sT}) { ${sT} = t; ${sF} = H.resolveChild(ex, t); ${sP} = ${sF} === null ? null : H.directPrototype(t); }\\n` +\n `let pp, r;\\n` +\n `if (${sF} === null || source) { ${slow} }\\n` +\n `else if (Array.isArray(fv) && fv.forEach === AFE) {\\n${arrayCode}}\\n` +\n `else if (!${isMapExpr} && ${isDirect('fv')}) { fv = ${callDirect('fv', 'level + 1')}; }\\n` +\n `else { ${slow} }\\n}\\n`\n );\n };\n\n /**\n * Generates the transformation of a single key. `key` is the static key, or undefined for the\n * generic code handling (at runtime) keys without any metadata, stored in the `key` variable.\n */\n const emitKey = (key: string | undefined): string => {\n if (key === '__proto__' || key === 'constructor') return '';\n const label = 'p' + String(labelCounter++);\n const keyExpr = key === undefined ? 'key' : str(key);\n\n // key renaming\n let newValueKey = key;\n let propertyName = key;\n if (key !== undefined && !options.ignoreDecorators && target) {\n if (isPlainToClass) {\n const exposeMetadata = storage.findExposeMetadataByCustomName(target, key);\n if (exposeMetadata) {\n propertyName = exposeMetadata.propertyName;\n newValueKey = exposeMetadata.propertyName;\n }\n } else {\n const exposeMetadata = storage.findExposeMetadata(target, key);\n if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {\n newValueKey = exposeMetadata.options.name;\n }\n }\n }\n const newKeyExpr = key === undefined ? 'key' : str(newValueKey);\n const propertyExpr = key === undefined ? 'key' : str(propertyName);\n const transformKey = isPlainToClass ? newValueKey : key;\n const transformKeyExpr = isPlainToClass ? newKeyExpr : keyExpr;\n\n let code = `${label}: {\\n`;\n\n // sub value\n code += isPlainToClass\n ? `const sv = value[${keyExpr}];\\n`\n : `const sv = value[${keyExpr}] instanceof Function ? value[${keyExpr}]() : value[${keyExpr}];\\n`;\n\n // type\n let typeExpr = 'undefined';\n let kind: TypeKind = 'none';\n let isMapExpr = 'sv instanceof Map';\n let arrayTypeExpr = 'undefined';\n const typeMetadata = key !== undefined && target ? storage.findTypeMetadata(target, propertyName) : undefined;\n if (typeMetadata) {\n const typeOptions: TypeOptions = typeMetadata.options;\n if (\n typeOptions &&\n typeOptions.discriminator &&\n typeOptions.discriminator.property &&\n typeOptions.discriminator.subTypes\n ) {\n code += `const type = H.discType(ex, ${ref(\n typeMetadata\n )}, value, ${keyExpr}, sv, newValue, ${propertyExpr});\\n`;\n typeExpr = 'type';\n kind = 'dynamic';\n } else if (typeMetadata.typeFunction) {\n code += `const type = ${ref(\n typeMetadata\n )}.typeFunction({ newObject: newValue, object: value, property: ${propertyExpr} });\\n`;\n typeExpr = 'type';\n kind = 'dynamic';\n } else {\n typeExpr = ref(typeMetadata.reflectedType);\n kind = kindOfStaticType(typeMetadata.reflectedType);\n }\n if (typeMetadata.reflectedType === Map) isMapExpr = 'true';\n if (typeMetadata.reflectedType !== undefined) {\n arrayTypeExpr = `(Array.isArray(value[${keyExpr}]) ? ${ref(typeMetadata.reflectedType)} : undefined)`;\n }\n } else if (target && options.enableImplicitConversion && isPlainToClass) {\n if (key === undefined) {\n code += `const type = H.implicitType(${ref(new Map())}, ${ref(target)}, key);\\n`;\n typeExpr = 'type';\n kind = 'dynamic';\n } else {\n const reflectedType = (Reflect as any).getMetadata('design:type', target.prototype, propertyName);\n if (reflectedType) {\n typeExpr = ref(reflectedType);\n kind = kindOfStaticType(reflectedType);\n }\n }\n }\n if (isMapExpr !== 'true') code += `const ism = ${isMapExpr};\\n`;\n const isMapVar = isMapExpr === 'true' ? 'true' : 'ism';\n\n // skip keys matching a getter / method of the new value\n if (createsInstance) {\n const staticSkip =\n key === undefined ? `H.descSkip(proto, key)` : String(helpers.descSkip(targetPrototype, newValueKey));\n const descriptorSkip =\n staticSkip === 'false'\n ? `(!protoIsTarget && H.descSkip(proto, ${newKeyExpr}))`\n : staticSkip === 'true'\n ? `(protoIsTarget || H.descSkip(proto, ${newKeyExpr}))`\n : `(protoIsTarget ? ${staticSkip} : H.descSkip(proto, ${newKeyExpr}))`;\n // `newValue.constructor.prototype` is read once per object, but must throw here like the interpreter\n code +=\n `if (nvc == null) newValue.constructor.prototype;\\n` +\n `if (proto && (${descriptorSkip} || newValue[${newKeyExpr}] instanceof Function)) break ${label};\\n`;\n }\n\n const transforms = key === undefined ? [] : getTransforms(transformKey);\n\n let main = 'let fv;\\n';\n if (isClassToPlain) {\n main += `fv = value[${transformKeyExpr}];\\n`;\n main += emitTransforms(transforms, transformKeyExpr);\n main += `fv = value[${transformKeyExpr}] === fv ? sv : fv;\\n`;\n main += emitChild(typeExpr, kind, arrayTypeExpr, isMapVar, keyExpr);\n } else {\n const transformSub =\n 'fv = sv;\\n' +\n emitChild(typeExpr, kind, arrayTypeExpr, isMapVar, keyExpr) +\n emitTransforms(transforms, transformKeyExpr);\n main += options.exposeDefaultValues\n ? `if (sv === undefined) { fv = newValue[${newKeyExpr}]; } else {\\n${transformSub}}\\n`\n : transformSub;\n }\n main += emitAssign(newKeyExpr);\n\n if (options.enableCircularCheck) {\n code += `if (!ex.recursionStack.has(sv)) {\\n${main}}\\n`;\n if (isClassToClass) {\n const circularTransforms = key === undefined ? [] : getTransforms(key);\n code += `else {\\nlet fv = sv;\\n${emitTransforms(circularTransforms, keyExpr)}${emitAssign(newKeyExpr)}}\\n`;\n }\n } else {\n code += main;\n }\n\n return code + '}\\n';\n };\n\n // -------------------------------------------------------------------------\n // keys to transform\n // -------------------------------------------------------------------------\n\n let strategy = storage.getStrategy(target);\n if (strategy === 'none') strategy = options.strategy || 'exposeAll';\n // with exposeAll, keys of the transformed object are used (see TransformOperationExecutor#getKeys)\n const dynamicKeys = strategy === 'exposeAll' && !(target && options.excludeExtraneousValues);\n // keys always transformed (exposed properties), or all keys when they are not dynamic\n const staticKeys: string[] = ex.getKeys(target, {}, false);\n\n let body = `const newValue = source ? source : ${\n createsInstance && target ? `new ${ref(target)}()` : '{}'\n };\\nconst nvm = newValue instanceof Map;\\n`;\n if (createsInstance) {\n body +=\n `const nvc = newValue.constructor;\\nconst proto = nvc == null ? undefined : nvc.prototype;\\n` +\n `const protoIsTarget = proto === ${ref(targetPrototype)};\\n`;\n }\n\n if (!dynamicKeys) {\n for (const key of staticKeys) body += emitKey(key);\n } else {\n // keys having metadata get their own compiled code, other keys use the generic code\n const knownKeys = new Set<string>(staticKeys);\n if (target) {\n storage.getMetadataPropertyNames(target).forEach(name => knownKeys.add(name));\n storage.getExposedMetadatas(target).forEach(metadata => {\n if (metadata.options && typeof metadata.options.name === 'string') knownKeys.add(metadata.options.name);\n });\n }\n knownKeys.delete('__proto__');\n knownKeys.delete('constructor');\n\n const extraKeys = staticKeys.filter(key => key !== '__proto__' && key !== 'constructor');\n // exposed keys missing from the object are transformed after the object keys\n // set when the key is found in the object keys\n extraKeys.forEach((key, index) => {\n body += `let has${String(index)} = false;\\n`;\n });\n\n let cases = `case \"__proto__\": case \"constructor\": continue;\\n`;\n knownKeys.forEach(key => {\n const probe: Record<string, any> = {};\n probe[key] = true;\n const blocked = !ex.getKeys(target, probe, false).includes(key);\n const extraIndex = extraKeys.indexOf(key);\n const seen = extraIndex === -1 ? '' : `has${String(extraIndex)} = true;\\n`;\n cases += blocked ? `case ${str(key)}: continue;\\n` : `case ${str(key)}: ${seen}${emitKey(key)}continue;\\n`;\n });\n\n body += `const keys = Object.keys(value);\\n`;\n body += `for (let i = 0; i < keys.length; i++) {\\nconst key = keys[i];\\nswitch (key) {\\n${cases}}\\n`;\n if (options.excludePrefixes && options.excludePrefixes.length) {\n body += `if (H.prefixBlocked(key, ${ref(options.excludePrefixes.slice())})) continue;\\n`;\n }\n body += emitKey(undefined);\n body += '}\\n';\n\n extraKeys.forEach((key, index) => {\n body += `if (!has${String(index)}) {\\n${emitKey(key)}}\\n`;\n });\n }\n body += 'return newValue;\\n';\n\n const declarations = constants.map((_, index) => `const k${index} = K[${index}];\\n`).join('');\n const source =\n `'use strict';\\n${declarations}const OP = Object.prototype;\\nconst AFE = Array.prototype.forEach;\\nconst UNSET = {};\\n${siteDeclarations.join(\n ''\n )}` + `return function compiledTransform(ex, source, value, level) {\\n${body}};`;\n\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n const factory = new Function('K', 'H', source) as (constants: any[], h: typeof helpers) => CompiledTransformer;\n return factory(constants, helpers);\n}\n"]}
|
|
@@ -33,6 +33,11 @@ class TransformOperationExecutor {
|
|
|
33
33
|
const newValue = arrayType && this.transformationType === enums_1.TransformationType.PLAIN_TO_CLASS
|
|
34
34
|
? instantiateArrayType(arrayType)
|
|
35
35
|
: [];
|
|
36
|
+
// compiled transformer called directly for the elements, see TransformCompiler
|
|
37
|
+
const direct = this.jit && !source && typeof targetType === 'function' ? this.jit.direct(targetType, this) : null;
|
|
38
|
+
if (direct && Array.isArray(value) && value.forEach === Array.prototype.forEach) {
|
|
39
|
+
return this.transformArrayDirect(direct, value, newValue, targetType, level);
|
|
40
|
+
}
|
|
36
41
|
value.forEach((subValue, index) => {
|
|
37
42
|
const subSource = source ? source[index] : undefined;
|
|
38
43
|
if (!this.options.enableCircularCheck || !this.isCircular(subValue)) {
|
|
@@ -61,7 +66,9 @@ class TransformOperationExecutor {
|
|
|
61
66
|
else {
|
|
62
67
|
realTargetType = targetType;
|
|
63
68
|
}
|
|
64
|
-
const value =
|
|
69
|
+
const value = direct && realTargetType === targetType && direct.accepts(subValue)
|
|
70
|
+
? this.transformDirect(direct.transformer, subValue, level + 1)
|
|
71
|
+
: this.transform(subSource, subValue, realTargetType, undefined, subValue instanceof Map, level + 1);
|
|
65
72
|
if (newValue instanceof Set) {
|
|
66
73
|
newValue.add(value);
|
|
67
74
|
}
|
|
@@ -156,6 +163,48 @@ class TransformOperationExecutor {
|
|
|
156
163
|
// -------------------------------------------------------------------------
|
|
157
164
|
// Private Methods
|
|
158
165
|
// -------------------------------------------------------------------------
|
|
166
|
+
/**
|
|
167
|
+
* Same as the forEach of the array branch of `transform`, when elements are transformed with a class having a
|
|
168
|
+
* compiled transformer (no source, no discriminator).
|
|
169
|
+
*/
|
|
170
|
+
transformArrayDirect(direct, value, newValue, targetType, level) {
|
|
171
|
+
const isSet = newValue instanceof Set;
|
|
172
|
+
const length = value.length;
|
|
173
|
+
for (let index = 0; index < length; index++) {
|
|
174
|
+
if (!(index in value))
|
|
175
|
+
continue; // forEach skips holes
|
|
176
|
+
const subValue = value[index];
|
|
177
|
+
let transformed;
|
|
178
|
+
if (this.options.enableCircularCheck && this.isCircular(subValue)) {
|
|
179
|
+
if (this.transformationType !== enums_1.TransformationType.CLASS_TO_CLASS)
|
|
180
|
+
continue;
|
|
181
|
+
transformed = subValue;
|
|
182
|
+
}
|
|
183
|
+
else if (direct.accepts(subValue)) {
|
|
184
|
+
transformed = this.transformDirect(direct.transformer, subValue, level + 1);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
transformed = this.transform(undefined, subValue, targetType, undefined, subValue instanceof Map, level + 1);
|
|
188
|
+
}
|
|
189
|
+
if (isSet)
|
|
190
|
+
newValue.add(transformed);
|
|
191
|
+
else
|
|
192
|
+
newValue.push(transformed);
|
|
193
|
+
}
|
|
194
|
+
return newValue;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Same as `transform(undefined, value, <type of the direct transformer>, undefined, false, level)`
|
|
198
|
+
* for a value accepted by the direct transformer.
|
|
199
|
+
*/
|
|
200
|
+
transformDirect(transformer, value, level) {
|
|
201
|
+
if (!this.options.enableCircularCheck)
|
|
202
|
+
return transformer(this, undefined, value, level);
|
|
203
|
+
this.recursionStack.add(value);
|
|
204
|
+
const newValue = transformer(this, undefined, value, level);
|
|
205
|
+
this.recursionStack.delete(value);
|
|
206
|
+
return newValue;
|
|
207
|
+
}
|
|
159
208
|
/**
|
|
160
209
|
* Interpreted transformation of a single object, used when no compiled transformer is available.
|
|
161
210
|
*/
|