How to use the esprima-fb.parse function in esprima-fb

To help you get started, we’ve selected a few esprima-fb 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 benjamn / es7-async-await / index.js View on Github external
var recast = require("recast");
var types = recast.types;
var through = require("through");
var esprima = require("esprima-fb");
var visitor = require("./visitor");

// Make sure that this esprima can parse async functions.
esprima.parse("async function test() {}");

function exports() {
  var data = [];
  return through(write, end);

  function write(buf) {
    data.push(buf);
  }

  function end() {
    this.queue(compile(data.join("")).code);
    this.queue(null);
  }
}

function compile(source, options) {
github bosonic / bosonic / index.js View on Github external
function reindentScript(script) {
    // We do another pass with Esprima in order to indent JS code correctly
    var outputAst = esprima.parse(script);
    return escodegen.generate(outputAst);
}
github kevinbarabash / debugger / src / transform.js View on Github external
var transform = function(code, _context, options) {
    let ast = esprima.parse(code, { loc: true });
    let scopeManager = escope.analyze(ast);
    scopeManager.attach();

    scopeStack = new Stack();
    context = _context;
    contextName = "context" + Date.now();
    path = [];

    estraverse.replace(ast, {
        enter: (node, parent) => {
            if (node.__$escope$__) {
                let scope = {};
                let isRoot = scopeStack.size === 0;

                node.__$escope$__.variables.forEach(variable => {
                    // don't include variables from the context in the root scope
github Skookum / react-autodoc / tests / js / integration.js View on Github external
Object.keys(annotations).forEach(function(displayName, i) {
      var result = annotations[displayName];
      var expect = expected[displayName];

      assert.deepEqual(
        result,
        expect,
        '\nExpectations for ' + displayName + ': \n' +
          JSON.stringify(result) +
          ' to be: \n' + JSON.stringify(expect)
      );
    });
  };

  var ast = estraverse[transformer.type](
    esprima.parse(contents),
    transformer
  );

  if (results.length === 0) {
    throw new Error(
      'No results were parsed. Expected ' + expected.length + ' annotations.'
    );
  }

};
github juandopazo / es-dependency-graph / tests / index.js View on Github external
.map(function (file) {
                    return graph(esprima.parse(fs.readFileSync(file, 'utf8')));
                });
github shalomeir / snippod-boilerplate / djangoapps / myapp / static / node_modules / react-tools / node_modules / jstransform / src / jstransform.js View on Github external
function transform(visitors, source, options) {
  options = options || {};
  var ast;
  try {
    var cachedAst = _astCache[source];
    ast = cachedAst ||
      (_astCache[source] = esprima.parse(source, {
        comment: true,
        loc: true,
        range: true
      }));
    } catch (e) {
    e.message = 'Parse Error: ' + e.message;
    throw e;
  }
  var state = utils.createState(source, ast, options);
  state.g.visitors = visitors;

  if (options.sourceMap) {
    var SourceMapGenerator = require('source-map').SourceMapGenerator;
    state.g.sourceMap = new SourceMapGenerator({file: options.filename || 'transformed.js'});
  }
github facebookarchive / jstransform / src / jstransform.js View on Github external
function getAstForSource(source, options) {
  if (_astCache[source] && !options.disableAstCache) {
    return _astCache[source];
  }
  var ast = esprima.parse(source, {
    comment: true,
    loc: true,
    range: true,
    sourceType: options.sourceType
  });
  if (!options.disableAstCache) {
    _astCache[source] = ast;
  }
  return ast;
}
github mrblueblue / gettext-loader / src / utils / parseECMA.js View on Github external
export default function parseECMA(source){
  return prop('body')(
    esprima.parse(source, {
      tolerant: true,
      loc: true
    })
  );
}