d3dc / swift.macro

A simple babel macro to use swift features in Javascript or Typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

babel-plugin-macros-example

This is a simple example of a babel-plugin-macros macro.

You'll notice that the code.js file is importing the greeting.macro.js file. Then the imported identifiers are used throughout the code. The macro itself is about as simple as you can get with a babel-plugin-macros macro. It accepts the references to those imports and replaces the references with string literals. Take a look at the output.js file to see what the result is. Now mess around with it a bit to see what you can do with this thing!

Hopefully this helps you get started trying out writing a macro!

Tips

Writing a macro is similar to writing a babel-plugin except you give up a little power in favor of a simpler setup for you and the user of your macro (maybe also you). Because it's so similar to writing a babel plugin, it could be really helpful to learn how to write babel plugins and using ASTs. Here are some resources for that:

From there, you may also want to reference the babel-plugin-macros docs

Good luck!

About

A simple babel macro to use swift features in Javascript or Typescript


Languages

Language:JavaScript 100.0%