@@ -126,11 +126,12 @@ func New(opts ...Opt) *Engine {
126
126
t .ReadFunc = e .readFile
127
127
128
128
e .jsFuncs = map [string ]func (call CallContext ) goja.Value {
129
- "require" : e .require ,
130
- "templateFile" : e .templateFileJS ,
131
- "templateString" : e .templateStringJS ,
132
- "templateStringInput" : e .templateStringInputJS ,
133
- "registerTemplateFunc" : e .registerTemplateFunc ,
129
+ "require" : e .require ,
130
+ "templateFile" : e .templateFileJS ,
131
+ "templateString" : e .templateStringJS ,
132
+ "templateStringInput" : e .templateStringInputJS ,
133
+ "registerTemplateFunc" : e .registerTemplateFunc ,
134
+ "unregisterTemplateFunc" : e .unregisterTemplateFunc ,
134
135
}
135
136
136
137
for _ , opt := range opts {
@@ -277,6 +278,17 @@ func (e *Engine) init(data any) (*vm.VM, error) {
277
278
return v , nil
278
279
}
279
280
281
+ func (e * Engine ) unregisterTemplateFunc (call CallContext ) goja.Value {
282
+ name := call .Argument (0 ).String ()
283
+ if _ , ok := e .templator .TmplFuncs [name ]; ! ok {
284
+ panic (call .VM .NewGoError (fmt .Errorf ("%w: template function %s does not exist" , ErrReserved , name )))
285
+ }
286
+
287
+ delete (e .templator .TmplFuncs , name )
288
+
289
+ return goja .Undefined ()
290
+ }
291
+
280
292
func (e * Engine ) require (call CallContext ) goja.Value {
281
293
vm := call .VM
282
294
0 commit comments