Skip to content

Commit

Permalink
Fix tests and cherry picking comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed May 9, 2017
1 parent 3007c25 commit 042847d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 71 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function selectors(parent, node) {

function pickComment(comment, after) {
if ( comment && comment.type === 'comment' ) {
return after.after(comment);
after.after(comment);
return comment;
} else {
return after;
}
Expand Down
108 changes: 38 additions & 70 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,125 +11,93 @@ function run(input, output, opts) {
}

it('unwraps rule inside rule', () => {
run('a { a: 1 } a { a: 1; b { b: 2; c { c: 3 } } }',
'a { a: 1 } a { a: 1; } a b { b: 2; } a b c { c: 3 }');
return run('a { a: 1 } a { a: 1; b { b: 2; c { c: 3 } } }',
'a { a: 1 } a { a: 1; } a b { b: 2; } a b c { c: 3 }');
});

it('cleans rules after unwrap', () => {
run('a { b .one {} b .two {} }',
'a b .one {}\na b .two {}');
return run('a { b .one {} b .two {} }',
'a b .one {} a b .two {}');
});

it('replaces ampersand', () => {
run('a { body &:hover b {} }',
'body a:hover b {}');
return run('a { body &:hover b {} }',
'body a:hover b {}');
});

it('replaces ampersands', () => {
run('a { &:hover, &:active {} }',
'a:hover, a:active {}');
return run('a { &:hover, &:active {} }',
'a:hover, a:active {}');
});

it('replaces ampersand in string', () => {
run('.block { &_elem {} }',
'.block_elem {}');
return run('.block { &_elem {} }',
'.block_elem {}');
});

it('unwrap rules inside at-rules', () => {
run('@media (max-width: 500px) { a { b {} } }',
'@media (max-width: 500px) { a b {} }');
return run('@media (max-width: 500px) { a { b {} } }',
'@media (max-width: 500px) { a b {} }');
});

it('unwraps at-rule', () => {
run('a { b { @media screen { width: auto } } }',
'@media screen {\n a b {\n width: auto\n }\n}');
return run('a { b { @media screen { width: auto } } }',
'@media screen {a b { width: auto } }');
});

it('unwraps at-rule with rules', () => {
run('a { @media screen { b { color: black } } }',
'@media screen {\n a b {\n color: black\n }\n}');
return run('a { @media screen { b { color: black } } }',
'@media screen { a b { color: black } }');
});

it('unwraps at-rules', () => {
run('a { a: 1 } a { @media screen { @supports (a: 1) { a: 1 } } }',
'a { a: 1 } @media screen { @supports (a: 1) { a { a: 1 } } }');
return run('a { a: 1 } a { @media screen { @supports (a: 1) { a: 1 } } }',
'a { a: 1 } @media screen { @supports (a: 1) { a { a: 1 } } }');
});

it('do not move custom at-rules', () => {
run('.one { @mixin test; } .two { @phone { color: black } }',
'.one { @mixin test; } @phone { .two { color: black } }',
{ bubble: ['phone'] });
return run('.one { @mixin test; } .two { @phone { color: black } }',
'.one { @mixin test; } @phone { .two { color: black } }',
{ bubble: ['phone'] });
});

it('supports bubble option with at-name', () => {
run('a { @phone { color: black } }',
'@phone {\n a {\n color: black\n }\n}',
{ bubble: ['@phone'] });
return run('a { @phone { color: black } }',
'@phone {a { color: black } }',
{ bubble: ['@phone'] });
});

it('processes comma', () => {
run('.one, .two { a {} }',
'.one a, .two a {}');
return run('.one, .two { a {} }',
'.one a, .two a {}');
});

it('processes comma with ampersand', () => {
run('.one, .two { &:hover {} }',
'.one:hover, .two:hover {}');
return run('.one, .two { &:hover {} }',
'.one:hover, .two:hover {}');
});

it('processes comma inside', () => {
run('a, b { .one, .two {} }',
'a .one, a .two, b .one, b .two {}');
return run('a, b { .one, .two {} }',
'a .one, a .two, b .one, b .two {}');
});

it('moves comment with rule', () => {
run('a {\n /*B*/\n b {}\n}',
'/*B*/\na b {}');
return run('a { /*B*/ b {} }',
'/*B*/ a b {}');
});

it('moves comment with at-rule', () => {
run('a {\n /*B*/\n @media {\n one: 1\n }\n}',
'/*B*/\n@media {\n a {\n one: 1\n }\n}');
return run('a { /*B*/ @media { one: 1 } }',
'/*B*/ @media {a { one: 1 } }');
});

it('moves comment with declaration', () => {
run('a {\n @media {\n /*B*/\n one: 1\n }\n}',
'@media {\n a {\n /*B*/\n one: 1\n }\n}');
});

it('parses example', () => {
var input = '.phone {\n' +
' &_title {\n' +
' width: 500px;\n' +
' @media (max-width: 500px) {\n' +
' width: auto;\n' +
' }\n' +
' }\n' +
' body.is_dark &_title {\n' +
' color: white;\n' +
' }\n' +
' img {\n' +
' display: block;\n' +
' }\n' +
'}';
var output = '.phone_title {\n' +
' width: 500px;\n' +
'}\n' +
'@media (max-width: 500px) {\n' +
' .phone_title {\n' +
' width: auto;\n' +
' }\n' +
'}\n' +
'body.is_dark .phone_title {\n' +
' color: white;\n' +
'}\n' +
'.phone img {\n' +
' display: block;\n' +
'}';
run(input, output);
return run('a { @media { /*B*/ one: 1 } }',
'@media {a { /*B*/ one: 1 } }');
});

it('saves order of rules', () => {
run('.one { & .two {} & .tree {} }',
'.one .two {} .one .tree {}');
return run('.one { & .two {} & .tree {} }',
'.one .two {} .one .tree {}');
});

0 comments on commit 042847d

Please sign in to comment.