mol_text_distance 0.0.1057 → 0.0.1059

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/node.test.js CHANGED
@@ -353,17 +353,36 @@ var $;
353
353
  "use strict";
354
354
  var $;
355
355
  (function ($) {
356
+ function cause_serialize(cause) {
357
+ return JSON.stringify(cause, null, ' ')
358
+ .replace(/\(/, '<')
359
+ .replace(/\)/, ' >');
360
+ }
361
+ function frame_normalize(frame) {
362
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
363
+ .trim()
364
+ .replace(/at /gm, ' at ')
365
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
366
+ }
356
367
  class $mol_error_mix extends AggregateError {
357
368
  cause;
358
369
  name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
359
370
  constructor(message, cause = {}, ...errors) {
360
371
  super(errors, message, { cause });
361
372
  this.cause = cause;
362
- const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
373
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
374
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
363
375
  Object.defineProperty(this, 'stack', {
364
- get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
365
- .replace(/at /gm, ' at ')
366
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
376
+ get: () => stack_get() + '\n' + [
377
+ this.cause ?? 'no cause',
378
+ ...this.errors.flatMap(e => [
379
+ e.stack,
380
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
381
+ ])
382
+ ].map(frame_normalize).join('\n')
383
+ });
384
+ Object.defineProperty(this, 'cause', {
385
+ get: () => cause
367
386
  });
368
387
  }
369
388
  static [Symbol.toPrimitive]() {