CallExpression()

in packages/babel-plugin-fbt/src/babel-processors/FbtFunctionCallProcessor.js [552:600]


        CallExpression(path: NodePathOf<BabelNodeCallExpression>) {
          // eslint-disable-next-line max-len
          // $FlowFixMe[object-this-reference] Babel transforms run with the plugin context by default
          const nodeChecker = (this.nodeChecker: FbtNodeChecker);
          const constructs = [
            FbtNodeType.Enum,
            FbtNodeType.Name,
            FbtNodeType.Param,
            FbtNodeType.Plural,
            FbtNodeType.Pronoun,
            FbtNodeType.SameParam,
          ];

          const childFbtConstructName =
            nodeChecker.getFbtConstructNameFromFunctionCall(path.node);
          if (!constructs.includes(childFbtConstructName)) {
            return;
          }

          let parentPath = path.parentPath;
          while (parentPath != null) {
            const parentNode = parentPath.node;
            if (
              FbtNodeChecker.forFbtFunctionCall(parentNode) != null ||
              // children JSX fbt aren't yet converted to function call by JSXFbtProcessor
              FbtNodeChecker.forJSXFbt(parentNode) != null
            ) {
              return;
            }

            const parentFbtConstructName =
              nodeChecker.getFbtConstructNameFromFunctionCall(parentNode);
            if (constructs.includes(parentFbtConstructName)) {
              throw errorAt(
                parentNode,
                `Expected fbt constructs to not nest inside fbt constructs, ` +
                  `but found ` +
                  `${nodeChecker.moduleName}.${(nullthrows(
                    childFbtConstructName,
                  ): string)} ` +
                  `nest inside ` +
                  `${nodeChecker.moduleName}.${(nullthrows(
                    parentFbtConstructName,
                  ): string)}`,
              );
            }
            parentPath = parentPath.parentPath;
          }
        },