UNPKG

eslint-plugin-react-native-unistyles

Version:
38 lines (37 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.genericUtils = void 0; const utils_1 = require("@typescript-eslint/utils"); function isEveryExpressionLiteral(expressions) { return expressions.every((expr) => { if (expr.type === utils_1.AST_NODE_TYPES.Literal) { return true; } if (expr.type === utils_1.AST_NODE_TYPES.TemplateLiteral) { const areAllExpressionsLiterals = isEveryExpressionLiteral(expr.expressions); return areAllExpressionsLiterals; } return false; }); } exports.genericUtils = { getStringFromTemplateLiteral(node) { const expressions = node.expressions; const areAllExpressionsLiterals = isEveryExpressionLiteral(expressions); if (!areAllExpressionsLiterals) return undefined; const finalString = node.quasis.reduce((result, quasi, index) => { const expr = node.expressions[index]; let exprValue; if (expr?.type === utils_1.AST_NODE_TYPES.Literal) { exprValue = expr.value?.toString(); } if (expr?.type === utils_1.AST_NODE_TYPES.TemplateLiteral) { const templateResult = exports.genericUtils.getStringFromTemplateLiteral(expr); exprValue = templateResult; } return result + quasi.value.cooked + (exprValue ?? ''); }, ''); return finalString; }, };