New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Program/BlockStatement rewrites #100
Conversation
@@ -40,7 +67,7 @@ describe('jsfmt.rewrite', function() { | |||
|
|||
// Inside of "BlockStatement" instead of "Program" | |||
jsfmt.rewrite('function test() { var myA = 1, myB = 2; }', 'var a = c, b = d; -> var a = c; var b = d;') | |||
.toString().should.eql('function test() {\n var myA = 1;\n var myB = 2;\n}'); | |||
.toString().should.eql('function test() { var myA = 1;\nvar myB = 2; }'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem exactly right:
function test() { var myA = 1, myB = 2; }
gets rewritten to:
function test() { var myA = 1;
var myB = 2; }
is this the actual expected? I would assume it shouldn't get the newline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yah. So, what happens now is that when rewriting it only mangles the matched expressions, without context. So only the matched expressions will be formatted, post-rewrite. It may make sense to explicitly re-format the entire output. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, we do that now dont we with rewriting? it'll reformat unless you give --no-format
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good point. So this is just the raw output from the rewrite before the formatting has been applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which actually might be ok, since we dont intend on testing formatting here, we want to test rewrite.
Unfortunately I haven't had the time to delve into this (I think its at least a day of work to sort it out). Some thoughts:
|
Needs a rewrite. |
Fixes #90
There is one failing test I haven't figured out how to fix yet. We need to unwrap
ExpressionStatements
for the general case but here if we don't then we end up with two semicolons.