_getDescription()

in packages/babel-plugin-fbt/src/babel-processors/JSXFbtProcessor.js [113:153]


  _getDescription(texts: BabelNodeArrayExpression) {
    const {moduleName, node} = this;
    const commonAttributeValue = this._getCommonAttributeValue();
    let desc;

    if (commonAttributeValue && commonAttributeValue.value) {
      const rawTextValue = (texts.elements || [])
        .map(stringNode => {
          try {
            invariant(
              isStringLiteral(stringNode),
              'Expected a StringLiteral but found `%s` instead',
              stringNode?.type || 'unknown',
            );
            return stringNode.value;
          } catch (error) {
            throw errorAt(stringNode, error.message);
          }
        })
        .join('');

      const textValue = normalizeSpaces(rawTextValue).trim();
      const descValue = FbtCommon.getDesc(textValue);
      if (descValue == null || descValue === '') {
        throw errorAt(
          node,
          FbtCommon.getUnknownCommonStringErrorMessage(moduleName, textValue),
        );
      }
      if (getAttributeByName(this._getOpeningElementAttributes(), 'desc')) {
        throw errorAt(
          node,
          `<${moduleName} common={true}> must not have "desc" attribute`,
        );
      }
      desc = stringLiteral(descValue);
    } else {
      desc = this._getDescAttributeValue();
    }
    return desc;
  }