function getOptionsFromAttributes()

in packages/babel-plugin-fbt/src/FbtUtil.js [238:282]


function getOptionsFromAttributes(
  t: BabelTypes,
  attributesNode: $FlowFixMe,
  validOptions: $FlowFixMe,
  ignoredAttrs: $FlowFixMe,
): BabelNodeObjectExpression {
  const options = [];

  attributesNode.forEach(function (node) {
    const option = node.name.name;

    // Required attributes are passed as a separate argument in the fbt(...)
    // call, because they're required. They're not passed as options.
    // Ignored attributes are simply stripped from the function call entirely
    // and ignored.  By default, we ignore all "private" attributes with a
    // leading '__' like '__source' and '__self' as added by certain
    // babel/react plugins
    if (ignoredAttrs[option] || option.startsWith('__')) {
      return;
    }

    let value = node.value;
    const name = node.name.name;

    if (value === null && canBeShortBoolAttr(String(name))) {
      value = t.booleanLiteral(true);
    } else if (isJSXExpressionContainer(value)) {
      value = value.expression;
    } else if (
      isStringLiteral(value) &&
      (value.value === 'true' || value.value === 'false')
    ) {
      value = t.booleanLiteral(value.value === 'true');
    }

    options.push(
      t.objectProperty(
        t.stringLiteral(checkOption(option, validOptions, value)),
        value,
      ),
    );
  });

  return t.objectExpression(options);
}