How to use the isObjectProperty function from @babel/types
Find comprehensive JavaScript @babel/types.isObjectProperty code examples handpicked from public code repositorys.
@babel/types.isObjectProperty is a function used to determine if a given object is an ObjectProperty node.
23 24 25 26 27 28 29 30 31 32
path.node.callee.object.name === 'WebexPlugin' && path.node.callee.property.name === 'extend' ) { const def = path.node.arguments[0]; const visited = def.properties.reduce( (acc, p) => acc || t.isObjectProperty(p, {key: 'version'}), false ); if (!visited) {
109 110 111 112 113 114 115 116 117 118
var isArrayObject = key.includes("[0]") key = key.replace(/\[0\]/g, "") var properties = null if (t.isObjectExpression(dataPath) || t.isObjectProperty(dataPath)) { //手工创建的是elements这个节点 properties = dataPath.properties || dataPath.value.properties || dataPath.value.elements } else { return null
How does @babel/types.isObjectProperty work?
@babel/types.isObjectProperty is a function provided by the Babel Types library that checks if a given object is a node of type ObjectProperty. When called with an object, it returns a boolean value indicating whether that object is a valid ObjectProperty node or not. An ObjectProperty node represents a property inside an object literal, like { key: value }, where key is the name of the property and value is the value assigned to it.
GitHub: langyo/glimmer.js
110 111 112 113 114 115 116 117 118 119
}); const ast = parse(`(${compiled})`); t.traverseFast(ast, (node) => { if ( t.isObjectProperty(node) && node.key.value === 'scope' && t.isArrowFunctionExpression(node.value) ) { const scopeFnNode = node.value;
GitHub: msojocs/wcc.js
129 130 131 132 133 134 135 136 137 138
path.stop(); return; } } } if (path.isIdentifier() && WhiteVariableIdentifier.indexOf(path.node.name) > -1 && babelTypes.isObjectProperty(path.parent)) { //对象属性 var a = {NaN: 1} let message = `${filePath}:${path.node.loc.start.line + startLine - 1}:${path.node.loc.start.column}: SyntaxError: invalid ObjectProperty \`${path.node.name}\`\n`; wccError = new error.WccError(error.CODE.INVALID_OBJECTPROPERTY, message); path.stop();
+ 5 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9
const t = require("@babel/types"); const node = t.objectProperty(t.identifier("key"), t.stringLiteral("value")); if (t.isObjectProperty(node)) { console.log("The node is an object property"); } else { console.log("The node is not an object property"); }
In this example, the isObjectProperty function is used to check if the node variable is an object property. If it is, the message "The node is an object property" is printed to the console; otherwise, "The node is not an object property" is printed.
GitHub: Aharonabadi/amphtmlML
44 45 46 47 48 49 50 51 52 53
let propertyChain = ''; const path = ancestors.map(({node}) => node); let at = path.pop(); while (at && types.isObjectProperty(at)) { const part = getNodeSource(source, at.key); if (types.isIdentifier(at.key)) { propertyChain = `.${part}` + propertyChain; } else {
GitHub: redexp/adv-parser
34 35 36 37 38 39 40 41 42 43
if (!Array.isArray(obj.properties)) { throw new Error(`Invalid object without properties: ${obj.type}`); } return obj.properties.find(function (prop) { return t.isObjectProperty(prop) && getPropName(prop) === name; }); } function getPropName(prop) {
+ 5 other calls in file
6 7 8 9 10 11 12 13 14 15
function handleObjectExpression (declaration, path, state) { if (state.options) { // name,inheritAttrs,props Object.keys(state.options).forEach(name => { const optionProperty = declaration.properties.filter(prop => { return t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === name })[0] if (optionProperty) {
+ 11 other calls in file
21 22 23 24 25 26 27 28 29
/** * @type {import("@babel/types").ObjectProperty|null} */ const property = node$.node.properties.find( property => T.isObjectProperty(property) && T.isIdentifier(property.key) && property.key.name === 'template' )
+ 11 other calls in file
@babel/types.identifier is the most popular function in @babel/types (20936 examples)