benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
4.99k stars 349 forks source link

Excessive Memory Consumption Due to Token Inclusion in AST #1413

Open Iswaryasl opened 2 months ago

Iswaryasl commented 2 months ago

I'm experiencing an issue with the recast library where the memory consumption becomes excessively high due to token data being included in the AST (Abstract Syntax Tree) even when the tokens option is set to false.

Steps to Reproduce:

  1. Use the recast.parse function with the following options const ast = recast.parse(code, { tokens: false, loc: true });

  2. Observe the resulting AST object

Expected Behavior:

The tokens property should not be present in the resulting AST if the tokens option is set to false. Memory usage should be reasonable for the size of the AST.

Actual Behavior:

Despite setting the tokens option to false, the resulting AST still includes a tokens property, which leads to excessive memory consumption.

Additional Information:

Recast version: 0.22.0 Node.js version: 14.21.3