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  isBinaryExpression,
193af6ab5fSopenharmony_ci  isCallExpression,
203af6ab5fSopenharmony_ci  isClassDeclaration,
213af6ab5fSopenharmony_ci  isComputedPropertyName,
223af6ab5fSopenharmony_ci  isConstructorDeclaration,
233af6ab5fSopenharmony_ci  isEnumDeclaration,
243af6ab5fSopenharmony_ci  isIdentifier,
253af6ab5fSopenharmony_ci  isObjectLiteralExpression,
263af6ab5fSopenharmony_ci  isParameter,
273af6ab5fSopenharmony_ci  isPropertyAccessExpression,
283af6ab5fSopenharmony_ci  isPropertyAssignment,
293af6ab5fSopenharmony_ci  isPropertyDeclaration,
303af6ab5fSopenharmony_ci  isStructDeclaration,
313af6ab5fSopenharmony_ci  isStringLiteral,
323af6ab5fSopenharmony_ci  isTypeLiteralNode,
333af6ab5fSopenharmony_ci  isVariableStatement,
343af6ab5fSopenharmony_ci  SyntaxKind,
353af6ab5fSopenharmony_ci  isExpressionStatement,
363af6ab5fSopenharmony_ci  isClassExpression,
373af6ab5fSopenharmony_ci  getModifiers,
383af6ab5fSopenharmony_ci  isGetAccessor,
393af6ab5fSopenharmony_ci  isSetAccessor,
403af6ab5fSopenharmony_ci  isShorthandPropertyAssignment,
413af6ab5fSopenharmony_ci  isSpreadAssignment,
423af6ab5fSopenharmony_ci  isMethodDeclaration,
433af6ab5fSopenharmony_ci  isGetAccessorDeclaration,
443af6ab5fSopenharmony_ci  isAccessor,
453af6ab5fSopenharmony_ci  isTypeNode
463af6ab5fSopenharmony_ci} from 'typescript';
473af6ab5fSopenharmony_ci
483af6ab5fSopenharmony_ciimport type {
493af6ab5fSopenharmony_ci  ClassDeclaration,
503af6ab5fSopenharmony_ci  ClassExpression,
513af6ab5fSopenharmony_ci  ElementAccessExpression,
523af6ab5fSopenharmony_ci  EnumDeclaration,
533af6ab5fSopenharmony_ci  Expression,
543af6ab5fSopenharmony_ci  GetAccessorDeclaration,
553af6ab5fSopenharmony_ci  HeritageClause,
563af6ab5fSopenharmony_ci  Identifier,
573af6ab5fSopenharmony_ci  InterfaceDeclaration,
583af6ab5fSopenharmony_ci  MethodDeclaration,
593af6ab5fSopenharmony_ci  Modifier,
603af6ab5fSopenharmony_ci  Node,
613af6ab5fSopenharmony_ci  NodeArray,
623af6ab5fSopenharmony_ci  ObjectLiteralExpression,
633af6ab5fSopenharmony_ci  PropertyAssignment,
643af6ab5fSopenharmony_ci  PropertyName,
653af6ab5fSopenharmony_ci  SetAccessorDeclaration,
663af6ab5fSopenharmony_ci  ShorthandPropertyAssignment,
673af6ab5fSopenharmony_ci  Statement,
683af6ab5fSopenharmony_ci  StructDeclaration,
693af6ab5fSopenharmony_ci  TypeAliasDeclaration
703af6ab5fSopenharmony_ci} from 'typescript';
713af6ab5fSopenharmony_ci
723af6ab5fSopenharmony_ciimport { ApiExtractor } from '../common/ApiExtractor';
733af6ab5fSopenharmony_ciimport { UnobfuscationCollections } from './CommonCollections';
743af6ab5fSopenharmony_ciimport { NodeUtils } from './NodeUtils';
753af6ab5fSopenharmony_ci
763af6ab5fSopenharmony_ciexport const stringPropsSet: Set<string> = new Set();
773af6ab5fSopenharmony_ci/**
783af6ab5fSopenharmony_ci * The struct properties may be initialized in other files, but the properties in the struct definition are not obfuscated.
793af6ab5fSopenharmony_ci * So the whitelist of struct properties is collected during the project scanning process.
803af6ab5fSopenharmony_ci */
813af6ab5fSopenharmony_ciexport const structPropsSet: Set<string> = new Set();
823af6ab5fSopenharmony_ci
833af6ab5fSopenharmony_ci/**
843af6ab5fSopenharmony_ci * Add enum elements into whitelist when compiling har module to avoid obfuscating enum elements
853af6ab5fSopenharmony_ci * since enum elements in js file cannot be obfuscated properly.
863af6ab5fSopenharmony_ci */
873af6ab5fSopenharmony_ciexport const enumPropsSet: Set<string> = new Set();
883af6ab5fSopenharmony_ci
893af6ab5fSopenharmony_ci/**
903af6ab5fSopenharmony_ci * Collect the original name of export elements to ensure we can collect their properties
913af6ab5fSopenharmony_ci */
923af6ab5fSopenharmony_ciexport const exportOriginalNameSet: Set<string> = new Set();
933af6ab5fSopenharmony_ci
943af6ab5fSopenharmony_cifunction containViewPU(heritageClauses: NodeArray<HeritageClause>): boolean {
953af6ab5fSopenharmony_ci  if (!heritageClauses) {
963af6ab5fSopenharmony_ci    return false;
973af6ab5fSopenharmony_ci  }
983af6ab5fSopenharmony_ci
993af6ab5fSopenharmony_ci  let hasViewPU: boolean = false;
1003af6ab5fSopenharmony_ci  heritageClauses.forEach(
1013af6ab5fSopenharmony_ci    (heritageClause) => {
1023af6ab5fSopenharmony_ci      if (!heritageClause || !heritageClause.types) {
1033af6ab5fSopenharmony_ci        return;
1043af6ab5fSopenharmony_ci      }
1053af6ab5fSopenharmony_ci
1063af6ab5fSopenharmony_ci      const types = heritageClause.types;
1073af6ab5fSopenharmony_ci      types.forEach((typeExpression) => {
1083af6ab5fSopenharmony_ci        if (!typeExpression || !typeExpression.expression) {
1093af6ab5fSopenharmony_ci          return;
1103af6ab5fSopenharmony_ci        }
1113af6ab5fSopenharmony_ci
1123af6ab5fSopenharmony_ci        const expression = typeExpression.expression;
1133af6ab5fSopenharmony_ci        if (isIdentifier(expression) && expression.text === 'ViewPU') {
1143af6ab5fSopenharmony_ci          hasViewPU = true;
1153af6ab5fSopenharmony_ci        }
1163af6ab5fSopenharmony_ci      });
1173af6ab5fSopenharmony_ci    });
1183af6ab5fSopenharmony_ci
1193af6ab5fSopenharmony_ci  return hasViewPU;
1203af6ab5fSopenharmony_ci}
1213af6ab5fSopenharmony_ci
1223af6ab5fSopenharmony_ci/**
1233af6ab5fSopenharmony_ci * used to ignore user defined ui component class property name
1243af6ab5fSopenharmony_ci * @param classNode
1253af6ab5fSopenharmony_ci */
1263af6ab5fSopenharmony_ciexport function isViewPUBasedClass(classNode: ClassDeclaration | undefined): boolean {
1273af6ab5fSopenharmony_ci  if (!classNode) {
1283af6ab5fSopenharmony_ci    return false;
1293af6ab5fSopenharmony_ci  }
1303af6ab5fSopenharmony_ci
1313af6ab5fSopenharmony_ci  if (!isClassDeclaration(classNode)) {
1323af6ab5fSopenharmony_ci    return false;
1333af6ab5fSopenharmony_ci  }
1343af6ab5fSopenharmony_ci
1353af6ab5fSopenharmony_ci  const heritageClause = classNode.heritageClauses;
1363af6ab5fSopenharmony_ci  return containViewPU(heritageClause);
1373af6ab5fSopenharmony_ci}
1383af6ab5fSopenharmony_ci
1393af6ab5fSopenharmony_ciexport function collectPropertyNamesAndStrings(memberName: PropertyName, propertySet: Set<string>): void {
1403af6ab5fSopenharmony_ci  if (isIdentifier(memberName)) {
1413af6ab5fSopenharmony_ci    propertySet.add(memberName.text);
1423af6ab5fSopenharmony_ci  }
1433af6ab5fSopenharmony_ci
1443af6ab5fSopenharmony_ci  if (isStringLiteral(memberName)) {
1453af6ab5fSopenharmony_ci    propertySet.add(memberName.text);
1463af6ab5fSopenharmony_ci    stringPropsSet.add(memberName.text);
1473af6ab5fSopenharmony_ci  }
1483af6ab5fSopenharmony_ci
1493af6ab5fSopenharmony_ci  if (isComputedPropertyName(memberName) && isStringLiteral(memberName.expression)) {
1503af6ab5fSopenharmony_ci    propertySet.add(memberName.expression.text);
1513af6ab5fSopenharmony_ci    stringPropsSet.add(memberName.expression.text);
1523af6ab5fSopenharmony_ci  }
1533af6ab5fSopenharmony_ci}
1543af6ab5fSopenharmony_ci
1553af6ab5fSopenharmony_ciexport function getElementAccessExpressionProperties(elementAccessExpressionNode: ElementAccessExpression, propertySet: Set<string>): void {
1563af6ab5fSopenharmony_ci  if (!elementAccessExpressionNode || !elementAccessExpressionNode.argumentExpression) {
1573af6ab5fSopenharmony_ci    return;
1583af6ab5fSopenharmony_ci  }
1593af6ab5fSopenharmony_ci
1603af6ab5fSopenharmony_ci  if (isStringLiteral(elementAccessExpressionNode.argumentExpression)) {
1613af6ab5fSopenharmony_ci    stringPropsSet.add(elementAccessExpressionNode.argumentExpression.text);
1623af6ab5fSopenharmony_ci  }
1633af6ab5fSopenharmony_ci}
1643af6ab5fSopenharmony_ci
1653af6ab5fSopenharmony_ciexport function getTypeAliasProperties(typeAliasNode: TypeAliasDeclaration, propertySet: Set<string>): void {
1663af6ab5fSopenharmony_ci  if (!typeAliasNode || !typeAliasNode.type || !isTypeLiteralNode(typeAliasNode.type)) {
1673af6ab5fSopenharmony_ci    return;
1683af6ab5fSopenharmony_ci  }
1693af6ab5fSopenharmony_ci
1703af6ab5fSopenharmony_ci  typeAliasNode.type.members.forEach((member) => {
1713af6ab5fSopenharmony_ci    if (!member || !member.name) {
1723af6ab5fSopenharmony_ci      return;
1733af6ab5fSopenharmony_ci    }
1743af6ab5fSopenharmony_ci    let memberName: PropertyName = member.name;
1753af6ab5fSopenharmony_ci    collectPropertyNamesAndStrings(memberName, propertySet);
1763af6ab5fSopenharmony_ci  });
1773af6ab5fSopenharmony_ci}
1783af6ab5fSopenharmony_ci
1793af6ab5fSopenharmony_ci/**
1803af6ab5fSopenharmony_ci * export interface interfaceName {
1813af6ab5fSopenharmony_ci *  a1: number;
1823af6ab5fSopenharmony_ci *  "a2": number;
1833af6ab5fSopenharmony_ci *  ["a3"]: number;
1843af6ab5fSopenharmony_ci * }
1853af6ab5fSopenharmony_ci */
1863af6ab5fSopenharmony_ci
1873af6ab5fSopenharmony_ciexport function getInterfaceProperties(interfaceNode: InterfaceDeclaration, propertySet: Set<string>): void {
1883af6ab5fSopenharmony_ci  if (!interfaceNode || !interfaceNode.members) {
1893af6ab5fSopenharmony_ci    return;
1903af6ab5fSopenharmony_ci  }
1913af6ab5fSopenharmony_ci
1923af6ab5fSopenharmony_ci  interfaceNode.members.forEach((member) => {
1933af6ab5fSopenharmony_ci    if (!member || !member.name) {
1943af6ab5fSopenharmony_ci      return;
1953af6ab5fSopenharmony_ci    }
1963af6ab5fSopenharmony_ci
1973af6ab5fSopenharmony_ci    let memberName: PropertyName = member.name;
1983af6ab5fSopenharmony_ci    collectPropertyNamesAndStrings(memberName, propertySet);
1993af6ab5fSopenharmony_ci  });
2003af6ab5fSopenharmony_ci}
2013af6ab5fSopenharmony_ci
2023af6ab5fSopenharmony_ciexport function isParameterPropertyModifier(modifier: Modifier): boolean {
2033af6ab5fSopenharmony_ci  if (modifier.kind === SyntaxKind.PublicKeyword ||
2043af6ab5fSopenharmony_ci    modifier.kind === SyntaxKind.PrivateKeyword ||
2053af6ab5fSopenharmony_ci    modifier.kind === SyntaxKind.ProtectedKeyword ||
2063af6ab5fSopenharmony_ci    modifier.kind === SyntaxKind.ReadonlyKeyword) {
2073af6ab5fSopenharmony_ci    return true;
2083af6ab5fSopenharmony_ci  }
2093af6ab5fSopenharmony_ci  return false;
2103af6ab5fSopenharmony_ci}
2113af6ab5fSopenharmony_ci
2123af6ab5fSopenharmony_ciexport function getClassProperties(classNode: ClassDeclaration | ClassExpression | StructDeclaration, propertySet: Set<string>): void {
2133af6ab5fSopenharmony_ci  if (!classNode || !classNode.members) {
2143af6ab5fSopenharmony_ci    return;
2153af6ab5fSopenharmony_ci  }
2163af6ab5fSopenharmony_ci
2173af6ab5fSopenharmony_ci  if (isStructDeclaration(classNode)) {
2183af6ab5fSopenharmony_ci    getStructProperties(classNode, structPropsSet);
2193af6ab5fSopenharmony_ci  }
2203af6ab5fSopenharmony_ci  traverseMembersOfClass(classNode, propertySet);
2213af6ab5fSopenharmony_ci  return;
2223af6ab5fSopenharmony_ci}
2233af6ab5fSopenharmony_ci
2243af6ab5fSopenharmony_cifunction traverseMembersOfClass(classNode: ClassDeclaration | ClassExpression | StructDeclaration, propertySet: Set<string>): void {
2253af6ab5fSopenharmony_ci  classNode.members.forEach((member) => {
2263af6ab5fSopenharmony_ci    if (!member) {
2273af6ab5fSopenharmony_ci      return;
2283af6ab5fSopenharmony_ci    }
2293af6ab5fSopenharmony_ci
2303af6ab5fSopenharmony_ci    const memberName: PropertyName = member.name;
2313af6ab5fSopenharmony_ci    if (memberName) {
2323af6ab5fSopenharmony_ci      collectPropertyNamesAndStrings(memberName, propertySet);
2333af6ab5fSopenharmony_ci    }
2343af6ab5fSopenharmony_ci
2353af6ab5fSopenharmony_ci    if (isConstructorDeclaration(member) && member.parameters) {
2363af6ab5fSopenharmony_ci      member.parameters.forEach((parameter) => {
2373af6ab5fSopenharmony_ci        const modifiers = getModifiers(parameter);
2383af6ab5fSopenharmony_ci        if (isParameter(parameter) && modifiers && modifiers.length > 0) {
2393af6ab5fSopenharmony_ci          if (parameter.name && isIdentifier(parameter.name)) {
2403af6ab5fSopenharmony_ci            let hasParameterPropertyModifier = modifiers.find(modifier => isParameterPropertyModifier(modifier)) !== undefined;
2413af6ab5fSopenharmony_ci            if (hasParameterPropertyModifier) {
2423af6ab5fSopenharmony_ci              propertySet.add(parameter.name.text);
2433af6ab5fSopenharmony_ci              ApiExtractor.mConstructorPropertySet?.add(parameter.name.text);
2443af6ab5fSopenharmony_ci            }
2453af6ab5fSopenharmony_ci          }
2463af6ab5fSopenharmony_ci          processMemberInitializer(parameter.initializer, propertySet);
2473af6ab5fSopenharmony_ci        }
2483af6ab5fSopenharmony_ci      });
2493af6ab5fSopenharmony_ci
2503af6ab5fSopenharmony_ci      if (member.body) {
2513af6ab5fSopenharmony_ci        member.body.statements.forEach((statement) => {
2523af6ab5fSopenharmony_ci          if (isExpressionStatement(statement) && isBinaryExpression(statement.expression) &&
2533af6ab5fSopenharmony_ci            statement.expression.operatorToken.kind === SyntaxKind.EqualsToken) {
2543af6ab5fSopenharmony_ci            processMemberInitializer(statement.expression.right, propertySet);
2553af6ab5fSopenharmony_ci          }
2563af6ab5fSopenharmony_ci        });
2573af6ab5fSopenharmony_ci      }
2583af6ab5fSopenharmony_ci    }
2593af6ab5fSopenharmony_ci
2603af6ab5fSopenharmony_ci    if (!isPropertyDeclaration(member) || !member.initializer) {
2613af6ab5fSopenharmony_ci      return;
2623af6ab5fSopenharmony_ci    }
2633af6ab5fSopenharmony_ci    processMemberInitializer(member.initializer, propertySet);
2643af6ab5fSopenharmony_ci  });
2653af6ab5fSopenharmony_ci  return;
2663af6ab5fSopenharmony_ci}
2673af6ab5fSopenharmony_ci
2683af6ab5fSopenharmony_cifunction processMemberInitializer(memberInitializer: Expression | undefined, propertySet: Set<string>): void {
2693af6ab5fSopenharmony_ci  if (!memberInitializer) {
2703af6ab5fSopenharmony_ci    return;
2713af6ab5fSopenharmony_ci  }
2723af6ab5fSopenharmony_ci
2733af6ab5fSopenharmony_ci  if (isObjectLiteralExpression(memberInitializer)) {
2743af6ab5fSopenharmony_ci    getObjectProperties(memberInitializer, propertySet);
2753af6ab5fSopenharmony_ci    return;
2763af6ab5fSopenharmony_ci  }
2773af6ab5fSopenharmony_ci
2783af6ab5fSopenharmony_ci  if (isClassDeclaration(memberInitializer) || isClassExpression(memberInitializer) || isStructDeclaration(memberInitializer)) {
2793af6ab5fSopenharmony_ci    getClassProperties(memberInitializer, propertySet);
2803af6ab5fSopenharmony_ci    return;
2813af6ab5fSopenharmony_ci  }
2823af6ab5fSopenharmony_ci
2833af6ab5fSopenharmony_ci  if (isEnumDeclaration(memberInitializer)) {
2843af6ab5fSopenharmony_ci    getEnumProperties(memberInitializer, propertySet);
2853af6ab5fSopenharmony_ci    return;
2863af6ab5fSopenharmony_ci  }
2873af6ab5fSopenharmony_ci}
2883af6ab5fSopenharmony_ci
2893af6ab5fSopenharmony_ciexport function getEnumProperties(enumNode: EnumDeclaration, propertySet: Set<string>): void {
2903af6ab5fSopenharmony_ci  if (!enumNode || !enumNode.members) {
2913af6ab5fSopenharmony_ci    return;
2923af6ab5fSopenharmony_ci  }
2933af6ab5fSopenharmony_ci
2943af6ab5fSopenharmony_ci  enumNode.members.forEach((member) => {
2953af6ab5fSopenharmony_ci    if (!member || !member.name) {
2963af6ab5fSopenharmony_ci      return;
2973af6ab5fSopenharmony_ci    }
2983af6ab5fSopenharmony_ci
2993af6ab5fSopenharmony_ci    const memberName: PropertyName = member.name;
3003af6ab5fSopenharmony_ci    collectPropertyNamesAndStrings(memberName, propertySet);
3013af6ab5fSopenharmony_ci    //other kind ignore
3023af6ab5fSopenharmony_ci  });
3033af6ab5fSopenharmony_ci
3043af6ab5fSopenharmony_ci  return;
3053af6ab5fSopenharmony_ci}
3063af6ab5fSopenharmony_ci
3073af6ab5fSopenharmony_ciexport function getObjectProperties(objNode: ObjectLiteralExpression, propertySet: Set<string>): void {
3083af6ab5fSopenharmony_ci  if (!objNode || !objNode.properties) {
3093af6ab5fSopenharmony_ci    return;
3103af6ab5fSopenharmony_ci  }
3113af6ab5fSopenharmony_ci
3123af6ab5fSopenharmony_ci  objNode.properties.forEach((propertyElement) => {
3133af6ab5fSopenharmony_ci    if (!propertyElement || !propertyElement.name) {
3143af6ab5fSopenharmony_ci      return;
3153af6ab5fSopenharmony_ci    }
3163af6ab5fSopenharmony_ci
3173af6ab5fSopenharmony_ci    const propertyName: PropertyName = propertyElement.name;
3183af6ab5fSopenharmony_ci    collectPropertyNamesAndStrings(propertyName, propertySet);
3193af6ab5fSopenharmony_ci
3203af6ab5fSopenharmony_ci    //extract class element's property, example: export const hello = {info={read: {}}}
3213af6ab5fSopenharmony_ci    if (!isPropertyAssignment(propertyElement) || !propertyElement.initializer) {
3223af6ab5fSopenharmony_ci      return;
3233af6ab5fSopenharmony_ci    }
3243af6ab5fSopenharmony_ci
3253af6ab5fSopenharmony_ci    if (isObjectLiteralExpression(propertyElement.initializer)) {
3263af6ab5fSopenharmony_ci      getObjectProperties(propertyElement.initializer, propertySet);
3273af6ab5fSopenharmony_ci      return;
3283af6ab5fSopenharmony_ci    }
3293af6ab5fSopenharmony_ci
3303af6ab5fSopenharmony_ci    if (isClassDeclaration(propertyElement.initializer)) {
3313af6ab5fSopenharmony_ci      getClassProperties(propertyElement.initializer, propertySet);
3323af6ab5fSopenharmony_ci      return;
3333af6ab5fSopenharmony_ci    }
3343af6ab5fSopenharmony_ci
3353af6ab5fSopenharmony_ci    if (isEnumDeclaration(propertyElement.initializer)) {
3363af6ab5fSopenharmony_ci      getEnumProperties(propertyElement.initializer, propertySet);
3373af6ab5fSopenharmony_ci      return;
3383af6ab5fSopenharmony_ci    }
3393af6ab5fSopenharmony_ci  });
3403af6ab5fSopenharmony_ci
3413af6ab5fSopenharmony_ci  return;
3423af6ab5fSopenharmony_ci}
3433af6ab5fSopenharmony_ci
3443af6ab5fSopenharmony_ciexport function getStructProperties(structNode: StructDeclaration, propertySet: Set<string>): void {
3453af6ab5fSopenharmony_ci  structNode?.members?.forEach((member) => {
3463af6ab5fSopenharmony_ci    const memberName: PropertyName = member?.name;
3473af6ab5fSopenharmony_ci    if (!memberName) {
3483af6ab5fSopenharmony_ci      return;
3493af6ab5fSopenharmony_ci    }
3503af6ab5fSopenharmony_ci    collectPropertyNamesAndStrings(memberName, propertySet);
3513af6ab5fSopenharmony_ci  });
3523af6ab5fSopenharmony_ci}
3533af6ab5fSopenharmony_ci
3543af6ab5fSopenharmony_ci/**
3553af6ab5fSopenharmony_ci * collect elements into export whitelist for module.exports = {A, B, C, D}
3563af6ab5fSopenharmony_ci * since these elements can be import by `const {A, B, C, D} = require("./filePath");`
3573af6ab5fSopenharmony_ci */
3583af6ab5fSopenharmony_ciexport function getObjectExportNames(objNode: ObjectLiteralExpression, exportNames: Set<string>): void {
3593af6ab5fSopenharmony_ci  if (!objNode || !objNode.properties) {
3603af6ab5fSopenharmony_ci    return;
3613af6ab5fSopenharmony_ci  }
3623af6ab5fSopenharmony_ci
3633af6ab5fSopenharmony_ci  objNode.properties.forEach((propertyElement) => {
3643af6ab5fSopenharmony_ci    if (isPropertyAssignment(propertyElement)) {
3653af6ab5fSopenharmony_ci      /**
3663af6ab5fSopenharmony_ci       * { prop1: 123 } // collect prop1
3673af6ab5fSopenharmony_ci       * { 'prop2': 123 } // collect prop2
3683af6ab5fSopenharmony_ci       * { ['prop3']: 123 } // collect prop3
3693af6ab5fSopenharmony_ci       */
3703af6ab5fSopenharmony_ci      addExportPropertyName(propertyElement, exportNames);
3713af6ab5fSopenharmony_ci
3723af6ab5fSopenharmony_ci      let initializer = propertyElement.initializer;
3733af6ab5fSopenharmony_ci      if (isIdentifier(initializer)) {
3743af6ab5fSopenharmony_ci        /**
3753af6ab5fSopenharmony_ci         * { prop: testObj } // collect testObj into exportOriginalNameSet so that its properties can be collected
3763af6ab5fSopenharmony_ci         */
3773af6ab5fSopenharmony_ci        exportOriginalNameSet.add(initializer.text);
3783af6ab5fSopenharmony_ci      }
3793af6ab5fSopenharmony_ci      return;
3803af6ab5fSopenharmony_ci    }
3813af6ab5fSopenharmony_ci
3823af6ab5fSopenharmony_ci    if (isShorthandPropertyAssignment(propertyElement)) {
3833af6ab5fSopenharmony_ci      /**
3843af6ab5fSopenharmony_ci       * let shorthandNode = {prop1: 123};
3853af6ab5fSopenharmony_ci       * module.exports = { shorthandNode } // collect shorthandNode
3863af6ab5fSopenharmony_ci       */
3873af6ab5fSopenharmony_ci      exportNames.add(propertyElement.name.text);
3883af6ab5fSopenharmony_ci      return;
3893af6ab5fSopenharmony_ci    }
3903af6ab5fSopenharmony_ci
3913af6ab5fSopenharmony_ci    if (isMethodDeclaration(propertyElement) || isGetAccessor(propertyElement) || isSetAccessor(propertyElement)) {
3923af6ab5fSopenharmony_ci      /**
3933af6ab5fSopenharmony_ci       * { method() {} } // collect method
3943af6ab5fSopenharmony_ci       * { 'method'() {} } // collect method
3953af6ab5fSopenharmony_ci       * { ['method']() {} } // collect method
3963af6ab5fSopenharmony_ci       * { get getProp() {} } // collect getProp
3973af6ab5fSopenharmony_ci       * { get 'getProp'() {} } // collect getProp
3983af6ab5fSopenharmony_ci       * { get ['getProp']() {}} // collect getProp
3993af6ab5fSopenharmony_ci       */
4003af6ab5fSopenharmony_ci      addExportPropertyName(propertyElement, exportNames);
4013af6ab5fSopenharmony_ci      return;
4023af6ab5fSopenharmony_ci    }
4033af6ab5fSopenharmony_ci  });
4043af6ab5fSopenharmony_ci
4053af6ab5fSopenharmony_ci  return;
4063af6ab5fSopenharmony_ci}
4073af6ab5fSopenharmony_ci
4083af6ab5fSopenharmony_ci/**
4093af6ab5fSopenharmony_ci * Collect property names in ObjectLiteralExpression
4103af6ab5fSopenharmony_ci */
4113af6ab5fSopenharmony_ciexport function addExportPropertyName(propertyElement: PropertyAssignment | MethodDeclaration |
4123af6ab5fSopenharmony_ci   GetAccessorDeclaration | SetAccessorDeclaration, exportNames: Set<string>): void {
4133af6ab5fSopenharmony_ci    let nameNode = propertyElement.name;
4143af6ab5fSopenharmony_ci
4153af6ab5fSopenharmony_ci    if (isIdentifier(nameNode) || isStringLiteral(nameNode)) {
4163af6ab5fSopenharmony_ci      exportNames.add(nameNode.text);
4173af6ab5fSopenharmony_ci    }
4183af6ab5fSopenharmony_ci
4193af6ab5fSopenharmony_ci    if (isComputedPropertyName(nameNode) && isStringLiteral(nameNode.expression)) {
4203af6ab5fSopenharmony_ci      exportNames.add(nameNode.expression.text);
4213af6ab5fSopenharmony_ci    }
4223af6ab5fSopenharmony_ci}
4233af6ab5fSopenharmony_ci
4243af6ab5fSopenharmony_ci/**
4253af6ab5fSopenharmony_ci * Collect reserved names in enum
4263af6ab5fSopenharmony_ci * e.g.
4273af6ab5fSopenharmony_ci * enum H {
4283af6ab5fSopenharmony_ci *   A,
4293af6ab5fSopenharmony_ci *   B = A + 1
4303af6ab5fSopenharmony_ci * }
4313af6ab5fSopenharmony_ci * A is reserved
4323af6ab5fSopenharmony_ci */
4333af6ab5fSopenharmony_ciexport function visitEnumInitializer(childNode: Node): void {
4343af6ab5fSopenharmony_ci  if (NodeUtils.isPropertyNode(childNode)) {
4353af6ab5fSopenharmony_ci    return;
4363af6ab5fSopenharmony_ci  }
4373af6ab5fSopenharmony_ci
4383af6ab5fSopenharmony_ci  if (isTypeNode(childNode)) {
4393af6ab5fSopenharmony_ci    return;
4403af6ab5fSopenharmony_ci  }
4413af6ab5fSopenharmony_ci
4423af6ab5fSopenharmony_ci  if (!isIdentifier(childNode)) {
4433af6ab5fSopenharmony_ci    forEachChild(childNode, visitEnumInitializer);
4443af6ab5fSopenharmony_ci    return;
4453af6ab5fSopenharmony_ci  }
4463af6ab5fSopenharmony_ci
4473af6ab5fSopenharmony_ci  UnobfuscationCollections.reservedEnum.add(childNode.text);
4483af6ab5fSopenharmony_ci}
4493af6ab5fSopenharmony_ci
4503af6ab5fSopenharmony_ci/**
4513af6ab5fSopenharmony_ci * collect properties of ViewPU class as reserved names
4523af6ab5fSopenharmony_ci */
4533af6ab5fSopenharmony_ciexport function getViewPUClassProperties(classNode: ClassDeclaration | ClassExpression): void {
4543af6ab5fSopenharmony_ci  if (!classNode || !classNode.members) {
4553af6ab5fSopenharmony_ci    return;
4563af6ab5fSopenharmony_ci  }
4573af6ab5fSopenharmony_ci
4583af6ab5fSopenharmony_ci  classNode.members.forEach((member) => {
4593af6ab5fSopenharmony_ci    const memberName: PropertyName = member.name;
4603af6ab5fSopenharmony_ci    if (!memberName) {
4613af6ab5fSopenharmony_ci      return;
4623af6ab5fSopenharmony_ci    }
4633af6ab5fSopenharmony_ci    collectPropertyNamesAndStrings(memberName, UnobfuscationCollections.reservedStruct);
4643af6ab5fSopenharmony_ci  });
4653af6ab5fSopenharmony_ci}