How to use the @babel/types.objectProperty 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 salesforce / lwc / packages / @lwc / template-compiler / src / codegen / index.ts View on Github external
on,
            forKey,
            locator,
            lwc,
        } = element;

        // Class attibute defined via string
        if (className) {
            const { expression: classExpression } = bindExpression(className, element);
            data.push(t.objectProperty(t.identifier('className'), classExpression));
        }

        // Class attribute defined via object
        if (classMap) {
            const classMapObj = objectToAST(classMap, () => t.booleanLiteral(true));
            data.push(t.objectProperty(t.identifier('classMap'), classMapObj));
        }

        // Style attribute defined via object
        if (styleMap) {
            const styleObj = objectToAST(styleMap, key =>
                typeof styleMap[key] === 'number'
                    ? t.numericLiteral(styleMap[key] as number)
                    : t.stringLiteral(styleMap[key] as string)
            );

            data.push(t.objectProperty(t.identifier('styleMap'), styleObj));
        }

        // Style attribute defined via string
        if (style) {
            const { expression: styleExpression } = bindExpression(style, element);
github salesforce / lwc / packages / lwc-template-compiler / src / codegen / index.ts View on Github external
lwc,
        } = element;

        // Class attibute defined via string
        if (className) {
            const { expression: classExpression } = bindExpression(
                className,
                element,
            );
            data.push(t.objectProperty(t.identifier('className'), classExpression));
        }

        // Class attribute defined via object
        if (classMap) {
            const classMapObj = objectToAST(classMap, () => t.booleanLiteral(true));
            data.push(t.objectProperty(t.identifier('classMap'), classMapObj));
        }

        // Style attribute defined via object
        if (styleMap) {
            const styleObj = objectToAST(
                styleMap,
                key =>
                    typeof styleMap[key] === 'number'
                        ? t.numericLiteral(styleMap[key] as number)
                        : t.stringLiteral(styleMap[key] as string),
            );

            data.push(t.objectProperty(t.identifier('styleMap'), styleObj));
        }

        // Style attribute defined via string
github salesforce / lwc / packages / lwc-template-compiler / src / codegen / index.ts View on Github external
});

        const lwcObj = t.objectProperty(t.identifier('lwc'), t.objectExpression(lwcObject));
        contextExpressions.push(lwcObj);
    }

    // Locators
    if (locator) {
        const locatorObject: t.ObjectProperty[] = [];
        const locatorId = t.objectProperty(t.identifier('id') , t.stringLiteral(locator.id));
        locatorObject.push(locatorId);
        if (locator.context) {
            let locatorContextFunction = bindExpression(locator.context, element).expression;
            locatorContextFunction = codeGen.genFunctionBind(locatorContextFunction);
            locatorContextFunction = memorizeHandler(codeGen, element, locator.context, locatorContextFunction);
            locatorObject.push(t.objectProperty(t.identifier('context'), locatorContextFunction));
        }
        const contextObj = t.objectProperty(t.identifier('locator'), t.objectExpression(locatorObject));
        contextExpressions.push(contextObj);
    }

    data.push(t.objectProperty(t.identifier('context'), t.objectExpression(contextExpressions)));
}
github uber / baseweb / documentation-site / components / yard / ast.ts View on Github external
t.objectPattern(
              newParams.map(param =>
                t.objectProperty(
                  t.identifier(param),
                  t.identifier(param),
                  false,
                  true,
                ),
              ),
            ),
          ];
        } else {
          path.node.params = [
            //@ts-ignore
            t.objectPattern([
              t.objectProperty(
                t.identifier('$theme'),
                t.identifier('$theme'),
                false,
                true,
              ),
            ]),
          ];
        }
        result = generate(path.node).code;
      },
    });
github uber / react-view / src / base / custom-props.ts View on Github external
const keys = activeValues.map(([key, val]: [string, any]) =>
        t.objectProperty(
          t.identifier(key),
          t.objectExpression([
            t.objectProperty(t.identifier('style'), template.expression(val.style)({}) as any),
          ])
        )
      );
