From 97ef316af884446835460706901a1b16d11259c8 Mon Sep 17 00:00:00 2001 From: Jack McDade Date: Fri, 8 Dec 2017 16:05:54 -0500 Subject: [PATCH 1/2] Prevent @apply from adding !important. --- __tests__/applyAtRule.test.js | 9 +++++++++ src/lib/substituteClassApplyAtRules.js | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/__tests__/applyAtRule.test.js b/__tests__/applyAtRule.test.js index 98a47b9d2..9fae80be5 100644 --- a/__tests__/applyAtRule.test.js +++ b/__tests__/applyAtRule.test.js @@ -14,6 +14,15 @@ test("it copies a class's declarations into itself", () => { }) }) +test("it removes important from applied classes", () => { + const output = '.a { color: red !important; } .b { color: red; }' + + return run('.a { color: red !important; } .b { @apply .a; }').then(result => { + expect(result.css).toEqual(output) + expect(result.warnings().length).toBe(0) + }) +}) + test('it fails if the class does not exist', () => { return run('.b { @apply .a; }').catch(e => { expect(e).toMatchObject({ name: 'CssSyntaxError' }) diff --git a/src/lib/substituteClassApplyAtRules.js b/src/lib/substituteClassApplyAtRules.js index 7517bbe08..2ee3eeb0e 100644 --- a/src/lib/substituteClassApplyAtRules.js +++ b/src/lib/substituteClassApplyAtRules.js @@ -58,6 +58,10 @@ export default function() { }) }) + decls.forEach((decl) => { + decl.important = false + }) + atRule.before(decls) atRule.params = customProperties.join(' ') From c84886e32eb8389a52a9b0ed028954434393d501 Mon Sep 17 00:00:00 2001 From: Jack McDade Date: Fri, 8 Dec 2017 16:15:58 -0500 Subject: [PATCH 2/2] Adjust syntax style to fit standards --- __tests__/applyAtRule.test.js | 2 +- src/lib/substituteClassApplyAtRules.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/applyAtRule.test.js b/__tests__/applyAtRule.test.js index 9fae80be5..52cf6f795 100644 --- a/__tests__/applyAtRule.test.js +++ b/__tests__/applyAtRule.test.js @@ -14,7 +14,7 @@ test("it copies a class's declarations into itself", () => { }) }) -test("it removes important from applied classes", () => { +test('it removes important from applied classes', () => { const output = '.a { color: red !important; } .b { color: red; }' return run('.a { color: red !important; } .b { @apply .a; }').then(result => { diff --git a/src/lib/substituteClassApplyAtRules.js b/src/lib/substituteClassApplyAtRules.js index 2ee3eeb0e..7305a6001 100644 --- a/src/lib/substituteClassApplyAtRules.js +++ b/src/lib/substituteClassApplyAtRules.js @@ -58,7 +58,7 @@ export default function() { }) }) - decls.forEach((decl) => { + decls.forEach(decl => { decl.important = false })