Skip to content

Fix #90 - whitespace between mixin and !important is optional #91

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

Merged
merged 4 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lib/.less-parser.js.swp
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/less-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export default class LessParser extends Parser {
// eslint-disable-next-line
delete this.current.nodes;

if (node.selector.indexOf('!important') >= 0) {
if (/!important/i.test(node.selector)) {
node.important = true;
node.selector = node.selector.replace(/\s!important/, '');
node.selector = node.selector.replace(/\s*!important/i, '');
}

// rules don't have trailing semicolons in vanilla css, so they get
Expand Down
22 changes: 22 additions & 0 deletions test/parser/mixins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ describe('Parser', () => {
expect(root.first.important).to.eql(true);
});

it('parses nested mixins with `!important` - insensitive to casing', () => {
const code = `
.foo() !IMPoRTant;
`;

const root = parse(code);

expect(root.first.selector).to.eql('.foo()');
expect(root.first.important).to.eql(true);
});

it('parses nested mixins with `!important` - appended without whitespace', () => {
const code = `
.foo()!important;
`;

const root = parse(code);

expect(root.first.selector).to.eql('.foo()');
expect(root.first.important).to.eql(true);
});

it('parses nested mixins with the rule set', () => {
const params = '({background-color: red;})';
const ruleSet = `.desktop-and-old-ie ${ params }`;
Expand Down