@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 2.66 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as SDK from"../../core/sdk/sdk.js";import*as Workspace from"../workspace/workspace.js";import{ContentProviderBasedProject}from"./ContentProviderBasedProject.js";export class DefaultScriptMapping{#e;#o;#t;#r;#i;constructor(e,o,t){defaultScriptMappings.add(this),this.#e=t,this.#o=new ContentProviderBasedProject(o,"debugger:"+e.target().id(),Workspace.Workspace.projectTypes.Debugger,"",!0),this.#t=[e.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared,this.globalObjectCleared,this),e.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSource,this.parsedScriptSource,this),e.addEventListener(SDK.DebuggerModel.Events.DiscardedAnonymousScriptSource,this.discardedScriptSource,this)],this.#r=new Map,this.#i=new Map}static createV8ScriptURL(e){const o=Common.ParsedURL.ParsedURL.extractName(e.sourceURL);return"debugger:///VM"+e.scriptId+(o?" "+o:"")}static scriptForUISourceCode(e){for(const o of defaultScriptMappings){const t=o.#r.get(e);if(void 0!==t)return t}return null}uiSourceCodeForScript(e){return this.#i.get(e)??null}rawLocationToUILocation(e){const o=e.script();if(!o)return null;const t=this.#i.get(o);if(!t)return null;const{lineNumber:r,columnNumber:i}=o.rawLocationToRelativeLocation(e);return t.uiLocation(r,i)}uiLocationToRawLocations(e,o,t){const r=this.#r.get(e);return r?(({lineNumber:o,columnNumber:t}=r.relativeLocationToRawLocation({lineNumber:o,columnNumber:t})),[r.debuggerModel.createRawLocation(r,o,t??0)]):[]}uiLocationRangeToRawLocationRanges(e,{startLine:o,startColumn:t,endLine:r,endColumn:i}){const c=this.#r.get(e);if(!c)return[];({lineNumber:o,columnNumber:t}=c.relativeLocationToRawLocation({lineNumber:o,columnNumber:t})),({lineNumber:r,columnNumber:i}=c.relativeLocationToRawLocation({lineNumber:r,columnNumber:i}));return[{start:c.debuggerModel.createRawLocation(c,o,t),end:c.debuggerModel.createRawLocation(c,r,i)}]}parsedScriptSource(e){const o=e.data,t=DefaultScriptMapping.createV8ScriptURL(o),r=this.#o.createUISourceCode(t,Common.ResourceType.resourceTypes.Script);o.isBreakpointCondition&&r.markAsUnconditionallyIgnoreListed(),this.#r.set(r,o),this.#i.set(o,r),this.#o.addUISourceCodeWithProvider(r,o,null,"text/javascript"),this.#e.updateLocations(o)}discardedScriptSource(e){const o=e.data,t=this.#i.get(o);void 0!==t&&(this.#i.delete(o),this.#r.delete(t),this.#o.removeUISourceCode(t.url()))}globalObjectCleared(){this.#i.clear(),this.#r.clear(),this.#o.reset()}dispose(){defaultScriptMappings.delete(this),Common.EventTarget.removeEventListeners(this.#t),this.globalObjectCleared(),this.#o.dispose()}}const defaultScriptMappings=new Set;