Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 1.02 KB

README.md

File metadata and controls

78 lines (56 loc) · 1.02 KB

js.macro

Macro in JavaScript powered by Babel.

This is an experimental project, do not use in production.

Babel Macro

Install

yarn add @zong/js.macro

Before use

Adding the plugin to your config

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["macros"]
}

more

Use

define

Base

import { define } from '@zong/js.macro'

define`
  @a:1;
  @b:2;
  @c:'cde';
  @d:"def";
  @e:true;
  @f:false;
`
// Compiled
const a = 1;
const b = 2;
const c = "cde";
const d = "def";
const e = true;
const f = false;

Advanced

import { define } from '@zong/js.macro'

const var1 = 2

define`
  @va:${1};
  @vb:${var1};
`
// Compiled
const var1 = 2;
const va = 1;
const vb = var1;