Urara-Blog/node_modules/.pnpm-store/v3/files/c9/75e5d840bdaf9099d7906e68b8dde473ef0223f7ce6b2becd3baa04c6cd0663ee57b851c814583e04180cb200503f2a771628fd755c0855b77025cf35ca0ad
2022-08-14 01:14:53 +08:00

41 lines
721 B
Text

/**
* @typedef {import('../types.js').Unsafe} Unsafe
*/
/**
* @param {Array<string>} stack
* @param {Unsafe} pattern
* @returns {boolean}
*/
export function patternInScope(stack, pattern) {
return (
listInScope(stack, pattern.inConstruct, true) &&
!listInScope(stack, pattern.notInConstruct, false)
)
}
/**
* @param {Array<string>} stack
* @param {Unsafe['inConstruct']} list
* @param {boolean} none
* @returns {boolean}
*/
function listInScope(stack, list, none) {
if (!list) {
return none
}
if (typeof list === 'string') {
list = [list]
}
let index = -1
while (++index < list.length) {
if (stack.includes(list[index])) {
return true
}
}
return false
}