Skip to content

Commit

Permalink
Don't collapse whitespaces inside comments #17
Browse files Browse the repository at this point in the history
  • Loading branch information
maltsev committed Feb 9, 2016
1 parent 873a1f2 commit a916e20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/modules/collapseWhitespace.es6
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { isComment } from '../helpers';


const noWhitespaceCollapseElements = ['script', 'style', 'pre', 'textarea'];


Expand All @@ -8,7 +11,7 @@ export default function collapseWhitespace(tree, options, collapseType) {
}

tree.forEach((node, index) => {
if (typeof node === 'string') {
if (typeof node === 'string' && ! isComment(node)) {
node = collapseRedundantWhitespaces(node, collapseType);
}

Expand Down
9 changes: 6 additions & 3 deletions test/modules/collapseWhitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ describe('collapseWhitespace', () => {
);
});

it('should not collapse whitespaces inside <script>, <style>, <pre>, <textarea>', () => {
it('should not collapse whitespaces inside comments, <script>, <style>, <pre>, <textarea>', () => {
return init(
' <script> alert() </script> <style>.foo {}</style> <pre> hello <b> , </b> </pre> <textarea> world! </textarea> ',
'<script> alert() </script><style>.foo {}</style><pre> hello <b> , </b> </pre><textarea> world! </textarea>',
` <script> alert() </script> <style>.foo {}</style> <pre> hello <b> , </b> </pre>
<div> <!-- hello world --> </div>
<textarea> world! </textarea> `,
'<script> alert() </script><style>.foo {}</style><pre> hello <b> , </b> </pre>' +
'<div><!-- hello world --></div><textarea> world! </textarea>',
options
);
});
Expand Down

0 comments on commit a916e20

Please sign in to comment.