<commit_before>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 * @format
 */

'use strict';

const areEqual = require('areEqual');
const invariant = require('invariant');

const {LINKED_FIELD} = require('../util/RelayConcreteNode');
const {getHandleStorageKey} = require('./RelayStoreUtils');

import type {
  NormalizationLinkedField,
  NormalizationSelection,
} from '../util/NormalizationNode';
import type {NormalizationLinkedHandle} from '../util/NormalizationNode';
import type {Variables} from '../util/RelayRuntimeTypes';

/**
 * @private
 *
 * Creates a clone of the supplied `handleField` by finding the original linked
 * field (on which the handle was declared) among the sibling `selections`, and
 * copying its selections into the clone.
 */
function cloneRelayHandleSourceField(
  handleField: NormalizationLinkedHandle,
  selections: $ReadOnlyArray<NormalizationSelection>,
  variables: Variables,
): NormalizationLinkedField {
  const sourceField = selections.find(
    source =>
      source.kind === LINKED_FIELD &&
      source.name === handleField.name &&
      source.alias === handleField.alias &&
      areEqual(source.args, handleField.args),
  );
  invariant(
    sourceField && sourceField.kind === LINKED_FIELD,
    'cloneRelayHandleSourceField: Expected a corresponding source field for ' +
      'handle `%s`.',
    handleField.handle,
  );
  const handleKey = getHandleStorageKey(handleField, variables);
  const clonedField = {
    ...sourceField,
    args: null,
    name: handleKey,
    storageKey: handleKey,
  };
  return clonedField;
}

module.exports = cloneRelayHandleSourceField;
<commit_msg>avoid object spread in cloneRelayHandleSourceField<commit_after>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 * @format
 */

'use strict';

const areEqual = require('areEqual');
const invariant = require('invariant');

const {LINKED_FIELD} = require('../util/RelayConcreteNode');
const {getHandleStorageKey} = require('./RelayStoreUtils');

import type {
  NormalizationLinkedField,
  NormalizationSelection,
} from '../util/NormalizationNode';
import type {NormalizationLinkedHandle} from '../util/NormalizationNode';
import type {Variables} from '../util/RelayRuntimeTypes';

/**
 * @private
 *
 * Creates a clone of the supplied `handleField` by finding the original linked
 * field (on which the handle was declared) among the sibling `selections`, and
 * copying its selections into the clone.
 */
function cloneRelayHandleSourceField(
  handleField: NormalizationLinkedHandle,
  selections: $ReadOnlyArray<NormalizationSelection>,
  variables: Variables,
): NormalizationLinkedField {
  const sourceField = selections.find(
    source =>
      source.kind === LINKED_FIELD &&
      source.name === handleField.name &&
      source.alias === handleField.alias &&
      areEqual(source.args, handleField.args),
  );
  invariant(
    sourceField && sourceField.kind === LINKED_FIELD,
    'cloneRelayHandleSourceField: Expected a corresponding source field for ' +
      'handle `%s`.',
    handleField.handle,
  );
  const handleKey = getHandleStorageKey(handleField, variables);
  return {
    kind: 'LinkedField',
    alias: sourceField.alias,
    name: handleKey,
    storageKey: handleKey,
    args: null,
    concreteType: sourceField.concreteType,
    plural: sourceField.plural,
    selections: sourceField.selections,
  };
}

module.exports = cloneRelayHandleSourceField;

{'fraction_non_alphanumeric': 0.1106064654020839, 'fraction_numerical': 0.0, 'mean_word_length': 4.32574679943101, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4937794', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1024, 'n_words': 302}