How to use the esprima-fb.Syntax.SpreadProperty function in esprima-fb

To help you get started, we’ve selected a few esprima-fb 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 facebookarchive / jstransform / visitors / es6-object-computed-property-visitors.js View on Github external
function es6ObjectComputedProperties(traverse, node, path, state) {
  var obj = utils.injectTempVar(state);
  utils.append('(' + obj + '={}', state);
  for (var ii = 0; ii < node.properties.length; ++ii) {
    var property = node.properties[ii];
    utils.append(',', state);

    if (property.type === Syntax.SpreadProperty) {
      utils.append('Object.assign(' + obj, state);
      var nextComputedPropertyIndex = ii + 1;
      while (
        nextComputedPropertyIndex < node.properties.length &&
        !node.properties[nextComputedPropertyIndex].computed
      ) {
        nextComputedPropertyIndex += 1;
      }
      utils.catchupWhiteSpace(node.properties[ii].range[0], state);
      var lastWasSpread = es7SpreadProperties.renderSpreadProperties(
        traverse,
        node.properties.slice(ii, nextComputedPropertyIndex),
        path,
        state,
        true // previousWasSpread
      );
github facebookarchive / jstransform / visitors / es7-spread-property-visitors.js View on Github external
function renderSpreadProperties(traverse, properties, path, state, previousWasSpread) {

  for (var i = 0; i < properties.length; i++) {
    var property = properties[i];
    if (property.type === Syntax.SpreadProperty) {

      // Close the previous object or initial object
      if (!previousWasSpread) {
        utils.append('}', state);
      }

      if (i === 0) {
        // Normally there will be a comma when we catch up, but not before
        // the first property.
        utils.append(',', state);
      }

      utils.catchup(property.range[0], state);

      // skip ...
      utils.move(property.range[0] + 3, state);
github joshuaslate / saas-tutorial / node_modules / jstransform / visitors / es7-spread-property-visitors.js View on Github external
function visitObjectLiteralSpread(traverse, node, path, state) {
  utils.catchup(node.range[0], state);

  utils.append('Object.assign({', state);

  // Skip the original {
  utils.move(node.range[0] + 1, state);

  var previousWasSpread = false;

  for (var i = 0; i < node.properties.length; i++) {
    var property = node.properties[i];
    if (property.type === Syntax.SpreadProperty) {

      // Close the previous object or initial object
      if (!previousWasSpread) {
        utils.append('}', state);
      }

      if (i === 0) {
        // Normally there will be a comma when we catch up, but not before
        // the first property.
        utils.append(',', state);
      }

      utils.catchup(property.range[0], state);

      // skip ...
      utils.move(property.range[0] + 3, state);
github Caltech-IPAC / firefly / node_modules / react / node_modules / envify / node_modules / jstransform / visitors / es6-destructuring-visitors.js View on Github external
if (!item) {
      continue;
    }

    if (item.type === Syntax.SpreadElement) {
      // Spread/rest of an array.
      // TODO(dmitrys): support spread in the middle of a pattern
      // and also for function param patterns: [x, ...xs, y]
      components.push(item.argument.name +
        '=Array.prototype.slice.call(' +
        utils.getTempVar(tmpIndex) + ',' + idx + ')'
      );
      continue;
    }

    if (item.type === Syntax.SpreadProperty) {
      var restExpression = restPropertyHelpers.renderRestExpression(
        utils.getTempVar(tmpIndex),
        patternItems
      );
      components.push(item.argument.name + '=' + restExpression);
      continue;
    }

    // Depending on pattern type (Array or Object), we get
    // corresponding pattern item parts.
    var accessor = getPatternItemAccessor(node, item, tmpIndex, idx);
    var value = getPatternItemValue(node, item);

    // TODO(dmitrys): implement default values: {x, y=5}
    if (value.type === Syntax.Identifier) {
      // Simple pattern item.
github facebookarchive / jstransform / visitors / es6-destructuring-visitors.js View on Github external
if (!item) {
      continue;
    }

    if (item.type === Syntax.SpreadElement) {
      // Spread/rest of an array.
      // TODO(dmitrys): support spread in the middle of a pattern
      // and also for function param patterns: [x, ...xs, y]
      components.push(item.argument.name +
        '=Array.prototype.slice.call(' +
        utils.getTempVar(tmpIndex) + ',' + idx + ')'
      );
      continue;
    }

    if (item.type === Syntax.SpreadProperty) {
      var restExpression = restPropertyHelpers.renderRestExpression(
        utils.getTempVar(tmpIndex),
        patternItems
      );
      components.push(item.argument.name + '=' + restExpression);
      continue;
    }

    // Depending on pattern type (Array or Object), we get
    // corresponding pattern item parts.
    var accessor = getPatternItemAccessor(node, item, tmpIndex, idx);
    var value = getPatternItemValue(node, item);

    // TODO(dmitrys): implement default values: {x, y=5}
    if (value.type === Syntax.Identifier) {
      // Simple pattern item.
github facebookarchive / jstransform / visitors / es7-rest-property-helpers.js View on Github external
function getPropertyNames(properties) {
  var names = [];
  for (var i = 0; i < properties.length; i++) {
    var property = properties[i];
    if (property.type === Syntax.SpreadProperty) {
      continue;
    }
    if (property.type === Syntax.Identifier) {
      names.push(property.name);
    } else {
      names.push(property.key.name);
    }
  }
  return names;
}