custom-formatter
Rich Harris 1 year ago
parent a24ea0a487
commit 4092b7cbde

@ -0,0 +1,43 @@
import { STATE_SYMBOL } from '../constants.js';
export function monkey_patch_console() {
for (const method of Object.keys(console)) {
// @ts-expect-error
const original = console[method];
// @ts-expect-error
console[method] = (...args) => {
for (const arg of args) {
if (contains_state_proxy(arg)) {
// TODO make this a proper warning
console.warn('contains state proxy!!!!');
break;
}
}
return original.apply(console, args);
};
}
}
/**
* @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;
seen.add(value);
if (STATE_SYMBOL in value) {
return true;
}
for (const key in value) {
if (contains_state_proxy(value[key], seen)) {
return true;
}
}
}

@ -1,3 +1,6 @@
import { DEV } from 'esm-env';
import { monkey_patch_console } from './dev/log.js';
export { FILENAME, HMR } from '../../constants.js';
export { add_locations } from './dev/elements.js';
export { hmr } from './dev/hmr.js';
@ -164,3 +167,7 @@ export {
validate_void_dynamic_element
} from '../shared/validate.js';
export { strict_equals, equals } from './dev/equality.js';
if (DEV) {
monkey_patch_console();
}

Loading…
Cancel
Save