How to use the @babel/core.types.memberExpression 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 babel / babel / packages / babel-plugin-proposal-optional-chaining / src / index.js View on Github external
node.callee = chain;
            } else {
              // Otherwise, we need to memoize the context object, and change the call into a Function#call.
              // `a.?b.?()` translates roughly to `(_b = _a.b) != null && _b.call(_a)`
              const { object } = chain;
              let context = scope.maybeGenerateMemoised(object);
              if (context) {
                chain.object = t.assignmentExpression("=", context, object);
              } else if (t.isSuper(object)) {
                context = t.thisExpression();
              } else {
                context = object;
              }

              node.arguments.unshift(t.cloneNode(context));
              node.callee = t.memberExpression(
                node.callee,
                t.identifier("call"),
              );
            }
          }

          replacementPath.replaceWith(
            t.conditionalExpression(
              loose
                ? t.binaryExpression("==", t.cloneNode(check), t.nullLiteral())
                : t.logicalExpression(
                    "||",
                    t.binaryExpression(
                      "===",
                      t.cloneNode(check),
                      t.nullLiteral(),
github babel / babel / packages / babel-plugin-transform-spread / src / index.js View on Github external
// If the first element is a ArrayExpression we can directly call
        // concat on it.
        // `[..].concat(..)`
        // If not then we have to use `[].concat(arr)` and not `arr.concat`
        // because `arr` could be extended/modified (e.g. Immutable) and we do not know exactly
        // what concat would produce.
        if (!t.isArrayExpression(first)) {
          first = t.arrayExpression([]);
        } else {
          nodes.shift();
        }

        path.replaceWith(
          t.callExpression(
            t.memberExpression(first, t.identifier("concat")),
            nodes,
          ),
        );
      },
github babel / babel / packages / babel-plugin-transform-classes / src / transformClass.js View on Github external
function wrapSuperCall(bareSuper, superRef, thisRef, body) {
    let bareSuperNode = bareSuper.node;
    let call;

    if (classState.isLoose) {
      bareSuperNode.arguments.unshift(t.thisExpression());
      if (
        bareSuperNode.arguments.length === 2 &&
        t.isSpreadElement(bareSuperNode.arguments[1]) &&
        t.isIdentifier(bareSuperNode.arguments[1].argument, {
          name: "arguments",
        })
      ) {
        // special case single arguments spread
        bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument;
        bareSuperNode.callee = t.memberExpression(
          t.cloneNode(superRef),
          t.identifier("apply"),
        );
      } else {
        bareSuperNode.callee = t.memberExpression(
          t.cloneNode(superRef),
          t.identifier("call"),
        );
      }

      call = t.logicalExpression("||", bareSuperNode, t.thisExpression());
    } else {
      bareSuperNode = optimiseCall(
        t.callExpression(classState.file.addHelper("getPrototypeOf"), [
          t.cloneNode(classState.classRef),
        ]),
github babel / babel / packages / babel-plugin-transform-modules-umd / src / index.js View on Github external
memberExpression = globalRef
          .split(".")
          .reduce(
            (accum, curr) => t.memberExpression(accum, t.identifier(curr)),
            t.identifier("global"),
          );
      } else {
        memberExpression = t.memberExpression(
          t.identifier("global"),
          t.identifier(t.toIdentifier(source)),
        );
      }
    } else {
      const requireName = basename(source, extname(source));
      const globalName = browserGlobals[requireName] || requireName;
      memberExpression = t.memberExpression(
        t.identifier("global"),
        t.identifier(t.toIdentifier(globalName)),
      );
    }
    return memberExpression;
  }
github babel / babel / packages / babel-plugin-transform-classes / src / lib / memoise-decorators.js View on Github external
const temp = scope.maybeGenerateMemoised(expression.object);
    let ref;

    const nodes = [];

    if (temp) {
      ref = temp;
      nodes.push(t.assignmentExpression("=", temp, expression.object));
    } else {
      ref = expression.object;
    }

    nodes.push(
      t.callExpression(
        t.memberExpression(
          t.memberExpression(ref, expression.property, expression.computed),
          t.identifier("bind"),
        ),
        [ref],
      ),
    );

    if (nodes.length === 1) {
      decorator.expression = nodes[0];
    } else {
      decorator.expression = t.sequenceExpression(nodes);
    }
  }

  return decorators;
}
github babel / babel / packages / babel-plugin-transform-classes / src / loose.js View on Github external
_insertProtoAliasOnce() {
    if (!this._protoAlias) {
      this._protoAlias = this.scope.generateUidIdentifier("proto");
      const classProto = t.memberExpression(
        this.classRef,
        t.identifier("prototype"),
      );
      const protoDeclaration = t.variableDeclaration("var", [
        t.variableDeclarator(this._protoAlias, classProto),
      ]);

      this.body.push(protoDeclaration);
    }
  }
github babel / babel / packages / babel-plugin-transform-template-literals / src / index.js View on Github external
return items.reduce(function(left, right) {
      let canBeInserted = t.isLiteral(right);

      if (!canBeInserted && avail) {
        canBeInserted = true;
        avail = false;
      }
      if (canBeInserted && t.isCallExpression(left)) {
        left.arguments.push(right);
        return left;
      }
      return t.callExpression(
        t.memberExpression(left, t.identifier("concat")),
        [right],
      );
    });
  }
github babel / babel / packages / babel-plugin-transform-classes / src / lib / memoise-decorators.js View on Github external
const temp = scope.maybeGenerateMemoised(expression.object);
    let ref;

    const nodes = [];

    if (temp) {
      ref = temp;
      nodes.push(t.assignmentExpression("=", temp, expression.object));
    } else {
      ref = expression.object;
    }

    nodes.push(
      t.callExpression(
        t.memberExpression(
          t.memberExpression(ref, expression.property, expression.computed),
          t.identifier("bind"),
        ),
        [ref],
      ),
    );

    if (nodes.length === 1) {
      decorator.expression = nodes[0];
    } else {
      decorator.expression = t.sequenceExpression(nodes);
    }
  }

  return decorators;
}
github danya / react-local / src / index.js View on Github external
function createCreateElementRef(path) {
    const reference = path.scope.generateUidIdentifier('createElement')
    const declaration = t.variableDeclaration('const', [
      t.variableDeclarator(
        reference,
        t.memberExpression(t.identifier('React'), t.identifier('createElement'))
      )
    ])
    path.insertAfter(declaration)
    path.scope.registerDeclaration(path.getNextSibling())
    return reference
  }
github sokra / rawact / src / transformCreateElement.js View on Github external
t.assignmentExpression(
							"=",
							t.memberExpression(
								node,
								t.numericLiteral(childrenCreate.length),
								true
							),
							t.memberExpression(scope.context(), childNode, true)
						)
					)
				);
			}
			unmountStatements.push(
				t.expressionStatement(
					t.callExpression(scope.importHelper("unmountInternal"), [
						t.memberExpression(
							scope.context(),
							t.identifier(childNode.value + "_")
						)
					])
				)
			);
			childrenCreate.push(t.memberExpression(scope.context(), childNode, true));
		}

		if (element.kind === "Fragment") {
			createStatements.push(
				t.expressionStatement(
					t.assignmentExpression(
						"=",
						node,
						t.callExpression(scope.importHelper("createFragment"), [