fix(common): add workaround for divergence of EventEmitter3 from node's version

Node's version has special behavior for events named 'error' - if no handler, it auto-throws.  EventEmitter3 does not include this.
This commit is contained in:
Joshua A. Horton 2024-07-04 11:05:34 +07:00 committed by Eberhard Beilharz
parent afe25eda24
commit 877cd9767d
No known key found for this signature in database
GPG key ID: E9140597606020D3

View file

@ -323,7 +323,11 @@ export class Parser extends EventEmitter {
} catch (error1) {
err = error1;
if (!(this.saxParser.errThrown || this.saxParser.ended)) {
this.emit('error', err);
if(this.listenerCount('error') > 0) {
this.emit('error', err);
} else {
throw err;
}
return this.saxParser.errThrown = true;
} else if (this.saxParser.ended) {
throw err;