js api_diff工具适配新规则

Signed-off-by: wangqing <wangqing136@huawei.com>
This commit is contained in:
wangqing 2024-07-15 15:20:09 +08:00
parent 6303194c8b
commit 871ac73d68
3 changed files with 12 additions and 14 deletions

View File

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

View File

@ -53,6 +53,8 @@ export class DiffHelper {
const oldSDKApiLocations: Map<string, string[]> = DiffHelper.getApiLocations(clonedOldSDKApiMap, isCheck);
const newSDKApiLocations: Map<string, string[]> = DiffHelper.getApiLocations(clonedNewSDKApiMap, isCheck);
DiffHelper.diffKit(clonedOldSDKApiMap, clonedNewSDKApiMap, diffInfos);
const oldFilePathSet: Set<string> = 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
)
);
});

View File

@ -1007,12 +1007,3 @@ export const isNotApiSet: Set<string> = new Set([
ApiType.ENUM,
ApiType.SOURCE_FILE,
])
/**
* API类型中新增必选属性/
*/
export const parentApiTypeSet: Set<string> = new Set([
ApiType.INTERFACE,
ApiType.STRUCT,
ApiType.CLASS
])