How to use the babel-types.isObjectExpression function in babel-types

To help you get started, we’ve selected a few babel-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tencent / omi / packages / omip / my-app-ts / scripts / taro-cli / src / h5.js View on Github external
const keyName = getObjKey(key)
      if (keyName === 'pages' && t.isArrayExpression(value)) {
        const subPackageParent = astPath.findParent(isUnderSubPackages)
        let root = ''
        if (subPackageParent) {
          /* 在subPackages属性下,说明是分包页面,需要处理root属性 */
          const rootNode = astPath.parent.properties.find(v => {
            return getObjKey(v.key) === 'root'
          })
          root = rootNode ? rootNode.value.value : ''
        }
        value.elements.forEach(v => {
          const pagePath = `${root}/${v.value}`.replace(/\/{2,}/g, '/')
          pages.push(pagePath.replace(/^\//, ''))
        })
      } else if (keyName === 'tabBar' && t.isObjectExpression(value)) {
        // tabBar
        tabBar = value
        value.properties.forEach(node => {
          if (node.keyName === 'position') tabbarPos = node.value.value
        })
      } else if ((keyName === 'iconPath' || keyName === 'selectedIconPath') && t.isStringLiteral(value)) {
        astPath.replaceWith(
          t.objectProperty(t.stringLiteral(keyName), t.callExpression(t.identifier('require'), [t.stringLiteral(`./${value.value}`)]))
        )
      }
    }
  }
github babel / babel / packages / babel-helper-builder-react-jsx / src / index.js View on Github external
if (t.isJSXSpreadAttribute(prop)) {
        pushProps();
        objs.push(prop.argument);
      } else {
        _props.push(convertAttribute(prop));
      }
    }

    pushProps();

    if (objs.length === 1) {
      // only one object
      attribs = objs[0];
    } else {
      // looks like we have multiple objects
      if (!t.isObjectExpression(objs[0])) {
        objs.unshift(t.objectExpression([]));
      }

      const helper = useBuiltIns ?
        t.memberExpression(t.identifier("Object"), t.identifier("assign")) :
        file.addHelper("extends");

      // spread it
      attribs = t.callExpression(helper, objs);
    }

    return attribs;
  }
}
github Tencent / omi / packages / omip / my-app-ts / scripts / taro-transformer-wx / lib / src / class.js View on Github external
AssignmentExpression(p) {
                                if (t.isMemberExpression(p.node.left) &&
                                    t.isThisExpression(p.node.left.object) &&
                                    t.isIdentifier(p.node.left.property) &&
                                    p.node.left.property.name === 'data' &&
                                    t.isObjectExpression(p.node.right)) {
                                    const properties = p.node.right.properties;
                                    properties.forEach(p => {
                                        if (t.isObjectProperty(p) && t.isIdentifier(p.key)) {
                                            self.initState.add(p.key.name);
                                        }
                                    });
                                }
                            }
                        });
github didi / mpx / packages / webpack-plugin / lib / wxs / wxs-pre-loader.js View on Github external
AssignmentExpression (path) {
          const left = path.node.left
          const right = path.node.right
          if (t.isMemberExpression(left) && left.object.name === 'module' && left.property.name === 'exports') {
            if (t.isObjectExpression(right)) {
              right.properties.forEach((property) => {
                selfCompilation.__swan_exports_map__[property.key.name] = true
              })
            } else {
              throw new Error('Swan filter module exports declaration must be an ObjectExpression!')
            }
          }
        },
        ExportDefaultDeclaration (path) {
github Tencent / omi / packages / omip / my-app-ts / scripts / taro-transformer-wx / lib / src / class.js View on Github external
ClassProperty(path) {
                const { key: { name }, value } = path.node;
                if (t.isArrowFunctionExpression(value) || t.isFunctionExpression(value)) {
                    self.methods.set(name, path);
                }
                if (name === 'data' && t.isObjectExpression(value)) {
                    value.properties.forEach(p => {
                        if (t.isObjectProperty(p)) {
                            if (t.isIdentifier(p.key)) {
                                self.initState.add(p.key.name);
                            }
                        }
                    });
                }
            },
            JSXExpressionContainer(path) {
github Tencent / omi / packages / cax-omip / scripts / taro-cli / src / h5.js View on Github external
function resetTSClassProperty (body) {
  for (const method of body) {
    if (t.isClassMethod(method) && method.kind === 'constructor') {
      for (const statement of _.cloneDeep(method.body.body)) {
        if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {
          const expr = statement.expression
          const { left, right } = expr
          if (
            t.isMemberExpression(left) &&
              t.isThisExpression(left.object) &&
              t.isIdentifier(left.property)
          ) {
            if (
              (t.isArrowFunctionExpression(right) || t.isFunctionExpression(right)) ||
                (left.property.name === 'config' && t.isObjectExpression(right))
            ) {
              body.push(
                t.classProperty(left.property, right)
              )
              _.remove(method.body.body, statement)
            }
          }
        }
      }
    }
  }
}
github Kureev / react-navigation-parser / src / parser / getTransitions.js View on Github external
function hasNavigationSignature(args) {
  return t.isStringLiteral(args[0]) && (
    /**
     * @todo Write a function that gets identifier's value
    */
    t.isObjectExpression(args[1]) ||
    t.isIdentifier(args[1]) ||
    typeof args === 'undefined'
  );
}
github trivago / babel-plugin-cloudinary / lib / ast-helpers.js View on Github external
const _replaceExpressions = node => {
    if (t.isArrayExpression(node)) {
      return node.elements.map(_replaceExpressions);
    } else if (t.isObjectExpression(node)) {
      return node.properties.reduce((obj, prop) => {
        obj[prop.key.name || prop.key.value] = _replaceExpressions(prop.value);
        return obj;
      }, {});
    } else if (
      t.isIdentifier(node) ||
      t.isConditionalExpression(node) ||
      t.isCallExpression(node) ||
      t.isMemberExpression(node) ||
      t.isTemplateLiteral(node) ||
      t.isBinaryExpression(node)
    ) {
      const nodeKey = `${placeholder}${count || ""}`;

      mappings[nodeKey] = node;
      count++;
github Tencent / omi / packages / omip / taro-transformer-wx / src / class.ts View on Github external
AssignmentExpression (p) {
                if (
                  t.isMemberExpression(p.node.left) &&
                  t.isThisExpression(p.node.left.object) &&
                  t.isIdentifier(p.node.left.property) &&
                  p.node.left.property.name === 'data' &&
                  t.isObjectExpression(p.node.right)
                ) {
                  const properties = p.node.right.properties
                  properties.forEach(p => {
                    if (t.isObjectProperty(p) && t.isIdentifier(p.key)) {
                      self.initState.add(p.key.name)
                    }
                  })
                }
              }
            })
github Lokaltog / baba-core / src / baba.js View on Github external
_getFunctions(node, path=[]) {
			let ret = [];
			if (Array.isArray(node)) {
				node.forEach(subNode => {
					ret = ret.concat(this._getFunctions(subNode, path.concat(subNode.key.name || subNode.key.value)));
				});
				return ret;
			}
			if (t.isObjectProperty(node)) {
				if (t.isObjectExpression(node.value)) {
					return ret.concat(this._getFunctions(node.value.properties, path));
				}
				return {path, ast: node.value};
			}
			else if (t.isObjectMethod(node)) {
				return {path, ast: t.functionExpression(null, node.params, node.body)};
			}
			return ret;
		}