How to use the @babel/template.default.expression 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 facebook / metro / packages / metro / src / JSTransformer / worker / import-export-plugin.js View on Github external
const exportTemplate = template(`
  exports.REMOTE = LOCAL;
`);

/**
 * Flags the exported module as a transpiled ES module. Needs to be kept in 1:1
 * compatibility with Babel.
 */
const esModuleExportTemplate = template(`
  Object.defineProperty(exports, '__esModule', {value: true});
`);

/**
 * Resolution template in case it is requested.
 */
const resolveTemplate = template.expression(`
  require.resolve(NODE)
`);

/**
 * Enforces the resolution of a path to a fully-qualified one, if set.
 */
function resolvePath(node: {value: string, ...}, resolve: boolean) {
  if (!resolve) {
    return node;
  }

  return resolveTemplate({
    NODE: node,
  });
}
github lttb / reshadow / packages / babel / index.js View on Github external
const fs = require('fs');
const path = require('path');
const t = require('@babel/types');
const template = require('@babel/template').default;
const syntaxJsx = require('@babel/plugin-syntax-jsx').default;
const {addDefault} = require('@babel/helper-module-imports');
const {stripIndent} = require('common-tags');
const stringHash = require('string-hash');

const utils = require('@reshadow/utils');
const {KEYS} = require('@reshadow/core');

const buildClassName = template.expression(`
    NAME.${KEYS.__styles__}["ELEMENT"]
`);

const toObjectExpression = obj =>
    t.objectExpression(
        Object.entries(obj).map(([key, value]) =>
            t.objectProperty(
                t.stringLiteral(key),
                t.templateLiteral(
                    [
                        t.templateElement({
                            raw: value,
                            cooked: value,
                        }),
                    ],
                    [],
github lttb / reshadow / packages / babel / index.js View on Github external
const fs = require('fs');
const path = require('path');
const t = require('@babel/types');
const template = require('@babel/template').default;
const syntaxJsx = require('@babel/plugin-syntax-jsx').default;
const {addDefault} = require('@babel/helper-module-imports');
const {stripIndent} = require('common-tags');
const stringHash = require('string-hash');

const utils = require('@reshadow/utils');

const reshadowPostcss = require('./postcss');

const buildClassName = template.expression(`
    NAME.styles["ELEMENT"]
`);

const toObjectExpression = obj =>
    t.objectExpression(
        Object.entries(obj).map(([key, value]) =>
            t.objectProperty(
                t.stringLiteral(key),
                t.templateLiteral(
                    [
                        t.templateElement({
                            raw: value,
                            cooked: value,
                        }),
                    ],
                    [],