1/* 2 * Copyright (c) 2021 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 { 17 validateUISyntax, 18 processSystemApi, 19 ReplaceResult, 20 sourceReplace, 21 componentCollection 22} from './validate_ui_syntax'; 23import { 24 LogInfo, 25 emitLogInfo, 26 storedFileInfo 27} from './utils'; 28import { BUILD_ON } from './pre_define'; 29import { parseVisual } from './process_visual'; 30import { 31 CUSTOM_BUILDER_METHOD, 32 GLOBAL_CUSTOM_BUILDER_METHOD, 33 INNER_CUSTOM_BUILDER_METHOD 34} from './component_map'; 35 36function preProcess(source: string): string { 37 process.env.compiler = BUILD_ON; 38 if (/\.ets$/.test(this.resourcePath)) { 39 storedFileInfo.setCurrentArkTsFile(); 40 clearCollection(); 41 const result: ReplaceResult = sourceReplace(source, this.resourcePath); 42 let newContent: string = result.content; 43 const log: LogInfo[] = result.log.concat(validateUISyntax(source, newContent, 44 this.resourcePath, this.resourceQuery)); 45 newContent = parseVisual(this.resourcePath, this.resourceQuery, newContent, log, source); 46 if (log.length) { 47 emitLogInfo(this, log); 48 } 49 return newContent; 50 } else { 51 return processSystemApi(source, false, this.resourcePath); 52 } 53} 54 55function clearCollection(): void { 56 componentCollection.customComponents.clear(); 57 CUSTOM_BUILDER_METHOD.clear(); 58 GLOBAL_CUSTOM_BUILDER_METHOD.clear(); 59 INNER_CUSTOM_BUILDER_METHOD.clear(); 60} 61 62module.exports = preProcess; 63