Поправил тесты

This commit is contained in:
Artem Vasilev 2021-06-04 09:56:27 +03:00
parent af73897b00
commit 8549f412a7
2 changed files with 12 additions and 11 deletions

View File

@ -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');

View File

@ -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(
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,