From 871ac73d682566552cc8785789a28adb76e912c2 Mon Sep 17 00:00:00 2001 From: wangqing Date: Mon, 15 Jul 2024 15:20:09 +0800 Subject: [PATCH] =?UTF-8?q?js=20api=5Fdiff=E5=B7=A5=E5=85=B7=E9=80=82?= =?UTF-8?q?=E9=85=8D=E6=96=B0=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangqing --- .../dts_parser/src/coreImpl/diff/DiffProcessor.ts | 7 +++---- build-tools/dts_parser/src/coreImpl/diff/diff.ts | 10 +++++++++- build-tools/dts_parser/src/typedef/diff/ApiInfoDiff.ts | 9 --------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/build-tools/dts_parser/src/coreImpl/diff/DiffProcessor.ts b/build-tools/dts_parser/src/coreImpl/diff/DiffProcessor.ts index 249e889e1..a8bac1edb 100644 --- a/build-tools/dts_parser/src/coreImpl/diff/DiffProcessor.ts +++ b/build-tools/dts_parser/src/coreImpl/diff/DiffProcessor.ts @@ -39,14 +39,12 @@ import { diffMap, incompatibleApiDiffTypes, JsDocDiffProcessor, - parentApiTypeSet, } from '../../typedef/diff/ApiInfoDiff'; import { StringUtils } from '../../utils/StringUtils'; import { CharMapType, CompareReturnObjType, PermissionsProcessorHelper, RangeChange } from './PermissionsProcessor'; import { DecoratorInfo } from '../../typedef/parser/Decorator'; import { CommonFunctions } from '../../utils/checkUtils'; import { NumberConstant } from '../../utils/Constant'; -import { CommentHelper } from '../parser/JsDocProcessor'; export namespace DiffProcessorHelper { /** @@ -1641,14 +1639,15 @@ export namespace DiffProcessorHelper { oldApiInfo: BasicApiInfo | undefined = undefined, newApiInfo: BasicApiInfo | undefined = undefined, diffTypeInfo: DiffTypeInfo, - isSameNameFunction?: boolean + isSameNameFunction?: boolean, + isNewFile?: boolean ): BasicDiffInfo { const newPropertyInfo = newApiInfo as PropertyInfo; const newMethodInfo = newApiInfo as MethodInfo; const parentApiType: string = (newApiInfo && newApiInfo.getParentApiType()) ? newApiInfo.getParentApiType() : ''; let isCompatible = true; if ( - parentApiTypeSet.has(parentApiType) && + !isNewFile && parentApiType === ApiType.INTERFACE && diffTypeInfo.getDiffType() === ApiDiffType.ADD && ((newApiInfo?.getApiType() === ApiType.METHOD && newMethodInfo.getIsRequired()) || (newApiInfo?.getApiType() === ApiType.PROPERTY && newPropertyInfo.getIsRequired())) diff --git a/build-tools/dts_parser/src/coreImpl/diff/diff.ts b/build-tools/dts_parser/src/coreImpl/diff/diff.ts index db6edcca6..e3b09de20 100644 --- a/build-tools/dts_parser/src/coreImpl/diff/diff.ts +++ b/build-tools/dts_parser/src/coreImpl/diff/diff.ts @@ -53,6 +53,8 @@ export class DiffHelper { const oldSDKApiLocations: Map = DiffHelper.getApiLocations(clonedOldSDKApiMap, isCheck); const newSDKApiLocations: Map = DiffHelper.getApiLocations(clonedNewSDKApiMap, isCheck); DiffHelper.diffKit(clonedOldSDKApiMap, clonedNewSDKApiMap, diffInfos); + const oldFilePathSet: Set = new Set(Array.from(clonedOldSDKApiMap.keys())); + Array.from(clonedOldSDKApiMap.keys()) // 先以旧版本为基础进行对比 for (const key of oldSDKApiLocations.keys()) { const apiLocation: string[] = oldSDKApiLocations.get(key) as string[]; @@ -81,11 +83,17 @@ export class DiffHelper { const locations: string[] = newSDKApiLocations.get(key) as string[]; const newApiInfos: ApiInfo[] = Parser.getApiInfo(locations, clonedNewSDKApiMap) as ApiInfo[]; newApiInfos.forEach((newApiInfo: ApiInfo) => { + let isNewFile: boolean = true; + if (oldFilePathSet.has(newApiInfo.getFilePath())) { + isNewFile = false; + } diffInfos.push( DiffProcessorHelper.wrapDiffInfo( undefined, newApiInfo, - new DiffTypeInfo(ApiStatusCode.NEW_API, ApiDiffType.ADD, undefined, newApiInfo.getDefinedText()) + new DiffTypeInfo(ApiStatusCode.NEW_API, ApiDiffType.ADD, undefined, newApiInfo.getDefinedText()), + false, + isNewFile ) ); }); diff --git a/build-tools/dts_parser/src/typedef/diff/ApiInfoDiff.ts b/build-tools/dts_parser/src/typedef/diff/ApiInfoDiff.ts index de341ee25..cb1431848 100644 --- a/build-tools/dts_parser/src/typedef/diff/ApiInfoDiff.ts +++ b/build-tools/dts_parser/src/typedef/diff/ApiInfoDiff.ts @@ -1007,12 +1007,3 @@ export const isNotApiSet: Set = new Set([ ApiType.ENUM, ApiType.SOURCE_FILE, ]) - -/** - * 以下API类型中新增必选属性/方法都是非兼容性变更 - */ -export const parentApiTypeSet: Set = new Set([ - ApiType.INTERFACE, - ApiType.STRUCT, - ApiType.CLASS -])