How to use the babel-core.transform 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 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 artisonian / erudite / index.js View on Github external
var codeBlocks = tokens.reduce(function (blocks, token) {
    if (token.type === 'code') {
      blocks.push(new Buffer(token.text));
      blocks.push(new Buffer(SEPARATOR));
    }

    return blocks;
  }, []);

  codeBlocks.pop(); // remove trailing EOL adding from the while loop

  // Concatentate the code blocks.
  buf = Buffer.concat(codeBlocks);

  // Return the concatenated code blocks as a `Buffer`.
  return new Buffer(babel.transform(buf.toString(), opts).code);
}
github webex / react-widgets / scripts / utils / build.js View on Github external
function buildFile(filename, destination, babelOptions = {}) {
  const options = Object.assign({}, babelOptions);
  const content = fs.readFileSync(filename, {encoding: 'utf8'});
  const ext = path.extname(filename);
  const outputPath = path.join(destination, path.basename(filename));

  // Ignore non-JS files and test scripts
  if (!filename.includes('.test.')) {
    if (ext === '.js') {
      options.filename = filename;
      const result = transform(content, options);

      return outputFileSync(outputPath, result.code, {encoding: 'utf8'});
    }
    // process with postcss if it's a css file
    if (ext === '.css') {
      return execSync(`postcss ${filename} -o ${outputPath}`);
    }

    // Copy if it's any other type of file
    return outputFileSync(outputPath, content);
  }

  return false;
}
github systemjs / builder / compilers / compiler.js View on Github external
var sourceRoot = pathToUrl(path.dirname(load.path) + '/');
  var options = {
    babelrc: false,
    compact: false,
    sourceType: 'script',
    filename: pathToUrl(load.path),
    filenameRelative: path.basename(load.path),
    inputSourceMap: load.metadata.sourceMap,
    moduleId: opts.moduleId,
    sourceFileName: path.basename(load.path),
    sourceMaps: !!opts.sourceMaps,
    sourceRoot: sourceRoot,
    plugins: [plugin]
  };

  var output = babel.transform(load.source, options);
  
  var sourceMap = output.map;
  if (sourceMap && !sourceMap.sourceRoot) // if input source map doesn't have sourceRoot - add it
    sourceMap.sourceRoot = sourceRoot;

  return Promise.resolve({
    source: output.code,
    sourceMap: sourceMap
  });
};
github Pauan / nulan / bootstrap / compiler / ffi.js View on Github external
make_module(state, path, (module) => {
    const code = read_file(path);

    const dir = $path.dirname(path);

    const output = $babel.transform(code, {
      "filename": path, // TODO is this correct ?
      "sourceMaps": true,
      "code": true,
      "babelrc": false,
      "ast": false,
      // sourceMapTarget
      // sourceFileName
      // sourceRoot
      // moduleIds
      // moduleId
      "presets": [
        "es2015-native-modules"
      ],
      "plugins": [
        [$module, {
          "file": path,
github PavelDymkov / babel-plugin-transform-react-statements / src / common-lib.js View on Github external
export function combineElements(elements, options) {
    if (options.wrapper == "no-wrap") {
        if (elements.length != 1)
            throw new Error(errors.NO_WRAP_ERROR);
    }

    if (elements.length == 1) return elements[0];

    let wrapper = options.wrapper || "<span>";

    if (wrapper == "array-supported") {
        return t.arrayExpression(elements.reduce(toJSExpression, []));
    }

    try {
        let {ast} = babel.transform(wrapper, { plugins: ["syntax-jsx"] });
        let [expressionStatement] = ast.program.body;

        if (!t.isExpressionStatement(expressionStatement))
            throw null;

        let wrapperASTSource = expressionStatement.expression;

        if (!t.isJSXElement(wrapperASTSource))
            throw null;

        let openingElementSource = wrapperASTSource.openingElement;
        let { name: tagIdentifier } = openingElementSource;

        let openingElement =
            t.jSXOpeningElement(tagIdentifier, openingElementSource.attributes);
        let closingElement = t.jSXClosingElement(tagIdentifier);</span>
github demiazz / lighty / build / build.js View on Github external
function transformSource(source, stripTypes) {
  const { code } = transform(source, {
    presets: [["es2015", { modules: false }]],
    plugins: [stripTypes ? "transform-flow-strip-types" : "syntax-flow"]
  });

  return code;
}
github ndp / csster / node_modules / babel-cli / lib / babel / util.js View on Github external
function transform(filename, code, opts) {
  opts = defaults(opts || {}, index.opts);
  opts.filename = filename;

  var result = babel.transform(code, opts);
  result.filename = filename;
  result.actual = code;
  return result;
}
github erzu / porter / packages / porter / lib / transform.js View on Github external
function transform(code, opts) {
  return babel.transform(code, Object.assign({
    sourceMaps: true,
    sourceRoot: '/',
    ast: false,
  }, opts))
}
github c8r / lab-cli / lib / index.js View on Github external
const compile = code =>
  transform(code, {
    presets: [
      require('babel-preset-env'),
      require('babel-preset-stage-0'),
      require('babel-preset-react')
    ]
  }).code