MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / withCurrentScript

Function withCurrentScript

packages/extension/rewrite/runtime.ts:24–43  ·  view source on GitHub ↗
(current: HTMLScriptElement, run: () => void)

Source from the content-addressed store, hash-verified

22}
23
24function withCurrentScript(current: HTMLScriptElement, run: () => void): void {
25 const descriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'currentScript')
26
27 Object.defineProperty(document, 'currentScript', {
28 configurable: true,
29 get() {
30 return current
31 }
32 })
33
34 try {
35 run()
36 } finally {
37 if (descriptor) {
38 Object.defineProperty(document, 'currentScript', descriptor)
39 } else {
40 Reflect.deleteProperty(document, 'currentScript')
41 }
42 }
43}
44
45function patchFigmaDelete(code: string): string {
46 return code.replaceAll(FIGMA_DELETE_PATCH_TARGET, FIGMA_DELETE_PATCH_VALUE)

Callers 1

rewriteCurrentScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected