How to use the @babel/core.types.objectProperty function in @babel/core

To help you get started, we’ve selected a few @babel/core 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 r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / classes / helpers / classes.js View on Github external
if (moveControllerPropsToOnInit) {
              continue; // don't push to props yet
            }
          }
          func.id = path.scope.generateUidIdentifier(func.id.name); // Give the function a unique name
          extendProps.push(t.objectProperty(member.key, func));
        }
      }
    } else if (t.isClassProperty(member)) {
      if (!member.value) continue; // un-initialized static class prop (typescript)
      if (memberName === "metadata" || memberName === "renderer") {
        // Special handling for TypeScript limitation where metadata and renderer must be properties.
        extendProps.unshift(t.objectProperty(member.key, member.value));
      } else if (member.static) {
        if (moveStaticStaticPropsToExtend) {
          extendProps.unshift(t.objectProperty(member.key, member.value));
        } else {
          staticMembers.push(
            t.expressionStatement(
              t.assignmentExpression("=", memberExpression, member.value)
            )
          );
        }
      } else {
        propsByName[memberName] = member.value;
        if (memberName === "constructor") {
          constructorComments = member.leadingComments;
          constructor = member.value;
          if (moveControllerPropsToOnInit) {
            continue; // don't push to props yet
          }
        }
github babel / babel / packages / babel-plugin-proposal-decorators / src / transformer.js View on Github external
function prop(key, value) {
  if (!value) return null;
  return t.objectProperty(t.identifier(key), value);
}
github babel / babel / packages / babel-plugin-transform-modules-systemjs / src / index.js View on Github external
if (exportNames.length === 1) {
    statements.push(
      t.expressionStatement(
        t.callExpression(exportIdent, [
          t.stringLiteral(exportNames[0]),
          exportValues[0],
        ]),
      ),
    );
  } else if (!exportStarTarget) {
    const objectProperties = [];
    for (let i = 0; i < exportNames.length; i++) {
      const exportName = exportNames[i];
      const exportValue = exportValues[i];
      objectProperties.push(
        t.objectProperty(t.identifier(exportName), exportValue),
      );
    }
    statements.push(
      t.expressionStatement(
        t.callExpression(exportIdent, [t.objectExpression(objectProperties)]),
      ),
    );
  } else {
    const exportObj = path.scope.generateUid("exportObj");

    statements.push(
      t.variableDeclaration("var", [
        t.variableDeclarator(t.identifier(exportObj), t.objectExpression([])),
      ]),
    );
github babel / babel / packages / babel-plugin-proposal-decorators / src / transformer-legacy.js View on Github external
decorators.map(dec => t.cloneNode(dec.expression)),
            ),
            t.objectExpression([
              t.objectProperty(
                t.identifier("configurable"),
                t.booleanLiteral(true),
              ),
              t.objectProperty(
                t.identifier("enumerable"),
                t.booleanLiteral(true),
              ),
              t.objectProperty(
                t.identifier("writable"),
                t.booleanLiteral(true),
              ),
              t.objectProperty(t.identifier("initializer"), initializer),
            ]),
          ]),
        ),
      ]);
    } else {
      acc = acc.concat(
        t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
          t.cloneNode(target),
          t.cloneNode(property),
          t.arrayExpression(decorators.map(dec => t.cloneNode(dec.expression))),
          t.isObjectProperty(node) || t.isClassProperty(node, { static: true })
            ? buildGetObjectInitializer({
                TEMP: path.scope.generateDeclaredUidIdentifier("init"),
                TARGET: t.cloneNode(target),
                PROPERTY: t.cloneNode(property),
              }).expression
github babel / babel / packages / babel-plugin-proposal-object-rest-spread / src / index.js View on Github external
const ZERO_REFS = (() => {
  const node = t.identifier("a");
  const property = t.objectProperty(t.identifier("key"), node);
  const pattern = t.objectPattern([property]);

  return t.isReferenced(node, property, pattern) ? 1 : 0;
})();
github babel / babel / packages / babel-helper-create-class-features-plugin / src / decorators.js View on Github external
function prop(key, value) {
  if (!value) return null;
  return t.objectProperty(t.identifier(key), value);
}
github sokra / rawact / src / transformCreateElement.js View on Github external
const createComponentInstructions = (element, helpers) => {
	const props = [];
	for (const [key, value] of element.props) {
		props.push(t.objectProperty(t.identifier(key), value));
	}
	if (element.children.length > 1) {
		const fragmentElement = {
			kind: "Fragment",
			children: element.children
		};
		props.push(
			t.objectProperty(
				t.identifier("children"),
				createNativeInstructions(fragmentElement, helpers)
			)
		);
	} else if (element.children.length === 1) {
		props.push(t.objectProperty(t.identifier("children"), element.children[0]));
	}
	let instructions = t.callExpression(helpers.importHelper("hooks"), [
		element.typeNode,
		t.objectExpression(props)
	]);
	instructions = ensureKey(instructions, helpers, element.keyNode);
	return instructions;
};
github babel / babel / packages / babel-plugin-transform-shorthand-properties / src / index.js View on Github external
ObjectMethod(path) {
        const { node } = path;
        if (node.kind === "method") {
          const func = t.functionExpression(
            null,
            node.params,
            node.body,
            node.generator,
            node.async,
          );
          func.returnType = node.returnType;

          path.replaceWith(t.objectProperty(node.key, func, node.computed));
        }
      },
github callstack / linaria / src / babel / evaluate / templateProcessor.ts View on Github external
interpolations.forEach(it => {
          const key = it.source + it.unit;

          if (key in result) {
            cssText = cssText.replace(
              `var(--${it.id})`,
              `var(--${result[key].id})`
            );
          } else {
            result[key] = it;
          }
        });

        props.push(
          types.objectProperty(
            types.identifier('vars'),
            types.objectExpression(
              Object.keys(result).map(key => {
                const { id, node, unit } = result[key];
                const items = [node];

                if (unit) {
                  items.push(types.stringLiteral(unit));
                }

                return types.objectProperty(
                  types.stringLiteral(id),
                  types.arrayExpression(items)
                );
              })
            )