All files / src/internal/client/dom/elements/bindings props.js

100% Statements 24/24
100% Branches 4/4
100% Functions 1/1
100% Lines 22/22

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 232x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 280x 280x 280x 2x 2x 2x 2x 2x 280x  
import { teardown } from '../../../reactivity/effects.js';
import { get_descriptor } from '../../../utils.js';
 
/**
 * Makes an `export`ed (non-prop) variable available on the `$$props` object
 * so that consumers can do `bind:x` on the component.
 * @template V
 * @param {Record<string, unknown>} props
 * @param {string} prop
 * @param {V} value
 * @returns {void}
 */
export function bind_prop(props, prop, value) {
	var desc = get_descriptor(props, prop);
 
	if (desc && desc.set) {
		props[prop] = value;
		teardown(() => {
			props[prop] = null;
		});
	}
}