Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Why add new tokens instead of purely decorating existing structures? #7
Just wondering if you could comment on why you chose to add new tokens to handle comments and whitespace, instead of purely decorating existing tokens or nodes with additional information?
By adding new tokens you make the output of rocambole incompatible with tools that consume esprima output. You also make processing of the output more complex.
For example, most formatting rules are based on what node a token is inside and sometimes what token came before them. On js-beautify, we found that comments and whitespace are secondary infomation to rules - keeping them as a sideband of information makes rules simpler while still letting the cases where they matter function.
Another example is the UglifyJs token structure. It adds the comment tokens as decoration for regular tokens.
my idea was mainly because in some cases line breaks should be kept/removed based on the comments.. and grabbing the Comments/LineBreaks inside a node is simpler if it is already inside the tokens list.
it's also way easier to rebuild the JS string if the