ts-flex-query
Version:
Flexible and type-safe data queries
27 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeExpressionForDebugging = serializeExpressionForDebugging;
/**
* Serializes an expression to JSON for debugging purposes.
* Uses the expression's constructor name to identify their type.
* Therefore, this method is not useful for minified JS code with changed class names.
*/
function serializeExpressionForDebugging(expression) {
let nextSymbolIndex = 1;
const knownSymbols = {};
return JSON.stringify(expression, (_, value) => {
var _a;
if (typeof value === 'object' && value && value.constructor !== Object) {
return Object.assign({
// eslint-disable-next-line @typescript-eslint/naming-convention -- By design.
__type: value.constructor.name }, value);
}
if (typeof value === 'symbol') {
const index = (_a = knownSymbols[value]) !== null && _a !== void 0 ? _a : nextSymbolIndex++;
knownSymbols[value] = index;
return `${index}: ${value.toString()}`;
}
return value;
});
}
//# sourceMappingURL=serialize-expression-for-debugging.js.map