diff --git a/src/helpers/_generateCadesFn.test.ts b/src/helpers/_generateCadesFn.test.ts index e9dc8c1..e11d8f4 100644 --- a/src/helpers/_generateCadesFn.test.ts +++ b/src/helpers/_generateCadesFn.test.ts @@ -15,8 +15,7 @@ describe('_generateCadesFn', () => { console.log('hello from named function'); }), ).toEqual( - `(function anonymous( -) { + `(function anonymous() { console.log('hello from named function'); @@ -26,8 +25,7 @@ describe('_generateCadesFn', () => { test('generates function body from arrow function callback', () => { expect(_generateCadesFn(() => console.log('hello from arrow function'))).toEqual( - `(function anonymous( -) { + `(function anonymous() { return console.log('hello from arrow function'); })();//# sourceURL=crypto-pro_dynamicFn.js`, ); @@ -43,8 +41,7 @@ describe('_generateCadesFn', () => { void (__cadesAsyncToken__ + cadesBarNoMatterWhat.whateverMethod(cadesFoo)); }), ).toEqual( - `(function anonymous( -) { + `(function anonymous() { var cadesFoo = cadesplugin.CreateObject('CADESCOM.Foo'); var cadesBar = cadesplugin.CreateObject('CAdESCOM.Bar'); @@ -72,8 +69,7 @@ describe('_generateCadesFn', () => { void (__cadesAsyncToken__ + cadesBarNoMatterWhat.whateverMethod(cadesFoo)); }), ).toEqual( - `cadesplugin.async_spawn(function* anonymous( -) { + `cadesplugin.async_spawn(function* anonymous() { var cadesFoo = yield cadesplugin.CreateObjectAsync('CADESCOM.Foo'); var cadesBar = yield cadesplugin.CreateObjectAsync('CAdESCOM.Bar'); diff --git a/src/helpers/_generateCadesFn.ts b/src/helpers/_generateCadesFn.ts index f3a5b49..d398d10 100644 --- a/src/helpers/_generateCadesFn.ts +++ b/src/helpers/_generateCadesFn.ts @@ -13,9 +13,14 @@ export const _generateCadesFn = (callback: Function): string => { const callbackLiteral = String(callback); const callbackArguments = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)?.[1] || ''; const callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1'); - let crossEnvCallbackLiteral = String( - new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody), - ); + let crossEnvCallbackLiteral; + if (callbackArguments) { + crossEnvCallbackLiteral = String( + new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody), + ); + } else { + crossEnvCallbackLiteral = String(new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackBody)); + } crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace( /\w+?\.__createCadesPluginObject__(\([\s\S]*?\))/gm,