All files / src/internal/client/dev legacy.js

81.25% Statements 26/32
66.66% Branches 2/3
33.33% Functions 2/6
78.57% Lines 22/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 292x 2x 2x 2x 2x 2x 2x 265x     265x 2x 2x 242x 242x 242x 242x         242x 242x 242x 242x 242x 242x 242x  
import * as e from '../errors.js';
import { current_component_context } from '../runtime.js';
import { FILENAME } from '../../../constants.js';
import { get_component } from './ownership.js';
 
/** @param {Function & { [FILENAME]: string }} target */
export function check_target(target) {
	if (target) {
		e.component_api_invalid_new(target[FILENAME] ?? 'a component', target.name);
	}
}
 
export function legacy_api() {
	const component = current_component_context?.function;
 
	/** @param {string} method */
	function error(method) {
		// @ts-expect-error
		const parent = get_component()?.[FILENAME] ?? 'Something';
		e.component_api_changed(parent, method, component[FILENAME]);
	}
 
	return {
		$destroy: () => error('$destroy()'),
		$on: () => error('$on(...)'),
		$set: () => error('$set(...)')
	};
}