Skip to content

Conversation

@alexlamsl
Copy link
Collaborator

Prefer sub-optimal sort over extraneous whitespaces.

fixes #805

Prefer sub-optimal sort over extraneous whitespaces.

fixes #805
output = '<span class="sprite sprite-{{sprite}}"></span> <span class="{{sprite}}"></span>';
assert.equal(minify(input, {
collapseWhitespace: true,
ignoreCustomFragments: [/{{.*}}/],
Copy link
Contributor

Choose a reason for hiding this comment

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

While it doesn't really matter with this input, I prefer using non-greedy .*? so it does not match unintential parts when multiple {{}} expressions are on the same line, for example: https://regex101.com/r/M50E40/1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm well aware of that, just didn't worry too much as this is a single test case of specific input.

As you can see in https://github.com/kangax/html-minifier#options-quick-reference, the default values for ignoreCustomFragments is not only non-greedy, but can also handle multi-line values in between the template markers.

Nonetheless, I'll add the ? to make it easier for your eyes. 😉

Copy link
Contributor

@silverwind silverwind left a comment

Choose a reason for hiding this comment

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

LGTM, wasn't able to reproduce the issue anymore with a few variations of inputs.

var minify = require('.').minify;
var opts = {
  collapseWhitespace: true,
  ignoreCustomFragments: [/{{.*?}}/],
  sortClassName: true,
};

console.log(minify(`<span class="sprite sprite-{{sprite}}"></span>`, opts));
console.log(minify(`<span class="{{sprite}}"></span>`, opts));
console.log(minify(`<span class="{{sprite}}-sprite sprite"></span>`, opts));
console.log(minify(`<span class="sprite-{{sprite}}-sprite"></span>`, opts));
console.log(minify(`<span class={{sprite}}></span>`, opts));
@alexlamsl
Copy link
Collaborator Author

@silverwind thanks for taking a look. I've expanded the tests using your example.

@alexlamsl alexlamsl merged commit b7b32cf into gh-pages May 6, 2017
@alexlamsl alexlamsl deleted the issue-805 branch May 6, 2017 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants