Auto Symbol Description
A Babel plugin to automatically set Symbol descriptions.
Note: Babel 7 is supported in version 2.0+.
Note: Babel 6 is supported in version 1.0+. Keep using version 0.0.1 for Babel 5 support.
Use Cases
Redux
Very useful with Redux if you use Symbols for action types:
In:
// TodoActions.jsconst CREATE = Symbol;const CREATE_SUCCESS = Symbol;const CREATE_FAILURE = Symbol;
Out (something like this):
// TodoActions.jsconst CREATE = Symbol'TodoActions.CREATE';const CREATE_SUCCESS = Symbol'TodoActions.CREATE_SUCCESS';const CREATE_FAILURE = Symbol'TodoActions.CREATE_FAILURE';
Then use these constants in a reducer:
// TodoReducer.js; { }
Symbol descriptions are only useful for debugging, so idealy you would only include this transformation in development.
Installation
npm install -D babel-plugin-auto-symbol-description
.babelrc:
{
"env": {
"development": {
"plugins": ["auto-symbol-description"]
}
}
}
Notes
This plugin won't transform any Symbol
calls with an argument, and it only
works for assignments and variable declarations for now. Let me know if there is
demand for the transformation when setting an object property or any other use
cases.