Files
NapCatQQ/.pnpm-store/v3/files/59/41dcc5560619d0dd65bd6913978bf5fbdc67cee09699584da26a6174bec90c93052ca38617e45a87a94e680daab97d3b2e55d1a7efe94ccf1046ce9b8371ff
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

55 lines
1.1 KiB
Plaintext

/**
* Adapted from `eslint-plugin-unicorn`
* @license MIT
*/
'use strict'
const {
isParenthesized,
isOpeningParenToken,
isClosingParenToken,
} = require('@eslint-community/eslint-utils')
/*
Get how many times the node is parenthesized.
@param {Node} node - The node to be checked.
@param {SourceCode} sourceCode - The source code object.
@returns {number}
*/
function getParenthesizedTimes(node, sourceCode) {
let times = 0
while (isParenthesized(times + 1, node, sourceCode)) {
times++
}
return times
}
/*
Get all parentheses tokens around the node.
@param {Node} node - The node to be checked.
@param {SourceCode} sourceCode - The source code object.
@returns {Token[]}
*/
function getParentheses(node, sourceCode) {
const count = getParenthesizedTimes(node, sourceCode)
if (count === 0) {
return []
}
return [
...sourceCode.getTokensBefore(node, { count, filter: isOpeningParenToken }),
...sourceCode.getTokensAfter(node, { count, filter: isClosingParenToken }),
]
}
module.exports = {
isParenthesized,
getParenthesizedTimes,
getParentheses,
}