From 08880c9b74c1b6da8a33e550f30c7bf6ac030cf1 Mon Sep 17 00:00:00 2001 From: yy8545 <854551495@qq.com> Date: Tue, 19 Sep 2023 15:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=BB=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=E8=A2=ABmock=E7=9A=84=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yy8545 <854551495@qq.com> --- .../generate/generateInterfaceDeclaration.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/automock/mock-generate/src/generate/generateInterfaceDeclaration.ts b/automock/mock-generate/src/generate/generateInterfaceDeclaration.ts index 3403b36..fdcd5c7 100644 --- a/automock/mock-generate/src/generate/generateInterfaceDeclaration.ts +++ b/automock/mock-generate/src/generate/generateInterfaceDeclaration.ts @@ -78,7 +78,11 @@ export function generateInterfaceDeclaration(rootName: string, interfaceEntity: interfaceBody += '}\n'; if (interfaceEntity.exportModifiers.includes(SyntaxKind.DeclareKeyword)) { - interfaceBody += `global.${interfaceName} = ${interfaceName};\n`; + interfaceBody += ` + if (!global.${interfaceName}) { + global.${interfaceName} = ${interfaceName};\n + } + `; } return interfaceBody; } @@ -113,12 +117,12 @@ function generateHeritageInterface(interfaceEntity: InterfaceEntity, sourceFile: } /** - * - * @param extraImport - * @param importDeclarations - * @param sourceFile - * @param value - * @returns + * + * @param extraImport + * @param importDeclarations + * @param sourceFile + * @param value + * @returns */ function addExtraImport( extraImport: string[], @@ -133,7 +137,7 @@ function addExtraImport( if (hasBeenImported(importDeclarations, propertyTypeName)) { return; } - const specialFilesList = [...specialFiles.map(specialFile=>path.join(getApiInputPath(), ...specialFile.split('/')))]; + const specialFilesList = [...specialFiles.map(specialFile => path.join(getApiInputPath(), ...specialFile.split('/')))]; if (!specialFilesList.includes(sourceFile.fileName)) { specialFilesList.unshift(sourceFile.fileName); } @@ -172,4 +176,4 @@ function addExtraImport( console.log(sourceFile.fileName, 'propertyTypeName', propertyTypeName); return; } -} \ No newline at end of file +}