All files / src/compiler/phases/2-analyze/visitors ImportDeclaration.js

100% Statements 31/31
100% Branches 9/9
100% Functions 1/1
100% Lines 30/30

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 29 30 312x 2x 2x 2x 2x 2x 2x 2x 2x 1795x 441x 441x 441x 2x 2x 439x 441x 49x 59x 59x 59x 58x 59x 1x 1x 59x 59x 48x 441x 1795x  
/** @import { ImportDeclaration } from 'estree' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
 
/**
 * @param {ImportDeclaration} node
 * @param {Context} context
 */
export function ImportDeclaration(node, context) {
	if (context.state.analysis.runes) {
		const source = /** @type {string} */ (node.source.value);
 
		if (source.startsWith('svelte/internal')) {
			e.import_svelte_internal_forbidden(node);
		}
 
		if (source === 'svelte') {
			for (const specifier of node.specifiers) {
				if (specifier.type === 'ImportSpecifier') {
					if (
						specifier.imported.name === 'beforeUpdate' ||
						specifier.imported.name === 'afterUpdate'
					) {
						e.runes_mode_invalid_import(specifier, specifier.imported.name);
					}
				}
			}
		}
	}
}