import{__exports as n}from"../../../_virtual/source-node.mjs";import{__require as e}from"./source-map-generator.mjs";import{__require as r}from"./util.mjs";var t;function o(){if(t)return n;t=1;var o=e().SourceMapGenerator,i=r(),l=/(\r?\n)/,u="$$$isSourceNode$$$";function s(n,e,r,t,o){this.children=[],this.sourceContents={},this.line=null==n?null:n,this.column=null==e?null:e,this.source=null==r?null:r,this.name=null==o?null:o,this[u]=!0,null!=t&&this.add(t)}return s.fromStringWithSourceMap=function(n,e,r){var t=new s,o=n.split(l),u=0,c=function(){return n()+(n()||"");function n(){return u<o.length?o[u++]:void 0}},a=1,h=0,d=null;return e.eachMapping(function(n){if(null!==d){if(!(a<n.generatedLine)){var e=(r=o[u]||"").substr(0,n.generatedColumn-h);return o[u]=r.substr(n.generatedColumn-h),h=n.generatedColumn,p(d,e),void(d=n)}p(d,c()),a++,h=0}for(;a<n.generatedLine;)t.add(c()),a++;if(h<n.generatedColumn){var r=o[u]||"";t.add(r.substr(0,n.generatedColumn)),o[u]=r.substr(n.generatedColumn),h=n.generatedColumn}d=n},this),u<o.length&&(d&&p(d,c()),t.add(o.splice(u).join(""))),e.sources.forEach(function(n){var o=e.sourceContentFor(n);null!=o&&(null!=r&&(n=i.join(r,n)),t.setSourceContent(n,o))}),t;function p(n,e){if(null===n||void 0===n.source)t.add(e);else{var o=r?i.join(r,n.source):n.source;t.add(new s(n.originalLine,n.originalColumn,o,e,n.name))}}},s.prototype.add=function(n){if(Array.isArray(n))n.forEach(function(n){this.add(n)},this);else{if(!n[u]&&"string"!=typeof n)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+n);n&&this.children.push(n)}return this},s.prototype.prepend=function(n){if(Array.isArray(n))for(var e=n.length-1;e>=0;e--)this.prepend(n[e]);else{if(!n[u]&&"string"!=typeof n)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+n);this.children.unshift(n)}return this},s.prototype.walk=function(n){for(var e,r=0,t=this.children.length;r<t;r++)(e=this.children[r])[u]?e.walk(n):""!==e&&n(e,{source:this.source,line:this.line,column:this.column,name:this.name})},s.prototype.join=function(n){var e,r,t=this.children.length;if(t>0){for(e=[],r=0;r<t-1;r++)e.push(this.children[r]),e.push(n);e.push(this.children[r]),this.children=e}return this},s.prototype.replaceRight=function(n,e){var r=this.children[this.children.length-1];return r[u]?r.replaceRight(n,e):"string"==typeof r?this.children[this.children.length-1]=r.replace(n,e):this.children.push("".replace(n,e)),this},s.prototype.setSourceContent=function(n,e){this.sourceContents[i.toSetString(n)]=e},s.prototype.walkSourceContents=function(n){for(var e=0,r=this.children.length;e<r;e++)this.children[e][u]&&this.children[e].walkSourceContents(n);var t=Object.keys(this.sourceContents);for(e=0,r=t.length;e<r;e++)n(i.fromSetString(t[e]),this.sourceContents[t[e]])},s.prototype.toString=function(){var n="";return this.walk(function(e){n+=e}),n},s.prototype.toStringWithSourceMap=function(n){var e={code:"",line:1,column:0},r=new o(n),t=!1,i=null,l=null,u=null,s=null;return this.walk(function(n,o){e.code+=n,null!==o.source&&null!==o.line&&null!==o.column?(i===o.source&&l===o.line&&u===o.column&&s===o.name||r.addMapping({source:o.source,original:{line:o.line,column:o.column},generated:{line:e.line,column:e.column},name:o.name}),i=o.source,l=o.line,u=o.column,s=o.name,t=!0):t&&(r.addMapping({generated:{line:e.line,column:e.column}}),i=null,t=!1);for(var c=0,a=n.length;c<a;c++)10===n.charCodeAt(c)?(e.line++,e.column=0,c+1===a?(i=null,t=!1):t&&r.addMapping({source:o.source,original:{line:o.line,column:o.column},generated:{line:e.line,column:e.column},name:o.name})):e.column++}),this.walkSourceContents(function(n,e){r.setSourceContent(n,e)}),{code:e.code,map:r}},n.SourceNode=s,n}export{o as __require};