How to use the objectProperty function from @babel/types

Find comprehensive JavaScript @babel/types.objectProperty code examples handpicked from public code repositorys.

150
151
152
153
154
155
156
157
158
159
160
  }


  var properties = [];
  for (var key in value) {
    var expr = literalValueToExpression(value[key]);
    var prop = types.objectProperty(types.stringLiteral(key), expr);
    properties.push(prop);
  }
  return types.objectExpression(properties);
}
fork icon257
star icon757
watch icon77

+ 264 other calls in file

66
67
68
69
70
71
72
73
74
75
    t.stringLiteral(IMPORT_SOURCE),
  );
};

const createUseTranslationExpression = function () {
  let objectProperty = t.objectProperty(
    t.identifier(I8N_FUNC_NAME),
    t.identifier(I8N_FUNC_NAME),
    false,
    true,
fork icon79
star icon190
watch icon15

+ 31 other calls in file

130
131
132
133
134
135
136
137
138
139
  break;
case 'indexes':
  node.value = t.arrayExpression(
    _.map(definition.indexes, (value) => {
      const properties = [
        t.objectProperty(
          t.identifier('name'),
          t.stringLiteral(value.name),
        ),
        t.objectProperty(
fork icon23
star icon115
watch icon4

+ 239 other calls in file

63
64
65
66
67
68
69
70
71
72
}
/**
 * 转换ClassProperty为ObjectProperty
 */
function transformClassPropertyToObjectProperty(pathNode) {
        let node = t.objectProperty(pathNode.key, pathNode.value);
        return node;
}

/*
fork icon7
star icon37
watch icon2

+ 35 other calls in file

24
25
26
27
28
29
30
31
32
33

DataSchema
  .filter(item => item.showInTable !== false) // 筛选数据是否在table中显示
  .forEach((item) => {
    const exArray = [
      t.objectProperty(t.identifier('title'), t.stringLiteral(item.title)),
      t.objectProperty(t.identifier('dataIndex'), t.stringLiteral(item.key)),
    ]
    const funcArray = [
      t.jsxAttribute(t.jsxIdentifier('value'), t.jSXExpressionContainer(t.identifier('val'))),
fork icon1
star icon25
watch icon0

31
32
33
34
35
36
37
38
39
40
  Object.entries(octicon.heights).map(([height, icon]) => {
    return t.objectProperty(
      t.stringLiteral(height),
      t.objectExpression([
        t.objectProperty(t.stringLiteral('width'), t.numericLiteral(icon.width)),
        t.objectProperty(t.stringLiteral('path'), svgToJSX(icon.ast))
      ])
    )
  })
)
fork icon912
star icon0
watch icon0

+ 11 other calls in file

21
22
23
24
25
26
27
28
29
30
} else if (Array.isArray(data)) {
  return t.arrayExpression(data.map(stringifyRecursive))
} else if (data === Object(data)) {
  return t.objectExpression(
    Object.entries(data).map(([key, value]) =>
      t.objectProperty(getKey(key), stringifyRecursive(value))
    )
  )
} else {
  throw new Error(`Unhandled type "${typeof data}" when creating object`)
fork icon72
star icon452
watch icon7

+ 5 other calls in file

69
70
71
72
73
74
75
76
77
78
  }
});

Object.keys(propertyMap).forEach((key) => {
  properties.push(
    types.objectProperty(
      types.Identifier(key),
      types.booleanLiteral(propertyMap[key]),
    ),
  );
fork icon69
star icon100
watch icon15

+ 5 other calls in file

28
29
30
31
32
33
34
35
36
37
if (hasFound) {
    return;
}
init.properties.push(types.objectProperty(types.identifier(get(context, 'constant.SWAN_ID_FOR_SYSTEM')),
    types.objectExpression([
        types.objectProperty(types.identifier('type'),
            types.identifier('String')),
        types.objectProperty(types.identifier('value'),
            types.stringLiteral(''))
    ]), false, false, null));
fork icon17
star icon123
watch icon10

+ 3 other calls in file

232
233
234
235
236
237
238
239
240
241
  return newStr;
}
function generateObjectAst(obj) {
  let properties = Object.entries(obj).map(([key, value]) => {
    if (typeof value === 'object' && !Array.isArray(value)) {
      return types.objectProperty(
        types.stringLiteral(key),
        generateObjectAst(value)
      );
    } else if (typeof value === 'object' && Array.isArray(value)) {
fork icon3
star icon91
watch icon5

+ 5 other calls in file

342
343
344
345
346
347
348
349
350
351
    if (!hasProviders && isEnd(path.getAllNextSiblings())) {
      // 判断如果遍历到最后一个ObjectProperty,仍没有providers属性,则添加键值对
      hasProviders = false;
      // 在当前节点后面添加一个键值对
      path.insertAfter(
        t.objectProperty(t.identifier('providers'), t.arrayExpression())
      );
    }
  },
});
fork icon4
star icon56
watch icon0

+ 11 other calls in file

89
90
91
92
93
94
95
96
97
98
for (let i=0; i< hj.length; i++){

    if (hj[i].node.type === "ObjectMethod"){

        if (hj[i].node.kind === "method"){
            hj[i].replaceInline( tee.objectProperty(hj[i].node.key, tee.functionExpression(null,hj[i].node.params, hj[i].node.body)))
            continue
        }
        off = 1
        if (!ofg[hj[i].node.key.name]){
fork icon19
star icon43
watch icon0

+ 7 other calls in file

107
108
109
110
111
112
113
114
115
116
        )]
    )
}else {
    if (node.arguments[1].type == 'ObjectExpression') {
        node.arguments[1] = types.objectExpression([
            types.objectProperty(types.stringLiteral('attrs'),
                types.objectExpression(
                    [
                        types.objectProperty(types.stringLiteral('viewtype'), types.stringLiteral(viewtype)),
                        types.obje(types.stringLiteral('obj'), arg1.properties ? arg1.properties : types.arrayExpression([])),
fork icon3
star icon20
watch icon2

+ 55 other calls in file

192
193
194
195
196
197
198
199
200
201
    this.expression = ObjectExpression(object)
}

addProperty(key, value) {
    this.expression.properties.push(
        t.objectProperty(t.identifier(key), getLiteral(value))
    )
}

get(key) {
fork icon5
star icon8
watch icon0

42
43
44
45
46
47
48
49
50
  );
}

function objPropStr2AST(key, value, t) {
  key = key.split('.');
  return t.objectProperty(
    t.identifier(key[0]),
    key2ObjCall(key, value, t)
  );
fork icon3
star icon6
watch icon1

+ 17 other calls in file

6
7
8
9
10
11
12
13
14
15
return t.objectExpression([
  t.objectProperty(t.identifier('path'), t.stringLiteral(path)),
  t.objectProperty(t.identifier('name'), t.stringLiteral(name)),
  // t.objectProperty(t.identifier('localName'), t.stringLiteral(localName)),
  t.objectProperty(t.identifier('paramIds'), t.arrayExpression(paramIds.map(pid => t.stringLiteral(pid)))),
  t.objectProperty(t.identifier('injectionWhitelist'), t.arrayExpression(injectionWhitelist.map(wl => t.stringLiteral(wl)))),
  t.objectProperty(t.identifier('isDefault'), t.booleanLiteral(isDefault)),
  t.objectProperty(t.identifier('isEcmaDefault'), t.booleanLiteral(isEcmaDefault)),
  t.objectProperty(t.identifier('isAsync'), t.booleanLiteral(isAsync)),
  t.objectProperty(t.identifier('isObject'), t.booleanLiteral(isObject)),
fork icon2
star icon80
watch icon3

+ 35 other calls in file

274
275
276
277
278
279
280
281
282
283
}
if (scope.esModule) {
  const varName = generateUniqueName('handler', scope);
  addDepModule(varName, getModulePath(step.handlerFile, scope), scope);

  return t.objectProperty(t.identifier('handler'), t.identifier(varName));
} else {
  return t.objectProperty(
    t.identifier('handler'),
    t.callExpression(t.identifier('require'), [
fork icon1
star icon2
watch icon0

+ 405 other calls in file

180
181
182
183
184
185
186
187
188
    const right = expression.right
    const letfNode = expression.left.property
    path.node.expression = t.callExpression(
        t.memberExpression(t.thisExpression(), t.identifier('setState')),
        [t.objectExpression([
            t.objectProperty(letfNode, right)
        ])]
    )
}
fork icon1
star icon2
watch icon1

35
36
37
38
39
40
41
42
43
}

if (typeof value === 'object') {
  return t.objectExpression(
    Object.entries(value).map(([key, value]) => {
      return t.objectProperty(t.identifier(key), jsToAST(value));
    })
  );
}
fork icon1
star icon0
watch icon5

+ 8 other calls in file

243
244
245
246
247
248
249
250
251
252
if (!(propertyNameLength === 2 || propertyNameLength === 5) || propertyNameLength !== cacheObj.prevKeyLength) {
    delete cache.doubtedProxyPathInfos[objectName];
} else {
    // 转换为ObjectProperty
    if (utils.findProperty(cacheObj.properties, propertyName) === null) {
        let newNode = types.objectProperty(types.stringLiteral(propertyName), path.node.right, true);
        cacheObj.properties.push(newNode);
        cacheObj.originPaths.push(path);
    }
}
fork icon0
star icon2
watch icon1

+ 11 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)