(function () {
const { core, internals, primordials } = __bootstrap;
const {
op_console_css_to_ansi,
op_console_format_value,
op_console_get_string_width,
op_console_inspect,
op_console_inspect_args,
op_console_parse_css,
op_console_parse_css_color,
op_console_quote_string,
op_console_strip_vt,
Console: ConsoleWrap,
} = core.ops;
const {
AggregateError,
AggregateErrorPrototype,
Array,
ArrayBuffer,
ArrayBufferPrototype,
ArrayPrototype,
BigIntPrototypeValueOf,
Boolean,
BooleanPrototype,
BooleanPrototypeValueOf,
DataView,
DataViewPrototype,
Date,
DatePrototype,
Error,
ErrorCaptureStackTrace,
ErrorPrototype,
Function,
FunctionPrototype,
FunctionPrototypeToString,
Map,
MapPrototype,
Number,
NumberPrototype,
NumberPrototypeValueOf,
Object,
ObjectAssign,
ObjectCreate,
ObjectDefineProperty,
ObjectIs,
ObjectPrototype,
ObjectPrototypeIsPrototypeOf,
ObjectSetPrototypeOf,
Promise,
PromisePrototype,
RangeError,
RangeErrorPrototype,
ReflectGetOwnPropertyDescriptor,
ReflectGetPrototypeOf,
RegExp,
RegExpPrototype,
RegExpPrototypeToString,
SafeArrayIterator,
SafeRegExp,
Set,
SetPrototype,
String,
StringPrototype,
StringPrototypeValueOf,
Symbol,
SymbolFor,
SymbolHasInstance,
SymbolPrototypeValueOf,
SymbolToStringTag,
TypedArray,
TypedArrayPrototype,
TypeError,
TypeErrorPrototype,
WeakMap,
WeakMapPrototype,
WeakSet,
WeakSetPrototype,
} = primordials;
let noColorStdout = () => false;
let noColorStderr = () => false;
function setNoColorFns(stdoutFn, stderrFn) {
noColorStdout = stdoutFn;
noColorStderr = stderrFn;
}
function getStdoutNoColor() {
return noColorStdout();
}
function getStderrNoColor() {
return noColorStderr();
}
const styles = {
special: "cyan",
number: "yellow",
bigint: "yellow",
boolean: "yellow",
undefined: "grey",
null: "bold",
string: "green",
symbol: "green",
date: "magenta",
regexp: "red",
module: "underline",
internalError: "red",
temporal: "cyan",
};
const defaultFG = 39;
const defaultBG = 49;
const colors = {
reset: [0, 0],
bold: [1, 22],
dim: [2, 22], italic: [3, 23],
underline: [4, 24],
blink: [5, 25],
inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], doubleunderline: [21, 24], black: [30, defaultFG],
red: [31, defaultFG],
green: [32, defaultFG],
yellow: [33, defaultFG],
blue: [34, defaultFG],
magenta: [35, defaultFG],
cyan: [36, defaultFG],
white: [37, defaultFG],
bgBlack: [40, defaultBG],
bgRed: [41, defaultBG],
bgGreen: [42, defaultBG],
bgYellow: [43, defaultBG],
bgBlue: [44, defaultBG],
bgMagenta: [45, defaultBG],
bgCyan: [46, defaultBG],
bgWhite: [47, defaultBG],
framed: [51, 54],
overlined: [53, 55],
gray: [90, defaultFG], redBright: [91, defaultFG],
greenBright: [92, defaultFG],
yellowBright: [93, defaultFG],
blueBright: [94, defaultFG],
magentaBright: [95, defaultFG],
cyanBright: [96, defaultFG],
whiteBright: [97, defaultFG],
bgGray: [100, defaultBG], bgRedBright: [101, defaultBG],
bgGreenBright: [102, defaultBG],
bgYellowBright: [103, defaultBG],
bgBlueBright: [104, defaultBG],
bgMagentaBright: [105, defaultBG],
bgCyanBright: [106, defaultBG],
bgWhiteBright: [107, defaultBG],
};
function defineColorAlias(target, alias) {
ObjectDefineProperty(colors, alias, {
__proto__: null,
get() {
return this[target];
},
set(value) {
this[target] = value;
},
configurable: true,
enumerable: false,
});
}
defineColorAlias("gray", "grey");
defineColorAlias("gray", "blackBright");
defineColorAlias("bgGray", "bgGrey");
defineColorAlias("bgGray", "bgBlackBright");
defineColorAlias("dim", "faint");
defineColorAlias("strikethrough", "crossedout");
defineColorAlias("strikethrough", "strikeThrough");
defineColorAlias("strikethrough", "crossedOut");
defineColorAlias("hidden", "conceal");
defineColorAlias("inverse", "swapColors");
defineColorAlias("inverse", "swapcolors");
defineColorAlias("doubleunderline", "doubleUnderline");
const stylizeMarker = SymbolFor("Deno.privateConsoleStylize");
function stylizeNoColor(str) {
return str;
}
ObjectDefineProperty(stylizeNoColor, stylizeMarker, {
__proto__: null,
value: "noColor",
enumerable: false,
});
function createStylizeWithColor(styles, colors) {
function stylizeWithColor(str, styleType) {
const style = styles[styleType];
if (style !== undefined) {
const color = colors[style];
if (color !== undefined) {
return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
}
}
return str;
}
ObjectDefineProperty(stylizeWithColor, stylizeMarker, {
__proto__: null,
value: [styles, colors],
enumerable: false,
});
return stylizeWithColor;
}
let _URLPrototype;
function getURLPrototype() {
if (!_URLPrototype) {
_URLPrototype = core.loadExtScript("ext:deno_web/00_url.js").URLPrototype;
}
return _URLPrototype;
}
function getCwd() {
try {
return Deno.cwd();
} catch {
return undefined;
}
}
function makeCrossContextStylize(stylize) {
return ObjectSetPrototypeOf((value, flavour) => {
let stylized;
try {
stylized = `${stylize(value, flavour)}`;
} catch {
}
if (typeof stylized !== "string") return value;
return stylized;
}, null);
}
const intrinsics = {
__proto__: null,
functionToString: function functionToString() {
return FunctionPrototypeToString(this);
},
regExpToString: function regExpToString() {
const re = ObjectPrototypeIsPrototypeOf(RegExpPrototype, this)
? this
: new SafeRegExp(this);
return RegExpPrototypeToString(re);
},
numberValueOf: function numberValueOf() {
return NumberPrototypeValueOf(this);
},
stringValueOf: function stringValueOf() {
return StringPrototypeValueOf(this);
},
booleanValueOf: function booleanValueOf() {
return BooleanPrototypeValueOf(this);
},
bigIntValueOf: function bigIntValueOf() {
return BigIntPrototypeValueOf(this);
},
symbolValueOf: function symbolValueOf() {
return SymbolPrototypeValueOf(this);
},
inspect,
stylizeNoColor,
createStylizeWithColor,
styles,
colors,
objectPrototype: ObjectPrototype,
errorPrototype: ErrorPrototype,
wellKnown: [
ArrayPrototype,
"Array",
Array,
ArrayBufferPrototype,
"ArrayBuffer",
ArrayBuffer,
FunctionPrototype,
"Function",
Function,
MapPrototype,
"Map",
Map,
SetPrototype,
"Set",
Set,
ObjectPrototype,
"Object",
Object,
TypedArrayPrototype,
"TypedArray",
TypedArray,
RegExpPrototype,
"RegExp",
RegExp,
DatePrototype,
"Date",
Date,
DataViewPrototype,
"DataView",
DataView,
ErrorPrototype,
"Error",
Error,
AggregateErrorPrototype,
"AggregateError",
AggregateError,
RangeErrorPrototype,
"RangeError",
RangeError,
TypeErrorPrototype,
"TypeError",
TypeError,
BooleanPrototype,
"Boolean",
Boolean,
NumberPrototype,
"Number",
Number,
StringPrototype,
"String",
String,
PromisePrototype,
"Promise",
Promise,
WeakMapPrototype,
"WeakMap",
WeakMap,
WeakSetPrototype,
"WeakSet",
WeakSet,
],
getURLPrototype,
getCwd,
makeCrossContextStylize,
};
const denoInspectDefaultOptions = {
indentationLvl: 0,
currentDepth: 0,
stylize: stylizeNoColor,
showHidden: false,
depth: 4,
colors: false,
showProxy: false,
breakLength: 80,
escapeSequences: true,
compact: 3,
sorted: false,
getters: false,
maxArrayLength: 100,
maxStringLength: 10_000, customInspect: true,
quotes: ['"', "'", "`"],
iterableLimit: 100, trailingComma: false,
inspect,
indentLevel: 0,
};
function getDefaultInspectOptions() {
return {
budget: {},
seen: [],
...denoInspectDefaultOptions,
};
}
class CSI {
static kClear = "\x1b[1;1H";
static kClearScreenDown = "\x1b[0J";
}
function quoteString(string, ctx) {
return op_console_quote_string(string, ctx);
}
function getStringWidth(str, removeControlChars = true) {
return op_console_get_string_width(str, removeControlChars);
}
function stripVTControlCharacters(str) {
return op_console_strip_vt(str);
}
function formatNumber(fn, value) {
return fn(ObjectIs(value, -0) ? "-0" : `${value}`, "number");
}
function formatBigInt(fn, value) {
return fn(`${value}n`, "bigint");
}
function formatValue(ctx, value, recurseTimes) {
return op_console_format_value(intrinsics, ctx, value, recurseTimes ?? 0);
}
function inspectArgs(args, inspectOptions = { __proto__: null }) {
const colors = inspectOptions.colors ?? !noColorStdout();
return op_console_inspect_args(intrinsics, args, {
__proto__: null,
...inspectOptions,
colors,
});
}
function inspect(
value,
inspectOptions = { __proto__: null },
) {
return op_console_inspect(intrinsics, value, inspectOptions);
}
function cssToAnsi(css, prevCss = null) {
return op_console_css_to_ansi(css, prevCss);
}
function parseCss(cssString) {
return op_console_parse_css(cssString);
}
function parseCssColor(colorString) {
return op_console_parse_css_color(colorString);
}
function getConsoleInspectOptions(noColor) {
return {
...getDefaultInspectOptions(),
colors: !noColor,
stylize: noColor ? stylizeNoColor : createStylizeWithColor(styles, colors),
};
}
const isConsoleInstance = Symbol("isConsoleInstance");
class Console {
#wrap = null;
#printFunc = null;
#consoleRef = null;
[isConsoleInstance] = false;
#indentLevel = 0;
#getWrap() {
if (this.#wrap === null) {
this.#wrap = new ConsoleWrap(
this.#printFunc,
intrinsics,
getStdoutNoColor,
getStderrNoColor,
);
this.#wrap.indentLevel = this.#indentLevel;
}
return this.#wrap;
}
constructor(printFunc) {
this.#printFunc = printFunc;
ObjectDefineProperty(this, "indentLevel", {
__proto__: null,
get: () => {
return this.#wrap === null ? this.#indentLevel : this.#wrap.indentLevel;
},
set: (value) => {
if (this.#wrap === null) {
this.#indentLevel = value;
} else {
this.#wrap.indentLevel = value;
}
},
enumerable: true,
configurable: true,
});
this[isConsoleInstance] = true;
const console = ObjectCreate({}, {
[SymbolToStringTag]: {
enumerable: false,
writable: false,
configurable: true,
value: "console",
},
});
ObjectAssign(console, this);
this.#consoleRef = console;
return console;
}
log = (...args) => {
this.#getWrap().log(...new SafeArrayIterator(args));
};
debug = (...args) => {
this.#getWrap().debug(...new SafeArrayIterator(args));
};
info = (...args) => {
this.#getWrap().info(...new SafeArrayIterator(args));
};
dir = (obj = undefined, options = { __proto__: null }) => {
this.#getWrap().dir(obj, options);
};
dirxml = (...args) => {
this.log(...new SafeArrayIterator(args));
};
warn = (...args) => {
this.#getWrap().warn(...new SafeArrayIterator(args));
};
error = (...args) => {
this.#getWrap().error(...new SafeArrayIterator(args));
};
assert = (condition = false, ...args) => {
this.#getWrap().assert(!!condition, ...new SafeArrayIterator(args));
};
count = (label = "default") => {
this.#getWrap().count(String(label));
};
countReset = (label = "default") => {
this.#getWrap().countReset(String(label));
};
table = (data = undefined, properties = undefined) => {
this.#getWrap().table(data, properties);
};
time = (label = "default") => {
this.#getWrap().time(String(label));
};
timeLog = (label = "default", ...args) => {
this.#getWrap().timeLog(String(label), ...new SafeArrayIterator(args));
};
timeEnd = (label = "default") => {
this.#getWrap().timeEnd(String(label));
};
group = (...label) => {
if (label.length > 0) {
this.#consoleRef.log(...new SafeArrayIterator(label));
}
this.#getWrap().indentLevel++;
};
groupCollapsed = this.group;
groupEnd = () => {
const wrap = this.#getWrap();
if (wrap.indentLevel > 0) {
wrap.indentLevel--;
}
};
clear = () => {
this.#getWrap().clear();
};
trace = (...args) => {
const message = inspectArgs(
args,
{
...getConsoleInspectOptions(noColorStderr()),
indentLevel: 0,
},
);
const err = {
name: "Trace",
message,
};
ErrorCaptureStackTrace(err, this.trace);
this.#printFunc(err.stack, 4);
this.#printFunc("\n", 4);
};
profile = (_label) => {};
profileEnd = (_label) => {};
timeStamp = (_label) => {};
static [SymbolHasInstance](instance) {
return instance[isConsoleInstance];
}
}
const customInspect = SymbolFor("Deno.customInspect");
function createFilteredInspectProxy({ object, keys, evaluate }) {
const cls = class {};
if (object.constructor?.name) {
ObjectDefineProperty(cls, "name", {
__proto__: null,
value: object.constructor.name,
});
}
const result = new cls();
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const descriptor = evaluate
? getEvaluatedDescriptor(object, key)
: (getDescendantPropertyDescriptor(object, key) ??
getEvaluatedDescriptor(object, key));
ObjectDefineProperty(result, key, descriptor);
}
return result;
function getDescendantPropertyDescriptor(object, key) {
let propertyDescriptor = ReflectGetOwnPropertyDescriptor(object, key);
if (!propertyDescriptor) {
const prototype = ReflectGetPrototypeOf(object);
if (prototype) {
propertyDescriptor = getDescendantPropertyDescriptor(prototype, key);
}
}
return propertyDescriptor;
}
function getEvaluatedDescriptor(object, key) {
return {
configurable: true,
enumerable: true,
value: object[key],
};
}
}
internals.Console = Console;
internals.cssToAnsi = cssToAnsi;
internals.inspectArgs = inspectArgs;
internals.parseCss = parseCss;
internals.parseCssColor = parseCssColor;
return {
colors,
Console,
createFilteredInspectProxy,
createStylizeWithColor,
CSI,
customInspect,
formatBigInt,
formatNumber,
formatValue,
getConsoleInspectOptions,
getDefaultInspectOptions,
getStderrNoColor,
getStringWidth,
getStdoutNoColor,
inspect,
inspectArgs,
quoteString,
setNoColorFns,
stripVTControlCharacters,
styles,
};
})();