13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ciimport { 173af6ab5fSopenharmony_ci forEachChild, 183af6ab5fSopenharmony_ci getLeadingCommentRangesOfNode, 193af6ab5fSopenharmony_ci isCallExpression, 203af6ab5fSopenharmony_ci isExpressionStatement, 213af6ab5fSopenharmony_ci isIdentifier, 223af6ab5fSopenharmony_ci isStructDeclaration, 233af6ab5fSopenharmony_ci SyntaxKind, 243af6ab5fSopenharmony_ci visitEachChild 253af6ab5fSopenharmony_ci} from 'typescript'; 263af6ab5fSopenharmony_ci 273af6ab5fSopenharmony_ciimport type { 283af6ab5fSopenharmony_ci CommentRange, 293af6ab5fSopenharmony_ci Identifier, 303af6ab5fSopenharmony_ci Node, 313af6ab5fSopenharmony_ci SourceFile, 323af6ab5fSopenharmony_ci StructDeclaration, 333af6ab5fSopenharmony_ci TransformationContext 343af6ab5fSopenharmony_ci} from 'typescript'; 353af6ab5fSopenharmony_ciimport type { IOptions } from '../configs/IOptions'; 363af6ab5fSopenharmony_ciimport { LocalVariableCollections, PropCollections, UnobfuscationCollections } from './CommonCollections'; 373af6ab5fSopenharmony_ciimport { historyUnobfuscatedNamesMap } from '../transformers/rename/RenameIdentifierTransformer'; 383af6ab5fSopenharmony_ci 393af6ab5fSopenharmony_ciexport interface ReservedNameInfo { 403af6ab5fSopenharmony_ci universalReservedArray: RegExp[]; // items contain wildcards 413af6ab5fSopenharmony_ci specificReservedArray: string[]; // items do not contain wildcards 423af6ab5fSopenharmony_ci} 433af6ab5fSopenharmony_ci 443af6ab5fSopenharmony_ci/** 453af6ab5fSopenharmony_ci * collect exist identifier names in current source file 463af6ab5fSopenharmony_ci * @param sourceFile 473af6ab5fSopenharmony_ci */ 483af6ab5fSopenharmony_ciexport function collectExistNames(sourceFile: SourceFile): Set<string> { 493af6ab5fSopenharmony_ci const identifiers: Set<string> = new Set<string>(); 503af6ab5fSopenharmony_ci 513af6ab5fSopenharmony_ci let visit = (node: Node): void => { 523af6ab5fSopenharmony_ci if (isIdentifier(node)) { 533af6ab5fSopenharmony_ci identifiers.add(node.text); 543af6ab5fSopenharmony_ci } 553af6ab5fSopenharmony_ci 563af6ab5fSopenharmony_ci forEachChild(node, visit); 573af6ab5fSopenharmony_ci }; 583af6ab5fSopenharmony_ci 593af6ab5fSopenharmony_ci forEachChild(sourceFile, visit); 603af6ab5fSopenharmony_ci return identifiers; 613af6ab5fSopenharmony_ci} 623af6ab5fSopenharmony_ci 633af6ab5fSopenharmony_citype IdentifiersAndStructs = {shadowIdentifiers: Identifier[], shadowStructs: StructDeclaration[]}; 643af6ab5fSopenharmony_ci 653af6ab5fSopenharmony_ci/** 663af6ab5fSopenharmony_ci * collect exist identifiers in current source file 673af6ab5fSopenharmony_ci * @param sourceFile 683af6ab5fSopenharmony_ci * @param context 693af6ab5fSopenharmony_ci */ 703af6ab5fSopenharmony_ciexport function collectIdentifiersAndStructs(sourceFile: SourceFile, context: TransformationContext): IdentifiersAndStructs { 713af6ab5fSopenharmony_ci const identifiers: Identifier[] = []; 723af6ab5fSopenharmony_ci const structs: StructDeclaration[] = []; 733af6ab5fSopenharmony_ci 743af6ab5fSopenharmony_ci let visit = (node: Node): Node => { 753af6ab5fSopenharmony_ci if (isStructDeclaration(node)) { 763af6ab5fSopenharmony_ci structs.push(node); 773af6ab5fSopenharmony_ci } 783af6ab5fSopenharmony_ci // @ts-ignore 793af6ab5fSopenharmony_ci if (getOriginalNode(node).virtual) { 803af6ab5fSopenharmony_ci return node; 813af6ab5fSopenharmony_ci } 823af6ab5fSopenharmony_ci if (!isIdentifier(node) || !node.parent) { 833af6ab5fSopenharmony_ci return visitEachChild(node, visit, context); 843af6ab5fSopenharmony_ci } 853af6ab5fSopenharmony_ci 863af6ab5fSopenharmony_ci identifiers.push(node); 873af6ab5fSopenharmony_ci return node; 883af6ab5fSopenharmony_ci }; 893af6ab5fSopenharmony_ci 903af6ab5fSopenharmony_ci visit(sourceFile); 913af6ab5fSopenharmony_ci return {shadowIdentifiers: identifiers, shadowStructs: structs}; 923af6ab5fSopenharmony_ci} 933af6ab5fSopenharmony_ci 943af6ab5fSopenharmony_ciexport function isCommentedNode(node: Node, sourceFile: SourceFile): boolean { 953af6ab5fSopenharmony_ci const ranges: CommentRange[] = getLeadingCommentRangesOfNode(node, sourceFile); 963af6ab5fSopenharmony_ci return ranges !== undefined; 973af6ab5fSopenharmony_ci} 983af6ab5fSopenharmony_ci 993af6ab5fSopenharmony_ciexport function isSuperCallStatement(node: Node): boolean { 1003af6ab5fSopenharmony_ci return isExpressionStatement(node) && 1013af6ab5fSopenharmony_ci isCallExpression(node.expression) && 1023af6ab5fSopenharmony_ci node.expression.expression.kind === SyntaxKind.SuperKeyword; 1033af6ab5fSopenharmony_ci} 1043af6ab5fSopenharmony_ci 1053af6ab5fSopenharmony_ci/** 1063af6ab5fSopenharmony_ci * separate wildcards from specific items. 1073af6ab5fSopenharmony_ci */ 1083af6ab5fSopenharmony_ciexport function separateUniversalReservedItem(originalArray: string[]): ReservedNameInfo { 1093af6ab5fSopenharmony_ci if (!originalArray) { 1103af6ab5fSopenharmony_ci throw new Error('Unable to handle the empty array.'); 1113af6ab5fSopenharmony_ci } 1123af6ab5fSopenharmony_ci const reservedInfo: ReservedNameInfo = { 1133af6ab5fSopenharmony_ci universalReservedArray: [], 1143af6ab5fSopenharmony_ci specificReservedArray: [] 1153af6ab5fSopenharmony_ci }; 1163af6ab5fSopenharmony_ci 1173af6ab5fSopenharmony_ci originalArray.forEach(reservedItem => { 1183af6ab5fSopenharmony_ci if (containWildcards(reservedItem)) { 1193af6ab5fSopenharmony_ci const regexPattern = wildcardTransformer(reservedItem); 1203af6ab5fSopenharmony_ci const regexOperator = new RegExp(`^${regexPattern}$`); 1213af6ab5fSopenharmony_ci reservedInfo.universalReservedArray.push(regexOperator); 1223af6ab5fSopenharmony_ci recordWildcardMapping(reservedItem, regexOperator); 1233af6ab5fSopenharmony_ci } else { 1243af6ab5fSopenharmony_ci reservedInfo.specificReservedArray.push(reservedItem); 1253af6ab5fSopenharmony_ci } 1263af6ab5fSopenharmony_ci }); 1273af6ab5fSopenharmony_ci return reservedInfo; 1283af6ab5fSopenharmony_ci} 1293af6ab5fSopenharmony_ci 1303af6ab5fSopenharmony_cifunction recordWildcardMapping(originString: string, regExpression: RegExp): void { 1313af6ab5fSopenharmony_ci if (UnobfuscationCollections.printKeptName) { 1323af6ab5fSopenharmony_ci UnobfuscationCollections.reservedWildcardMap.set(regExpression, originString); 1333af6ab5fSopenharmony_ci } 1343af6ab5fSopenharmony_ci} 1353af6ab5fSopenharmony_ci 1363af6ab5fSopenharmony_ci/** 1373af6ab5fSopenharmony_ci * check if the item contains '*', '?'. 1383af6ab5fSopenharmony_ci */ 1393af6ab5fSopenharmony_ciexport function containWildcards(item: string): boolean { 1403af6ab5fSopenharmony_ci return /[\*\?]/.test(item); 1413af6ab5fSopenharmony_ci} 1423af6ab5fSopenharmony_ci 1433af6ab5fSopenharmony_ci/** 1443af6ab5fSopenharmony_ci * Convert specific characters into regular expressions. 1453af6ab5fSopenharmony_ci */ 1463af6ab5fSopenharmony_ciexport function wildcardTransformer(wildcard: string, isPath?: boolean): string { 1473af6ab5fSopenharmony_ci // Add an escape character in front of special characters 1483af6ab5fSopenharmony_ci // special characters: '\', '^', '$', '.', '+', '|', '[', ']', '{', '}', '(', ')' 1493af6ab5fSopenharmony_ci let escapedItem = wildcard.replace(/[\\+^${}()|\[\]\.]/g, '\\$&'); 1503af6ab5fSopenharmony_ci 1513af6ab5fSopenharmony_ci // isPath: containing '**', and '*', '?' can not be matched with '/'. 1523af6ab5fSopenharmony_ci if (isPath) { 1533af6ab5fSopenharmony_ci // before: ../**/a/b/c*/?.ets 1543af6ab5fSopenharmony_ci // after: ../.*/a/b/c[^/]*/[^/].ets 1553af6ab5fSopenharmony_ci return escapedItem.replace(/\*\*/g, '.*').replace(/(?<!\.)\*/g, '[^/]*').replace(/\?/g, '[^/]'); 1563af6ab5fSopenharmony_ci } 1573af6ab5fSopenharmony_ci // before: *a? 1583af6ab5fSopenharmony_ci // after: .*a. 1593af6ab5fSopenharmony_ci return escapedItem.replace(/\*/g, '.*').replace(/\?/g, '.'); 1603af6ab5fSopenharmony_ci} 1613af6ab5fSopenharmony_ci 1623af6ab5fSopenharmony_ci/** 1633af6ab5fSopenharmony_ci * Determine whether the original name needs to be preserved. 1643af6ab5fSopenharmony_ci */ 1653af6ab5fSopenharmony_ciexport function needToBeReserved(reservedSet: Set<string>, universalArray: RegExp[], originalName: string): boolean { 1663af6ab5fSopenharmony_ci return reservedSet.has(originalName) || isMatchWildcard(universalArray, originalName); 1673af6ab5fSopenharmony_ci} 1683af6ab5fSopenharmony_ci 1693af6ab5fSopenharmony_ci/** 1703af6ab5fSopenharmony_ci * Determine whether it can match the wildcard character in the array. 1713af6ab5fSopenharmony_ci */ 1723af6ab5fSopenharmony_ciexport function isMatchWildcard(wildcardArray: RegExp[], item: string): boolean { 1733af6ab5fSopenharmony_ci for (const wildcard of wildcardArray) { 1743af6ab5fSopenharmony_ci if (wildcard.test(item)) { 1753af6ab5fSopenharmony_ci return true; 1763af6ab5fSopenharmony_ci } 1773af6ab5fSopenharmony_ci } 1783af6ab5fSopenharmony_ci return false; 1793af6ab5fSopenharmony_ci} 1803af6ab5fSopenharmony_ci 1813af6ab5fSopenharmony_ci/** 1823af6ab5fSopenharmony_ci * Separate parts of an array that contain wildcard characters. 1833af6ab5fSopenharmony_ci */ 1843af6ab5fSopenharmony_ciexport function handleReservedConfig(config: IOptions, optionName: string, reservedListName: string, 1853af6ab5fSopenharmony_ci universalLisName: string, enableRemove?: string): void { 1863af6ab5fSopenharmony_ci const reservedConfig = config?.[optionName]; 1873af6ab5fSopenharmony_ci let needSeparate: boolean = !!(reservedConfig?.[reservedListName]); 1883af6ab5fSopenharmony_ci if (enableRemove) { 1893af6ab5fSopenharmony_ci needSeparate &&= reservedConfig[enableRemove]; 1903af6ab5fSopenharmony_ci } 1913af6ab5fSopenharmony_ci if (needSeparate) { 1923af6ab5fSopenharmony_ci // separate items which contain wildcards from others 1933af6ab5fSopenharmony_ci const reservedInfo: ReservedNameInfo = separateUniversalReservedItem(reservedConfig[reservedListName]); 1943af6ab5fSopenharmony_ci reservedConfig[reservedListName] = reservedInfo.specificReservedArray; 1953af6ab5fSopenharmony_ci reservedConfig[universalLisName] = reservedInfo.universalReservedArray; 1963af6ab5fSopenharmony_ci } 1973af6ab5fSopenharmony_ci} 1983af6ab5fSopenharmony_ci 1993af6ab5fSopenharmony_ciexport function isReservedLocalVariable(mangledName: string): boolean { 2003af6ab5fSopenharmony_ci return LocalVariableCollections.reservedLangForLocal.has(mangledName) || 2013af6ab5fSopenharmony_ci LocalVariableCollections.reservedConfig?.has(mangledName) || 2023af6ab5fSopenharmony_ci LocalVariableCollections.reservedStruct?.has(mangledName) || 2033af6ab5fSopenharmony_ci UnobfuscationCollections.reservedSdkApiForProp?.has(mangledName) || 2043af6ab5fSopenharmony_ci UnobfuscationCollections.reservedExportName?.has(mangledName); 2053af6ab5fSopenharmony_ci} 2063af6ab5fSopenharmony_ci 2073af6ab5fSopenharmony_ciexport function isReservedTopLevel(originalName: string): boolean { 2083af6ab5fSopenharmony_ci if (PropCollections.enablePropertyObfuscation) { 2093af6ab5fSopenharmony_ci return isReservedProperty(originalName); 2103af6ab5fSopenharmony_ci } 2113af6ab5fSopenharmony_ci 2123af6ab5fSopenharmony_ci // The 'mReservedToplevelNames' has already been added to 'PropCollections.reservedProperties'. 2133af6ab5fSopenharmony_ci return UnobfuscationCollections.reservedLangForTopLevel.has(originalName) || 2143af6ab5fSopenharmony_ci UnobfuscationCollections.reservedSdkApiForGlobal?.has(originalName) || 2153af6ab5fSopenharmony_ci UnobfuscationCollections.reservedExportName?.has(originalName) || 2163af6ab5fSopenharmony_ci PropCollections.reservedProperties?.has(originalName) || 2173af6ab5fSopenharmony_ci isMatchWildcard(PropCollections.universalReservedProperties, originalName); 2183af6ab5fSopenharmony_ci} 2193af6ab5fSopenharmony_ci 2203af6ab5fSopenharmony_ciexport function isReservedProperty(originalName: string): boolean { 2213af6ab5fSopenharmony_ci return UnobfuscationCollections.reservedSdkApiForProp?.has(originalName) || 2223af6ab5fSopenharmony_ci UnobfuscationCollections.reservedLangForProperty?.has(originalName) || 2233af6ab5fSopenharmony_ci UnobfuscationCollections.reservedStruct?.has(originalName) || 2243af6ab5fSopenharmony_ci UnobfuscationCollections.reservedExportNameAndProp?.has(originalName) || 2253af6ab5fSopenharmony_ci UnobfuscationCollections.reservedStrProp?.has(originalName) || 2263af6ab5fSopenharmony_ci UnobfuscationCollections.reservedEnum?.has(originalName) || 2273af6ab5fSopenharmony_ci PropCollections.reservedProperties?.has(originalName) || 2283af6ab5fSopenharmony_ci isMatchWildcard(PropCollections.universalReservedProperties, originalName); 2293af6ab5fSopenharmony_ci} 2303af6ab5fSopenharmony_ci 2313af6ab5fSopenharmony_ci /** 2323af6ab5fSopenharmony_ci * Reasons for not being obfuscated. 2333af6ab5fSopenharmony_ci */ 2343af6ab5fSopenharmony_ciexport enum WhitelistType { 2353af6ab5fSopenharmony_ci SDK = 'sdk', 2363af6ab5fSopenharmony_ci LANG = 'lang', 2373af6ab5fSopenharmony_ci CONF = 'conf', 2383af6ab5fSopenharmony_ci STRUCT = 'struct', 2393af6ab5fSopenharmony_ci EXPORT = 'exported', 2403af6ab5fSopenharmony_ci STRPROP = 'strProp', 2413af6ab5fSopenharmony_ci ENUM = 'enum' 2423af6ab5fSopenharmony_ci} 2433af6ab5fSopenharmony_ci 2443af6ab5fSopenharmony_cifunction needToRecordTopLevel(originalName: string, recordMap: Map<string, Set<string>>, nameWithScope: string): boolean { 2453af6ab5fSopenharmony_ci if (PropCollections.enablePropertyObfuscation) { 2463af6ab5fSopenharmony_ci return needToRecordProperty(originalName, recordMap, nameWithScope); 2473af6ab5fSopenharmony_ci } 2483af6ab5fSopenharmony_ci 2493af6ab5fSopenharmony_ci let reservedFlag = false; 2503af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedLangForTopLevel.has(originalName)) { 2513af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.LANG, recordMap); 2523af6ab5fSopenharmony_ci reservedFlag = true; 2533af6ab5fSopenharmony_ci } 2543af6ab5fSopenharmony_ci 2553af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedSdkApiForGlobal?.has(originalName)) { 2563af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.SDK, recordMap); 2573af6ab5fSopenharmony_ci reservedFlag = true; 2583af6ab5fSopenharmony_ci } 2593af6ab5fSopenharmony_ci 2603af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedExportName?.has(originalName)) { 2613af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.EXPORT, recordMap); 2623af6ab5fSopenharmony_ci reservedFlag = true; 2633af6ab5fSopenharmony_ci } 2643af6ab5fSopenharmony_ci 2653af6ab5fSopenharmony_ci // The 'mReservedToplevelNames' has already been added to 'PropCollections.reservedProperties'. 2663af6ab5fSopenharmony_ci if (PropCollections.reservedProperties?.has(originalName) || 2673af6ab5fSopenharmony_ci isMatchWildcard(PropCollections.universalReservedProperties, originalName)) { 2683af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.CONF, recordMap); 2693af6ab5fSopenharmony_ci reservedFlag = true; 2703af6ab5fSopenharmony_ci } 2713af6ab5fSopenharmony_ci 2723af6ab5fSopenharmony_ci return reservedFlag; 2733af6ab5fSopenharmony_ci} 2743af6ab5fSopenharmony_ci 2753af6ab5fSopenharmony_cifunction needToReservedLocal(originalName: string, recordMap: Map<string, Set<string>>, nameWithScope: string): boolean { 2763af6ab5fSopenharmony_ci let reservedFlag = false; 2773af6ab5fSopenharmony_ci 2783af6ab5fSopenharmony_ci if (LocalVariableCollections.reservedLangForLocal.has(originalName)) { 2793af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.LANG, recordMap); 2803af6ab5fSopenharmony_ci reservedFlag = true; 2813af6ab5fSopenharmony_ci } 2823af6ab5fSopenharmony_ci 2833af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedSdkApiForLocal?.has(originalName)) { 2843af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.SDK, recordMap); 2853af6ab5fSopenharmony_ci reservedFlag = true; 2863af6ab5fSopenharmony_ci } 2873af6ab5fSopenharmony_ci 2883af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedExportName?.has(originalName)) { 2893af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.EXPORT, recordMap); 2903af6ab5fSopenharmony_ci reservedFlag = true; 2913af6ab5fSopenharmony_ci } 2923af6ab5fSopenharmony_ci 2933af6ab5fSopenharmony_ci if (LocalVariableCollections.reservedConfig?.has(originalName)) { 2943af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.CONF, recordMap); 2953af6ab5fSopenharmony_ci reservedFlag = true; 2963af6ab5fSopenharmony_ci } 2973af6ab5fSopenharmony_ci 2983af6ab5fSopenharmony_ci if (LocalVariableCollections.reservedStruct?.has(originalName)) { 2993af6ab5fSopenharmony_ci recordReservedName(nameWithScope, WhitelistType.STRUCT, recordMap); 3003af6ab5fSopenharmony_ci reservedFlag = true; 3013af6ab5fSopenharmony_ci } 3023af6ab5fSopenharmony_ci 3033af6ab5fSopenharmony_ci return reservedFlag; 3043af6ab5fSopenharmony_ci} 3053af6ab5fSopenharmony_ci 3063af6ab5fSopenharmony_ci/** 3073af6ab5fSopenharmony_ci * If the property name is in the whitelist, record the reason for not being obfuscated. 3083af6ab5fSopenharmony_ci * @param nameWithScope: If both property obfuscation and top-level obfuscation or export obfuscation are enabled, 3093af6ab5fSopenharmony_ci * this interface is also used to record the reasons why the top-level names or export names were not obfuscated, 3103af6ab5fSopenharmony_ci * and the top-level names or export names include the scope. 3113af6ab5fSopenharmony_ci */ 3123af6ab5fSopenharmony_ciexport function needToRecordProperty(originalName: string, recordMap?: Map<string, Set<string>>, nameWithScope?: string): boolean { 3133af6ab5fSopenharmony_ci let reservedFlag = false; 3143af6ab5fSopenharmony_ci let recordName = nameWithScope ? nameWithScope : originalName; 3153af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedSdkApiForProp?.has(originalName)) { 3163af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.SDK, recordMap); 3173af6ab5fSopenharmony_ci reservedFlag = true; 3183af6ab5fSopenharmony_ci } 3193af6ab5fSopenharmony_ci 3203af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedLangForProperty?.has(originalName)) { 3213af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.LANG, recordMap); 3223af6ab5fSopenharmony_ci reservedFlag = true; 3233af6ab5fSopenharmony_ci } 3243af6ab5fSopenharmony_ci 3253af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedStruct?.has(originalName)) { 3263af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.STRUCT, recordMap); 3273af6ab5fSopenharmony_ci reservedFlag = true; 3283af6ab5fSopenharmony_ci } 3293af6ab5fSopenharmony_ci 3303af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedExportNameAndProp?.has(originalName)) { 3313af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.EXPORT, recordMap); 3323af6ab5fSopenharmony_ci reservedFlag = true; 3333af6ab5fSopenharmony_ci } 3343af6ab5fSopenharmony_ci 3353af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedStrProp?.has(originalName)) { 3363af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.STRPROP, recordMap); 3373af6ab5fSopenharmony_ci reservedFlag = true; 3383af6ab5fSopenharmony_ci } 3393af6ab5fSopenharmony_ci 3403af6ab5fSopenharmony_ci if (UnobfuscationCollections.reservedEnum?.has(originalName)) { 3413af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.ENUM, recordMap); 3423af6ab5fSopenharmony_ci reservedFlag = true; 3433af6ab5fSopenharmony_ci } 3443af6ab5fSopenharmony_ci 3453af6ab5fSopenharmony_ci if (PropCollections.reservedProperties?.has(originalName) || 3463af6ab5fSopenharmony_ci isMatchWildcard(PropCollections.universalReservedProperties, originalName)) { 3473af6ab5fSopenharmony_ci recordReservedName(recordName, WhitelistType.CONF, recordMap); 3483af6ab5fSopenharmony_ci reservedFlag = true; 3493af6ab5fSopenharmony_ci } 3503af6ab5fSopenharmony_ci 3513af6ab5fSopenharmony_ci return reservedFlag; 3523af6ab5fSopenharmony_ci} 3533af6ab5fSopenharmony_ci 3543af6ab5fSopenharmony_ciexport function isInTopLevelWhitelist(originalName: string, recordMap: Map<string, Set<string>>, nameWithScope: string): boolean { 3553af6ab5fSopenharmony_ci if (UnobfuscationCollections.printKeptName) { 3563af6ab5fSopenharmony_ci return needToRecordTopLevel(originalName, recordMap, nameWithScope); 3573af6ab5fSopenharmony_ci } 3583af6ab5fSopenharmony_ci 3593af6ab5fSopenharmony_ci return isReservedTopLevel(originalName); 3603af6ab5fSopenharmony_ci} 3613af6ab5fSopenharmony_ci 3623af6ab5fSopenharmony_ciexport function isInPropertyWhitelist(originalName: string, recordMap: Map<string, Set<string>>): boolean { 3633af6ab5fSopenharmony_ci if (UnobfuscationCollections.printKeptName) { 3643af6ab5fSopenharmony_ci return needToRecordProperty(originalName, recordMap); 3653af6ab5fSopenharmony_ci } 3663af6ab5fSopenharmony_ci 3673af6ab5fSopenharmony_ci return isReservedProperty(originalName); 3683af6ab5fSopenharmony_ci} 3693af6ab5fSopenharmony_ci 3703af6ab5fSopenharmony_ciexport function isInLocalWhitelist(originalName: string, recordMap: Map<string, Set<string>>, nameWithScope: string): boolean { 3713af6ab5fSopenharmony_ci if (UnobfuscationCollections.printKeptName) { 3723af6ab5fSopenharmony_ci return needToReservedLocal(originalName, recordMap, nameWithScope); 3733af6ab5fSopenharmony_ci } 3743af6ab5fSopenharmony_ci 3753af6ab5fSopenharmony_ci return isReservedLocalVariable(originalName); 3763af6ab5fSopenharmony_ci} 3773af6ab5fSopenharmony_ci 3783af6ab5fSopenharmony_ciexport function recordReservedName(originalName: string, type: string, recordObj?: Map<string, Set<string>>): void { 3793af6ab5fSopenharmony_ci if (!UnobfuscationCollections.printKeptName || !recordObj) { 3803af6ab5fSopenharmony_ci return; 3813af6ab5fSopenharmony_ci } 3823af6ab5fSopenharmony_ci if (!recordObj.has(originalName)) { 3833af6ab5fSopenharmony_ci recordObj.set(originalName, new Set()); 3843af6ab5fSopenharmony_ci } 3853af6ab5fSopenharmony_ci recordObj.get(originalName).add(type); 3863af6ab5fSopenharmony_ci} 3873af6ab5fSopenharmony_ci 3883af6ab5fSopenharmony_ciexport function recordHistoryUnobfuscatedNames(nameWithScope: string): void { 3893af6ab5fSopenharmony_ci if (historyUnobfuscatedNamesMap?.has(nameWithScope)) { 3903af6ab5fSopenharmony_ci UnobfuscationCollections.unobfuscatedNamesMap.set(nameWithScope, 3913af6ab5fSopenharmony_ci new Set(historyUnobfuscatedNamesMap.get(nameWithScope))); 3923af6ab5fSopenharmony_ci } 3933af6ab5fSopenharmony_ci}