How to use the babel-core.transformFileSync function in babel-core

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 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 motiz88 / babel-plugin-transform-hoist-nested-functions / test / specs / transform-fixtures.js View on Github external
it(`should ${caseName.split('-').join(' ')}`, () => {
      const fixtureDir = path.join(fixturesDir, caseName);
      const actualPath = path.join(fixtureDir, 'actual.js');
      const optionsPath = path.join(fixtureDir, 'options.json');
      const options = fs.existsSync(optionsPath) ? JSON.parse(fs.readFileSync(optionsPath).toString()) : {};
      const actual = transformFileSync(actualPath, fixturesBabelConfig(options)).code;

      const expected = fs.readFileSync(
          path.join(fixtureDir, 'expected.js')
      ).toString();

      assert.equal(normalize(actual), normalize(expected));
    });
  });
github sunyongjian / babel-usage / babel-core / index.js View on Github external
var babel = require('babel-core');
var transform = babel.transform;
var path = require('path');
var result = babel.transformFileSync(path.resolve(__dirname) + "/test.js", {
  presets: ['env'],
  plugins: ['transform-runtime'],
});

console.log(result, 'res');
github auth0 / cosmos / tooling / update-progress.js View on Github external
glob.sync(path.join(__dirname, '../src/manage/**/*.js')).map(file => {
    if (file === path.join(__dirname, '../src/manage/dummy-components.js')) return
    babel.transformFileSync(file, options)
  })
  console.log(sources)
github akameco / PixivDeck / config / scripts / s2s.js View on Github external
const transfromWrite = (input, output, plugin) => {
  try {
    const { code } = transformFileSync(input, {
      babelrc: false,
      plugins: [plugin],
    })

    const fomattedCode = prettier.format(code, {
      semi: false,
      singleQuote: true,
      trailingComma: 'es5',
    })

    fs.writeFileSync(output, fomattedCode, 'utf-8')
  } catch (err) {
    console.log(err)
  }
}
github fluidtrends / chunky / dev / index.js View on Github external
function transpile (src, target) {
  const code = babel.transformFileSync(path.resolve(src), {
    sourceRoot: path.join(process.cwd(), 'node_modules'),
    plugins: ['styled-jsx/babel', 'transform-react-jsx', 'transform-es2015-destructuring', 'transform-object-rest-spread'],
    presets: ['react', 'env']
  }).code

  if (fs.existsSync(target)) {
    fs.removeSync(target)
  }

  if (!fs.existsSync(path.dirname(target))) {
    fs.mkdirsSync(path.dirname(target))
  }

  fs.writeFileSync(target, code)
}
github pluralsight / design-system / packages / icon / src / js / icon-transformer.js View on Github external
const transformFile = filePath => {
  let content = babel.transformFileSync(filePath, {
    presets: ['react', 'stage-2']
  }).code

  content = content.replace('"use strict";', '')
  content = content.replace(';', '')
  content = insertBeforeChar(content, '{', 'Object.assign(')
  content = insertAfterChar(
    content,
    '}',
    ", filterReactProps(props, { tagName: 'svg' }))"
  )

  content = content.replace('fill-rule', 'fillRule')
  content = content.replace('clip-rule', 'clipRule')

  return content
github jmurzy / react-router-native / gulpfile.js View on Github external
require.extensions['.js'] = (module, filename) => {
      if (filename.indexOf(path) < 0) {
        defaultLoader(module, filename);
        return;
      }

      const { code } = require('babel-core').transformFileSync(
        filename,
        babelConfig,
      );

      module._compile(code, filename);
      return;
    };
  };