github hsiaosiyuan0 / jlua / src / js / code.js View on Github external
visitObjectProperty(node) {
    return loc(
      t.objectProperty(
        this.visitExpr(node.key),
        this.visitExpr(node.value),
        node.computed
      ),
      node
    );
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-vue-app-routing / src / index.ts View on Github external
type: 'local',
        path: `${pageDependencyPrefix}${fileName}${pageComponentSuffix}`,
      }

      return t.objectExpression([
        t.objectProperty(t.identifier('name'), t.stringLiteral(pageKey)),
        t.objectProperty(t.identifier('path'), t.stringLiteral(navLink)),
        t.objectProperty(t.identifier('component'), t.identifier(componentName)),
      ])
    })

    const exportStatement = t.exportDefaultDeclaration(
      t.newExpression(t.identifier('Router'), [
        t.objectExpression([
          t.objectProperty(t.identifier('mode'), t.stringLiteral('history')),
          t.objectProperty(t.identifier('routes'), t.arrayExpression(routesAST)),
        ]),
      ])
    )

    chunks.push({
      name: codeChunkName,
      linkAfter: [importChunkName],
      type: ChunkType.AST,
      fileType: FileType.JS,
      content: [routerDeclaration, metaDeclaration, exportStatement],
    })

    return structure
  }
github alibaba / rax / packages / babel-plugin-transform-jsx-to-html / src / index.js View on Github external
if (value.extra && value.extra.raw) {
      delete value.extra.raw;
    }
  }

  if (t.isJSXNamespacedName(node.name)) {
    node.name = t.stringLiteral(
      node.name.namespace.name + ':' + node.name.name.name,
    );
  } else if (esutils.keyword.isIdentifierNameES6(node.name.name)) {
    node.name.type = 'Identifier';
  } else {
    node.name = t.stringLiteral(node.name.name);
  }

  return t.inherits(t.objectProperty(node.name, value), node);
}
github zhangdaren / miniprogram-to-uniapp / src / wx2uni / js / componentConverter.js View on Github external
}
					if (observerItem) {
						let objProp;
						//observer换成watch
						let op_value = null;
						if (typeItem.node.value.name == "Array" || typeItem.node.value.name == "Object") {
							//Array和Object换成深度监听
							if (t.isObjectProperty(observerItem.node)) {
								op_value = observerItem.node.value;
							} else if (t.isObjectMethod(observerItem.node)) {
								op_value = t.functionExpression(null, observerItem.node.params, observerItem.node.body);
							} else {
								op_value = observerItem.node.value;
							}

							let objExp_handle = t.objectProperty(t.identifier("handler"), op_value);
							let objExp_deep = t.objectProperty(t.identifier("deep"), t.booleanLiteral(true));
							let properties = [objExp_handle, objExp_deep];
							let objExp = t.objectExpression(properties);
							//如果observer的属性名是字符串,那就进行命名的修正
							if (t.isStringLiteral(objExp)) objExp.value = utils.getPropsAlias(objExp.value);
							objProp = t.objectProperty(t.identifier(propItemName), objExp);
						} else {
							if (t.isObjectProperty(observerItem.node)) {
								op_value = observerItem.node.value;
							} else if (t.isObjectMethod(observerItem.node)) {
								op_value = t.functionExpression(null, observerItem.node.params, observerItem.node.body);
							} else {
								op_value = observerItem.node.value;
							}
							//如果observer的属性名是字符串,那就进行命名的修正
							if (t.isStringLiteral(op_value)) op_value.value = utils.getPropsAlias(op_value.value);
github salesforce / lwc / packages / @lwc / template-compiler / src / codegen / index.ts View on Github external
            codeGen.memorizedIds.map(id => t.objectProperty(id, id, false, true))
        );