function sizeofPlugin(): SemanticPlugin {
  return {
    semantics() {
      return {
        [Syntax.FunctionCall]: next => args => {
          const [sizeof, context] = args;

          if (sizeof.value !== 'sizeof') {
            return next(args);
          }

          const { scopes, userTypes, functions } = context;
          const [, target] = sizeof.params;
          const ref = find(scopes, target.value);
          const { type = '' } = ref || {};
          const userType = userTypes[target.value] || userTypes[type];
          const func = functions[target.value];

          if (userType != null) {
            const metaSize = userType.meta[OBJECT_SIZE];
            invariant(metaSize, 'Object size information is missing');
            return {
              ...sizeof,
              value: metaSize,
              params: [],
              type: 'i32',
              Type: Syntax.Constant,
            };
          }

          const node = ref || func;

          return {
            ...sizeof,
            value: sizes[String(node ? node.type : target.value)],
            type: 'i32',
            params: [],
            Type: Syntax.Constant,
          };
        },
      };
    },
  };
}
Sizeof helper plugin. Maps size(<THING>) to a static i32 constant

@flow