Templater always overrides a selection made inside a script

What I’m trying to do

I’m trying to write a script (snippet) that selects the entire line at the cursor position and leaves it selected for the next operation. The script works (I can see that the selection is applied with a debugger breakpoint at the end of the script), but the templater ends up replacing the selected line with a blank line.

Things I have tried

I’ve tinkered with setting tR inside and outside the script, nothing seems to prevent the templater from messing with my selected line.

Templater template contents:

<%* await tp.user.selectSomething(tp) %>

Script:

async function selectSomething(tp) {
	if(tp.file.selection() == '') {
		let cmEditorAct = app.workspace.activeLeaf.view.editor;
		const curLine = cmEditorAct.getCursor().line;
		let lineContent = cmEditorAct.getLine(curLine);
		let lineLength = lineContent.length;
		cmEditorAct.setSelection({ line: curLine, ch: 0 }, { line: curLine, ch: lineLength });
	}
}

module.exports = selectSomething;
'''