How to use the objectProperty function from @babel/types
Find comprehensive JavaScript @babel/types.objectProperty code examples handpicked from public code repositorys.
GitHub: qooxdoo/qooxdoo
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); }
257
757
77
+ 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,
79
190
15
+ 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(
23
115
4
+ 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; } /*
7
37
2
+ 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'))),
1
25
0
GitHub: C-EO/octicons
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)) ]) ) }) )
912
0
0
+ 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`)
72
452
7
+ 5 other calls in file
GitHub: raxjs/rax-app
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]), ), );
69
100
15
+ 5 other calls in file
GitHub: baidu/wx2
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));
17
123
10
+ 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)) {
3
91
5
+ 5 other calls in file
GitHub: kerwin-ly/Blog
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()) ); } }, });
4
56
0
+ 11 other calls in file
GitHub: 2833844911/cy_jsvmp
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]){
19
43
0
+ 7 other calls in file
GitHub: fangkyi03/spack-new
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([])),
3
20
2
+ 55 other calls in file
GitHub: Leman-li/tanfu.js
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) {
5
8
0
GitHub: gxlmyacc/react-vue-like
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) );
3
6
1
+ 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)),
2
80
3
+ 35 other calls in file
GitHub: ruleenginejs/ruleengine
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'), [
1
2
0
+ 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) ])] ) }
1
2
1
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)); }) ); }
1
0
5
+ 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); } }
0
2
1
+ 11 other calls in file
@babel/types.identifier is the most popular function in @babel/types (20936 examples)