Registry / web-framework / babel-plugin-remove-object-properties

babel-plugin-remove-object-properties

JSON →
library1.0.2jsnpmunverified

Babel plugin for stripping object properties from AST nodes that match a supplied regex pattern. The current stable version is 1.0.2, released with low release cadence. It works during Babel's transpilation phase, removing nodes of type 'ObjectProperty' via regex. Unlike generic Babel visitors or AST manipulation utilities, this plugin provides a simple configurable approach to remove object properties (e.g., data-* attributes in React). Suitable for cleaning test attributes from production builds. Has minimal dependencies and is distributed on npm.

npm install babel-plugin-remove-object-properties
INSTALL
IMPORT
SIG · BABEL-PLUGIN-REMOV
B
babel-plugin-remove-object-properties
web-frameworkjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
No import needed; configured via .babelrc or programmatic API.
import babelPluginRemoveObjectProperties from 'babel-plugin-remove-object-properties'
This is a Babel plugin, not imported directly in application code.
plugin reference in .babelrc
"plugins": [["remove-object-properties", { "regexp": "data-*" }]]
"plugins": ["babel-plugin-remove-object-properties"]
Without options array, the plugin may fail or not apply regex correctly.
programmatic usage
require('@babel/core').transform(code, { plugins: [[require('babel-plugin-remove-object-properties'), { regexp: 'data-*' }]] })
require('babel-plugin-remove-object-properties')({ regexp: 'data-*' })
Must be nested inside plugins array as a tuple with options.

Configures Babel plugin to remove properties matching 'data-*' regex from JSX elements.

// In .babelrc or babel.config.js // Remove all properties matching regex 'data-*' { "plugins": [["remove-object-properties", { "regexp": "data-*" }]] } // Before transpilation: <div data-id="test">Hello</div> // After transpilation: <div>Hello</div>
Debug
Known issues
gotchaThe regex is applied to the property key, not the entire property string. Ensure regex matches exactly the property name (e.g., 'data-*' matches 'data-' followed by any chars, but not 'data-test' without wildcard? Actually 'data-*' matching? Use '^data-' to be safe.
fix
Use a proper regex like '^data-' to match keys starting with 'data-'.
affects: >=1.0.0
gotchaPlugin removes all object properties matching the regex, including non-JSX object properties; be aware it's not limited to JSX attributes.
fix
Restrict usage to specific files or conditions if unwanted removal occurs.
affects: >=1.0.0
deprecatedThe package has not been updated since 2017; may not work with Babel 7 or newer without adjustments.
fix
Test with your Babel version; consider using modern alternatives like babel-plugin-strip-sourcemap or custom visitor.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'type')
Plugin not receiving options object correctly in .babelrc.
fix
Use double array syntax: "plugins": [["remove-object-properties", { "regexp": "data-*" }]]
Error: [BABEL] unknown: Cannot find module 'babel-plugin-remove-object-properties'
Plugin not installed or not in node_modules.
fix
Run npm install babel-plugin-remove-object-properties --save-dev
The regexp option must be a string
Passing regex literal instead of string in config.
fix
Use string form: "regexp": "data-*" (not /data-*/)
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
babel-plugin-remove-object-properties — npm install babel-plugin-remove-object-properties · libregistry