Skip to content

Commit

Permalink
Allow export to define properties on self
Browse files Browse the repository at this point in the history
Signed-off-by: William So <polyipseity@gmail.com>
  • Loading branch information
polyipseity committed May 1, 2023
1 parent 72c619c commit 14c8813
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions sources/terminal/pseudoterminal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type AnyObject, deopaque, launderUnchecked } from "sources/utils/types"
import {
CONTROL_SEQUENCE_INTRODUCER as CSI,
CursoredText,
Expand Down Expand Up @@ -37,6 +36,7 @@ import {
sleep2,
spawnPromise,
typedKeys,
typedOwnKeys,
writePromise,
} from "../utils/util"
import type { IMarker, Terminal } from "xterm"
Expand All @@ -55,6 +55,7 @@ import { Platform } from "sources/utils/platforms"
import type { Program } from "estree"
import type { TerminalPlugin } from "../main"
import ansi from "ansi-escape-sequences"
import { deopaque } from "sources/utils/types"
import { dynamicRequire } from "../imports"
import unixPseudoterminalPy from "./unix_pseudoterminal.py"
import win32ResizerPy from "./win32_resizer.py"
Expand Down Expand Up @@ -406,7 +407,7 @@ export class ConsolePseudoterminal
locations: false,
preserveParens: true,
ranges: false,
sourceType: "script",
sourceType: "module",
})
} catch (error) {
console.error(error)
Expand All @@ -430,7 +431,10 @@ export class ConsolePseudoterminal
))
try {
const [success, ret] = await (
async (): Promise<[false] | [true, unknown]> => {
async (): Promise<[false] | [true, {
readonly [_: keyof any]: unknown
readonly default?: unknown
}]> => {
if (url2) {
try {
return [true, await import(url2)]
Expand All @@ -450,7 +454,18 @@ export class ConsolePseudoterminal
}
})()
if (!success) { return }
console.log(launderUnchecked<AnyObject>(ret)["default"])
console.log(ret.default)
for (const key of typedOwnKeys(ret)) {
if (key === "default" || key === Symbol.toStringTag) { continue }
try {
Object.defineProperty(self, key, {
configurable: true,
enumerable: true,
value: ret[key],
writable: true,
})
} catch (error) { self.console.warn(error) }
}
} finally { if (url2) { URL.revokeObjectURL(url2) } }
} finally { URL.revokeObjectURL(url) }
}
Expand Down

0 comments on commit 14c8813

Please sign in to comment.