{"id":18033,"library":"babel-helper-builder-binary-assignment-operator-visitor","title":"Babel Helper: Binary Assignment Operator Visitor Builder","description":"This package, `babel-helper-builder-binary-assignment-operator-visitor`, is a low-level utility within the Babel ecosystem, specifically designed to assist plugin authors in creating AST (Abstract Syntax Tree) visitors for JavaScript's binary and assignment operators. It abstracts the common patterns required to transform expressions like `a += b` or `x &&= y` consistently across different operator types. The provided version `6.24.1` indicates it's from the Babel 6 era, which is now considered legacy. The current stable major version of Babel is `v7.x`, with `v7.29.2` being a very recent release, and `v8.x` is in release candidate (`v8.0.0-rc.3`). Babel generally maintains a rapid release cadence for patch and minor versions, with major versions introducing breaking changes every few years. Key differentiators include its specialized focus on a specific AST transformation pattern, reducing boilerplate for plugin developers who need to handle these operators, and its tight integration within the larger Babel monorepo for consistent AST manipulation.","status":"active","version":"6.24.1","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel/tree/master/packages/babel-helper-builder-binary-assignment-operator-visitor","tags":["javascript"],"install":[{"cmd":"npm install babel-helper-builder-binary-assignment-operator-visitor","lang":"bash","label":"npm"},{"cmd":"yarn add babel-helper-builder-binary-assignment-operator-visitor","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-helper-builder-binary-assignment-operator-visitor","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For Babel 7+ and modern projects, use the `@babel/` scoped package with ES module imports. The `babel-helper-builder-binary-assignment-operator-visitor` (unscoped) package is for Babel 6 and earlier.","wrong":"const buildBinaryAssignmentOperatorVisitor = require('babel-helper-builder-binary-assignment-operator-visitor');","symbol":"buildBinaryAssignmentOperatorVisitor","correct":"import { buildBinaryAssignmentOperatorVisitor } from '@babel/helper-builder-binary-assignment-operator-visitor';"},{"note":"While Babel 7+ packages support CJS `require`, ensure you use named destructuring as this helper is exported as a named export, not a default export.","wrong":"import buildBinaryAssignmentOperatorVisitor from '@babel/helper-builder-binary-assignment-operator-visitor';","symbol":"buildBinaryAssignmentOperatorVisitor","correct":"const { buildBinaryAssignmentOperatorVisitor } = require('@babel/helper-builder-binary-assignment-operator-visitor');"},{"note":"This helper is typically used within Babel plugins, which operate on `NodePath` objects from `@babel/traverse`. This is a common associated import, though not directly from this helper package.","symbol":"NodePath","correct":"import { NodePath } from '@babel/traverse';"}],"quickstart":{"code":"import { declare } from '@babel/helper-plugin-utils';\nimport { buildBinaryAssignmentOperatorVisitor } from '@babel/helper-builder-binary-assignment-operator-visitor';\n\nexport default declare((api, options) => {\n  api.assertVersion(7);\n\n  // This helper builds a visitor that handles binary and assignment operators.\n  // It can simplify transformations for operators like `+=`, `-=`, `&&=`, `??=` etc.\n  // The helper typically expects a 'kind' (binary or assignment) and a map of operators\n  // to visitor methods. Since the README is a TODO, this is an illustrative example\n  // based on common Babel plugin patterns.\n\n  // Example: A plugin to replace all `+=` operators with a function call.\n  // This specific helper might be overkill for just one operator, but shows the pattern.\n  // In a real scenario, you'd define methods for multiple operators.\n\n  const visitor = buildBinaryAssignmentOperatorVisitor({\n    operator(path) {\n      // `path` is a NodePath for the operator expression (e.g., BinaryExpression, AssignmentExpression).\n      const { node } = path;\n      if (node.operator === '+=' && node.type === 'AssignmentExpression') {\n        // Transform 'a += b' into 'assignAndAdd(a, b)'\n        path.replaceWith(\n          api.types.callExpression(\n            api.types.identifier('assignAndAdd'),\n            [node.left, node.right]\n          )\n        );\n      }\n    },\n    // More specific operator handlers could be defined here\n    // '+=_assignment'(path) { /* ... */ },\n    // '+_binary'(path) { /* ... */ }\n  });\n\n  return {\n    name: 'transform-binary-assignment-operators',\n    visitor: {\n      // The visitor is returned directly from the helper.\n      // It usually contains handlers for 'BinaryExpression' and 'AssignmentExpression'.\n      ...visitor\n    },\n  };\n});","lang":"javascript","description":"This quickstart shows how to use `buildBinaryAssignmentOperatorVisitor` within a Babel plugin to create a specialized visitor for handling binary and assignment operators. It demonstrates a basic transformation of `+=` assignment expressions."},"warnings":[{"fix":"Update `package.json` dependencies to `@babel/helper-builder-binary-assignment-operator-visitor` and adjust all `require()` or `import` statements to use the new scoped name.","message":"Major version upgrade from Babel 6 to Babel 7 (and subsequently Babel 8) introduces a significant breaking change in package naming. `babel-helper-builder-binary-assignment-operator-visitor` was renamed to `@babel/helper-builder-binary-assignment-operator-visitor` and moved to a monorepo structure. Any project using the old unscoped package will fail with module not found errors when upgrading to Babel 7+ without updating imports.","severity":"breaking","affected_versions":"<7.0.0"},{"fix":"Ensure your Babel plugins and consuming code are configured for ESM when targeting Babel 8. This may involve changes to `package.json` (`\"type\": \"module\"`) and using `import/export` syntax exclusively.","message":"Babel 8 (currently in Release Candidate) introduces a fundamental shift to ES Modules (ESM) only. While Babel 7 largely supports both CommonJS (CJS) and ESM for plugins, Babel 8 will ship as an ESM-only package. This means plugins (and by extension, helpers) built for Babel 8 will need to be written as ESM and consumed accordingly.","severity":"breaking","affected_versions":">=8.0.0-rc.1"},{"fix":"Before using low-level helpers, consider if a higher-level Babel plugin or preset could achieve the desired transformation with less direct AST manipulation.","message":"This helper is part of Babel's internal API. While exposed, it's primarily intended for core Babel plugins or highly advanced transformations. Direct usage for simple transformations might be overkill, and its API can change more frequently than public-facing Babel plugins.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your development and production environments use a supported Node.js LTS version (e.g., Node.js 14+ for Babel 7, and Node.js 20+ for Babel 8).","message":"Node.js version compatibility changes with Babel major versions. Babel 7 dropped support for Node.js 0.10, 0.12, 4, and 5. Future Babel 8 releases will likely require even newer Node.js versions.","severity":"breaking","affected_versions":">=7.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install the correct scoped package: `npm install @babel/helper-builder-binary-assignment-operator-visitor` or `yarn add @babel/helper-builder-binary-assignment-operator-visitor`. Also, update all import paths in your code to `@babel/helper-builder-binary-assignment-operator-visitor`.","cause":"Attempting to use the Babel 6 package name with a Babel 7+ setup, or the package is simply not installed.","error":"Error: Cannot find module 'babel-helper-builder-binary-assignment-operator-visitor'"},{"fix":"Ensure you are using named destructuring for `require()`: `const { buildBinaryAssignmentOperatorVisitor } = require('@babel/helper-builder-binary-assignment-operator-visitor');` or switch to `import` statements if using ESM.","cause":"Trying to import a Babel 7+ scoped package using a CommonJS `require()` call, but the export structure is not correctly handled (e.g., trying a default import on a named export).","error":"TypeError: Cannot destructure property 'buildBinaryAssignmentOperatorVisitor' of 'require(...)' as it is undefined."},{"fix":"Completely upgrade your project's Babel dependencies to version 7 or 8. This often involves updating `@babel/core`, `@babel/cli`, presets, and plugins to their scoped Babel 7/8 versions, and removing any old `babel-` prefixed packages. Refer to the Babel 7 and Babel 8 migration guides.","cause":"A Babel plugin or helper (like this one) built for Babel 7+ is being used in an environment where Babel 6 is still loaded or specified, causing version conflicts.","error":"Requires Babel \"^7.0.0-0\", but was loaded with \"6.x.x\""}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}