Permalink
Cannot retrieve contributors at this time
24 lines (23 sloc)
843 Bytes
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/expressions/ObjectExpression.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 assign from 'object.assign'; | |
/** | |
* Extractor function for an ObjectExpression type value node. | |
* An object expression is using {}. | |
* | |
* @returns - a representation of the object | |
*/ | |
export default function extractValueFromObjectExpression(value) { | |
// eslint-disable-next-line global-require | |
const getValue = require('.').default; | |
return value.properties.reduce((obj, property) => { | |
const object = { ...obj }; | |
// Support types: SpreadProperty and ExperimentalSpreadProperty | |
if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) { | |
if (property.argument.type === 'ObjectExpression') { | |
return assign(object, extractValueFromObjectExpression(property.argument)); | |
} | |
} else { | |
object[getValue(property.key)] = getValue(property.value); | |
} | |
return object; | |
}, {}); | |
} |