1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import type {IOptions} from '../configs/IOptions'; 17import type {Node, TransformerFactory} from 'typescript'; 18 19export interface TransformPlugin { 20 name: string; 21 order: number 22 createTransformerFactory: (option: IOptions) => TransformerFactory<Node>; 23} 24 25// The order of identifier obfuscation should be as early as possible, because create or update nodes will cause the NodeFlags of the parent node 26// on the ast to be cleared. NodeFlags will affect the binding result. The following scenarios have been found to affect the obfuscation function: 27// Problem scenario: A export name in a namespace scope within a declaration file 28// ``` 29// declare namespace ns { 30// class A { // -keep-global-name A is invalid. 31// temp: number; 32// } 33// } 34// ``` 35// Problem description: because the property temp is obfuscated, a node update occurs, causing -keep-global-name A to be invalid. 36export enum TransformerOrder { 37 SHORTHAND_PROPERTY_TRANSFORMER, 38 RENAME_IDENTIFIER_TRANSFORMER, 39 VIRTUAL_CONSTRUCTOR_TRANSFORMER, 40 DISABLE_CONSOLE_TRANSFORMER, 41 RENAME_PROPERTIES_TRANSFORMER, 42 RENAME_FILE_NAME_TRANSFORMER 43}