Permalink
Cannot retrieve contributors at this time
45 lines (40 sloc)
1.38 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/jsx-ast-utils/src/getPropValue.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getValue, { getLiteralValue } from './values'; | |
const extractValue = (attribute, extractor) => { | |
if (attribute && attribute.type === 'JSXAttribute') { | |
if (attribute.value === null) { | |
// Null valued attributes imply truthiness. | |
// For example: <div aria-hidden /> | |
// See: https://facebook.github.io/react/docs/jsx-in-depth.html#boolean-attributes | |
return true; | |
} | |
return extractor(attribute.value); | |
} | |
return undefined; | |
}; | |
/** | |
* Returns the value of a given attribute. | |
* Different types of attributes have their associated | |
* values in different properties on the object. | |
* | |
* This function should return the most *closely* associated | |
* value with the intention of the JSX. | |
* | |
* @param attribute - The JSXAttribute collected by AST parser. | |
*/ | |
export default function getPropValue(attribute) { | |
return extractValue(attribute, getValue); | |
} | |
/** | |
* Returns the value of a given attribute. | |
* Different types of attributes have their associated | |
* values in different properties on the object. | |
* | |
* This function should return a value only if we can extract | |
* a literal value from its attribute (i.e. values that have generic | |
* types in JavaScript - strings, numbers, booleans, etc.) | |
* | |
* @param attribute - The JSXAttribute collected by AST parser. | |
*/ | |
export function getLiteralPropValue(attribute) { | |
return extractValue(attribute, getLiteralValue); | |
} |