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

91.11% Statements 41/45
55.55% Branches 5/9
100% Functions 2/2
90.9% Lines 40/44

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 452x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 86x 81x 15x 15x 15x 15x 15x 15x 15x 15x 81x 5x 5x 86x 2x 2x 2x 2x 2x 2x 2x 5x 5x 5x 5x 5x     5x 5x     5x  
/** @import { ExportSpecifier, Node } from 'estree' */
/** @import { Binding } from '#compiler' */
/** @import { Context } from '../types' */
/** @import { Scope } from '../../scope' */
import * as e from '../../../errors.js';
 
/**
 * @param {ExportSpecifier} node
 * @param {Context} context
 */
export function ExportSpecifier(node, context) {
	if (context.state.ast_type === 'instance') {
		if (context.state.analysis.runes) {
			context.state.analysis.exports.push({
				name: node.local.name,
				alias: node.exported.name
			});
 
			const binding = context.state.scope.get(node.local.name);
			if (binding) binding.reassigned = binding.updated = true;
		}
	} else {
		validate_export(node, context.state.scope, node.local.name);
	}
}
 
/**
 *
 * @param {Node} node
 * @param {Scope} scope
 * @param {string} name
 */
function validate_export(node, scope, name) {
	const binding = scope.get(name);
	if (!binding) return;
 
	if (binding.kind === 'derived') {
		e.derived_invalid_export(node);
	}
 
	if ((binding.kind === 'state' || binding.kind === 'raw_state') && binding.reassigned) {
		e.state_invalid_export(node);
	}
}