What is the use case for babel-plugin-macros vs Sweet.js?

I'm interested in macros in JavaScript, and I'm a little confused how babel-plugin-macro and Sweet.js compare to each other. Do they both solve the same problem? Do they both fit into the same toolchain?

In particular, I hope to use one of these tools with ES2015 code, which will be transferred to ES5 using Webpack and Babel, and I'm not sure how one of these tools interacts with transpilation.

+4
source share
1 answer

Yes, they solve the same general problem of "adding" macros to JavaScript, but they approach it differently. To begin with, each of them has a different syntax for defining macros. I don’t understand if any standard is suitable. Sweet.js is standalone, and babel-plugin-macro is the Babel plugin. I would suggest that you can use them as part of the same toolchain, and people can do this if they prefer Sweet.js. However, it may be much easier to use the Babel plugin if it already uses Babel.

I would be careful to go too deep into this, as there is no standard for JavaScript yet. This will likely lead to headaches in terms of the source working correctly, especially when combining Sweet.js with Babel.

, ( Sweet.js) JavaScript. ECMAScript.

UPDATE

- , , Sweet.js Babel , , , . . http://sweetjs.org/doc/1.0/tutorial.html#_babel_backend

+3

Source: https://habr.com/ru/post/1629784/


All Articles