in packages/babel-plugin-fbt/src/getNamespacedArgs.js [42:95]
param(node) {
const attributes = node.openingElement.attributes;
const nameAttr = getAttributeByNameOrThrow(attributes, 'name');
const options = getOptionsFromAttributes(
t,
attributes,
ValidParamOptions,
RequiredParamOptions,
);
let paramChildren = filterEmptyNodes(node.children).filter(function (
child,
) {
return (
child.type === 'JSXExpressionContainer' || child.type === 'JSXElement'
);
});
// <fbt:param> </fbt:param>
// should be the equivalent of
// <fbt:param>{' '}</fbt:param>
if (
paramChildren.length === 0 &&
node.children.length === 1 &&
node.children[0].type === 'JSXText' &&
node.children[0].value === ' '
) {
paramChildren = [
jsxExpressionContainer(stringLiteral(node.children[0].value)),
];
}
if (paramChildren.length !== 1) {
throw errorAt(
node,
`${moduleName}:param expects an {expression} or JSX element, and only one`,
);
}
const nameAttrValue = nameAttr.value;
if (nameAttrValue.loc.end.line > nameAttrValue.loc.start.line) {
nameAttrValue.value = normalizeSpaces(nameAttrValue.value);
}
const paramArgs = [
nameAttrValue,
paramChildren[0].expression || paramChildren[0],
];
if (options.properties.length > 0) {
paramArgs.push(options);
}
return paramArgs;
},