How to use the ast-types.builders.assignmentExpression 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 paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
function replaceExportNamedDeclaration(path: Path): void {
  const declaration = path.node.declaration;
  if (n.VariableDeclaration.check(declaration)) {
    // e.g. export var a = 0;
    const id = declaration.declarations[0].id;
    path.replace(declaration);
    path.insertAfter(
      b.expressionStatement(
        b.assignmentExpression(
          '=',
          moduleExportsExpression((id as ESTree.Identifier).name),
          b.identifier((id as ESTree.Identifier).name)
        )
      )
    );
  } else if (n.FunctionDeclaration.check(declaration) || n.ClassDeclaration.check(declaration)) {
    // e.g. export function f() {}
    path.replace(declaration);
    path.insertAfter(
      b.expressionStatement(
        b.assignmentExpression(
          '=',
          moduleExportsExpression(declaration.id.name),
          b.identifier(declaration.id.name)
        )
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
klasses.getClass('XTypeBuffer').enums
        )) {
          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(
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
}
        break;
      case 'exprfield':
        let child_name = child.attr('name').value();
        let child_type = child.attr('type').value();
        read_stmts.push(
          b.expressionStatement(b.assignmentExpression(
            '=',
            b.memberExpression(
              b.identifier('obj'), b.identifier(child_name)),
            b.callExpression(
              b.memberExpression(
                b.thisExpression(),
                b.identifier(`read${child_type}`)),
              []))));
        write_stmts.push(b.expressionStatement(b.assignmentExpression(
          '=',
          b.memberExpression(
            b.identifier('obj'), b.identifier(child_name)),
          parseOp(child.get('*'), 'obj'))));
        break;
      case 'valueparam':
        if (!(
          klasses.getClass('XTypeBuffer') &&
          klasses.getClass('XTypeBuffer').enums
        )) {
          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();
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
      )
    )
  ]));
}
github rexxars / sql-to-graphql / steps / ast-builders / resolve-map.js View on Github external
function buildResolveMapExport(map, opts) {
    if (opts.es6) {
        return [b.exportDeclaration(false, buildVariable('resolveMap', map, opts.es6))];
    }

    return [
        buildVariable('resolveMap', map, opts.es6),
        b.expressionStatement(
            b.assignmentExpression(
                '=',
                b.memberExpression(
                    b.identifier('exports'),
                    b.identifier('resolveMap'),
                    false
                ),
                b.identifier('resolveMap')
            )
        )
    ];
}
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
false
            )
          ]
        ),
        b.identifier('forEach'),
        false
      ),
      [
        b.functionExpression(
          null,
          [
            b.identifier('key')
          ],
          b.blockStatement([
            b.expressionStatement(
              b.assignmentExpression(
                '=',
                b.memberExpression(
                  b.memberExpression(
                    b.identifier('module'),
                    b.identifier('exports'),
                    false
                  ),
                  b.identifier('key'),
                  true
                ),
                b.memberExpression(
                  b.memberExpression(
                    identifier,
                    b.identifier('exports'),
                    false
                  ),
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
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)]));
          }
          write_stmts.push(b.variableDeclaration(
            'var',
            [b.variableDeclarator(
              b.identifier(`${child_name}_length`),
              fieldref)]));
          read_stmts.push(b.expressionStatement(b.assignmentExpression(
            '=',
            b.memberExpression(b.identifier('obj'), b.identifier(child_name)),
            b.arrayExpression([]))));

          let read_stmt = b.expressionStatement(b.callExpression(
            b.memberExpression(
              b.memberExpression(
                b.identifier('obj'), b.identifier(child_name)),
              b.identifier('push')),
            [b.callExpression(
              b.memberExpression(
                b.thisExpression(), b.identifier(`read${child_type}`)),
              [])]));
          if (fieldref === null) {
            read_stmts.push(
              b.whileStatement(
github interfaced / zombiebox / scripts / generate-config-docs.js View on Github external
_renderJsExports(classes) {
		return escodegen.generate(b.assignmentExpression(
			'=',
			b.memberExpression(
				b.identifier('module'),
				b.identifier('exports')
			),
			b.objectExpression(
				classes.map((object) => b.property(
					'init',
					b.identifier(this._getJsInterfaceName(object['$id'])),
					b.identifier(this._getJsInterfaceName(object['$id']))
				))
			)
		));
	}
}
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
module.exports = function parseBody(parent, klasses) {
  let children = parent.find('*');
  let parent_name = parent.attr('name') && parent.attr('name').value();
  let read_stmts = [];
  
  let lists = parent.find('list');
  let write_stmts = [];
  if (lists && lists.length) {
    for (let list of lists) {
      let name = list.attr('name').value();
      write_stmts.push(b.expressionStatement(b.assignmentExpression(
        '=',
        b.memberExpression(
          b.identifier('obj'), b.identifier(`${name}_len`)),
        b.memberExpression(
          b.memberExpression(
            b.identifier('obj'), b.identifier(name)),
          b.identifier('length'))
      )));
    }
  }

  for (let child of children) {
    let child_tag = child.name();
    switch (child_tag) {
      case 'pad':
        let bytes = parseInt(child.attr('bytes').value());
github rainforestapp / decaf / src / parser.js View on Github external
function mapAssignmentExpression(node: CNode, meta: Object) {
  let variable;
  if (get(node, 'variable.base.properties.length') > 0) {
    variable = mapAssignmentPattern(node.variable.base, meta);
  } else {
    variable = mapExpression(node.variable, meta);
  }

  const assignment = b.assignmentExpression(
    '=',
    variable,
    mapExpression(node.value, meta));

  if (node.context === '||=') {
    return b.logicalExpression('||', variable, assignment);
  } else if (node.context === '?=') {
    return b.conditionalExpression(
      b.binaryExpression('!=', variable, b.identifier('null')),
      variable,
      assignment
    );
  }

  assignment.operator = node.context || node.operator || '=';