How to use the @babel/helper-replace-supers function in @babel/helper-replace-supers

To help you get started, we’ve selected a few @babel/helper-replace-supers 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-helper-create-class-features-plugin / src / decorators.js View on Github external
function extractElementDescriptor(/* this: File, */ classRef, superRef, path) {
  const { node, scope } = path;
  const isMethod = path.isClassMethod();

  if (path.isPrivate()) {
    throw path.buildCodeFrameError(
      `Private ${
        isMethod ? "methods" : "fields"
      } in decorated classes are not supported yet.`,
    );
  }

  new ReplaceSupers(
    {
      methodPath: path,
      methodNode: node,
      objectRef: classRef,
      isStatic: node.static,
      superRef,
      scope,
      file: this,
    },
    true,
  ).replace();

  const properties = [
    prop("kind", t.stringLiteral(isMethod ? node.kind : "field")),
    prop("decorators", takeDecorators(node)),
    prop("static", node.static && t.booleanLiteral(true)),
github babel / babel / packages / babel-plugin-proposal-decorators / src / transformer.js View on Github external
function getSingleElementDefinition(path, superRef, classRef, file) {
  const { node, scope } = path;
  const isMethod = path.isClassMethod();

  if (path.isPrivate()) {
    throw path.buildCodeFrameError(
      `Private ${
        isMethod ? "methods" : "fields"
      } in decorated classes are not supported yet.`,
    );
  }

  new ReplaceSupers(
    {
      methodPath: path,
      methodNode: node,
      objectRef: classRef,
      isStatic: node.static,
      superRef,
      scope,
      file,
    },
    true,
  ).replace();

  const properties = [
    prop("kind", t.stringLiteral(isMethod ? node.kind : "field")),
    prop("decorators", takeDecorators(path)),
    prop("static", node.static && t.booleanLiteral(true)),
github babel / babel / packages / babel-plugin-transform-classes / src / transformClass.js View on Github external
const node = path.node;

      if (path.isClassProperty()) {
        throw path.buildCodeFrameError("Missing class properties transform.");
      }

      if (node.decorators) {
        throw path.buildCodeFrameError(
          "Method has decorators, put the decorator plugin before the classes one.",
        );
      }

      if (t.isClassMethod(node)) {
        const isConstructor = node.kind === "constructor";

        const replaceSupers = new ReplaceSupers({
          methodPath: path,
          objectRef: classState.classRef,
          superRef: classState.superName,
          isLoose: classState.isLoose,
          file: classState.file,
        });

        replaceSupers.replace();

        const superReturns = [];
        path.traverse(
          traverse.visitors.merge([
            environmentVisitor,
            {
              ReturnStatement(path) {
                if (!path.getFunctionParent().isArrowFunctionExpression()) {
github babel / babel / packages / babel-helper-create-class-features-plugin / src / fields.js View on Github external
function replaceThisContext(path, ref, superRef, file, loose) {
  const state = { classRef: ref, needsClassRef: false };

  const replacer = new ReplaceSupers({
    methodPath: path,
    isLoose: loose,
    superRef,
    file,
    getObjectRef() {
      state.needsClassRef = true;
      return path.node.static
        ? ref
        : t.memberExpression(ref, t.identifier("prototype"));
    },
  });
  replacer.replace();
  if (path.isProperty()) {
    path.traverse(thisContextVisitor, state);
  }
  return state.needsClassRef;
github babel / babel / packages / babel-plugin-transform-es2015-object-super / src / index.js View on Github external
function replacePropertySuper(path, node, scope, getObjectRef, file) {
  const replaceSupers = new ReplaceSupers({
    getObjectRef: getObjectRef,
    methodNode: node,
    methodPath: path,
    isStatic: true,
    scope: scope,
    file: file,
  });

  replaceSupers.replace();
}
github babel / babel / packages / babel-plugin-transform-object-super / src / index.js View on Github external
function replacePropertySuper(path, getObjectRef, file) {
  const replaceSupers = new ReplaceSupers({
    getObjectRef: getObjectRef,
    methodPath: path,
    file: file,
  });

  replaceSupers.replace();
}

@babel/helper-replace-supers

Helper function to replace supers

MIT
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis

Similar packages