UNPKG

1.27 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * strict
8 * @format
9 */
10'use strict';
11
12/**
13 * Generates an identifier for an argument value. The identifier is based on the
14 * structure/order of items and keys in the value.
15 */
16function getIdentifierForArgumentValue(value) {
17 switch (value.kind) {
18 case 'Variable':
19 return {
20 variable: value.variableName
21 };
22
23 case 'Literal':
24 return {
25 value: value.value
26 };
27
28 case 'ListValue':
29 return {
30 list: value.items.map(function (item) {
31 return getIdentifierForArgumentValue(item);
32 })
33 };
34
35 case 'ObjectValue':
36 return {
37 object: value.fields.map(function (field) {
38 return {
39 name: field.name,
40 value: getIdentifierForArgumentValue(field.value)
41 };
42 })
43 };
44
45 default:
46 !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'getIdentifierForArgumentValue(): Unsupported AST kind `%s`.', value.kind) : require("fbjs/lib/invariant")(false) : void 0;
47 }
48}
49
50module.exports = getIdentifierForArgumentValue;
\No newline at end of file