Permalink
Cannot retrieve contributors at this time
45 lines (41 sloc)
1.11 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/values/index.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 Literal from './Literal'; | |
import JSXElement from './JSXElement'; | |
import JSXText from './JSXText'; | |
import JSXExpressionContainer, { extractLiteral } from './expressions'; | |
// Composition map of types to their extractor functions. | |
const TYPES = { | |
Literal, | |
JSXElement, | |
JSXExpressionContainer, | |
JSXText, | |
}; | |
// Composition map of types to their extractor functions to handle literals. | |
const LITERAL_TYPES = { | |
...TYPES, | |
JSXElement: () => null, | |
JSXExpressionContainer: extractLiteral, | |
}; | |
/** | |
* This function maps an AST value node | |
* to its correct extractor function for its | |
* given type. | |
* | |
* This will map correctly for *all* possible types. | |
* | |
* @param value - AST Value object on a JSX Attribute. | |
*/ | |
export default function getValue(value) { | |
return TYPES[value.type](value); | |
} | |
/** | |
* This function maps an AST value node | |
* to its correct extractor function for its | |
* given type. | |
* | |
* This will map correctly for *some* possible types that map to literals. | |
* | |
* @param value - AST Value object on a JSX Attribute. | |
*/ | |
export function getLiteralValue(value) { | |
return LITERAL_TYPES[value.type](value); | |
} |