Registering the same custom function twice does not work
Example code:
import {evaluateXPathToString, registerCustomXPathFunction, Options} from 'fontoxpath'
const foo = 'https://example.org/foo.dtd'
registerCustomXPathFunction(
{localName: 'foo', namespaceURI: foo},
['xs:string'], 'xs:string', (_, arg: string) => {
return arg
}
)
registerCustomXPathFunction(
{localName: 'foo', namespaceURI: foo},
['xs:string'], 'xs:string', (_, arg: string) => {
return `${arg}bar`
}
)
const URI_BY_PREFIX: {[key: string]: string} = {foo}
const xQueryOptions: Options = {
namespaceResolver: (prefix: string) => URI_BY_PREFIX[prefix],
}
console.log(evaluateXPathToString('foo:foo("foo")', null, null, null, xQueryOptions))
Expected output: foobar. Actual output: foo. Tested with 3.19.0.
Thanks for reporting @rrthomas! Out of intrest, do you have a use case for "overwriting" an existing function?
Arguably, the 2nd call to registerCustomXPathFunction should have thrown.
My use was a custom function with a hidden variable that is set in the context. Originally, that variable was a normal TypeScript value, which meant that I wanted to re-register the function, which didn't work. I worked around the limitation by instead making the hidden variable an object property, which I could then update without re-registering the function. So it's not essential to me, no. It would be good if I had got an error rather than the re-registering being silently ignored.