From d599337502d5c9717c35172216e5e4760d3dc712 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Wed, 28 May 2014 11:00:19 -0700 Subject: [PATCH 1/2] Add support for @host --- History.md | 20 ++++++++++---------- lib/compress.js | 11 +++++++++++ lib/identity.js | 15 +++++++++++++++ test/cases/host.compressed.css | 1 + test/cases/host.css | 5 +++++ 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 test/cases/host.compressed.css create mode 100644 test/cases/host.css diff --git a/History.md b/History.md index 6a916b8..a35765a 100644 --- a/History.md +++ b/History.md @@ -9,20 +9,20 @@ * add source map generation -1.3.2 / 2013-10-18 +1.3.2 / 2013-10-18 ================== * fix whitespace and indentation in the Compressed compiler. * add @namespace support * add .stylesheet(node) -1.3.1 / 2013-06-02 +1.3.1 / 2013-06-02 ================== * fix output of rules with no declarations for Identity compiler * fix defaulting of options -1.3.0 / 2013-05-28 +1.3.0 / 2013-05-28 ================== * add ignoring of empty rulesets. Closes #7 @@ -33,38 +33,38 @@ * fix trailing ; with comments within rules * fix comment indentation -1.2.0 / 2013-05-21 +1.2.0 / 2013-05-21 ================== * add @document compilation. Closes #82 -1.1.0 / 2013-03-19 +1.1.0 / 2013-03-19 ================== * add omission of comments when compressed * add comment support -1.0.5 / 2013-03-15 +1.0.5 / 2013-03-15 ================== * fix indentation of multiple selectors in @media. Closes #11 -1.0.4 / 2012-11-15 +1.0.4 / 2012-11-15 ================== * fix indentation -1.0.3 / 2012-09-04 +1.0.3 / 2012-09-04 ================== * add __@charset__ support [rstacruz] -1.0.2 / 2012-09-01 +1.0.2 / 2012-09-01 ================== * add component support -1.0.1 / 2012-07-26 +1.0.1 / 2012-07-26 ================== * add "selectors" array support diff --git a/lib/compress.js b/lib/compress.js index c1309f0..98c105a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -155,6 +155,17 @@ Compiler.prototype['font-face'] = function(node){ + this.emit('}'); }; +/** + * Visit host node. + */ + +Compiler.prototype.host = function(node){ + return this.emit('@host', node.position, true) + + this.emit('{') + + this.mapVisit(node.rules) + + this.emit('}'); +}; + /** * Visit rule node. */ diff --git a/lib/identity.js b/lib/identity.js index f20c4b9..2dc891b 100644 --- a/lib/identity.js +++ b/lib/identity.js @@ -187,6 +187,21 @@ Compiler.prototype['font-face'] = function(node){ + this.emit('\n}'); }; +/** + * Visit host node. + */ + +Compiler.prototype.host = function(node){ + return this.emit('@host', node.position, true) + + this.emit( + ' {\n' + + this.indent(1)) + + this.mapVisit(node.rules, '\n\n') + + this.emit( + this.indent(-1) + + '\n}'); +}; + /** * Visit rule node. */ diff --git a/test/cases/host.compressed.css b/test/cases/host.compressed.css new file mode 100644 index 0000000..509667c --- /dev/null +++ b/test/cases/host.compressed.css @@ -0,0 +1 @@ +@host{:scope{display:block;}} diff --git a/test/cases/host.css b/test/cases/host.css new file mode 100644 index 0000000..0ec989c --- /dev/null +++ b/test/cases/host.css @@ -0,0 +1,5 @@ +@host { + :scope { + display: block; + } +} From 8751db3855950d4e8a405628b1cb1fc0ebee03e8 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Wed, 28 May 2014 11:15:17 -0700 Subject: [PATCH 2/2] Add support for @custom-media Fix #34 --- lib/compress.js | 8 ++++++++ lib/identity.js | 8 ++++++++ test/cases/custom-media.css | 1 + 3 files changed, 17 insertions(+) create mode 100644 test/cases/custom-media.css diff --git a/lib/compress.js b/lib/compress.js index 98c105a..bdd5f1f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -166,6 +166,14 @@ Compiler.prototype.host = function(node){ + this.emit('}'); }; +/** + * Visit custom-media node. + */ + +Compiler.prototype['custom-media'] = function(node){ + return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position); +}; + /** * Visit rule node. */ diff --git a/lib/identity.js b/lib/identity.js index 2dc891b..9c8d3c9 100644 --- a/lib/identity.js +++ b/lib/identity.js @@ -202,6 +202,14 @@ Compiler.prototype.host = function(node){ + '\n}'); }; +/** + * Visit custom-media node. + */ + +Compiler.prototype['custom-media'] = function(node){ + return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position); +}; + /** * Visit rule node. */ diff --git a/test/cases/custom-media.css b/test/cases/custom-media.css new file mode 100644 index 0000000..035deba --- /dev/null +++ b/test/cases/custom-media.css @@ -0,0 +1 @@ +@custom-media --wide-window screen and (min-width: 40em);