I have a plugin which exports a couple of functions. These functions depend on a few script-local functions. I want to test these script-local functions.
The best way I can think of to do that, without simply exporting every function, is to conditionally export a wrapper if an environment variable is set.
vim9script
export def MyPublicFunction(foo: string): string
# ...
enddef
def SomeHelperFunction(bar: string): string
# ...
enddef
if exists("$TEST")
export def SomeHelperFunction__(bar: string): string
return SomeHelperFunction(bar)
enddef
endif
This works fine when $TEST
is set. But when it isn't, which it isn't in normal operation, I get the error:
E133: :return not inside a function
– with a line number pointing to the line return SomeHelperFunction(bar)
.
How can I avoid this error?