0.0.7 • Published 4 years ago

babel-plugin-syntax-symbol v0.0.7

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

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
0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago