Skip to content

Commit

Permalink
Fixed 150
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored and jonathantneal committed Sep 17, 2018
1 parent 4c6dfdb commit ccd499a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/__tests__/attributes.js
Expand Up @@ -401,6 +401,32 @@ test('non standard modifiers', '[href="foo" y]', (t, tree) => {
t.deepEqual(tree.toString(), '[href="foo" y]');
});

test('comment after insensitive(non space)', '[href="foo" i/**/]', (t, tree) => {
// https://github.com/postcss/postcss-selector-parser/issues/150
let attr = tree.atPosition(1, 13);
t.deepEqual(attr.insensitive, true);
t.deepEqual(attr.insensitiveFlag, 'i');
t.is(attr.raws.insensitiveFlag, undefined);
t.deepEqual(attr.raws.spaces.insensitive.after, '/**/');
t.deepEqual(tree.toString(), '[href="foo" i/**/]');
});

test('comment after insensitive(space after)', '[href="foo" i/**/ ]', (t, tree) => {
let attr = tree.atPosition(1, 13);
t.deepEqual(attr.insensitive, true);
t.deepEqual(attr.insensitiveFlag, 'i');
t.deepEqual(attr.raws.spaces.insensitive.after, '/**/ ');
t.deepEqual(tree.toString(), '[href="foo" i/**/ ]');
});

test('comment after insensitive(space before)', '[href="foo" i /**/]', (t, tree) => {
let attr = tree.atPosition(1, 13);
t.deepEqual(attr.insensitive, true);
t.deepEqual(attr.insensitiveFlag, 'i');
t.deepEqual(attr.raws.spaces.insensitive.after, ' /**/');
t.deepEqual(tree.toString(), '[href="foo" i /**/]');
});

const testDeprecation = nodeVersionAtLeast('7.0.0') || nodeVersionBefore('6.0.0') ? test : test.skip;

testDeprecation('deprecated constructor', '', (t) => {
Expand Down
4 changes: 3 additions & 1 deletion src/parser.js
Expand Up @@ -357,7 +357,9 @@ export default class Parser {
break;
case tokens.comment:
if (lastAdded) {
if (spaceAfterMeaningfulToken || (next && next[TOKEN.TYPE] === tokens.space)) {
if (spaceAfterMeaningfulToken || (next && next[TOKEN.TYPE] === tokens.space) ||
lastAdded === 'insensitive'
) {
const lastComment = getProp(node, 'spaces', lastAdded, 'after') || '';
const rawLastComment = getProp(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;

Expand Down

1 comment on commit ccd499a

@jonathantneal
Copy link
Member

Choose a reason for hiding this comment

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

This resolves an issue with comments after attribute insensitive flags. I incorrectly named the commit. For more details, see #151

Please sign in to comment.