babel-plugin-syntax-symbol

0.0.7 • Public • Published

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!

Demo

ESLint

Try to use with babel-eslint@11.0.0-beta.1.

Test

npm run test

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-syntax-symbol

Weekly Downloads

2

Version

0.0.7

License

ISC

Unpacked Size

3.67 kB

Total Files

3

Last publish

Collaborators

  • forek