How to use babel-core - 10 common examples

To help you get started, we’ve selected a few babel-core 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 Aedron / Muse / test / babel.js View on Github external
};

render(
<div>
  <h1>Hello</h1>
  <input placeholder="Hello" type="number">
</div>
)
`;

const result = babel.transform(code, {
    plugins: [
        ["../plugins/TwoWayDataBinding.js", {
            "attrName": "f-model"
        }],
        ["../plugins/IfDirection.js", {
            "attrName": "f-if"
        }],
        "transform-jsx"
    ]
});


// console.log(result);
github tmpfs / trucks / test / spec / compiler / empty-attribute.js View on Github external
it('should generate AST for element with empty attribute', function(done) {
    const tpl = '<template id="x-foo">'
      + '<span></span></template>';

    const res = trucks.compile(tpl);

    expect(res.list).to.be.an('array').to.have.length(1);

    // component id
    expect(res.list[0].id).to.eql('x-foo');

    // function body AST
    expect(res.list[0].body).to.be.an('object');

    const result = babel.transformFromAst(res.list[0].body);
    expect(result.code).to.eql('skate.vdom.element("span", {\n'
      + '  "icon": ""\n'
      + '});');

    done();
  });
github tmpfs / trucks / test / spec / compiler / normalize.js View on Github external
const tpl = '<template id="x-foo">'
      + '  <span></span>'
      + '  <em></em>'
      + '</template>';

    const res = trucks.compile(tpl, {normalize: false});

    expect(res.list).to.be.an('array').to.have.length(1);

    // component id
    expect(res.list[0].id).to.eql('x-foo');

    // function body AST
    expect(res.list[0].body).to.be.an('object');

    const result = babel.transformFromAst(res.list[0].body);
    expect(result.code).to.eql(
      'skate.vdom.text("  ");\n' + 
      'skate.vdom.element("span");\n' + 
      'skate.vdom.text("  ");\n' + 
      'skate.vdom.element("em");' 
    );

    done();
  });
github Legitcode / forms / src / __tests__ / preprocessor.js View on Github external
process: function(src, filename) {
    // Allow the stage to be configured by an environment
    // variable, but use Babel's default stage (2) if
    // no environment variable is specified.
    var stage = process.env.BABEL_JEST_STAGE || 0;

    // Ignore all files within node_modules
    // babel files can be .js, .es, .jsx or .es6
    if (filename.indexOf("node_modules") === -1 && babel.canCompile(filename)) {
      return babel.transform(src, { filename: filename, stage: stage, retainLines: true }).code;
    }

    return src;
  }
}
github emberjs / ember.js / broccoli / deprecated-features.js View on Github external
function svelte(infile, outfile) {
  console.log(DEPRECATED_FEATURES); // eslint-disable-line no-console
  const babel = require('babel-core'); // eslint-disable-line node/no-extraneous-require

  let { code } = babel.transformFileSync(infile, {
    plugins: [
      [
        'debug-macros',
        {
          debugTools: {
            source: '@ember/debug',
            assertPredicateIndex: 1,
            isDebug: false,
          },
          svelte: {
            'ember-source': '3.3.0',
          },
          flags: [
            {
              source: '@glimmer/env',
              flags: { DEBUG: false },
github ForbesLindesay / authentication / scripts / build.js View on Github external
lsrSync(cwd + '/lib').forEach(entry => {
  if (entry.isFile() && /\.jsx?$/.test(entry.path)) {
    const isPublic = /\@public\b/.test(readFileSync(entry.fullPath, 'utf8'));
    writeFileSync(
      entry.fullPath.replace(/\.jsx$/, '.js'),
      babel.transformFileSync(entry.fullPath, {
        babelrc: false,
        presets: [
          pkg['@authentication/target'] === 'browser'
            ? require.resolve('@moped/babel-preset/browser')
            : require.resolve('@moped/babel-preset/server'),
        ],
      }).code,
    );
    if (/\.jsx$/.test(entry.fullPath)) {
      unlinkSync(entry.fullPath);
    }
    if (isPublic) {
      writeFileSync(
        cwd + '/' + entry.path.substr(2).replace(/\.jsx$/, '.js'),
        "// @autogenerated\n\nmodule.exports = require('./lib/" +
          entry.path.substr(2).replace(/\.jsx?$/, '') +
github ant-ife / apfe-cli / src / lib / compose-apps / utils.js View on Github external
return new Promise((resolve, reject) => {
    babel.transformFile(file, {
      ...options,
      babelrc: false, // Keep the file origin smell
    }, function (err, result) {
      if (err) {
        if (err.loc) {
          console.log(`${file} syntax error:`)
          console.log(codeFrame(readFileSync(file, 'utf8'), err.loc.line, err.loc.column))
        }
        reject(err)
        return
      }
      writeFileSync(file, result.code)
      try {
        beautifulFile(file)
      } catch (err) {
github wdfe / weweb / lib / util.js View on Github external
function loadJavascript (full_path, useBabel, cb) {
  if (useBabel && useBabel != '0') {
    // console.log('useBabel:true',useBabel)
    babel.transformFile(
      full_path,
      {
        presets: ['babel-preset-env', 'babel-preset-stage-0'].map(
          require.resolve
        ),
        sourceMaps: !inProd,
        sourceRoot: process.cwd(),
        sourceFileName: full_path,
        babelrc: false,
        ast: false,
        resolveModuleSource: false
      },
      function (err, result) {
        if (err) return cb(err)
        if (inProd) {
          result.code = UglifyJS.minify(result.code, { fromString: true }).code
github tmpfs / trucks / packages / transform-skate / src / compiler.js View on Github external
function render(el, opts, prefix) {

  opts = options(opts);

  const $ = opts.vdom
    , babel = require('babel-core')
    , t = babel.types
    , body = [];

  function getTemplateLiteralExpression(val) {
    return babel.transform(
      '`' + val  + '`', opts.babel).ast.program.body[0].expression;
  }

  function attributeIterator(key, val) {
    if(key && ON_PATTERN.test(key)) {
      const ast = babel.transform(val, opts.babel).ast;
      t.assertExpressionStatement(ast.program.body[0]);
      return ast.program.body[0].expression;
    }else if(val === true || val === false) {
      return t.booleanLiteral(val);
    // treat as string
    }else{
github fnando / babel-schmooze-sprockets / node_modules / babel-register / lib / node.js View on Github external
function compile(filename) {
  var result = /*istanbul ignore next*/void 0;

  // merge in base options and resolve all the plugins and presets relative to this file
  var opts = new /*istanbul ignore next*/_babelCore.OptionManager().init( /*istanbul ignore next*/(0, _extend2.default)( /*istanbul ignore next*/(0, _cloneDeep2.default)(transformOpts), {
    filename: filename
  }));

  var cacheKey = /*istanbul ignore next*/ /*istanbul ignore next*/(0, _stringify2.default)(opts) + ":" + babel.version;

  var env = process.env.BABEL_ENV || process.env.NODE_ENV;
  if (env) cacheKey += /*istanbul ignore next*/":" + env;

  if (cache) {
    var cached = cache[cacheKey];
    if (cached && cached.mtime === mtime(filename)) {
      result = cached;
    }
  }

  if (!result) {