How to use the @babel/core.transformAsync 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 nicolo-ribaudo / legacy-decorators-migration-utility / packages / wrap-legacy-decorators / src / index.js View on Github external
const opts = Object.assign(
    {
      ast: true,
      code: false
    },
    transformerOpts,
    {
      plugins: [
        // For some reason, recast doesn't work with transformFromAst.
        // Use this hack instead.
        [setAst, { ast }]
      ].concat(transformerOpts.plugins || [])
    }
  );

  const output = await babel.transformAsync("", opts);

  return recast.print(output.ast).code;
}
github open-wc / open-wc / packages / es-dev-server / src / utils / babel-compiler.js View on Github external
function compile(filename, source) {
    // babel runs out of memory when processing source maps for large files
    const sourceMaps = source.length > BABEL_DEOPTIMIZED_LENGTH ? false : 'inline';
    return transformAsync(source, { filename, sourceMaps, ...babelConfig }).then(
      result => result.code,
    );
  }
github 4Catalyzer / astroturf / test / helpers.js View on Github external
export async function run(src, options, filename = 'MyStyleFile.js') {
  const { code, metadata } = await transformAsync(src, {
    filename,
    babelrc: false,
    plugins: [
      [require('../src/plugin.js'), { ...options, writeFiles: false }],
    ].filter(Boolean),
    parserOpts: PARSER_OPTS,
  });

  return [
    prettier.format(code, { filepath: filename }),
    metadata.astroturf.styles,
  ];
}
github jamieYou / weapp-starter-kit / config / gulp-wx-babel / index.js View on Github external
function (file, encoding, cb) {
      if (file.isNull()) return cb(null, file)

      const opts = {
        filename: file.path,
        filenameRelative: file.relative,
        sourceMap: Boolean(file.sourceMap),
        sourceFileName: file.relative,
        configFile: false,
        plugins: [plugin],
      }

      babel.transformAsync(file.contents.toString(), opts)
        .then(res => {
          file.contents = Buffer.from(res.code.replace(/"use strict";/g, ''), 'utf-8')
          this.push(file)
        })
        .catch(err => {
          this.emit('error', new PluginError('gulp-wx-babel', err, {
            fileName: file.path,
            showProperties: true
          }))
        })
        .finally(cb)
    },
github babel / gulp-babel / index.js View on Github external
cb(new PluginError('gulp-babel', '@babel/core@^7.0.0 is required'));
			return;
		}

		const fileOpts = Object.assign({}, opts, {
			filename: file.path,
			filenameRelative: file.relative,
			sourceMap: Boolean(file.sourceMap),
			sourceFileName: file.relative,
			caller: Object.assign(
				{name: 'babel-gulp'},
				opts.caller
			)
		});

		babel.transformAsync(file.contents.toString(), fileOpts).then(res => {
			if (res) {
				if (file.sourceMap && res.map) {
					res.map.file = replaceExtension(file.relative);
					applySourceMap(file, res.map);
				}

				file.contents = Buffer.from(res.code);
				file.path = replaceExtension(file.path);

				file.babel = res.metadata;
			}

			this.push(file);
		}).catch(error => {
			this.emit('error', new PluginError('gulp-babel', error, {
				fileName: file.path,
github open-wc / open-wc / packages / demoing-storybook / src / shared / createMdxToJsTransformer.js View on Github external
return async function transformMdxToJs(filePath, body) {
    const jsx = `
      import { React, mdx } from '${urlToPrebuilt}';

      ${await mdx(body, { compilers, filepath: filePath })}
    `.replace('@storybook/addon-docs/blocks', urlToPrebuilt);

    return transformAsync(jsx, {
      filename: filePath,
      sourceMaps: true,
      plugins: [require.resolve('@babel/plugin-transform-react-jsx')],
    });
  };
};
github xyc / vscode-mdx-preview / packages / extension / transpiler / babel.ts View on Github external
export const transformAsync = code => {
  return babel.transformAsync(code, babelOptions);
};
github mediamonks / muban / build-tools / script / build-components.js View on Github external
function processTs(file, fileContent) {
  return babel.transformAsync(fileContent, {filename: file, plugins: [pluginTransformRemoveImport, pluginTransformRemoveExport]}).then((result) => {
    return result.code;
  });
}
github gregberge / svgr / packages / rollup / src / index.js View on Github external
start: 0,
        end: null,
        body: [],
      }

      const jsCode = await convert(load, options, {
        filePath: id,
        caller: {
          name: '@svgr/rollup',
          previousExport,
          defaultPlugins: [svgo, jsx],
        },
      })

      if (babel) {
        const { code } = await transformAsync(jsCode, babelOptions)
        return { code, map: { mappings: '' } }
      }

      return { ast, code: jsCode, map: { mappings: '' } }
    },
  }
github rollup / plugins / packages / babel / src / transformCode.js View on Github external
return null;
  }

  let transformOptions = !overrides.config
    ? config.options
    : await overrides.config.call(this, config, {
        code: inputCode,
        customOptions
      });

  if (finalizeOptions) {
    transformOptions = await finalizeOptions(transformOptions);
  }

  if (!overrides.result) {
    const { code, map } = await babel.transformAsync(inputCode, transformOptions);
    return {
      code,
      map
    };
  }

  const result = await babel.transformAsync(inputCode, transformOptions);
  const { code, map } = await overrides.result.call(ctx, result, {
    code: inputCode,
    customOptions,
    config,
    transformOptions
  });
  return {
    code,
    map