Repository: sveltejs/svelte
File: packages/svelte/src/compiler/migrate/index.js (JavaScript)

Code before:
		// Strip off any namespace from the beginning of the node name.
		const node_name = node.name.replace(/[a-zA-Z-]*:/g, '');

		if (state.analysis.source[node.end - 2] === '/' && !is_void(node_name) && !is_svg(node_name)) {
			let trimmed_position = node.end - 2;
			while (state.str.original.charAt(trimmed_position - 1) === ' ') trimmed_position--;
			state.str.remove(trimmed_position, node.end - 1);
			state.str.appendRight(node.end, `</${node.name}>`);
		}
		next();
	},
	SvelteSelf(node, { state, next }) {
		const source = state.str.original.substring(node.start, node.end);
		if (!state.filename) {
			const indent = guess_indent(source);
			state.str.prependRight(
				node.start,
				`<!-- @migration-task: migrate this by hand or call the migrate function with the filename of this file -->\n${indent}`
			);
			next();
			return;
		}
		// by default we overwrite until the end of the node - 1
		let end = node.end - 1;
		// if it has some children we need to overwrite from start to start of the fragment
		if (node.fragment.nodes.length > 0) {
			end = node.fragment.nodes[0].start;
		} else if (!source.endsWith('/>')) {
			// special case `<svelte:self></svelte:self>` it has no fragment but
			// we still can't remove to the node end
			end = node.start + source.lastIndexOf('><', node.end) + 1;
		}
		// if at has some attributes we stop at the start of the first
		if (node.attributes.length > 0) {
			end = node.attributes[0].start;
		}
		// overwrite the open tag
		state.str.overwrite(node.start + 1, end - 1, `${state.names.svelte_self}`);
		// if it has a fragment we need to overwrite the closing tag too
		if (node.fragment.nodes.length > 0) {
			const start_closing =
				state.str.original.indexOf('<', node.fragment.nodes[node.fragment.nodes.length - 1].end) +
				2;
			state.str.overwrite(start_closing, node.end - 1, `${state.names.svelte_self}`);
		} else if (!source.endsWith('/>')) {
			// special case for case `<svelte:self></svelte:self>` it has no fragment but
			// we still need to overwrite the end tag
			state.str.overwrite(
				node.start + source.lastIndexOf('</', node.end) + 2,
				node.end - 1,
				`${state.names.svelte_self}`

Review comment (suggestion):
This seems a bit complicated, can you elaborate why? AFAIK we can just `str.update(node.start + 1, node.start + 1 + 'svelte:self'.length)`. For the end tag it needs a few more checks, that's true

Code after:
		// Strip off any namespace from the beginning of the node name.
		const node_name = node.name.replace(/[a-zA-Z-]*:/g, '');

		if (state.analysis.source[node.end - 2] === '/' && !is_void(node_name) && !is_svg(node_name)) {
			let trimmed_position = node.end - 2;
			while (state.str.original.charAt(trimmed_position - 1) === ' ') trimmed_position--;
			state.str.remove(trimmed_position, node.end - 1);
			state.str.appendRight(node.end, `</${node.name}>`);
		}
		next();
	},
	SvelteSelf(node, { state, next }) {
		const source = state.str.original.substring(node.start, node.end);
		if (!state.filename) {
			const indent = guess_indent(source);
			state.str.prependRight(
				node.start,
				`<!-- @migration-task: svelte:self is deprecated, import this Svelte file into itself instead -->\n${indent}`
			);
			next();
			return;
		}
		// overwrite the open tag
		state.str.overwrite(
			node.start + 1,
			node.start + 1 + 'svelte:self'.length,
			`${state.names.svelte_self}`
		);
		// if it has a fragment we need to overwrite the closing tag too
		if (node.fragment.nodes.length > 0) {
			state.str.overwrite(
				state.str.original.lastIndexOf('<', node.end) + 2,
				node.end - 1,
				`${state.names.svelte_self}`
			);
		} else if (!source.endsWith('/>')) {
			// special case for case `<svelte:self></svelte:self>` it has no fragment but
			// we still need to overwrite the end tag
			state.str.overwrite(
				node.start + source.lastIndexOf('</', node.end) + 2,
				node.end - 1,
				`${state.names.svelte_self}`
			);
		}
		state.has_svelte_self = true;
		next();
	},
	SvelteElement(node, { state, path, next }) {
		migrate_slot_usage(node, path, state);
		if (node.tag.type === 'Literal') {
			let is_static = true;