How to use the babel.transform function in babel

To help you get started, we’ve selected a few babel 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 continuationlabs / insync / test / transformer.js View on Github external
transform: function (content, filename) {

            // Make sure to only transform your code or the dependencies you want
            if (filename.indexOf('lib') >= 0) {
                var result = Babel.transform(content, {
                    sourceMap: 'inline',
                    filename: filename,
                    sourceFileName: filename
                });
                return result.code;
            }

            return content;
        }
    }
github sighjs / sigh / src / plugin / babel.js View on Github external
filename: event.path,
      sourceMap: true,
      moduleIds: true
    }

    if (opts.modules === 'amd') {
      var modulePath = event.projectPath.replace(/\.js$/, '')
      if (opts.getModulePath)
        modulePath = opts.getModulePath(modulePath)
      babelOpts.moduleId = modulePath
    }

    // if (event.basePath)
    //   babelOpts.filenameRelative = event.basePath

    var result = babel.transform(event.data, babelOpts)
    return _.pick(result, 'code', 'map')
  }
}
github node-modules / autod / lib / autod.js View on Github external
Autod.prototype.parseFile = function (filePath) {
  var file;
  try {
    file = fs.readFileSync(filePath, 'utf-8');
    file = babel.transform(file, { ast: false }).code || '';
  } catch (err) {
    this.emit('warn', util.format('Read(or transfrom) file %s error', filePath));
    return [];
  }
  var modules = [];
  var self = this;

  crequire(file).forEach(function (r) {
    var parsed = MODULE_REG.exec(r.path);
    if (!parsed) {
      return;
    }
    var scope = parsed[1];
    var name = parsed[2];
    if (scope) {
      name = scope + name;
github ldesplat / react-picture / lab-transform.js View on Github external
transform: function (content, filename) {

        if (filename.indexOf('node_modules') === -1) {
            var options = {
                sourceMap: 'inline',
                filename: filename,
                sourceFileName: filename
            };
            var result = Babel.transform(content, options);

            return result.code;
        }

        return content;
    }
}];
github ggoodman / plunker-run-plugin / adapters / transformers / babel.js View on Github external
transform: function (context) {
    var options = _.defaults({}, context.compileOptions, defaultCompileOptions);
    
    var babelrc = context.preview.files['.babelrc'];
    
    if (typeof babelrc !== 'undefined') {
      try {
        babelrc = JSON.parse(babelrc);
        
        _.extend(options, babelrc);
      } catch (__) {}
    }
    
    try {
      var result = Compiler.transform(context.sourceContent, options);
      
      return result.code;
    } catch (err) {
      context.preview.log({
        source: 'babel',
        data: err,
      });
      
      throw new Boom.badRequest('Compilation failed: ' + err.message, err);
    }
  }
};
github eventualbuddha / keysim.js / gobblefile.js View on Github external
function convertToES5(code) {
  return babel.transform(
    code, {
      loose: true,
      stage: 0,
      blacklist: ['es6.modules', 'useStrict']
    });
}
github riot / riot / lib / server / parsers.js View on Github external
es6: function(js) {
      return require('babel').transform(js, { blacklist: ['useStrict'] }).code
    },
    coffee: function(js) {
github zswang / jdists / processor-extend / processor-babel.js View on Github external
module.exports = function processor(content, attrs, scope) {
  if (!content) {
    return content;
  }

  return babel.transform(content, {
    filename: scope.getDirname()
  }).code;
};
github coma / svg-reactify / index.js View on Github external
var out = function (svg) {

        var source = render(filename, svg.data),
            output = babel.transform(source, settings.babel);

        var replaceAttribute = function (a, str) {
          switch (str) {
            case 'class':
              return 'className';

            default:
              return str.replace(/-(.)/g, function (_, letter) {
                return letter.toUpperCase();
              });
          }
        };

        output.code = output.code.replace(/\"(class|clip-path|fill-opacity|font-family|font-size|marker-end|marker-mid|marker-start|stop-color|stop-opacity|stroke-width|stroke-linecap|stroke-dasharray|stroke-opacity|text-anchor)\"/g, replaceAttribute);

        stream.queue(output.code);
github nodejam / nodejam / build.js View on Github external
this.watch(["src/*.js"].concat(excluded), function*(filePath, ev, match) {
        var outputPath = filePath.replace(/^src\//, "lib/");
        var outputDir = path.dirname(outputPath);
        if (!(yield* fsutils.exists(outputDir))) {
            yield* fsutils.mkdirp(outputDir);
        }
        var contents = yield* fsutils.readFile(filePath);
        var result = babel.transform(contents, { blacklist: ["regenerator", "es6.constants", "es6.blockScoping"] });
        yield* fsutils.writeFile(outputPath, result.code);
    }, "babel");