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

Correct regex for function source cleaning #2212

Merged
merged 1 commit into from Jun 11, 2016
Merged

Correct regex for function source cleaning #2212

merged 1 commit into from Jun 11, 2016

Conversation

ScottFreeCode
Copy link
Contributor

@ScottFreeCode ScottFreeCode commented Apr 15, 2016

Fixes #2208

  • Treat tabs etc. as spaces.
  • Match function name for removal.
  • Match only non-) inside the function parameter list for removal instead of .; prevents matching through later in the first line e.g. function(){ if ([condition]) { ....
  • Match 0 or more spaces before } on the end for removal rather than 1 or more.
  • Make the closing } optional for arrow functions with a single-statement body just like the opening {.
  • Add tests for these cases.

@ScottFreeCode
Copy link
Contributor Author


it('should handle named functions', function() {
clean('function withName() {\n//code\n}').should.equal('//code');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an it for when the function's name is followed by a space?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a quite common coding style.

@ScottFreeCode
Copy link
Contributor Author

Updated based on review.

- Treat tabs etc. as spaces.
- Match function name for removal.
- Match only non-`)` inside the function parameter list for removal instead of `.`; prevents matching through later in the first line e.g. `function(){ if ([condition]) { ...`.
- Match 0 or more spaces before } on the end for removal rather than 1 or more.
- Make the closing } optional for arrow functions with a single-statement body just like the opening {.
- Add tests for these cases.
@boneskull
Copy link
Member

looks good to me.

@boneskull boneskull merged commit 6ebee5a into mochajs:master Jun 11, 2016
@dasilvacontin
Copy link
Contributor

dasilvacontin commented Jun 11, 2016

yay 🎉

@ScottFreeCode ScottFreeCode deleted the fix/2208 branch June 12, 2016 01:44
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.

None yet

3 participants