UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

52 lines (45 loc) 1.53 kB
const _ = require('lodash'); function getPrefix(str) { const indexOfDot = str.indexOf('.'); return indexOfDot === -1 ? str : str.substring(0, indexOfDot); } function getSuffix(str) { const indexOfDot = str.indexOf('.'); return indexOfDot === -1 ? undefined : str.substring(indexOfDot + 1); } function findValueNodeOfIdentifier(identifierName, scope) { const varsInScope = scope.variables; let valueNode = false; varsInScope.forEach((variable) => { if (variable.name === identifierName) { if (variable.defs && variable.defs.length > 0) { valueNode = variable.defs[variable.defs.length - 1].node.init; } } }); if (valueNode === false || _.isNil(valueNode) || valueNode.value !== undefined) { if (_.get(scope, 'block.body.length', 0) > 0) { scope.block.body.forEach(scopeNode => { if (_.get(scopeNode, 'type') === 'ExpressionStatement') { const variableName = _.get(scopeNode, 'expression.left.name'); if (variableName === identifierName && _.get(scopeNode, 'expression.right')) { valueNode = scopeNode.expression.right; } } }); } } if (scope.upper === null) { return valueNode; } return valueNode || findValueNodeOfIdentifier(identifierName, scope.upper); } function handleError(ruleId, error, fileName) { console.log(`Found error in rule: ${ruleId}\n`, `Error: ${error}\n`, `In file: ${fileName}`); } module.exports = { getPrefix, getSuffix, findValueNodeOfIdentifier, handleError };