Recast removes comments

61 Views Asked by At

I have used recast for my code generation with babel as i have checked it is compatible with babel but recast is removing all my comments Here is my recast code

 const generatedAst = recast.print(ast, {
      tabWidth: 2,
      quote: 'single',
  });

I am passing AST generated from babel parse and directly if i use babel generate to generate my code then parenthesis are removed Can anyone help me with this Thank you in advance

I don't know any other package that is compatible with babel i used recast because i have checked this text and in this it is mentioned that babel removes parenthesis

This is the AST that is generated using babel parse

Node {
  type: 'File',
  start: 0,
  end: 1046,
  loc: SourceLocation {
    start: Position { line: 1, column: 0, index: 0 },
    end: Position { line: 45, column: 0, index: 1046 },
    filename: undefined,
    identifierName: undefined
  },
  errors: [],
  program: Node {
    type: 'Program',
    start: 0,
    end: 1046,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    sourceType: 'module',
    interpreter: null,
    body: [ [Node], [Node], [Node], [Node], [Node] ],
    directives: []
  },
  comments: [
    {
      type: 'CommentLine',
      value: ' eslint-disable-next-line react/no-array-index-key',
      start: 191,
      end: 243,
      loc: [SourceLocation]
    }
  ]
}    

and using babel-generate the parenthesis are being removed
Using this i am parsing the code and from where the AST is being generated

  const ast = parse(originalCode, {
    sourceType: 'module',
    plugins: ['jsx'],
    
  });
0

There are 0 best solutions below