{"version":3,"file":"parse-sax.js","names":["SaxesParser","require","PassThrough","bufferToString","module","exports","iterable","pipe","Symbol","asyncIterator","saxesParser","error","on","err","events","value","push","eventType","chunk","write"],"sources":["../../../lib/utils/parse-sax.js"],"sourcesContent":["const {SaxesParser} = require('saxes');\nconst {PassThrough} = require('readable-stream');\nconst {bufferToString} = require('./browser-buffer-decode');\n\nmodule.exports = async function* (iterable) {\n // TODO: Remove once node v8 is deprecated\n // Detect and upgrade old streams\n if (iterable.pipe && !iterable[Symbol.asyncIterator]) {\n iterable = iterable.pipe(new PassThrough());\n }\n const saxesParser = new SaxesParser();\n let error;\n saxesParser.on('error', err => {\n error = err;\n });\n let events = [];\n saxesParser.on('opentag', value => events.push({eventType: 'opentag', value}));\n saxesParser.on('text', value => events.push({eventType: 'text', value}));\n saxesParser.on('closetag', value => events.push({eventType: 'closetag', value}));\n for await (const chunk of iterable) {\n saxesParser.write(bufferToString(chunk));\n // saxesParser.write and saxesParser.on() are synchronous,\n // so we can only reach the below line once all events have been emitted\n if (error) throw error;\n // As a performance optimization, we gather all events instead of passing\n // them one by one, which would cause each event to go through the event queue\n yield events;\n events = [];\n }\n};\n"],"mappings":";;AAAA,MAAM;EAACA;AAAW,CAAC,GAAGC,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM;EAACC;AAAW,CAAC,GAAGD,OAAO,CAAC,iBAAiB,CAAC;AAChD,MAAM;EAACE;AAAc,CAAC,GAAGF,OAAO,CAAC,yBAAyB,CAAC;AAE3DG,MAAM,CAACC,OAAO,GAAG,iBAAiBC,QAAQ,EAAE;EAC1C;EACA;EACA,IAAIA,QAAQ,CAACC,IAAI,IAAI,CAACD,QAAQ,CAACE,MAAM,CAACC,aAAa,CAAC,EAAE;IACpDH,QAAQ,GAAGA,QAAQ,CAACC,IAAI,CAAC,IAAIL,WAAW,CAAC,CAAC,CAAC;EAC7C;EACA,MAAMQ,WAAW,GAAG,IAAIV,WAAW,CAAC,CAAC;EACrC,IAAIW,KAAK;EACT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