All files / style9/src list-static-keys.js

100% Statements 14/14
100% Branches 8/8
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 228x     58x   58x 4x     54x 3x 3x 3x   1x     51x     8x  
const { isDynamicKey, getStaticKey } = require('./utils/ast');
 
function listStaticKeys(callExpr, allKeys) {
  const { parentPath } = callExpr;
 
  if (parentPath.isMemberExpression()) {
    return isDynamicKey(parentPath) ? allKeys : [getStaticKey(parentPath)];
  }
 
  if (parentPath.get('id').isObjectPattern()) {
    const properties = parentPath.get('id.properties');
    const hasRestElement = properties.some(prop => prop.isRestElement());
    if (hasRestElement) return allKeys;
 
    return properties.map(prop => prop.node.key.name);
  }
 
  return [];
}
 
module.exports = listStaticKeys;