Files
NapCatQQ/.pnpm-store/v3/files/64/3a4562550bcddeffa27fae5fda961b98701c5b8c000b99c9cd7c5e2d6d30e7a635639bce7f0f15a142b178c2e943dd778613d04816e0fd2878e173a6ac916c
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

67 lines
2.3 KiB
Plaintext

"use strict"
const path = require("path")
const isTypescript = require("./is-typescript")
const getTypescriptExtensionMap = require("./get-typescript-extension-map")
/**
* Maps the typescript file extension that should be added in an import statement,
* based on the given file extension of the referenced file OR fallsback to the original given extension.
*
* For example, in typescript, when referencing another typescript from a typescript file,
* a .js extension should be used instead of the original .ts extension of the referenced file.
*
* @param {import('eslint').Rule.RuleContext} context
* @param {string} filePath The filePath of the import
* @param {string} fallbackExtension The non-typescript fallback
* @returns {string} The file extension to append to the import statement.
*/
function convertTsExtensionToJs(context, filePath, fallbackExtension) {
const { forward } = getTypescriptExtensionMap(context)
const ext = path.extname(filePath)
if (
isTypescript(context) &&
ext in forward &&
Object.hasOwn(forward, ext) &&
typeof forward[ext] === "string"
) {
return forward[ext]
}
return fallbackExtension
}
/**
* Maps the typescript file extension that should be added in an import statement,
* based on the given file extension of the referenced file OR fallsback to the original given extension.
*
* For example, in typescript, when referencing another typescript from a typescript file,
* a .js extension should be used instead of the original .ts extension of the referenced file.
*
* @param {import('eslint').Rule.RuleContext} context
* @param {string} filePath The filePath of the import
* @param {string} fallbackExtension The non-typescript fallback
* @returns {string[]} The file extension to append to the import statement.
*/
function convertJsExtensionToTs(context, filePath, fallbackExtension) {
const { backward } = getTypescriptExtensionMap(context)
const ext = path.extname(filePath)
if (
isTypescript(context) &&
ext in backward &&
Object.hasOwn(backward, ext) &&
Array.isArray(backward[ext])
) {
return backward[ext]
}
return [fallbackExtension]
}
module.exports = {
convertTsExtensionToJs,
convertJsExtensionToTs,
}