mol_regexp 0.0.1408 → 0.0.1410

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
@@ -610,17 +610,36 @@ var $;
610
610
  "use strict";
611
611
  var $;
612
612
  (function ($) {
613
+ function cause_serialize(cause) {
614
+ return JSON.stringify(cause, null, ' ')
615
+ .replace(/\(/, '<')
616
+ .replace(/\)/, ' >');
617
+ }
618
+ function frame_normalize(frame) {
619
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
620
+ .trim()
621
+ .replace(/at /gm, ' at ')
622
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
623
+ }
613
624
  class $mol_error_mix extends AggregateError {
614
625
  cause;
615
626
  name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
616
627
  constructor(message, cause = {}, ...errors) {
617
628
  super(errors, message, { cause });
618
629
  this.cause = cause;
619
- const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
630
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
631
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
620
632
  Object.defineProperty(this, 'stack', {
621
- 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()
622
- .replace(/at /gm, ' at ')
623
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
633
+ get: () => stack_get() + '\n' + [
634
+ this.cause ?? 'no cause',
635
+ ...this.errors.flatMap(e => [
636
+ e.stack,
637
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
638
+ ])
639
+ ].map(frame_normalize).join('\n')
640
+ });
641
+ Object.defineProperty(this, 'cause', {
642
+ get: () => cause
624
643
  });
625
644
  }
626
645
  static [Symbol.toPrimitive]() {