mirror of https://github.com/sveltejs/svelte
parent
4092b7cbde
commit
32e3a5f2ac
@ -1,43 +1,43 @@
|
|||||||
import { STATE_SYMBOL } from '../constants.js';
|
import { STATE_SYMBOL } from '../constants.js';
|
||||||
|
import { VERSION } from '../../../version.js';
|
||||||
|
import { snapshot } from '../../shared/clone.js';
|
||||||
|
import * as w from '../warnings.js';
|
||||||
|
|
||||||
export function monkey_patch_console() {
|
export function install_custom_formatter() {
|
||||||
for (const method of Object.keys(console)) {
|
// Custom formatters are 'supported' in Firefox, but they're worse than useless.
|
||||||
// @ts-expect-error
|
// They're not supported in Firefox. We can maybe tweak this over time
|
||||||
const original = console[method];
|
var is_chrome = navigator.userAgent.includes('Chrome');
|
||||||
|
var custom_formatters_enabled = false;
|
||||||
|
|
||||||
|
if (is_chrome) {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
console[method] = (...args) => {
|
(window.devtoolsFormatters ??= []).push({
|
||||||
for (const arg of args) {
|
/**
|
||||||
if (contains_state_proxy(arg)) {
|
* @param {any} object
|
||||||
// TODO make this a proper warning
|
* @param {any} config
|
||||||
console.warn('contains state proxy!!!!');
|
*/
|
||||||
break;
|
header(object, config) {
|
||||||
}
|
custom_formatters_enabled = true;
|
||||||
}
|
|
||||||
|
|
||||||
return original.apply(console, args);
|
if (STATE_SYMBOL in object) {
|
||||||
};
|
return [
|
||||||
}
|
'div',
|
||||||
}
|
{},
|
||||||
|
['span', { style: 'font-weight: bold' }, '$state'],
|
||||||
/**
|
['object', { object: snapshot(object), config }]
|
||||||
* @param {any} value
|
];
|
||||||
* @param {Set<any>} seen
|
}
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function contains_state_proxy(value, seen = new Set()) {
|
|
||||||
if (typeof value !== 'object' || value === null) return false;
|
|
||||||
|
|
||||||
if (seen.has(value)) return false;
|
return null;
|
||||||
seen.add(value);
|
},
|
||||||
|
|
||||||
if (STATE_SYMBOL in value) {
|
hasBody: () => false
|
||||||
return true;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const key in value) {
|
console.log(`Running Svelte in development mode`, { version: VERSION });
|
||||||
if (contains_state_proxy(value[key], seen)) {
|
|
||||||
return true;
|
if (is_chrome && !custom_formatters_enabled) {
|
||||||
}
|
w.enable_custom_formatters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue