persona-community-5/.pnpm-store/v3/files/4f/fddbc0f8ce68fc644d52fc9dfd188a87dca47930517969df1ba200ff823fac3abb435b52f42086c89f5d6ac184c7a4bf24aa7c64ffe393256ef504d0a27455
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

45 lines
1.9 KiB
Plaintext

"use strict";
// adapted from https://github.com/eslint/eslint/blob/5bdaae205c3a0089ea338b382df59e21d5b06436/lib/rules/utils/ast-utils.js#L191-L230
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStaticStringValue = getStaticStringValue;
const utils_1 = require("@typescript-eslint/utils");
const isNullLiteral_1 = require("./isNullLiteral");
/**
* Returns the result of the string conversion applied to the evaluated value of the given expression node,
* if it can be determined statically.
*
* This function returns a `string` value for all `Literal` nodes and simple `TemplateLiteral` nodes only.
* In all other cases, this function returns `null`.
* @param node Expression node.
* @returns String value if it can be determined. Otherwise, `null`.
*/
function getStaticStringValue(node) {
switch (node.type) {
case utils_1.AST_NODE_TYPES.Literal:
// eslint-disable-next-line eqeqeq -- intentional strict comparison for literal value
if (node.value === null) {
if ((0, isNullLiteral_1.isNullLiteral)(node)) {
return String(node.value); // "null"
}
if ('regex' in node) {
return `/${node.regex.pattern}/${node.regex.flags}`;
}
if ('bigint' in node) {
return node.bigint;
}
// Otherwise, this is an unknown literal. The function will return null.
}
else {
return String(node.value);
}
break;
case utils_1.AST_NODE_TYPES.TemplateLiteral:
if (node.expressions.length === 0 && node.quasis.length === 1) {
return node.quasis[0].value.cooked;
}
break;
// no default
}
return null;
}
//# sourceMappingURL=getStaticStringValue.js.map