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 createCompilerHost, 183af6ab5fSopenharmony_ci createSourceMapGenerator, 193af6ab5fSopenharmony_ci} from 'typescript'; 203af6ab5fSopenharmony_ci 213af6ab5fSopenharmony_ciimport type { 223af6ab5fSopenharmony_ci CompilerHost, 233af6ab5fSopenharmony_ci CompilerOptions, 243af6ab5fSopenharmony_ci EmitHost, 253af6ab5fSopenharmony_ci SourceMapGenerator, 263af6ab5fSopenharmony_ci SourceMapGeneratorOptions, 273af6ab5fSopenharmony_ci} from 'typescript'; 283af6ab5fSopenharmony_ci 293af6ab5fSopenharmony_ci/** 303af6ab5fSopenharmony_ci * create sourcemap generator use api of typescript 313af6ab5fSopenharmony_ci * @param sourceFile: file path of source code 323af6ab5fSopenharmony_ci */ 333af6ab5fSopenharmony_ciexport function getSourceMapGenerator(sourceFile: string): SourceMapGenerator { 343af6ab5fSopenharmony_ci if (!sourceFile) { 353af6ab5fSopenharmony_ci return undefined; 363af6ab5fSopenharmony_ci } 373af6ab5fSopenharmony_ci 383af6ab5fSopenharmony_ci let compilerOptions: CompilerOptions = {}; 393af6ab5fSopenharmony_ci let compilerHost: CompilerHost = createCompilerHost(compilerOptions); 403af6ab5fSopenharmony_ci 413af6ab5fSopenharmony_ci function getCanonicalFileName(fileName: string): string { 423af6ab5fSopenharmony_ci return compilerHost.getCanonicalFileName(fileName); 433af6ab5fSopenharmony_ci } 443af6ab5fSopenharmony_ci 453af6ab5fSopenharmony_ci const currentDirectory: string = compilerHost.getCurrentDirectory(); 463af6ab5fSopenharmony_ci 473af6ab5fSopenharmony_ci let host: EmitHost = { 483af6ab5fSopenharmony_ci getSourceFileFromReference: undefined, 493af6ab5fSopenharmony_ci redirectTargetsMap: undefined, 503af6ab5fSopenharmony_ci fileExists(path: string): boolean { 513af6ab5fSopenharmony_ci return false; 523af6ab5fSopenharmony_ci }, 533af6ab5fSopenharmony_ci isEmitBlocked(emitFileName: string): boolean { 543af6ab5fSopenharmony_ci return false; 553af6ab5fSopenharmony_ci }, 563af6ab5fSopenharmony_ci useCaseSensitiveFileNames(): boolean { 573af6ab5fSopenharmony_ci return false; 583af6ab5fSopenharmony_ci }, 593af6ab5fSopenharmony_ci getPrependNodes: undefined, 603af6ab5fSopenharmony_ci getCanonicalFileName: getCanonicalFileName, 613af6ab5fSopenharmony_ci getCommonSourceDirectory: undefined, 623af6ab5fSopenharmony_ci getCompilerOptions: undefined, 633af6ab5fSopenharmony_ci getCurrentDirectory: () => currentDirectory, 643af6ab5fSopenharmony_ci getNewLine: undefined, 653af6ab5fSopenharmony_ci getSourceFile: undefined, 663af6ab5fSopenharmony_ci getSourceFileByPath: undefined, 673af6ab5fSopenharmony_ci getSourceFiles: undefined, 683af6ab5fSopenharmony_ci getLibFileFromReference: undefined, 693af6ab5fSopenharmony_ci isSourceFileFromExternalLibrary: undefined, 703af6ab5fSopenharmony_ci getResolvedProjectReferenceToRedirect: undefined, 713af6ab5fSopenharmony_ci getProjectReferenceRedirect: undefined, 723af6ab5fSopenharmony_ci isSourceOfProjectReferenceRedirect: undefined, 733af6ab5fSopenharmony_ci writeFile: undefined 743af6ab5fSopenharmony_ci }; 753af6ab5fSopenharmony_ci 763af6ab5fSopenharmony_ci const generatorOptions: SourceMapGeneratorOptions = {extendedDiagnostics: false}; 773af6ab5fSopenharmony_ci return createSourceMapGenerator(host, sourceFile, currentDirectory, currentDirectory, generatorOptions); 783af6ab5fSopenharmony_ci} 79