How to use the recast.print function in recast

To help you get started, we’ve selected a few recast 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 tmeasday / create-graphql-server / generate / model / index.js View on Github external
.declaration // class declaration
    .body.body;

  const findOneMethod = classMethodsAst.find(m => m.key.name === 'all');
  let nextIndex = classMethodsAst.indexOf(findOneMethod) + 1;


  generatePerField(type, generators).forEach((resolverFunctionAst) => {
    const classMethodAst = resolverFunctionAst.program.body[0] // class declaration
      .body.body[0]; // classMethod

    classMethodsAst.splice(nextIndex, 0, classMethodAst);
    nextIndex += 1;
  });

  return print(ast, { trailingComma: true }).code;
}
github ember-cli / ember-exam / lib / commands / scatter.js View on Github external
testGroups.forEach(function(group, idx) {
      ast.program.body = group;

      // Add the test helpers at the beginning of the batch
      ast.program.body.unshift.apply(ast.program.body, testHelperModules);

      // Add the test-helper require statement at the end of the batch
      ast.program.body.push(requireStatement);

      var fileName = 'tests-' + (idx + 1) + '.js';
      var filePath = path.resolve(outputPath, 'assets', fileName);

      fs.writeFileSync(filePath, recast.print(ast).code);
    });
github martinandert / react-inline / src / transformObjectExpressionIntoStyleSheetObject.js View on Github external
context.evaluate = function(node) {
    return vm.runInContext(print(node).code, this);
  };
github facebook / jscodeshift / src / Collection.js View on Github external
toSource(options) {
    if (this._parent) {
      return this._parent.toSource(options);
    }
    if (this.__paths.length === 1) {
      return recast.print(this.__paths[0], options).code;
    } else {
      return this.__paths.map(p => recast.print(p, options).code);
    }
  }
github martinandert / react-inline / src / Extractor.js View on Github external
options.filename = options.filename || 'unknown';

  let stylesheets = {};
  let ast = parse(source, {
    sourceFileName: options.filename
  });

  transformAST(ast, stylesheets, options);

  let printOptions = {};

  if (options.sourceMapName) {
    printOptions.sourceMapName = options.sourceMapName;
  }

  const result = print(ast, printOptions);
  const { code, map } = result;
  const css = buildCSS(stylesheets, options);

  return { code, map, css };
}
github esnext / es6-class / lib / index.js View on Github external
function compile(source, mapOptions) {
  mapOptions = mapOptions || {};

  var recastOptions = {
    sourceFileName: mapOptions.sourceFileName,
    sourceMapName: mapOptions.sourceMapName
  };

  var ast = recast.parse(source, recastOptions);
  return recast.print(transform(ast), recastOptions);
}
github eslint / eslint / tools / code-sample-minimizer.js View on Github external
continue;
            }

            if (isMaybeExpression(childNode)) {
                if (reproducesBadCase(recast.print(childNode).code)) {
                    return extractRelevantChild(childNode);
                }

            } else if (isStatement(childNode)) {
                if (reproducesBadCase(recast.print(childNode).code)) {
                    return extractRelevantChild(childNode);
                }
            } else {
                const childResult = extractRelevantChild(childNode);

                if (reproducesBadCase(recast.print(childResult).code)) {
                    return childResult;
                }
            }
        }
        return node;
    }
github sx1989827 / DOClever / Desktop / node_modules / es6-templates / lib / index.js View on Github external
function compile(source, mapOptions) {
  mapOptions = mapOptions || {};

  var recastOptions = {
    sourceFileName: mapOptions.sourceFileName,
    sourceMapName: mapOptions.sourceMapName
  };

  var ast = recast.parse(source, recastOptions);
  return recast.print(transform(ast), recastOptions);
}
github abuiles / ember-watson / lib / formulas / destroy-app-transform.js View on Github external
appName = path.node.left;
      }

      this.traverse(path);
    }
  });

  if (addDestroyAppImport) {
    addDefaultImport(ast, '../helpers/destroy-app', 'destroyApp');
  }

  if (removeEmberImport && emberImport) {
    emberImport.prune();
  }

  return recast.print(ast, { tabWidth: 2, quote: 'single' }).code;
};