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 -])