107ac75b1Sopenharmony_ci/* 207ac75b1Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 307ac75b1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 407ac75b1Sopenharmony_ci * you may not use this file except in compliance with the License. 507ac75b1Sopenharmony_ci * You may obtain a copy of the License at 607ac75b1Sopenharmony_ci * 707ac75b1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 807ac75b1Sopenharmony_ci * 907ac75b1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1007ac75b1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1107ac75b1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1207ac75b1Sopenharmony_ci * See the License for the specific language governing permissions and 1307ac75b1Sopenharmony_ci * limitations under the License. 1407ac75b1Sopenharmony_ci */ 1507ac75b1Sopenharmony_ci 1607ac75b1Sopenharmony_ciimport ts from 'typescript'; 1707ac75b1Sopenharmony_ci 1807ac75b1Sopenharmony_ciimport { 1907ac75b1Sopenharmony_ci ELMTID, 2007ac75b1Sopenharmony_ci FINALIZE_CONSTRUCTION 2107ac75b1Sopenharmony_ci} from './pre_define'; 2207ac75b1Sopenharmony_ci 2307ac75b1Sopenharmony_ciimport { 2407ac75b1Sopenharmony_ci IFileLog, 2507ac75b1Sopenharmony_ci LogInfo 2607ac75b1Sopenharmony_ci} from './utils'; 2707ac75b1Sopenharmony_ci 2807ac75b1Sopenharmony_ciclass FileLog implements IFileLog { 2907ac75b1Sopenharmony_ci private _sourceFile: ts.SourceFile | undefined; 3007ac75b1Sopenharmony_ci private _errors: LogInfo[] = []; 3107ac75b1Sopenharmony_ci 3207ac75b1Sopenharmony_ci public get sourceFile(): ts.SourceFile | undefined { 3307ac75b1Sopenharmony_ci return this._sourceFile; 3407ac75b1Sopenharmony_ci } 3507ac75b1Sopenharmony_ci 3607ac75b1Sopenharmony_ci public set sourceFile(newValue: ts.SourceFile) { 3707ac75b1Sopenharmony_ci this._sourceFile = newValue; 3807ac75b1Sopenharmony_ci } 3907ac75b1Sopenharmony_ci 4007ac75b1Sopenharmony_ci public get errors(): LogInfo[] { 4107ac75b1Sopenharmony_ci return this._errors; 4207ac75b1Sopenharmony_ci } 4307ac75b1Sopenharmony_ci 4407ac75b1Sopenharmony_ci public set errors(newValue: LogInfo[]) { 4507ac75b1Sopenharmony_ci this._errors = newValue; 4607ac75b1Sopenharmony_ci } 4707ac75b1Sopenharmony_ci 4807ac75b1Sopenharmony_ci public cleanUp(): void { 4907ac75b1Sopenharmony_ci this._sourceFile = undefined; 5007ac75b1Sopenharmony_ci this._errors = []; 5107ac75b1Sopenharmony_ci } 5207ac75b1Sopenharmony_ci} 5307ac75b1Sopenharmony_ci 5407ac75b1Sopenharmony_ci 5507ac75b1Sopenharmony_cifunction createParameterDeclaration(name: string): ts.ParameterDeclaration { 5607ac75b1Sopenharmony_ci let initializer: ts.Expression; 5707ac75b1Sopenharmony_ci if (name === ELMTID) { 5807ac75b1Sopenharmony_ci initializer = ts.factory.createPrefixUnaryExpression( 5907ac75b1Sopenharmony_ci ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral('1')); 6007ac75b1Sopenharmony_ci } 6107ac75b1Sopenharmony_ci return ts.factory.createParameterDeclaration(undefined, undefined, 6207ac75b1Sopenharmony_ci ts.factory.createIdentifier(name), undefined, undefined, initializer); 6307ac75b1Sopenharmony_ci} 6407ac75b1Sopenharmony_ci 6507ac75b1Sopenharmony_cifunction createFinalizeConstruction(freezeParamNode: ts.Expression): ts.Statement { 6607ac75b1Sopenharmony_ci const params: ts.Expression[] = []; 6707ac75b1Sopenharmony_ci if (freezeParamNode) { 6807ac75b1Sopenharmony_ci params.push(freezeParamNode); 6907ac75b1Sopenharmony_ci } 7007ac75b1Sopenharmony_ci return ts.factory.createExpressionStatement(ts.factory.createCallExpression( 7107ac75b1Sopenharmony_ci ts.factory.createPropertyAccessExpression( 7207ac75b1Sopenharmony_ci ts.factory.createThis(), 7307ac75b1Sopenharmony_ci ts.factory.createIdentifier(FINALIZE_CONSTRUCTION) 7407ac75b1Sopenharmony_ci ), 7507ac75b1Sopenharmony_ci undefined, 7607ac75b1Sopenharmony_ci params 7707ac75b1Sopenharmony_ci )); 7807ac75b1Sopenharmony_ci} 7907ac75b1Sopenharmony_ci 8007ac75b1Sopenharmony_cifunction createImportNodeForModuleInfo(): ts.ImportDeclaration { 8107ac75b1Sopenharmony_ci return ts.factory.createImportDeclaration( 8207ac75b1Sopenharmony_ci undefined, ts.factory.createImportClause(false, undefined, 8307ac75b1Sopenharmony_ci ts.factory.createNamedImports([ts.factory.createImportSpecifier( 8407ac75b1Sopenharmony_ci false, undefined, ts.factory.createIdentifier('__MODULE_NAME__') 8507ac75b1Sopenharmony_ci ), ts.factory.createImportSpecifier(false, undefined, 8607ac75b1Sopenharmony_ci ts.factory.createIdentifier('__BUNDLE_NAME__'))]) 8707ac75b1Sopenharmony_ci ), ts.factory.createStringLiteral('ModuleInfo'), undefined 8807ac75b1Sopenharmony_ci ); 8907ac75b1Sopenharmony_ci} 9007ac75b1Sopenharmony_ci 9107ac75b1Sopenharmony_ciexport default { 9207ac75b1Sopenharmony_ci FileLog: FileLog, 9307ac75b1Sopenharmony_ci createParameterDeclaration: createParameterDeclaration, 9407ac75b1Sopenharmony_ci createFinalizeConstruction: createFinalizeConstruction, 9507ac75b1Sopenharmony_ci createImportNodeForModuleInfo: createImportNodeForModuleInfo 9607ac75b1Sopenharmony_ci}; 97