How to use the ast-types.builders.memberExpression function in ast-types

To help you get started, we’ve selected a few ast-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
b.memberExpression(
                  b.thisExpression(), b.identifier('endian')),
                b.binaryExpression(
                  '!==',
                  b.memberExpression(
                    b.identifier('obj'), b.identifier(child_name)),
                  b.literal(66))
                )));
            // data.readUInt8(0) !== 66
          }
          write_stmts.push(
            b.expressionStatement(b.callExpression(
              b.memberExpression(
                b.thisExpression(),
                b.identifier(`write${child_type}`)),
              [b.memberExpression(
                b.identifier('obj'),
                b.identifier(child_name))])));
        }
        break;
      case 'list':
        {
          let child_name = child.attr('name').value();
          let child_type = child.attr('type').value();

          let fieldref = parseOp(child.get('*'), 'obj');
          if (fieldref !== null) {
            read_stmts.push(b.variableDeclaration(
              'var',
              [b.variableDeclarator(
                b.identifier(`${child_name}_length`),
                fieldref)]));
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
throw new Error(
            "Shouldn't be able to get to valueparam before enums are parsed");
        }
        let enum_map = klasses.getClass('XTypeBuffer').enums;
        let value_mask_type = child.attr('value-mask-type').value();
        let value_mask_name = child.attr('value-mask-name').value();
        let value_list_name = child.attr('value-list-name').value();
        if (! enum_map.has(value_list_name)) {
          console.error(`FIXME: The stupid cases for ${value_list_name}`);
          continue;
        }
        let enum_class_name = enum_map.get(value_list_name).name;

        read_stmts.push(b.expressionStatement(b.assignmentExpression(
          '=',
          b.memberExpression(
            b.identifier('obj'), b.identifier(value_mask_name)),
          b.callExpression(b.memberExpression(
            b.parenthesizedExpression(b.newExpression(
              b.identifier(enum_class_name),
              [])),
            b.identifier('decode')),
            [b.callExpression(
              b.memberExpression(
                b.thisExpression(),
                b.identifier(`read${value_mask_type}`)),
              [])]
          ))));

        write_stmts.push(b.variableDeclaration(
          'var',
          [b.variableDeclarator(
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
}
        let enum_map = klasses.getClass('XTypeBuffer').enums;
        let value_mask_type = child.attr('value-mask-type').value();
        let value_mask_name = child.attr('value-mask-name').value();
        let value_list_name = child.attr('value-list-name').value();
        if (! enum_map.has(value_list_name)) {
          console.error(`FIXME: The stupid cases for ${value_list_name}`);
          continue;
        }
        let enum_class_name = enum_map.get(value_list_name).name;

        read_stmts.push(b.expressionStatement(b.assignmentExpression(
          '=',
          b.memberExpression(
            b.identifier('obj'), b.identifier(value_mask_name)),
          b.callExpression(b.memberExpression(
            b.parenthesizedExpression(b.newExpression(
              b.identifier(enum_class_name),
              [])),
            b.identifier('decode')),
            [b.callExpression(
              b.memberExpression(
                b.thisExpression(),
                b.identifier(`read${value_mask_type}`)),
              [])]
          ))));

        write_stmts.push(b.variableDeclaration(
          'var',
          [b.variableDeclarator(
            b.identifier('value'),
            b.memberExpression(b.identifier('obj'), b.identifier('value'))
github rexxars / sql-to-graphql / steps / ast-builders / type-imports.js View on Github external
b.identifier('connectionArgs'),
                    b.memberExpression(
                        b.identifier('GraphQLRelay'),
                        b.identifier('connectionArgs'),
                        false
                    )
                )]
            ));
        }
    }

    declarations.push(
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('getType'),
                b.memberExpression(
                    b.identifier('resolveMap'),
                    b.identifier('getType'),
                    false
                )
            )]
        )
    );

    declarations.push(
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('registerType'),
                b.memberExpression(
                    b.identifier('resolveMap'),
                    b.identifier('registerType'),
                    false
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
function moduleExportsExpression(id: string): any {
  return b.memberExpression(
    b.memberExpression(
      b.identifier('module'),
      b.identifier('exports'),
      false
    ),
    b.literal(id),
    true
  );
}
github rainforestapp / decaf / src / parser.js View on Github external
boundMethods.map(identifier =>
          b.expressionStatement(
            b.callExpression(
              b.memberExpression(
                b.memberExpression(
                  b.thisExpression(),
                  identifier
                ),
                b.identifier('bind')
              ),
              [b.thisExpression()]
            )
          )
        )
github paeckchen / paeckchen / packages / paeckchen-core / src / bundle-json.ts View on Github external
export async function wrapJsonFile(modulePath: string, context: PaeckchenContext): Promise {
  const data = JSON.parse(await context.host.readFile(modulePath));
  return b.program([
    b.expressionStatement(
      b.assignmentExpression(
        '=',
        b.memberExpression(
          b.identifier('module'),
          b.identifier('exports'),
          false
        ),
        buildValue(data)
      )
    )
  ]);
}
github rexxars / sql-to-graphql / steps / ast-builders / schema-imports.js View on Github external
b.identifier('nodeField'),
                    b.memberExpression(
                        b.identifier('Node'),
                        b.identifier('nodeField'),
                        false
                    )
                )]
            )
        );
    }

    declarations.push(
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('registerType'),
                b.memberExpression(
                    b.identifier('resolveMap'),
                    b.identifier('registerType'),
                    false
                )
            )]
        )
    );

    return declarations;
}
github rainforestapp / decaf / src / parser.js View on Github external
function mapMemberProperties(properties: CBaseList, meta: Object) {
  const head = properties.slice(0, properties.length - 1);
  const lastProperty = last(properties);
  const isIndex = lastProperty.constructor.name === 'Index';
  const right = mapExpression(lastProperty, meta);
  const isComputed = (right.type === 'Literal' || isIndex);
  let left;

  if (head.length === 1) {
    left = mapExpression(head[0], meta);
  } else {
    left = mapMemberProperties(head, meta);
  }

  return b.memberExpression(left, right, isComputed);
}
github paeckchen / paeckchen / packages / paeckchen-core / src / modules.ts View on Github external
function wrapExternalModule(modulePath: string, context: PaeckchenContext): Promise {
  const external = context.config.externals[modulePath] === false
    ? b.objectExpression([])
    : b.identifier(context.config.externals[modulePath] as string);
  return Promise.resolve(b.program([
    b.expressionStatement(
      b.assignmentExpression(
        '=',
        b.memberExpression(
          b.identifier('module'),
          b.identifier('exports'),
          false
        ),
        external
      )
    )
  ]));
}