babel-plugin-syntax-symbol
v0.0.7
Published
Allow parsing of symbol literals like Ruby
Downloads
19
Readme
babel-plugin-syntax-symbol
Allow parsing of symbol literals like Ruby!
Syntax
Symbol syntax will call Symbol.for
to create a JS Symbol Object
. They are generated using the :name
and :"string"
literals syntax.
// :name
const a = :abc
const b = { [:_def]: true }
// :"string"
const c = :"+123"
const d = :'1024'
Install
npm install --save-dev babel-plugin-syntax-symbol
Usage
Via .babelrc
{
"plugins": ["babel-plugin-syntax-symbol"]
}
Example
in
const foo = :abc
const bar = :'+123'
const baz = { [:def]: true }
class Example {
[:mySymbolKey] () {
console.log('hello world')
}
}
out
const foo = Symbol.for("abc")
const bar = Symbol.for("+123")
const baz = { [Symbol.for("def")]: true }
class Example {
[Symbol.for("mySymbolKey")] () {
console.log('hello world')
}
}
Try it out!
ESLint
Try to use with [email protected]
.
Test
npm run test