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

100% Statements 27/27
100% Branches 5/5
100% Functions 1/1
100% Lines 25/25

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 262x 2x 2x 2x 2x 2x 2x 2x 2x 2x 103x 97x 97x 103x 103x 103x 103x 103x 103x 103x 1x 1x 103x 103x 103x  
/** @import { ClassDeclaration } from 'estree' */
/** @import { Context } from '../types' */
import * as w from '../../../warnings.js';
import { validate_identifier_name } from './shared/utils.js';
 
/**
 * @param {ClassDeclaration} node
 * @param {Context} context
 */
export function ClassDeclaration(node, context) {
	if (context.state.analysis.runes) {
		validate_identifier_name(context.state.scope.get(node.id.name));
	}
 
	// In modules, we allow top-level module scope only, in components, we allow the component scope,
	// which is function_depth of 1. With the exception of `new class` which is also not allowed at
	// component scope level either.
	const allowed_depth = context.state.ast_type === 'module' ? 0 : 1;
 
	if (context.state.scope.function_depth > allowed_depth) {
		w.perf_avoid_nested_class(node);
	}
 
	context.next();
}