@react-native/debugger-frontend
Version:
Debugger frontend for React Native based on Chrome DevTools
1 lines • 87.4 kB
JavaScript
import*as e from"../../core/common/common.js";import*as t from"../../core/platform/platform.js";import{assertNotNullOrUndefined as o}from"../../core/platform/platform.js";import*as r from"../../core/sdk/sdk.js";import*as s from"../text_utils/text_utils.js";import*as i from"../workspace/workspace.js";import*as n from"../../core/i18n/i18n.js";const a={unknownErrorLoadingFile:"Unknown error loading file"},c=n.i18n.registerUIStrings("models/bindings/ContentProviderBasedProject.ts",a),u=n.i18n.getLocalizedString.bind(void 0,c);class l extends i.Workspace.ProjectStore{#e;#t;constructor(e,t,o,r,s){super(e,t,o,r),this.#e=s,this.#t=new WeakMap,e.addProject(this)}async requestFileContent(e){const{contentProvider:t}=this.#t.get(e);try{return await t.requestContentData()}catch(e){return{error:e?String(e):u(a.unknownErrorLoadingFile)}}}isServiceProject(){return this.#e}async requestMetadata(e){const{metadata:t}=this.#t.get(e);return t}canSetFileContent(){return!1}async setFileContent(e,t,o){}fullDisplayName(e){let t=e.parentURL().replace(/^(?:https?|file)\:\/\//,"");try{t=decodeURI(t)}catch(e){}return t+"/"+e.displayName(!0)}mimeType(e){const{mimeType:t}=this.#t.get(e);return t}canRename(){return!1}rename(e,t,o){const r=e.url();this.performRename(r,t,((t,r)=>{t&&r&&this.renameUISourceCode(e,r),o(t,r)}))}excludeFolder(e){}canExcludeFolder(e){return!1}async createFile(e,t,o,r){return null}canCreateFile(){return!1}deleteFile(e){}remove(){}performRename(e,t,o){o(!1)}searchInFileContent(e,t,o,r){const{contentProvider:s}=this.#t.get(e);return s.searchInContent(t,o,r)}async findFilesMatchingSearchRequest(e,o,r){const i=new Map;return r.setTotalWork(o.length),await Promise.all(o.map(async function(o){let n=!0,a=[];for(const r of e.queries().slice()){const i=await this.searchInFileContent(o,r,!e.ignoreCase(),e.isRegex());if(!i.length){n=!1;break}a=t.ArrayUtilities.mergeOrdered(a,i,s.ContentProvider.SearchMatch.comparator)}n&&i.set(o,a);r.incrementWorked(1)}.bind(this))),r.done(),i}indexContent(e){queueMicrotask(e.done.bind(e))}addUISourceCodeWithProvider(e,t,o,r){this.#t.set(e,{mimeType:r,metadata:o,contentProvider:t}),this.addUISourceCode(e)}addContentProvider(e,t,o){const r=this.createUISourceCode(e,t.contentType());return this.addUISourceCodeWithProvider(r,t,null,o),r}reset(){this.removeProject(),this.workspace().addProject(this)}dispose(){this.removeProject()}}var d=Object.freeze({__proto__:null,ContentProviderBasedProject:l});const g={removeFromIgnoreList:"Remove from ignore list",addScriptToIgnoreList:"Add script to ignore list",addDirectoryToIgnoreList:"Add directory to ignore list",addAllContentScriptsToIgnoreList:"Add all extension scripts to ignore list",addAllThirdPartyScriptsToIgnoreList:"Add all third-party scripts to ignore list"},p=n.i18n.registerUIStrings("models/bindings/IgnoreListManager.ts",g),h=n.i18n.getLocalizedString.bind(void 0,p);let m;class S{#o;#r;#s;constructor(t){this.#o=t,r.TargetManager.TargetManager.instance().addModelListener(r.DebuggerModel.DebuggerModel,r.DebuggerModel.Events.GlobalObjectCleared,this.clearCacheIfNeeded.bind(this),this),e.Settings.Settings.instance().moduleSetting("skip-stack-frames-pattern").addChangeListener(this.patternChanged.bind(this)),e.Settings.Settings.instance().moduleSetting("skip-content-scripts").addChangeListener(this.patternChanged.bind(this)),e.Settings.Settings.instance().moduleSetting("automatically-ignore-list-known-third-party-scripts").addChangeListener(this.patternChanged.bind(this)),e.Settings.Settings.instance().moduleSetting("enable-ignore-listing").addChangeListener(this.patternChanged.bind(this)),this.#r=new Set,this.#s=new Map,r.TargetManager.TargetManager.instance().observeModels(r.DebuggerModel.DebuggerModel,this)}static instance(e={forceNew:null,debuggerWorkspaceBinding:null}){const{forceNew:t,debuggerWorkspaceBinding:o}=e;if(!m||t){if(!o)throw new Error(`Unable to create settings: debuggerWorkspaceBinding must be provided: ${(new Error).stack}`);m=new S(o)}return m}static removeInstance(){m=void 0}addChangeListener(e){this.#r.add(e)}removeChangeListener(e){this.#r.delete(e)}modelAdded(e){this.setIgnoreListPatterns(e);const t=e.sourceMapManager();t.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),t.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)}modelRemoved(e){this.clearCacheIfNeeded();const t=e.sourceMapManager();t.removeEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),t.removeEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)}clearCacheIfNeeded(){this.#s.size>1024&&this.#s.clear()}getSkipStackFramesPatternSetting(){return e.Settings.Settings.instance().moduleSetting("skip-stack-frames-pattern")}setIgnoreListPatterns(e){const t=this.enableIgnoreListing?this.getSkipStackFramesPatternSetting().getAsArray():[],o=[];for(const e of t)!e.disabled&&e.pattern&&o.push(e.pattern);return e.setBlackboxPatterns(o)}getGeneralRulesForUISourceCode(e){return{isContentScript:e.project().type()===i.Workspace.projectTypes.ContentScripts,isKnownThirdParty:e.isKnownThirdParty()}}isUserOrSourceMapIgnoreListedUISourceCode(e){if(e.isUnconditionallyIgnoreListed())return!0;const t=this.uiSourceCodeURL(e);return this.isUserIgnoreListedURL(t,this.getGeneralRulesForUISourceCode(e))}isUserIgnoreListedURL(e,t){if(!this.enableIgnoreListing)return!1;if(t?.isContentScript&&this.skipContentScripts)return!0;if(t?.isKnownThirdParty&&this.automaticallyIgnoreListKnownThirdPartyScripts)return!0;if(!e)return!1;if(this.#s.has(e))return Boolean(this.#s.get(e));const o=this.getSkipStackFramesPatternSetting().asRegExp(),r=o&&o.test(e)||!1;return this.#s.set(e,r),r}sourceMapAttached(e){const t=e.data.client,o=e.data.sourceMap;this.updateScriptRanges(t,o)}sourceMapDetached(e){const t=e.data.client;this.updateScriptRanges(t,void 0)}async updateScriptRanges(e,t){let o=!1;if(S.instance().isUserIgnoreListedURL(e.sourceURL,{isContentScript:e.isContentScript()})||(o=t?.sourceURLs().some((e=>this.isUserIgnoreListedURL(e,{isKnownThirdParty:t.hasIgnoreListHint(e)})))??!1),!o)return L.get(e)&&await e.setBlackboxedRanges([])&&L.delete(e),void await this.#o.updateLocations(e);if(!t)return;const r=t.findRanges((e=>this.isUserIgnoreListedURL(e,{isKnownThirdParty:t.hasIgnoreListHint(e)})),{isStartMatching:!0}).flatMap((e=>[e.start,e.end]));!function(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(e[o].lineNumber!==t[o].lineNumber||e[o].columnNumber!==t[o].columnNumber)return!1;return!0}(L.get(e)||[],r)&&await e.setBlackboxedRanges(r)&&L.set(e,r),this.#o.updateLocations(e)}uiSourceCodeURL(e){return e.project().type()===i.Workspace.projectTypes.Debugger?null:e.url()}canIgnoreListUISourceCode(e){const t=this.uiSourceCodeURL(e);return!!t&&Boolean(this.urlToRegExpString(t))}ignoreListUISourceCode(e){const t=this.uiSourceCodeURL(e);t&&this.ignoreListURL(t)}unIgnoreListUISourceCode(e){this.unIgnoreListURL(this.uiSourceCodeURL(e),this.getGeneralRulesForUISourceCode(e))}get enableIgnoreListing(){return e.Settings.Settings.instance().moduleSetting("enable-ignore-listing").get()}set enableIgnoreListing(t){e.Settings.Settings.instance().moduleSetting("enable-ignore-listing").set(t)}get skipContentScripts(){return this.enableIgnoreListing&&e.Settings.Settings.instance().moduleSetting("skip-content-scripts").get()}get automaticallyIgnoreListKnownThirdPartyScripts(){return this.enableIgnoreListing&&e.Settings.Settings.instance().moduleSetting("automatically-ignore-list-known-third-party-scripts").get()}ignoreListContentScripts(){this.enableIgnoreListing||(this.enableIgnoreListing=!0),e.Settings.Settings.instance().moduleSetting("skip-content-scripts").set(!0)}unIgnoreListContentScripts(){e.Settings.Settings.instance().moduleSetting("skip-content-scripts").set(!1)}ignoreListThirdParty(){this.enableIgnoreListing||(this.enableIgnoreListing=!0),e.Settings.Settings.instance().moduleSetting("automatically-ignore-list-known-third-party-scripts").set(!0)}unIgnoreListThirdParty(){e.Settings.Settings.instance().moduleSetting("automatically-ignore-list-known-third-party-scripts").set(!1)}ignoreListURL(e){const t=this.urlToRegExpString(e);t&&this.ignoreListRegex(t,e)}ignoreListRegex(e,t){const o=this.getSkipStackFramesPatternSetting().getAsArray();let r=!1;for(let s=0;s<o.length;++s){const i=o[s];(i.pattern===e||t&&i.disabledForUrl===t)&&(i.disabled=!1,i.disabledForUrl=void 0,r=!0)}r||o.push({pattern:e,disabled:!1}),this.enableIgnoreListing||(this.enableIgnoreListing=!0),this.getSkipStackFramesPatternSetting().setAsArray(o)}unIgnoreListURL(e,t){if(t?.isContentScript&&this.unIgnoreListContentScripts(),t?.isKnownThirdParty&&this.unIgnoreListThirdParty(),!e)return;let o=this.getSkipStackFramesPatternSetting().getAsArray();const r=S.instance().urlToRegExpString(e);if(r){o=o.filter((function(e){return e.pattern!==r}));for(let t=0;t<o.length;++t){const r=o[t];if(!r.disabled)try{new RegExp(r.pattern).test(e)&&(r.disabled=!0,r.disabledForUrl=e)}catch(e){}}this.getSkipStackFramesPatternSetting().setAsArray(o)}}removeIgnoreListPattern(e){let t=this.getSkipStackFramesPatternSetting().getAsArray();t=t.filter((function(t){return t.pattern!==e})),this.getSkipStackFramesPatternSetting().setAsArray(t)}ignoreListHasPattern(e,t){return this.getSkipStackFramesPatternSetting().getAsArray().some((o=>!(t&&o.disabled)&&o.pattern===e))}async patternChanged(){this.#s.clear();const e=[];for(const t of r.TargetManager.TargetManager.instance().models(r.DebuggerModel.DebuggerModel)){e.push(this.setIgnoreListPatterns(t));const o=t.sourceMapManager();for(const r of t.scripts())e.push(this.updateScriptRanges(r,o.sourceMapForClient(r)))}await Promise.all(e);const t=Array.from(this.#r);for(const e of t)e();this.patternChangeFinishedForTests()}patternChangeFinishedForTests(){}urlToRegExpString(o){const r=new e.ParsedURL.ParsedURL(o);if(r.isAboutBlank()||r.isDataURL())return"";if(!r.isValid)return"^"+t.StringUtilities.escapeForRegExp(o)+"$";let s=r.lastPathComponent;if(s?s="/"+s:r.folderPathComponents&&(s=r.folderPathComponents+"/"),s||(s=r.host),!s)return"";const i=r.scheme;let n="";return i&&"http"!==i&&"https"!==i&&(n="^"+i+"://","chrome-extension"===i&&(n+=r.host+"\\b"),n+=".*"),n+t.StringUtilities.escapeForRegExp(s)+(o.endsWith(s)?"$":"\\b")}getIgnoreListURLContextMenuItems(e){if(e.project().type()===i.Workspace.projectTypes.FileSystem)return[];const t=[],o=this.canIgnoreListUISourceCode(e),r=this.isUserOrSourceMapIgnoreListedUISourceCode(e),{isContentScript:s,isKnownThirdParty:n}=this.getGeneralRulesForUISourceCode(e);return r?(o||s||n)&&t.push({text:h(g.removeFromIgnoreList),callback:this.unIgnoreListUISourceCode.bind(this,e),jslogContext:"remove-script-from-ignorelist"}):(o&&t.push({text:h(g.addScriptToIgnoreList),callback:this.ignoreListUISourceCode.bind(this,e),jslogContext:"add-script-to-ignorelist"}),t.push(...this.getIgnoreListGeneralContextMenuItems({isContentScript:s,isKnownThirdParty:n}))),t}getIgnoreListGeneralContextMenuItems(e){const t=[];return e?.isContentScript&&t.push({text:h(g.addAllContentScriptsToIgnoreList),callback:this.ignoreListContentScripts.bind(this),jslogContext:"add-content-scripts-to-ignorelist"}),e?.isKnownThirdParty&&t.push({text:h(g.addAllThirdPartyScriptsToIgnoreList),callback:this.ignoreListThirdParty.bind(this),jslogContext:"add-3p-scripts-to-ignorelist"}),t}getIgnoreListFolderContextMenuItems(e,o){const r=[],s="^"+t.StringUtilities.escapeForRegExp(e)+"/";return this.ignoreListHasPattern(s,!0)?r.push({text:h(g.removeFromIgnoreList),callback:this.removeIgnoreListPattern.bind(this,s),jslogContext:"remove-from-ignore-list"}):this.isUserIgnoreListedURL(e,o)?r.push({text:h(g.removeFromIgnoreList),callback:this.unIgnoreListURL.bind(this,e,o),jslogContext:"remove-from-ignore-list"}):o?.isCurrentlyIgnoreListed||(r.push({text:h(g.addDirectoryToIgnoreList),callback:this.ignoreListRegex.bind(this,s),jslogContext:"add-directory-to-ignore-list"}),r.push(...this.getIgnoreListGeneralContextMenuItems(o))),r}}const L=new WeakMap;var M=Object.freeze({__proto__:null,IgnoreListManager:S});const f=new WeakMap,b=new WeakMap;let C;class v extends e.ObjectWrapper.ObjectWrapper{constructor(){super()}static instance({forceNew:e}={forceNew:!1}){return C&&!e||(C=new v),C}}class w{static resolveFrame(e,t){const o=w.targetForUISourceCode(e),s=o&&o.model(r.ResourceTreeModel.ResourceTreeModel);return s?s.frameForId(t):null}static setInitialFrameAttribution(e,t){if(!t)return;const o=w.resolveFrame(e,t);if(!o)return;const r=new Map;r.set(t,{frame:o,count:1}),f.set(e,r)}static cloneInitialFrameAttribution(e,t){const o=f.get(e);if(!o)return;const r=new Map;for(const e of o.keys()){const t=o.get(e);void 0!==t&&r.set(e,{frame:t.frame,count:t.count})}f.set(t,r)}static addFrameAttribution(e,t){const o=w.resolveFrame(e,t);if(!o)return;const r=f.get(e);if(!r)return;const s=r.get(t)||{frame:o,count:0};if(s.count+=1,r.set(t,s),1!==s.count)return;const i={uiSourceCode:e,frame:o};v.instance().dispatchEventToListeners("FrameAttributionAdded",i)}static removeFrameAttribution(e,t){const o=f.get(e);if(!o)return;const r=o.get(t);if(console.assert(Boolean(r),"Failed to remove frame attribution for url: "+e.url()),!r)return;if(r.count-=1,r.count>0)return;o.delete(t);const s={uiSourceCode:e,frame:r.frame};v.instance().dispatchEventToListeners("FrameAttributionRemoved",s)}static targetForUISourceCode(e){return b.get(e.project())||null}static setTargetForProject(e,t){b.set(e,t)}static getTargetForProject(e){return b.get(e)||null}static framesForUISourceCode(e){const t=w.targetForUISourceCode(e),o=t&&t.model(r.ResourceTreeModel.ResourceTreeModel),s=f.get(e);if(!o||!s)return[];return Array.from(s.keys()).map((e=>o.frameForId(e))).filter((e=>Boolean(e)))}}var I=Object.freeze({__proto__:null,NetworkProjectManager:v,NetworkProject:w});class T{#i;#o;#n=new Map;#a;#c;#u=new Map;#l=new Map;#d=new t.MapUtilities.Multimap;constructor(e,t,o){this.#i=e.sourceMapManager(),this.#o=o,this.#a=new l(t,"jsSourceMaps:stub:"+e.target().id(),i.Workspace.projectTypes.Service,"",!0),this.#c=[this.#i.addEventListener(r.SourceMapManager.Events.SourceMapWillAttach,this.sourceMapWillAttach,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapFailedToAttach,this.sourceMapFailedToAttach,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}addStubUISourceCode(t){const o=this.#a.addContentProvider(e.ParsedURL.ParsedURL.concatenate(t.sourceURL,":sourcemap"),s.StaticContentProvider.StaticContentProvider.fromString(t.sourceURL,e.ResourceType.resourceTypes.Script,"\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown while source map is being loaded!"),"text/javascript");this.#n.set(t,o)}removeStubUISourceCode(e){const t=this.#n.get(e);this.#n.delete(e),t&&this.#a.removeUISourceCode(t.url())}getLocationRangesForSameSourceLocation(e){const t=e.debuggerModel,o=e.script();if(!o)return[];const r=this.#i.sourceMapForClient(o);if(!r)return[];const{lineNumber:s,columnNumber:i}=o.rawLocationToRelativeLocation(e),n=r.findEntry(s,i);if(!n||!n.sourceURL)return[];const a=this.#l.get(r);if(!a)return[];const c=a.uiSourceCodeForURL(n.sourceURL);if(!c)return[];if(!this.#d.hasValue(c,r))return[];return r.findReverseRanges(n.sourceURL,n.sourceLineNumber,n.sourceColumnNumber).map((({startLine:e,startColumn:r,endLine:s,endColumn:i})=>{const n=o.relativeLocationToRawLocation({lineNumber:e,columnNumber:r}),a=o.relativeLocationToRawLocation({lineNumber:s,columnNumber:i});return{start:t.createRawLocation(o,n.lineNumber,n.columnNumber),end:t.createRawLocation(o,a.lineNumber,a.columnNumber)}}))}uiSourceCodeForURL(e,t){const o=t?i.Workspace.projectTypes.ContentScripts:i.Workspace.projectTypes.Network;for(const t of this.#u.values()){if(t.type()!==o)continue;const r=t.uiSourceCodeForURL(e);if(r)return r}return null}rawLocationToUILocation(e){const t=e.script();if(!t)return null;const{lineNumber:o,columnNumber:r}=t.rawLocationToRelativeLocation(e),s=this.#n.get(t);if(s)return new i.UISourceCode.UILocation(s,o,r);const n=this.#i.sourceMapForClient(t);if(!n)return null;const a=this.#l.get(n);if(!a)return null;const c=n.findEntry(o,r,e.inlineFrameIndex);if(!c||!c.sourceURL)return null;const u=a.uiSourceCodeForURL(c.sourceURL);return u&&this.#d.hasValue(u,n)?u.uiLocation(c.sourceLineNumber,c.sourceColumnNumber):null}uiLocationToRawLocations(e,t,o){const r=[];for(const s of this.#d.get(e)){const i=s.sourceLineMapping(e.url(),t,o);if(!i)continue;const n=this.#i.clientForSourceMap(s);if(!n)continue;const a=n.relativeLocationToRawLocation(i);r.push(n.debuggerModel.createRawLocation(n,a.lineNumber,a.columnNumber))}return r}uiLocationRangeToRawLocationRanges(e,t){if(!this.#d.has(e))return null;const o=[];for(const r of this.#d.get(e)){const s=this.#i.clientForSourceMap(r);if(s)for(const i of r.reverseMapTextRanges(e.url(),t)){const e=s.relativeLocationToRawLocation(i.start),t=s.relativeLocationToRawLocation(i.end),r=s.debuggerModel.createRawLocation(s,e.lineNumber,e.columnNumber),n=s.debuggerModel.createRawLocation(s,t.lineNumber,t.columnNumber);o.push({start:r,end:n})}}return o}getMappedLines(e){if(!this.#d.has(e))return null;const t=new Set;for(const o of this.#d.get(e))for(const r of o.mappings())r.sourceURL===e.url()&&t.add(r.sourceLineNumber);return t}sourceMapWillAttach(e){const{client:t}=e.data;this.addStubUISourceCode(t),this.#o.updateLocations(t),S.instance().isUserIgnoreListedURL(t.sourceURL,{isContentScript:t.isContentScript()})&&this.#i.cancelAttachSourceMap(t)}sourceMapFailedToAttach(e){const{client:t}=e.data;this.removeStubUISourceCode(t),this.#o.updateLocations(t)}sourceMapAttached(t){const{client:o,sourceMap:n}=t.data,a=new Set([o]);this.removeStubUISourceCode(o);const c=o.target(),u=`jsSourceMaps:${o.isContentScript()?"extensions":""}:${c.id()}`;let d=this.#u.get(u);if(!d){const e=o.isContentScript()?i.Workspace.projectTypes.ContentScripts:i.Workspace.projectTypes.Network;d=new l(this.#a.workspace(),u,e,"",!1),w.setTargetForProject(d,c),this.#u.set(u,d)}this.#l.set(n,d);for(const t of n.sourceURLs()){const c=e.ResourceType.resourceTypes.SourceMapScript,u=d.createUISourceCode(t,c);n.hasIgnoreListHint(t)&&u.markKnownThirdParty();const l=n.embeddedContentByURL(t),g=null!==l?s.StaticContentProvider.StaticContentProvider.fromString(t,c,l):new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(t,c,o.createPageResourceLoadInitiator());let p=null;if(null!==l){const e=new TextEncoder;p=new i.UISourceCode.UISourceCodeMetadata(null,e.encode(l).length)}const h=e.ResourceType.ResourceType.mimeFromURL(t)??c.canonicalMimeType();this.#d.set(u,n),w.setInitialFrameAttribution(u,o.frameId);const m=d.uiSourceCodeForURL(t);if(null!==m){for(const e of this.#d.get(m)){this.#d.delete(m,e);const o=this.#i.clientForSourceMap(e);o&&(w.removeFrameAttribution(m,o.frameId),n.compatibleForURL(t,e)&&(this.#d.set(u,e),w.addFrameAttribution(u,o.frameId)),a.add(o))}d.removeUISourceCode(t)}d.addUISourceCodeWithProvider(u,g,p,h)}Promise.all([...a].map((e=>this.#o.updateLocations(e)))).then((()=>this.sourceMapAttachedForTest(n)))}sourceMapDetached(e){const{client:t,sourceMap:o}=e.data,r=this.#l.get(o);if(r){for(const e of r.uiSourceCodes())this.#d.delete(e,o)&&(w.removeFrameAttribution(e,t.frameId),this.#d.has(e)||r.removeUISourceCode(e.url()));this.#l.delete(o),this.#o.updateLocations(t)}}scriptsForUISourceCode(e){const t=[];for(const o of this.#d.get(e)){const e=this.#i.clientForSourceMap(o);e&&t.push(e)}return t}sourceMapAttachedForTest(e){}dispose(){e.EventTarget.removeEventListeners(this.#c);for(const e of this.#u.values())e.dispose();this.#a.dispose()}}var R=Object.freeze({__proto__:null,CompilerScriptMapping:T});class y{#g;#p;#h;constructor(e,t){this.#g=e,this.#p=t,this.#p.add(this),this.#h=null}async update(){this.#g&&(this.#h?await this.#h.then((()=>this.update())):(this.#h=this.#g(this),await this.#h,this.#h=null))}async uiLocation(){throw"Not implemented"}dispose(){this.#p.delete(this),this.#g=null}isDisposed(){return!this.#p.has(this)}async isIgnoreListed(){throw"Not implemented"}}class F{#m;constructor(){this.#m=new Set}add(e){this.#m.add(e)}delete(e){this.#m.delete(e)}has(e){return this.#m.has(e)}disposeAll(){for(const e of this.#m)e.dispose()}}var U=Object.freeze({__proto__:null,LiveLocationWithPool:y,LiveLocationPool:F});class P{#i;#S;#c;#L;constructor(e,t,o){this.#i=t,this.#S=new l(o,"cssSourceMaps:"+e.id(),i.Workspace.projectTypes.Network,"",!1),w.setTargetForProject(this.#S,e),this.#L=new Map,this.#c=[this.#i.addEventListener(r.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#i.addEventListener(r.SourceMapManager.Events.SourceMapDetached,this.sourceMapDetached,this)]}sourceMapAttachedForTest(e){}async sourceMapAttached(e){const t=e.data.client,o=e.data.sourceMap,r=this.#S,s=this.#L;for(const e of o.sourceURLs()){let i=s.get(e);i||(i=new j(r,e,t.createPageResourceLoadInitiator()),s.set(e,i)),i.addSourceMap(o,t.frameId)}await z.instance().updateLocations(t),this.sourceMapAttachedForTest(o)}async sourceMapDetached(e){const t=e.data.client,o=e.data.sourceMap,r=this.#L;for(const e of o.sourceURLs()){const s=r.get(e);s&&(s.removeSourceMap(o,t.frameId),s.getUiSourceCode()||r.delete(e))}await z.instance().updateLocations(t)}rawLocationToUILocation(e){const t=e.header();if(!t)return null;const o=this.#i.sourceMapForClient(t);if(!o)return null;let{lineNumber:r,columnNumber:s}=e;o.mapsOrigin()&&t.isInline&&(r-=t.startLine,0===r&&(s-=t.startColumn));const i=o.findEntry(r,s);if(!i||!i.sourceURL)return null;const n=this.#S.uiSourceCodeForURL(i.sourceURL);return n?n.uiLocation(i.sourceLineNumber,i.sourceColumnNumber):null}uiLocationToRawLocations(e){const{uiSourceCode:t,lineNumber:o,columnNumber:s=0}=e,i=k.get(t);if(!i)return[];const n=[];for(const e of i.getReferringSourceMaps()){const i=e.findReverseEntries(t.url(),o,s),a=this.#i.clientForSourceMap(e);a&&n.push(...i.map((e=>new r.CSSModel.CSSLocation(a,e.lineNumber,e.columnNumber))))}return n}static uiSourceOrigin(e){const t=k.get(e);return t?t.getReferringSourceMaps().map((e=>e.compiledURL())):[]}dispose(){e.EventTarget.removeEventListeners(this.#c),this.#S.dispose()}}const k=new WeakMap;class j{#S;#M;#f;referringSourceMaps;uiSourceCode;constructor(e,t,o){this.#S=e,this.#M=t,this.#f=o,this.referringSourceMaps=[],this.uiSourceCode=null}recreateUISourceCodeIfNeeded(t){const o=this.referringSourceMaps[this.referringSourceMaps.length-1],n=e.ResourceType.resourceTypes.SourceMapStyleSheet,a=o.embeddedContentByURL(this.#M),c=null!==a?s.StaticContentProvider.StaticContentProvider.fromString(this.#M,n,a):new r.CompilerSourceMappingContentProvider.CompilerSourceMappingContentProvider(this.#M,n,this.#f),u=this.#S.createUISourceCode(this.#M,n);k.set(u,this);const l=e.ResourceType.ResourceType.mimeFromURL(this.#M)||n.canonicalMimeType(),d="string"==typeof a?new i.UISourceCode.UISourceCodeMetadata(null,a.length):null;this.uiSourceCode?(w.cloneInitialFrameAttribution(this.uiSourceCode,u),this.#S.removeUISourceCode(this.uiSourceCode.url())):w.setInitialFrameAttribution(u,t),this.uiSourceCode=u,this.#S.addUISourceCodeWithProvider(this.uiSourceCode,c,d,l)}addSourceMap(e,t){this.uiSourceCode&&w.addFrameAttribution(this.uiSourceCode,t),this.referringSourceMaps.push(e),this.recreateUISourceCodeIfNeeded(t)}removeSourceMap(e,t){const o=this.uiSourceCode;w.removeFrameAttribution(o,t);const r=this.referringSourceMaps.lastIndexOf(e);-1!==r&&this.referringSourceMaps.splice(r,1),this.referringSourceMaps.length?this.recreateUISourceCodeIfNeeded(t):(this.#S.removeUISourceCode(o.url()),this.uiSourceCode=null)}getReferringSourceMaps(){return this.referringSourceMaps}getUiSourceCode(){return this.uiSourceCode}}var D=Object.freeze({__proto__:null,SASSSourceMapping:P});function N(e){for(const t of r.TargetManager.TargetManager.instance().models(r.ResourceTreeModel.ResourceTreeModel)){const o=t.resourceForURL(e);if(o)return o}return null}function E(e,t,o){const s=e.model(r.ResourceTreeModel.ResourceTreeModel);if(!s)return null;const i=s.frameForId(t);return i?x(i.resourceForURL(o)):null}function x(e){return!e||"number"!=typeof e.contentSize()&&!e.lastModified()?null:new i.UISourceCode.UISourceCodeMetadata(e.lastModified(),e.contentSize())}var A=Object.freeze({__proto__:null,resourceForURL:N,displayNameForURL:function(o){if(!o)return"";const s=N(o);if(s)return s.displayName;const n=i.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(o);if(n)return n.displayName();const a=r.TargetManager.TargetManager.instance().inspectedURL();if(!a)return t.StringUtilities.trimURL(o,"");const c=e.ParsedURL.ParsedURL.fromString(a);if(!c)return o;const u=c.lastPathComponent,l=a.indexOf(u);if(-1!==l&&l+u.length===a.length){const e=a.substring(0,l);if(o.startsWith(e)&&o.length>l)return o.substring(l)}const d=t.StringUtilities.trimURL(o,c.host);return"/"===d?c.host+"/":d},metadataForURL:E,resourceMetadata:x});const O=new WeakMap;class W{#b;#S;#C;#c;constructor(e,t){this.#b=e;const o=this.#b.target();this.#S=new l(t,"css:"+o.id(),i.Workspace.projectTypes.Network,"",!1),w.setTargetForProject(this.#S,o),this.#C=new Map,this.#c=[this.#b.addEventListener(r.CSSModel.Events.StyleSheetAdded,this.styleSheetAdded,this),this.#b.addEventListener(r.CSSModel.Events.StyleSheetRemoved,this.styleSheetRemoved,this),this.#b.addEventListener(r.CSSModel.Events.StyleSheetChanged,this.styleSheetChanged,this)]}addSourceMap(e,t){this.#C.get(e)?.addSourceMap(e,t)}rawLocationToUILocation(e){const t=e.header();if(!t||!this.acceptsHeader(t))return null;const o=this.#C.get(t.resourceURL());if(!o)return null;let r=e.lineNumber,s=e.columnNumber;if(t.isInline&&t.hasSourceURL){r-=t.lineNumberInSource(0);const e=t.columnNumberInSource(r,0);void 0===e?s=e:s-=e}return o.getUiSourceCode().uiLocation(r,s)}uiLocationToRawLocations(e){const t=O.get(e.uiSourceCode);if(!t)return[];const o=[];for(const s of t.getHeaders()){let t=e.lineNumber,i=e.columnNumber;s.isInline&&s.hasSourceURL&&(i=s.columnNumberInSource(t,e.columnNumber||0),t=s.lineNumberInSource(t)),o.push(new r.CSSModel.CSSLocation(s,t,i))}return o}acceptsHeader(e){return!e.isConstructedByNew()&&(!(e.isInline&&!e.hasSourceURL&&"inspector"!==e.origin)&&!!e.resourceURL())}styleSheetAdded(e){const t=e.data;if(!this.acceptsHeader(t))return;const o=t.resourceURL();let r=this.#C.get(o);r?r.addHeader(t):(r=new B(this.#b,this.#S,t),this.#C.set(o,r))}styleSheetRemoved(e){const t=e.data;if(!this.acceptsHeader(t))return;const o=t.resourceURL(),r=this.#C.get(o);r&&(1===r.getHeaders().size?(r.dispose(),this.#C.delete(o)):r.removeHeader(t))}styleSheetChanged(e){const t=this.#b.styleSheetHeaderForId(e.data.styleSheetId);if(!t||!this.acceptsHeader(t))return;const o=this.#C.get(t.resourceURL());o&&o.styleSheetChanged(t)}dispose(){for(const e of this.#C.values())e.dispose();this.#C.clear(),e.EventTarget.removeEventListeners(this.#c),this.#S.removeProject()}}class B{#b;#S;headers;uiSourceCode;#c;#v;#w;#I;#T;constructor(t,o,r){this.#b=t,this.#S=o,this.headers=new Set([r]);const s=t.target(),n=r.resourceURL(),a=E(s,r.frameId,n);this.uiSourceCode=this.#S.createUISourceCode(n,r.contentType()),O.set(this.uiSourceCode,this),w.setInitialFrameAttribution(this.uiSourceCode,r.frameId),this.#S.addUISourceCodeWithProvider(this.uiSourceCode,this,a,"text/css"),this.#c=[this.uiSourceCode.addEventListener(i.UISourceCode.Events.WorkingCopyChanged,this.workingCopyChanged,this),this.uiSourceCode.addEventListener(i.UISourceCode.Events.WorkingCopyCommitted,this.workingCopyCommitted,this)],this.#v=new e.Throttler.Throttler(B.updateTimeout),this.#w=!1}addHeader(e){this.headers.add(e),w.addFrameAttribution(this.uiSourceCode,e.frameId)}removeHeader(e){this.headers.delete(e),w.removeFrameAttribution(this.uiSourceCode,e.frameId)}styleSheetChanged(e){if(console.assert(this.headers.has(e)),this.#T||!this.headers.has(e))return;const t=this.mirrorContent.bind(this,e,!0);this.#v.schedule(t,"Default")}workingCopyCommitted(){if(this.#I)return;const e=this.mirrorContent.bind(this,this.uiSourceCode,!0);this.#v.schedule(e,"AsSoonAsPossible")}workingCopyChanged(){if(this.#I)return;const e=this.mirrorContent.bind(this,this.uiSourceCode,!1);this.#v.schedule(e,"Default")}async mirrorContent(e,t){if(this.#w)return void this.styleFileSyncedForTest();let o=null;if(o=e===this.uiSourceCode?this.uiSourceCode.workingCopy():s.ContentData.ContentData.textOr(await e.requestContentData(),null),null===o||this.#w)return void this.styleFileSyncedForTest();e!==this.uiSourceCode&&(this.#I=!0,this.uiSourceCode.addRevision(o),this.#I=!1),this.#T=!0;const r=[];for(const s of this.headers)s!==e&&r.push(this.#b.setStyleSheetText(s.id,o,t));await Promise.all(r),this.#T=!1,this.styleFileSyncedForTest()}styleFileSyncedForTest(){}dispose(){this.#w||(this.#w=!0,this.#S.removeUISourceCode(this.uiSourceCode.url()),e.EventTarget.removeEventListeners(this.#c))}contentURL(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().contentURL()}contentType(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().contentType()}requestContent(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().requestContent()}requestContentData(){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().requestContentData()}searchInContent(e,t,o){return console.assert(this.headers.size>0),this.headers.values().next().value.originalContentProvider().searchInContent(e,t,o)}static updateTimeout=200;getHeaders(){return this.headers}getUiSourceCode(){return this.uiSourceCode}addSourceMap(e,t){const o=this.#b.sourceMapManager();this.headers.forEach((r=>{o.detachSourceMap(r),o.attachSourceMap(r,e,t)}))}}var H=Object.freeze({__proto__:null,StylesSourceMapping:W,StyleFile:B});let _;class z{#R;#y;#F;constructor(e,t){this.#R=e,this.#y=new Map,t.observeModels(r.CSSModel.CSSModel,this),this.#F=new Set}static instance(e={forceNew:null,resourceMapping:null,targetManager:null}){const{forceNew:t,resourceMapping:o,targetManager:r}=e;if(!_||t){if(!o||!r)throw new Error(`Unable to create CSSWorkspaceBinding: resourceMapping and targetManager must be provided: ${(new Error).stack}`);_=new z(o,r)}return _}static removeInstance(){_=void 0}get modelToInfo(){return this.#y}getCSSModelInfo(e){return this.#y.get(e)}modelAdded(e){this.#y.set(e,new V(e,this.#R))}modelRemoved(e){this.getCSSModelInfo(e).dispose(),this.#y.delete(e)}async pendingLiveLocationChangesPromise(){await Promise.all(this.#F)}recordLiveLocationChange(e){e.then((()=>{this.#F.delete(e)})),this.#F.add(e)}async updateLocations(e){const t=this.getCSSModelInfo(e.cssModel()).updateLocations(e);this.recordLiveLocationChange(t),await t}createLiveLocation(e,t,o){const r=this.getCSSModelInfo(e.cssModel()).createLiveLocation(e,t,o);return this.recordLiveLocationChange(r),r}propertyRawLocation(e,t){const o=e.ownerStyle;if(!o||o.type!==r.CSSStyleDeclaration.Type.Regular||!o.styleSheetId)return null;const s=o.cssModel().styleSheetHeaderForId(o.styleSheetId);if(!s)return null;const i=t?e.nameRange():e.valueRange();if(!i)return null;const n=i.startLine,a=i.startColumn;return new r.CSSModel.CSSLocation(s,s.lineNumberInSource(n),s.columnNumberInSource(n,a))}propertyUILocation(e,t){const o=this.propertyRawLocation(e,t);return o?this.rawLocationToUILocation(o):null}rawLocationToUILocation(e){return this.getCSSModelInfo(e.cssModel()).rawLocationToUILocation(e)}uiLocationToRawLocations(e){const t=[];for(const o of this.#y.values())t.push(...o.uiLocationToRawLocations(e));return t}}class V{#c;#R;#U;#P;#m;#k;constructor(e,o){this.#c=[e.addEventListener(r.CSSModel.Events.StyleSheetAdded,(e=>{this.styleSheetAdded(e)}),this),e.addEventListener(r.CSSModel.Events.StyleSheetRemoved,(e=>{this.styleSheetRemoved(e)}),this)],this.#R=o,this.#U=new W(e,o.workspace);const s=e.sourceMapManager();this.#P=new P(e.target(),s,o.workspace),this.#m=new t.MapUtilities.Multimap,this.#k=new t.MapUtilities.Multimap}get locations(){return this.#m}async createLiveLocation(e,t,o){const r=new q(e,this,t,o),s=e.header();return s?(r.setHeader(s),this.#m.set(s,r),await r.update()):this.#k.set(e.url,r),r}disposeLocation(e){const t=e.header();t?this.#m.delete(t,e):this.#k.delete(e.url,e)}updateLocations(e){const t=[];for(const o of this.#m.get(e))t.push(o.update());return Promise.all(t)}async styleSheetAdded(e){const t=e.data;if(!t.sourceURL)return;const o=[];for(const e of this.#k.get(t.sourceURL))e.setHeader(t),this.#m.set(t,e),o.push(e.update());await Promise.all(o),this.#k.deleteAll(t.sourceURL)}async styleSheetRemoved(e){const t=e.data,o=[];for(const e of this.#m.get(t))e.setHeader(t),this.#k.set(e.url,e),o.push(e.update());await Promise.all(o),this.#m.deleteAll(t)}addSourceMap(e,t){this.#U.addSourceMap(e,t)}rawLocationToUILocation(e){let t=null;return t=t||this.#P.rawLocationToUILocation(e),t=t||this.#U.rawLocationToUILocation(e),t=t||this.#R.cssLocationToUILocation(e),t}uiLocationToRawLocations(e){let t=this.#P.uiLocationToRawLocations(e);return t.length?t:(t=this.#U.uiLocationToRawLocations(e),t.length?t:this.#R.uiLocationToCSSLocations(e))}dispose(){e.EventTarget.removeEventListeners(this.#c),this.#U.dispose(),this.#P.dispose()}}class q extends y{url;#j;#D;#N;headerInternal;constructor(e,t,o,r){super(o,r),this.url=e.url,this.#j=e.lineNumber,this.#D=e.columnNumber,this.#N=t,this.headerInternal=null}header(){return this.headerInternal}setHeader(e){this.headerInternal=e}async uiLocation(){if(!this.headerInternal)return null;const e=new r.CSSModel.CSSLocation(this.headerInternal,this.#j,this.#D);return z.instance().rawLocationToUILocation(e)}dispose(){super.dispose(),this.#N.disposeLocation(this)}async isIgnoreListed(){return!1}}var G=Object.freeze({__proto__:null,CSSWorkspaceBinding:z,ModelInfo:V,LiveLocation:q});const K={errorInDebuggerLanguagePlugin:"Error in debugger language plugin: {PH1}",loadingDebugSymbolsForVia:"[{PH1}] Loading debug symbols for {PH2} (via {PH3})...",loadingDebugSymbolsFor:"[{PH1}] Loading debug symbols for {PH2}...",loadedDebugSymbolsForButDidnt:"[{PH1}] Loaded debug symbols for {PH2}, but didn't find any source files",loadedDebugSymbolsForFound:"[{PH1}] Loaded debug symbols for {PH2}, found {PH3} source file(s)",failedToLoadDebugSymbolsFor:"[{PH1}] Failed to load debug symbols for {PH2} ({PH3})",failedToLoadDebugSymbolsForFunction:'No debug information for function "{PH1}"',debugSymbolsIncomplete:"The debug information for function {PH1} is incomplete"},$=n.i18n.registerUIStrings("models/bindings/DebuggerLanguagePlugins.ts",K),J=n.i18n.getLocalizedString.bind(void 0,$);function X(e){return`${e.sourceURL}@${e.hash}`}function Q(e){const{script:t}=e;return{rawModuleId:X(t),codeOffset:e.location().columnNumber-(t.codeOffset()||0),inlineFrameIndex:e.inlineFrameIndex}}class Y extends Error{exception;exceptionDetails;constructor(e,t){const{description:o}=t.exception||{};super(o||t.text),this.exception=e,this.exceptionDetails=t}static makeLocal(e,t){const o={type:"object",subtype:"error",description:t},r={text:"Uncaught",exceptionId:-1,columnNumber:0,lineNumber:0,exception:o},s=e.debuggerModel.runtimeModel().createRemoteObject(o);return new Y(s,r)}}class Z extends r.RemoteObject.LocalJSONObject{constructor(e){super(e)}get description(){return this.type}get type(){return"namespace"}}async function ee(e,t,o){if("reftype"===t.type){const o=await async function(e,t){if(!/^(local|global|operand)$/.test(t.valueClass))return{type:"undefined"};const o=Number(t.index),r=`${t.valueClass}s[${o}]`,s=await e.debuggerModel.agent.invoke_evaluateOnCallFrame({callFrameId:e.id,expression:r,silent:!0,generatePreview:!0,throwOnSideEffect:!0});return s.getError()||s.exceptionDetails?{type:"undefined"}:s.result}(e,t);return e.debuggerModel.runtimeModel().createRemoteObject(o)}return new re(e,t,o)}class te extends r.RemoteObject.RemoteObjectImpl{variables;#E;#x;stopId;constructor(e,t,o){super(e.debuggerModel.runtimeModel(),void 0,"object",void 0,null),this.variables=[],this.#E=e,this.#x=o,this.stopId=t}async doGetProperties(e,t,o){if(t)return{properties:[],internalProperties:[]};const s=[],i={};function n(e,t){return new r.RemoteObject.RemoteObjectProperty(e,t,!1,!1,!0,!1)}for(const e of this.variables){let t;try{const o=await this.#x.evaluate(e.name,Q(this.#E),this.stopId);t=o?await ee(this.#E,o,this.#x):new r.RemoteObject.LocalJSONObject(void 0)}catch(e){console.warn(e),t=new r.RemoteObject.LocalJSONObject(void 0)}if(e.nestedName&&e.nestedName.length>1){let o=i;for(let t=0;t<e.nestedName.length-1;t++){const r=e.nestedName[t];let s=o[r];s||(s=new Z({}),o[r]=s),o=s.value}o[e.nestedName[e.nestedName.length-1]]=t}else s.push(n(e.name,t))}for(const e in i)s.push(n(e,i[e]));return{properties:s,internalProperties:[]}}}class oe{#A;#O;#W;#B;#H;constructor(e,t,o,r,s,i){if(s&&"data:"!==new URL(s).protocol)throw new Error("The icon must be a data:-URL");this.#A=e,this.#O=o,this.#W=r,this.#B=s,this.#H=new te(e,t,i)}async getVariableValue(e){for(let t=0;t<this.#H.variables.length;++t){if(this.#H.variables[t].name!==e)continue;const o=await this.#H.getAllProperties(!1,!1);if(!o.properties)continue;const{value:r}=o.properties[t];if(r)return r}return null}callFrame(){return this.#A}type(){return this.#O}typeName(){return this.#W}name(){}range(){return null}object(){return this.#H}description(){return""}icon(){return this.#B}extraProperties(){return[]}}class re extends r.RemoteObject.RemoteObject{extensionObject;plugin;callFrame;constructor(e,t,o){super(),this.extensionObject=t,this.plugin=o,this.callFrame=e}get linearMemoryAddress(){return this.extensionObject.linearMemoryAddress}get linearMemorySize(){return this.extensionObject.linearMemorySize}get objectId(){return this.extensionObject.objectId}get type(){return"array"===this.extensionObject.type||"null"===this.extensionObject.type?"object":this.extensionObject.type}get subtype(){if("array"===this.extensionObject.type||"null"===this.extensionObject.type)return this.extensionObject.type}get value(){return this.extensionObject.value}unserializableValue(){}get description(){return this.extensionObject.description}set description(e){}get hasChildren(){return this.extensionObject.hasChildren}get preview(){}get className(){return this.extensionObject.className??null}arrayLength(){return 0}arrayBufferByteLength(){return 0}getOwnProperties(e,t){return this.getAllProperties(!1,e,t)}async getAllProperties(e,t,s){const{objectId:i}=this.extensionObject;if(i){o(this.plugin.getProperties);const e=await this.plugin.getProperties(i);return{properties:await Promise.all(e.map((async e=>new r.RemoteObject.RemoteObjectProperty(e.name,await ee(this.callFrame,e.value,this.plugin))))),internalProperties:null}}return{properties:null,internalProperties:null}}release(){const{objectId:e}=this.extensionObject;e&&(o(this.plugin.releaseObject),this.plugin.releaseObject(e))}debuggerModel(){return this.callFrame.debuggerModel}runtimeModel(){return this.callFrame.debuggerModel.runtimeModel()}isLinearMemoryInspectable(){return void 0!==this.extensionObject.linearMemoryAddress}}class se{#_;#o;#z;#V;#q;callFrameByStopId=new Map;stopIdByCallFrame=new Map;nextStopId=0n;constructor(e,t,o){this.#_=t,this.#o=o,this.#z=[],this.#V=new Map,e.observeModels(r.DebuggerModel.DebuggerModel,this),this.#q=new Map}async evaluateOnCallFrame(e,t){const{script:o}=e,{expression:s,returnByValue:i,throwOnSideEffect:n}=t,{plugin:a}=await this.rawModuleIdAndPluginForScript(o);if(!a)return null;const c=Q(e);if(0===(await a.rawLocationToSourceLocation(c)).length)return null;if(i)return{error:"Cannot return by value"};if(n)return{error:"Cannot guarantee side-effect freedom"};try{const t=await a.evaluate(s,c,this.stopIdForCallFrame(e));return t?{object:await ee(e,t,a),exceptionDetails:void 0}:{object:new r.RemoteObject.LocalJSONObject(void 0),exceptionDetails:void 0}}catch(t){if(t instanceof Y){const{exception:e,exceptionDetails:o}=t;return{object:e,exceptionDetails:o}}const{exception:o,exceptionDetails:r}=Y.makeLocal(e,t.message);return{object:o,exceptionDetails:r}}}stopIdForCallFrame(e){let t=this.stopIdByCallFrame.get(e);return void 0!==t||(t=this.nextStopId++,this.stopIdByCallFrame.set(e,t),this.callFrameByStopId.set(t,e)),t}callFrameForStopId(e){return this.callFrameByStopId.get(e)}expandCallFrames(e){return Promise.all(e.map((async e=>{const t=await this.getFunctionInfo(e.script,e.location());if(t){if("frames"in t&&t.frames.length)return t.frames.map((({name:t},o)=>e.createVirtualCallFrame(o,t)));if("missingSymbolFiles"in t&&t.missingSymbolFiles.length){const o=t.missingSymbolFiles,r=J(K.debugSymbolsIncomplete,{PH1:e.functionName});e.missingDebugInfoDetails={details:r,resources:o}}else e.missingDebugInfoDetails={details:J(K.failedToLoadDebugSymbolsForFunction,{PH1:e.functionName}),resources:[]}}return e}))).then((e=>e.flat()))}modelAdded(e){this.#V.set(e,new ie(e,this.#_)),e.addEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),e.addEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),e.addEventListener(r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),e.setEvaluateOnCallFrameCallback(this.evaluateOnCallFrame.bind(this)),e.setExpandCallFramesCallback(this.expandCallFrames.bind(this))}modelRemoved(t){t.removeEventListener(r.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),t.removeEventListener(r.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),t.removeEventListener(r.DebuggerModel.Events.DebuggerResumed,this.debuggerResumed,this),t.setEvaluateOnCallFrameCallback(null),t.setExpandCallFramesCallback(null);const o=this.#V.get(t);o&&(o.dispose(),this.#V.delete(t)),this.#q.forEach(((o,r)=>{const s=o.scripts.filter((e=>e.debuggerModel!==t));0===s.length?(o.plugin.removeRawModule(r).catch((t=>{e.Console.Console.instance().error(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message}))})),this.#q.delete(r)):o.scripts=s}))}globalObjectCleared(e){const t=e.data;this.modelRemoved(t),this.modelAdded(t)}addPlugin(e){this.#z.push(e);for(const e of this.#V.keys())for(const t of e.scripts())this.hasPluginForScript(t)||this.parsedScriptSource({data:t})}removePlugin(e){this.#z=this.#z.filter((t=>t!==e));const t=new Set;this.#q.forEach(((o,r)=>{o.plugin===e&&(o.scripts.forEach((e=>t.add(e))),this.#q.delete(r))}));for(const e of t){this.#V.get(e.debuggerModel).removeScript(e),this.parsedScriptSource({data:e})}}hasPluginForScript(e){const t=X(e),o=this.#q.get(t);return void 0!==o&&o.scripts.includes(e)}async rawModuleIdAndPluginForScript(e){const t=X(e),o=this.#q.get(t);return o&&(await o.addRawModulePromise,o===this.#q.get(t))?{rawModuleId:t,plugin:o.plugin}:{rawModuleId:t,plugin:null}}uiSourceCodeForURL(e,t){const o=this.#V.get(e);return o?o.getProject().uiSourceCodeForURL(t):null}async rawLocationToUILocation(t){const o=t.script();if(!o)return null;const{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(o);if(!s)return null;const i={rawModuleId:r,codeOffset:t.columnNumber-(o.codeOffset()||0),inlineFrameIndex:t.inlineFrameIndex};try{const e=await s.rawLocationToSourceLocation(i);for(const t of e){const e=this.uiSourceCodeForURL(o.debuggerModel,t.sourceFileURL);if(e)return e.uiLocation(t.lineNumber,t.columnNumber>=0?t.columnNumber:void 0)}}catch(t){e.Console.Console.instance().error(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message}))}return null}uiLocationToRawLocationRanges(t,o,s=-1){const i=[];return this.scriptsForUISourceCode(t).forEach((e=>{const n=X(e),a=this.#q.get(n);if(!a)return;const{plugin:c}=a;i.push(async function(e,i,n){const a={rawModuleId:e,sourceFileURL:t.url(),lineNumber:o,columnNumber:s},c=await i.sourceLocationToRawLocation(a);if(!c)return[];return c.map((e=>({start:new r.DebuggerModel.Location(n.debuggerModel,n.scriptId,0,Number(e.startOffset)+(n.codeOffset()||0)),end:new r.DebuggerModel.Location(n.debuggerModel,n.scriptId,0,Number(e.endOffset)+(n.codeOffset()||0))})))}(n,c,e))})),0===i.length?Promise.resolve(null):Promise.all(i).then((e=>e.flat())).catch((t=>(e.Console.Console.instance().error(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message})),null)))}async uiLocationToRawLocations(e,t,o){const r=await this.uiLocationToRawLocationRanges(e,t,o);return r?r.map((({start:e})=>e)):null}async uiLocationRangeToRawLocationRanges(e,t){const o=[];for(let r=t.startLine;r<=t.endLine;++r)o.push(this.uiLocationToRawLocationRanges(e,r));const r=[];for(const e of await Promise.all(o)){if(null===e)return null;for(const o of e){const[e,i]=await Promise.all([this.rawLocationToUILocation(o.start),this.rawLocationToUILocation(o.end)]);if(null===e||null===i)continue;t.intersection(new s.TextRange.TextRange(e.lineNumber,e.columnNumber??0,i.lineNumber,i.columnNumber??1/0)).isEmpty()||r.push(o)}}return r}scriptsForUISourceCode(e){for(const t of this.#V.values()){const o=t.uiSourceCodeToScripts.get(e);if(o)return o}return[]}setDebugInfoURL(e,t){this.hasPluginForScript(e)||(e.debugSymbols={type:"ExternalDWARF",externalURL:t},this.parsedScriptSource({data:e}),e.debuggerModel.setDebugInfoURL(e,t))}parsedScriptSource(t){const o=t.data;if(o.sourceURL)for(const t of this.#z){if(!t.handleScript(o))continue;const r=X(o);let s=this.#q.get(r);if(s)s.scripts.push(o);else{const i=(async()=>{const i=e.Console.Console.instance(),n=o.sourceURL,a=o.debugSymbols&&o.debugSymbols.externalURL||"";a?i.log(J(K.loadingDebugSymbolsForVia,{PH1:t.name,PH2:n,PH3:a})):i.log(J(K.loadingDebugSymbolsFor,{PH1:t.name,PH2:n}));try{const c=!a&&e.ParsedURL.schemeIs(n,"wasm:")?await o.getWasmBytecode():void 0,u=await t.addRawModule(r,a,{url:n,code:c});if(s!==this.#q.get(r))return[];if("missingSymbolFiles"in u){const e=t.createPageResourceLoadInitiator();return{missingSymbolFiles:u.missingSymbolFiles.map((t=>({resourceUrl:t,initiator:e})))}}const l=u;return 0===l.length?i.warn(J(K.loadedDebugSymbolsForButDidnt,{PH1:t.name,PH2:n})):i.log(J(K.loadedDebugSymbolsForFound,{PH1:t.name,PH2:n,PH3:l.length})),l}catch(e){return i.error(J(K.failedToLoadDebugSymbolsFor,{PH1:t.name,PH2:n,PH3:e.message})),this.#q.delete(r),[]}})();s={rawModuleId:r,plugin:t,scripts:[o],addRawModulePromise:i},this.#q.set(r,s)}return void s.addRawModulePromise.then((e=>{if(!("missingSymbolFiles"in e)&&o.debuggerModel.scriptForId(o.scriptId)===o){const t=this.#V.get(o.debuggerModel);t&&(t.addSourceFiles(o,e),this.#o.updateLocations(o))}}))}}debuggerResumed(e){const t=Array.from(this.callFrameByStopId.values()).filter((t=>t.debuggerModel===e.data));for(const e of t){const t=this.stopIdByCallFrame.get(e);o(t),this.stopIdByCallFrame.delete(e),this.callFrameByStopId.delete(t)}}getSourcesForScript(e){const t=X(e),o=this.#q.get(t);return o?o.addRawModulePromise:Promise.resolve(void 0)}async resolveScopeChain(t){const o=t.script,{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(o);if(!s)return null;const i={rawModuleId:r,codeOffset:t.location().columnNumber-(o.codeOffset()||0),inlineFrameIndex:t.inlineFrameIndex},n=this.stopIdForCallFrame(t);try{if(0===(await s.rawLocationToSourceLocation(i)).length)return null;const e=new Map,o=await s.listVariablesInScope(i);for(const r of o||[]){let o=e.get(r.scope);if(!o){const{type:i,typeName:a,icon:c}=await s.getScopeInfo(r.scope);o=new oe(t,n,i,a,c,s),e.set(r.scope,o)}o.object().variables.push(r)}return Array.from(e.values())}catch(t){return e.Console.Console.instance().error(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message})),null}}async getFunctionInfo(t,o){const{rawModuleId:r,plugin:s}=await this.rawModuleIdAndPluginForScript(t);if(!s)return null;const i={rawModuleId:r,codeOffset:o.columnNumber-(t.codeOffset()||0),inlineFrameIndex:0};try{const e=await s.getFunctionInfo(i);if("missingSymbolFiles"in e){const t=s.createPageResourceLoadInitiator();return{missingSymbolFiles:e.missingSymbolFiles.map((e=>({resourceUrl:e,initiator:t}))),..."frames"in e&&{frames:e.frames}}}return e}catch(t){return e.Console.Console.instance().warn(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message})),{frames:[]}}}async getInlinedFunctionRanges(t){const o=t.script();if(!o)return[];const{rawModuleId:s,plugin:i}=await this.rawModuleIdAndPluginForScript(o);if(!i)return[];const n={rawModuleId:s,codeOffset:t.columnNumber-(o.codeOffset()||0)};try{return(await i.getInlinedFunctionRanges(n)).map((e=>({start:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.startOffset)+(o.codeOffset()||0)),end:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.endOffset)+(o.codeOffset()||0))})))}catch(t){return e.Console.Console.instance().warn(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message})),[]}}async getInlinedCalleesRanges(t){const o=t.script();if(!o)return[];const{rawModuleId:s,plugin:i}=await this.rawModuleIdAndPluginForScript(o);if(!i)return[];const n={rawModuleId:s,codeOffset:t.columnNumber-(o.codeOffset()||0)};try{return(await i.getInlinedCalleesRanges(n)).map((e=>({start:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.startOffset)+(o.codeOffset()||0)),end:new r.DebuggerModel.Location(o.debuggerModel,o.scriptId,0,Number(e.endOffset)+(o.codeOffset()||0))})))}catch(t){return e.Console.Console.instance().warn(J(K.errorInDebuggerLanguagePlugin,{PH1:t.message})),[]}}async getMappedLines(e){const t=await Promise.all(this.scriptsForUISourceCode(e).map((e=>this.rawModuleIdAndPluginForScript(e))));let o=null;for(const{rawModuleId:r,plugin:s}of t){if(!s)continue;const t=await s.getMappedLines(r,e.url());void 0!==t&&(null===o?o=new Set(t):t.forEach((e=>o.add(e))))}return o}}class ie{project;uiSourceCodeToScripts;constructor(e,t){this.project=new l(t,"language_plugins::"+e.target().id(),i.Workspace.projectTypes.Network,"",!1),w.setTarget