1/* 2 * Copyright (c) 2024 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, softwareP 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 * as ts from 'typescript'; 17import * as path from 'node:path'; 18 19export function getScriptKind(srcFile: ts.SourceFile): ts.ScriptKind { 20 const fileName = srcFile.fileName; 21 const ext = path.extname(fileName).toLowerCase(); 22 switch (ext) { 23 case ts.Extension.Js: 24 return ts.ScriptKind.JS; 25 case ts.Extension.Jsx: 26 return ts.ScriptKind.JSX; 27 case ts.Extension.Ts: 28 return ts.ScriptKind.TS; 29 case ts.Extension.Tsx: 30 return ts.ScriptKind.TSX; 31 case ts.Extension.Json: 32 return ts.ScriptKind.JSON; 33 case ts.Extension.Ets: 34 return ts.ScriptKind.ETS; 35 default: 36 return ts.ScriptKind.Unknown; 37 } 38} 39