From 8549f412a7c99d2f4c8fdb80e189c30dc90216a3 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Fri, 4 Jun 2021 09:56:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/_generateCadesFn.test.ts | 12 ++++-------- src/helpers/_generateCadesFn.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) 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,