How to use the jscodeshift.property function in jscodeshift

To help you get started, we’ve selected a few jscodeshift 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 Polymer / tools / src / document-processor.ts View on Github external
// A Polymer 2.0 class-based element
        const getter = jsc.methodDefinition(
            'get',
            jsc.identifier('importMeta'),
            jsc.functionExpression(
                null,
                [],
                jsc.blockStatement([jsc.returnStatement(importMeta)])),
            true);
        node.body.body.splice(0, 0, getter);
      } else if (node.type === 'CallExpression') {
        // A Polymer hybrid/legacy factory function element
        const arg = node.arguments[0];
        if (arg && arg.type === 'ObjectExpression') {
          arg.properties.unshift(
              jsc.property('init', jsc.identifier('importMeta'), importMeta));
        }
      } else {
        console.error(`Internal Error, Class or CallExpression expected, got ${
            node.type}`);
      }
    }
  }
github Polymer / tools / src / document-processor.ts View on Github external
// A Polymer 2.0 class-based element
        node.body.body.splice(
            0,
            0,
            jsc.methodDefinition(
                'get',
                jsc.identifier('template'),
                jsc.functionExpression(
                    null, [], jsc.blockStatement([jsc.returnStatement(
                                  templateLiteral)])),
                true));
      } else if (node.type === 'CallExpression') {
        // A Polymer hybrid/legacy factory function element
        const arg = node.arguments[0];
        if (arg && arg.type === 'ObjectExpression') {
          arg.properties.unshift(jsc.property(
              'init', jsc.identifier('_template'), templateLiteral));
        }
      } else {
        console.error(`Internal Error, Class or CallExpression expected, got ${
            node.type}`);
      }
    }
    return claimedDomModules;
  }
github Astrocoders / old-astroman / lib / utils / js / reduxAction / appendActionCreator.js View on Github external
function appendActionCreatorFunction({ast, constantName, actionCreatorName}) {
  const newFunction = j.functionDeclaration(j.identifier(actionCreatorName), [], j.blockStatement([
    j.returnStatement(
      j.objectExpression([
        j.property('init', j.literal('type'), j.identifier(constantName)),
      ])
    ),
  ]))
  const newExport = j.exportNamedDeclaration(newFunction, [], null)
  const exports = ast
    .find(j.ExportNamedDeclaration)

  exports
    .at(exports.length - 1)
    .insertAfter(newExport)
}
github noahsug / json5-writer / src / writeValue.js View on Github external
Object.keys(obj).forEach((key, index) => {
    const existingProperty = findPropertyByKey(node.properties, key)
    if (existingProperty) {
      existingProperty.value = writeValue(existingProperty.value, obj[key])
      newProperties.push(existingProperty)
    } else {
      if (obj[key] === undefined) return
      const newKey = getNewPropertyKey(node.properties, key)
      const newValue = writeValue(undefined, obj[key])
      const newProperty = j.property('init', newKey, newValue)
      newProperties.push(newProperty)
    }
  })
  node.properties = newProperties
github dvajs / dva-ast / src / collections / Model.js View on Github external
`_addModelItem: ${itemsKey} should be ObjectExpression, but got ${prop.value.type}`
          );
          items = prop;
        }
      });

      if (!items) {
        items = j.property(
          'init',
          j.identifier(itemsKey),
          j.objectExpression([])
        );
        path.node.properties.push(items);
      }

      const item = j.property(
        'init',
        j.identifier(name),
        utils.getExpression(source || defaultSource)
      );
      items.value.properties.push(item);
    });
  },
github dvajs / dva-ast / src / collections / Model.js View on Github external
return this.forEach(path => {
      let items = null;
      path.node.properties.forEach(prop => {
        if (j.Property.check(prop) && prop.key.name === itemsKey) {
          assert(
            j.ObjectExpression.check(prop.value),
            `_addModelItem: ${itemsKey} should be ObjectExpression, but got ${prop.value.type}`
          );
          items = prop;
        }
      });

      if (!items) {
        items = j.property(
          'init',
          j.identifier(itemsKey),
          j.objectExpression([])
        );
        path.node.properties.push(items);
      }

      const item = j.property(
        'init',
        j.identifier(name),
        utils.getExpression(source || defaultSource)
      );
      items.value.properties.push(item);
    });
  },