babel-check-duplicated-nodes

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

Babel helper utility (v1.0.0) that checks an AST for duplicated nodes, throwing a descriptive error if any are found. Originally extracted from Babel's test fixture runner, this tool helps Babel transform authors catch subtle bugs caused by node reuse. It is a niche package with a single API call, no active release cadence, and is intended for internal use during transform development rather than general production.

error TypeError: checkDuplicatedNodes is not a function
cause Default import usage instead of named import.
fix
Use import { checkDuplicatedNodes } from 'babel-check-duplicated-nodes' or const { checkDuplicatedNodes } = require('babel-check-duplicated-nodes').
error Cannot find module 'babel-check-duplicated-nodes'
cause Package not installed or missing from node_modules.
fix
Run npm install babel-check-duplicated-nodes --save-dev.
gotcha The pattern 'require('babel-check-duplicated-nodes').default' is incorrect; the package does not have a default export.
fix Use 'const { checkDuplicatedNodes } = require('babel-check-duplicated-nodes')'.
gotcha This package is intended for internal use by Babel transform authors, not for general AST manipulation. Incorrect usage may produce false negatives.
fix Ensure you only call this function on ASTs generated by Babel's parser, not third-party parsers.
npm install babel-check-duplicated-nodes
yarn add babel-check-duplicated-nodes
pnpm add babel-check-duplicated-nodes

Demonstrates how to use checkDuplicatedNodes with @babel/core to detect duplicated AST nodes.

import { checkDuplicatedNodes } from 'babel-check-duplicated-nodes';
import * as babel from '@babel/core';

const code = 'const x = 1; const y = 2;';
const ast = babel.parseSync(code, { filename: 'test.js' });

// Simulate a duplicated node: reuse the same node twice
const duplicateNode = ast.program.body[0];
ast.program.body.push(duplicateNode);

try {
  checkDuplicatedNodes(babel, ast);
} catch (e) {
  console.error(e.message);
}