How to use the @babel/helper-annotate-as-pure function in @babel/helper-annotate-as-pure

To help you get started, we’ve selected a few @babel/helper-annotate-as-pure 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 alan-ai / alan-sdk-reactnative / testtools / node_modules / @babel / helper-builder-react-jsx-experimental / src / index.js View on Github external
if (options.pre) {
      options.pre(state, file);
    }

    // no attributes are allowed with <> syntax
    args.push(t.nullLiteral(), ...path.node.children);

    if (options.post) {
      options.post(state, file);
    }

    file.set("@babel/plugin-react-jsx/usedFragment", true);

    const call =
      state.call || t.callExpression(state.createElementCallee, args);
    if (state.pure) annotateAsPure(call);

    return call;
  }
github babel / babel / packages / babel-plugin-transform-es2015-template-literals / src / index.js View on Github external
let templateObject = this.templates.get(name);
        if (templateObject) {
          templateObject = t.clone(templateObject);
        } else {
          const programPath = path.find(p => p.isProgram());
          templateObject = programPath.scope.generateUidIdentifier(
            "templateObject",
          );
          this.templates.set(name, templateObject);

          const helperId = this.addHelper(helperName);
          const init = t.callExpression(helperId, [
            t.arrayExpression(strings),
            t.arrayExpression(raws),
          ]);
          annotateAsPure(init);
          init._compact = true;
          programPath.scope.push({
            id: templateObject,
            init,
            // This ensures that we don't fail if not using function expression helpers
            _blockHoist: 1.9,
          });
        }

        path.replaceWith(
          t.callExpression(node.tag, [templateObject, ...quasi.expressions]),
        );
      },
github babel / babel / packages / babel-helper-remap-async-to-generator / src / index.js View on Github external
const isIIFE = checkIsIIFE(path);

  path.node.async = false;
  path.node.generator = true;

  wrapFunction(path, t.cloneNode(helpers.wrapAsync));

  const isProperty =
    path.isObjectMethod() ||
    path.isClassMethod() ||
    path.parentPath.isObjectProperty() ||
    path.parentPath.isClassProperty();

  if (!isProperty && !isIIFE && path.isExpression()) {
    annotateAsPure(path);
  }

  function checkIsIIFE(path: NodePath) {
    if (path.parentPath.isCallExpression({ callee: path.node })) {
      return true;
    }

    // try to catch calls to Function#bind, as emitted by arrowFunctionToExpression in spec mode
    // this may also catch .bind(this) written by users, but does it matter? 🤔
    const { parentPath } = path;
    if (
      parentPath.isMemberExpression() &&
      t.isIdentifier(parentPath.node.property, { name: "bind" })
    ) {
      const { parentPath: bindCall } = parentPath;
github babel / babel / packages / babel-plugin-transform-react-constant-elements / src / index.js View on Github external
namePath = namePath.get("property");
          }

          const elementName = namePath.node.name;
          state.mutablePropsAllowed =
            allowMutablePropsOnTags.indexOf(elementName) > -1;
        }

        // Traverse all props passed to this element for immutability.
        path.traverse(immutabilityVisitor, state);

        if (state.isImmutable) {
          const hoisted = path.hoist();

          if (hoisted) {
            annotateAsPure(hoisted);
          }
        }
      },
    },
github alan-ai / alan-sdk-reactnative / testtools / node_modules / @babel / helper-builder-react-jsx-experimental / src / index.js View on Github external
path.scope.buildUndefinedNode(),
        t.booleanLiteral(path.node.children.length > 1),
      );
    }

    if (options.post) {
      options.post(state, file);
    }

    const call =
      state.call ||
      t.callExpression(
        path.node.children.length > 1 ? state.jsxStaticCallee : state.jsxCallee,
        args,
      );
    if (state.pure) annotateAsPure(call);

    return call;
  }
github alan-ai / alan-sdk-reactnative / testtools / node_modules / @babel / helper-builder-react-jsx-experimental / src / index.js View on Github external
extracted.__source ?? path.scope.buildUndefinedNode(),
        extracted.__self ?? t.thisExpression(),
      );
    }

    if (options.post) {
      options.post(state, file);
    }

    const call =
      state.call ||
      t.callExpression(
        path.node.children.length > 1 ? state.jsxStaticCallee : state.jsxCallee,
        args,
      );
    if (state.pure) annotateAsPure(call);

    return call;
  }
github alan-ai / alan-sdk-reactnative / testtools / node_modules / @babel / helper-builder-react-jsx-experimental / src / index.js View on Github external
}

    const attribs = buildCreateElementOpeningElementAttributes(
      path,
      openingPath.node.attributes,
    );

    args.push(attribs, ...path.node.children);

    if (options.post) {
      options.post(state, file);
    }

    const call =
      state.call || t.callExpression(state.createElementCallee, args);
    if (state.pure) annotateAsPure(call);

    return call;
  }
github babel / babel / packages / babel-plugin-transform-classes / src / index.js View on Github external
if (node[VISITED]) return;

        const inferred = nameFunction(path);
        if (inferred && inferred !== node) {
          path.replaceWith(inferred);
          return;
        }

        node[VISITED] = true;

        path.replaceWith(
          transformClass(path, state.file, builtinClasses, loose),
        );

        if (path.isCallExpression()) {
          annotateAsPure(path);
          if (path.get("callee").isArrowFunctionExpression()) {
            path.get("callee").arrowFunctionToExpression();
          }
        }
      },
    },
github styled-components / babel-plugin-styled-components / src / visitors / pure.js View on Github external
export default t => (path, state) => {
  if (usePureAnnotation(state)) {
    if (
      isStyled(t)(path.node, state) ||
      isStyled(t)(path.node.callee, state) ||
      isPureHelper(t)(path.node.tag || path.node.callee, state)
    ) {
      if (
        path.parent.type === 'VariableDeclarator' ||
        path.parent.type === 'TaggedTemplateExpression'
      ) {
        annotateAsPure(path)
      }
    }
  }
}

@babel/helper-annotate-as-pure

Helper function to annotate paths and nodes with #__PURE__ comment

MIT
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis

Popular @babel/helper-annotate-as-pure functions

Similar packages