Babel Helper Simple Access

raw JSON →
7.0.0-beta.3 verified Sat Apr 25 auth: no javascript deprecated

A Babel helper package (currently at v7.0.0-beta.3) that transforms complex assignment patterns (e.g., `i += 1`, `--i`) into simple assignments for easier AST manipulation. It is part of the Babel ecosystem, primarily used internally by Babel plugins. Unlike general-purpose AST utilities, it specifically handles converting compound assignments and unary mutations to straightforward `i = i + 1` style assignments. This package is in beta and likely deprecated in favor of modern Babel 8 helpers.

error TypeError: simpleAccess is not a function
cause Incorrect import: using named import instead of default import.
fix
Use import simpleAccess from 'babel-helper-simple-access' (default import).
error Error: Cannot find module 'babel-helper-simple-access'
cause Package not installed or version mismatch.
fix
Run npm install babel-helper-simple-access@7.0.0-beta.3 and ensure it's in package.json.
error ReferenceError: t is not defined
cause Missing @babel/types dependency.
fix
Install @babel/types: npm install @babel/types and import it.
deprecated This package is part of Babel 7 beta and is deprecated. Use Babel 8's internal helpers instead.
fix Migrate to @babel/helper-simple-access if available, or use Babel 8 plugins.
gotcha This helper does not handle destructuring patterns like `{ a } = foo`.
fix Manually handle destructuring or use a different transformation pass.
breaking API may change in future versions; this package is experimental.
fix Pin to a specific version and test thoroughly.
npm install babel-helper-simple-access
yarn add babel-helper-simple-access
pnpm add babel-helper-simple-access

Demonstrates using simpleAccess to convert a compound assignment into a simple assignment.

import simpleAccess from 'babel-helper-simple-access';
import * as t from '@babel/types';

// Example: convert `i += 1` to `i = i + 1`
const ast = t.expressionStatement(
  t.assignmentExpression('+=', t.identifier('i'), t.numericLiteral(1))
);
simpleAccess(ast, [t.identifier('i')]);
console.log(ast); // Now `ast` contains simple assignment

// Note: This is a low-level helper; not intended for standalone use.