Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

Don't strip comments (both inline and end of line) #3

Open
twolfson opened this issue Jun 27, 2015 · 3 comments
Open

Don't strip comments (both inline and end of line) #3

twolfson opened this issue Jun 27, 2015 · 3 comments

Comments

@twolfson
Copy link
Owner

Our latest iteration is better than our first as it preserves node/token linkages. However, we are currently stripping out the content between VariableDeclarator's. We should preserve this information by some means (e.g. generating a new betweenDeclarationTokens set for each declaration pair).

Here are some test cases:

var a, b;

to

var a; var b;

var a, b,
    c = 1;

to

var a; var b;
var c = 1;

var a, /* hi */ b;

to

var a; /* hi */ var b;

var a,/* hi */ b;

to

var a;/* hi */ var b;

var a, b, // hello
    c = 1;

to

var a; var b; // hello
var c = 1;
@twolfson
Copy link
Owner Author

After thinking about this more, we should always normalize to 1 var per line to keep our sanity. Here are some updated cases:

After thinking about this more, we should always normalize to 1 var per line to keep our sanity. Here are some updated cases:

var a, b;

to

var a;
var b;

var a /* sup */, b;

to

var a; /* sup */
var b;

var a, // sup
    b;

to

var a; //sup
var b;

var a // sup
  , b;

to

var a; //sup
var b;

@twolfson
Copy link
Owner Author

Started on this but stopping due to draining time and other priorities.

https://github.com/twolfson/esformatter-var-each/tree/dev/allow.comments

@twolfson twolfson reopened this Jun 27, 2015
@twolfson
Copy link
Owner Author

If we ever resume this, my parting thoughts are:

  • Our current implementation links declarations as their ends are defined
    • This was practical for the "in between" logic where we are defining new heads/tails for these chunks
  • However, when we move to reuse, it makes more sense to define the heads/tails independently
  • Then link them together in a final step. As this removes the possibility for the next head from not existing when we want to link it.

To rephrase:

  1. Set up VariableDeclaration nodes and attach to inner VariableDeclarator (e.g. parent/child)
  2. Connect VariableDeclaration nodes prev/next and to parent BlockStatement/Program
  3. Set up VariableDeclaration tokens and attach to inner VariableDeclarator (e.g. startToken.prev/endToken.next)
  4. Connect VariableDeclaration tokens prev/next (unless HEAD/TAIL, in which case trade places with original varDeclaration.startToken/varDeclaration.endToken)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant