Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

jimfleming
Copy link
Contributor

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.75%) when pulling e000c0d on jimfleming:block_statement into 358532a on rdio:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) when pulling 376b24a on jimfleming:block_statement into 358532a on rdio:master.

@jimfleming jimfleming mentioned this pull request Aug 8, 2014
@@ -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; }');
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@jimfleming
Copy link
Contributor Author

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:

  • Maybe we don't need to unwrap ExpressionStatement? I feel like I tried this and it caused different problems but we have more tests now.
  • Maybe this is a more fundamental problem with how I'm doing the rewriting.

@jimfleming
Copy link
Contributor Author

Needs a rewrite.

@jimfleming jimfleming closed this May 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BlockStatement rewrite discards unmatched content
3 participants