var Common;!function(e){!function(e){"use strict";class t{constructor(e,r=""){this._source=e.source;this._mimeType=e.mimeType;this._generatedSourceSpans=[];this._canBePrettyPrinted=!1;this._error=!1;this._firstCompilerError="";if(!t.ScriptsImported&&"function"==typeof importScripts){t.ScriptsImported=!0;try{importScripts(e.commonUrl+"assert.js");importScripts(e.loader+"loader.js");importScripts(r+"typescript/formatterTypescriptServices.js")}catch(t){importScripts(e.commonUrl.substr(3)+"assert.js");importScripts(e.loader.substr(3)+"loader.js")}importScripts(r+"sourceSpanBuilder.js");importScripts(r+"sourcemapParser.js");importScripts(r+"workerMessaging.js");importScripts(r+"htmlScriptFinder.js");importScripts(r+"base64.js")}}get formattedText(){return this._formattedText}get canBePrettyPrinted(){return this._canBePrettyPrinted}get generatedSourceSpans(){return this._generatedSourceSpans}get error(){return this._error}get firstCompilerError(){return this._firstCompilerError}getNumLines(e){for(var t=0,r=0;r<e.length;r++)"\n"===e[r]&&++t;return t}parseSource(t,r){if(e.HTMLScriptFinder.isSupportedScript(r)){this._generatedSourceSpans.push(new e.SourceSpanBuilder(0,t.length,!0));this._canBePrettyPrinted=!0}else if("text/html"===r)try{var s=new e.HTMLScriptFinder(t);if(s.sourceSpans.length>1){this._generatedSourceSpans=s.sourceSpans;this._canBePrettyPrinted=!0}}catch(e){}}formatJavaScript(t){if(0!==t.length){F12.Tools.Utility.Assert.isTrue(this._canBePrettyPrinted);F12.Tools.Utility.Assert.isTrue(this._generatedSourceSpans.length>0);var r=0,s=0;this._generatedSourceSpans[0].generatedLineOffset=r;this._formattedText="";for(;;){var i=this._generatedSourceSpans[s];if(!i.isScript){i.generatedLineOffset+=r;var a=t.slice(i.start,i.end+1);r+=i.calculateLineOffsets(a);this._formattedText+=a;if(++s<this._generatedSourceSpans.length){this._formattedText+="\n";++r}}if(s===this._generatedSourceSpans.length)return;i=this._generatedSourceSpans[s];F12.Tools.Utility.Assert.isTrue(i.isScript);i.generatedLineOffset+=r;var n,o,c,p=!1;try{n=t.slice(i.start,i.end+1);o=i.calculateLineOffsets(n);"\n"!==n.charAt(n.length-1)&&(n+="\r\n");var u,S,m,g="input",l={getSourceFile:(e,t)=>e===g+".ts"?m=self.ts.createSourceFile(e,n,t,"0"):self.ts.createSourceFile(e,"",t,"0"),writeFile:(e,t,r)=>{e===g+".js"?u=t:S=t},getDefaultLibFilename:e=>"",useCaseSensitiveFileNames:()=>!1,getCanonicalFileName:e=>e,getCurrentDirectory:()=>"",getNewLine:()=>"\r\n"},h={sourceMap:!0,noLib:!0,removeComments:!1},d=self.ts.createProgram([g+".ts"],h,l),f=d.getDiagnostics(m);if(!f.length){d.getTypeChecker(!0).emitFiles(m)}p=!(!u||!S)}catch(e){c=e.message;p=!1}finally{if(p){try{0===S.indexOf(")]}")&&(S=S.slice(3));var _=JSON.parse(S)}catch(e){}i._mappings=e.SourcemapParser.calculateMappings(_);i._mappings||(p=!1)}if(p){var v=u.lastIndexOf("//# sourceMappingURL=input.js.map");"\n"===u[v-1]&&"\n"===u[v-2]&&--v;var y=-1!==v?u.slice(0,v):u;r+=this.getNumLines(y);this._formattedText+=y}else{r+=o;this._formattedText+=n;this._error=!0;this._firstCompilerError="Error: "+(f&&f[0]&&f[0].messageText||c)}}if(++s===this._generatedSourceSpans.length)return}}}processSource(){this.parseSource(this._source,this._mimeType);this._canBePrettyPrinted&&this.formatJavaScript(this._source)}}t.ScriptsImported=!1;e.FormatWorker=t;var r=1e3,s=2e5;onmessage=function(i){var a=i.data,n=new t(a);n.processSource();var o=new e.WorkerResponseMessage;o.formattedText=n.formattedText;o.canBePrettyPrinted=n.canBePrettyPrinted;o.error=n.error;o.errorMessage=n.firstCompilerError;var c=n.generatedSourceSpans;o.generatedSourceSpanData=[];for(var p=0,u=0;u<c.length;u++){c[u].data.mappings&&(p+=c[u].data.mappings.length);o.generatedSourceSpanData.push(c[u].data)}if(!1===a.forceResponseChunking||!a.forceResponseChunking&&p<s){this.postMessage(o);this.close()}else{var S=[];for(u=0;u<c.length;u++){S.push(o.generatedSourceSpanData[u].mappings);o.generatedSourceSpanData[u].mappings=null}var m=0,g=()=>{if(m<S.length){if(S[m]){var t=new e.WorkerMappingSubsetResponseMessage;t.generatedSourceSpanIndex=m;var i=a.forceResponseChunking?r:s;t.mappings=S[m].splice(0,i);this.postMessage(t);S[m].length||m++}else m++;setTimeout(g,0)}else{this.postMessage(o);this.close()}};setTimeout(g,0)}}}(e.FormatService||(e.FormatService={}))}(Common||(Common={}));
