How to use the @babel/core.transformSync 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 decaffeinate / decaffeinate / test / support / validate.ts View on Github external
function runValidation(source: string, expectedOutput: {}, options: Options, skipNodeCheck: boolean): void {
  const compile = options.useCS2 ? cs2Compile : cs1Compile;
  const coffeeES5 = compile(source, { bare: true }) as string;
  const decaffeinateES6 = convert(source, options).code;
  const transformed = babel.transformSync(decaffeinateES6, {
    presets: ['@babel/preset-env']
  });
  const decaffeinateES5 = (transformed && transformed.code) || '';

  const coffeeOutput = runCodeAndExtract(coffeeES5);
  const decaffeinateOutput = runCodeAndExtract(decaffeinateES5);
  try {
    assertDeepEqual(decaffeinateOutput, coffeeOutput, 'decaffeinate and coffee output were different.');
  } catch (err) {
    // add some additional context for debugging
    err.message = `Additional Debug:
SOURCE
${source}
********************
INPUT -> COFFEE-SCRIPT -> ES5
${coffeeES5}
github vfeskov / vanilla-back-to-top / npm-scripts / build.js View on Github external
async function makeBackwardsCompatible (source) {
  const cssProcessed = await processCss(source)
  return babel.transformSync(cssProcessed, {
    presets: [[presetEnv, {
      // use browserslist config from package.json
      useBuiltIns: 'entry'
    }]]
  }).code
}
github EdgeApp / edge-core-js / make-types.js View on Github external
// Fix differently-named types:
    .replace(/\bmixed\b/g, 'unknown')
    .replace(/\| void\b/g, '| undefined')
    // Fix `import type` syntax:
    .replace(/\bimport type\b/g, 'import')
    .replace(/\btype ([_a-zA-Z]+)( *[,\n}])/g, '$1$2')
    // We aren't JS anymore:
    .replace(/\/\/ @flow/, '')
    .replace(/'(\.[^']*)\.js'/, "'$1'")

  return output
}

// Transpile errors to plain Javascript and TypeScript:
const errorFile = fs.readFileSync('src/types/error.js', 'utf8')
const errorJs = babel.transformSync(errorFile, {
  presets: ['@babel/preset-flow'],
  plugins: [
    '@babel/plugin-transform-modules-commonjs',
    'babel-plugin-transform-fake-error-class'
  ]
}).code
fs.writeFileSync('types.js', errorJs)
fs.writeFileSync('src/types/error.ts', jsToTs(errorFile))

// Transpile Flow types to Typescript:
const typesFile = fs.readFileSync('src/types/types.js', 'utf8')
fs.writeFileSync('src/types/types.ts', jsToTs(typesFile))

// Fix the files with ESLint:
const cli = new eslint.CLIEngine({ fix: true, ignore: false })
const report = cli.executeOnFiles(['./src/types/*.ts'])
github mdx-js / mdx / packages / mdx / mdx-hast-to-jsx.js View on Github external
const fn = `function MDXContent({ components, ...props }) {
  return (
    
${jsxNodes.map(childNode => toJSX(childNode, node)).join('')}
    
  )
};
MDXContent.isMDXComponent = true`

    // Check JSX nodes against imports
    const babelPluginExtractImportNamesInstance = new BabelPluginExtractImportNames()
    transformSync(importStatements, {
      configFile: false,
      babelrc: false,
      plugins: [
        require('@babel/plugin-syntax-jsx'),
        require('@babel/plugin-syntax-object-rest-spread'),
        babelPluginExtractImportNamesInstance.plugin
      ]
    })
    const importNames = babelPluginExtractImportNamesInstance.state.names

    const babelPluginApplyMdxPropInstance = new BabelPluginApplyMdxProp()
    const babelPluginApplyMdxPropToExportsInstance = new BabelPluginApplyMdxProp()

    const fnPostMdxTypeProp = transformSync(fn, {
      configFile: false,
      babelrc: false,
github cerebral / cerebral / packages / node_modules / babel-plugin-cerebral / __tests__ / compile.js View on Github external
it('should allow for default import', () => {
    const code = `
      import App, * as proxies from 'cerebral';
      proxies.state.hello.world;
    `
    const { code: result } = transformSync(code, pluginOptions)
    expect(result).toMatchSnapshot()
  })
})
github emotion-js / next / scripts / babel-tester / src / index.js View on Github external
const tester = allOpts => async opts => {
  let rawCode = opts.code
  if (!opts.code && opts.filename) {
    rawCode = await readFile(opts.filename, 'utf-8')
  }
  if (allOpts.transform) {
    rawCode = allOpts.transform(rawCode)
  }
  const { code } = babel.transformSync(rawCode, {
    plugins: [
      'macros',
      '@babel/plugin-syntax-jsx',
      `@babel/plugin-syntax-class-properties`,
      ...(allOpts.plugins || [])
    ],
    presets: allOpts.presets,
    babelrc: false,
    filename: opts.babelFileName || __filename
  })

  expect(`${rawCode}${separator}${code}`).toMatchSnapshot()
}
github emotion-js / emotion / packages / babel-plugin-jsx-pragmatic / __tests__ / index.js View on Github external
expect(() => {
    transformSync('<>', {
      filename: __filename,
      plugins: [[jsxPragmatic, { export: 'jsx' }]]
    })
  }).toThrow(
    '@emotion/babel-plugin-jsx-pragmatic: You must specify `module` and `import`'
github framework7io / framework7 / scripts / build-phenome.js View on Github external
function transformFile(filePath) {
    const fileContent = fs.readFileSync(filePath);
    const { code } = transformSync(fileContent, {
      babelrc: false,
      configFile: false,
      plugins: [
        ['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }],
      ],
    });
    fs.writeFileSync(filePath, code);
  }
  reactFiles.forEach((fileName) => {
github meteor / babel / index.js View on Github external
}];

    optionsCopy.presets = presets;
    optionsCopy.sourceMaps = true;
    if (result.map) {
      optionsCopy.inputSourceMap = result.map;
    }

    if (result.ast) {
      result = babelCore.transformFromAstSync(
        result.ast,
        result.code,
        optionsCopy
      );
    } else {
      result = babelCore.transformSync(result.code, optionsCopy);
    }

    if (ast === false) {
      delete result.ast;
    }
  }
github jfadev / jfa-pwa-toolkit / webpack.config.js View on Github external
transform(content, path) {
                    return babel.transformSync(content, {
                        presets: [
                            require("@babel/preset-env"),
                            require("babel-preset-minify")
                        ],
                        comments: false
                    }).code;
                }
            }])