How to use the @babel/template/lib/formatters.smart function in @babel/template

To help you get started, we’ve selected a few @babel/template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xtuc / webassemblyjs / .babelrc.js View on Github external
const template = require("@babel/template").default;
const parseAndBuildMetadata = require("@babel/template/lib/parse").default;
const smartFormater = require("@babel/template/lib/formatters").smart;

function macro({types: t}) {
  const macroMap = {};

  function defineMacro(ident, body) {
    let content = '';

    if (t.isStringLiteral(body)) {
      content = body.value;
    }

    // Just merge elements
    if (t.isTemplateLiteral(body)) {
      content = body.quasis.reduce((acc, e) => {
        acc += e.value.raw;
        return acc;