From 0dccbc555136e3143439bfff83177c4300acad9a Mon Sep 17 00:00:00 2001 From: David Evans Date: Thu, 10 Apr 2014 11:00:58 -0700 Subject: [PATCH 1/5] Re-parse input JSON to normalize line endings on different platforms. --- test/css-parse.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/css-parse.js b/test/css-parse.js index 81312b1..a1a623c 100644 --- a/test/css-parse.js +++ b/test/css-parse.js @@ -18,6 +18,8 @@ describe('parse(str)', function(){ var css = read(path.join('test', 'cases', file + '.css'), 'utf8'); var json = read(path.join('test', 'cases', file + '.json'), 'utf8'); var ret = parse(css, { source: file + '.css' }); + json = JSON.parse(json); + json = JSON.stringify(ret, null, 2); ret = JSON.stringify(ret, null, 2); ret.should.equal(json); }) From 160156694a20834eed6adfa724e60c94334c767d Mon Sep 17 00:00:00 2001 From: David Evans Date: Thu, 10 Apr 2014 11:12:55 -0700 Subject: [PATCH 2/5] Add test for :-ms-lang() support --- test/cases/ms-lang.css | 3 +++ test/cases/ms-lang.json | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/cases/ms-lang.css create mode 100644 test/cases/ms-lang.json diff --git a/test/cases/ms-lang.css b/test/cases/ms-lang.css new file mode 100644 index 0000000..7507073 --- /dev/null +++ b/test/cases/ms-lang.css @@ -0,0 +1,3 @@ +foo:-ms-lang( ar, dv, fa, he, ku-Arab, pa-Arab, prs, ps, sd-Arab, syr, ug, ur, qps-plocm) { + bar: 'baz'; +} \ No newline at end of file diff --git a/test/cases/ms-lang.json b/test/cases/ms-lang.json new file mode 100644 index 0000000..36a0145 --- /dev/null +++ b/test/cases/ms-lang.json @@ -0,0 +1,42 @@ +{ + "type": "stylesheet", + "stylesheet": { + "rules": [ + { + "type": "rule", + "selectors": [ + "foo:-ms-lang(ar, dv, fa, he, ku-Arab, pa-Arab, prs, ps, sd-Arab, syr, ug, ur, qps-plocm)" + ], + "declarations": [ + { + "type": "declaration", + "property": "bar", + "value": "'baz'", + "position": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 13 + }, + "source": "rule.css" + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + }, + "source": "rule.css" + } + } + ] + } +} \ No newline at end of file From 6ddf8ae414647ec6da17f403635e3b0555a9fadb Mon Sep 17 00:00:00 2001 From: David Evans Date: Thu, 10 Apr 2014 12:49:23 -0700 Subject: [PATCH 3/5] Fix typo in test changes --- test/cases/ms-lang.css | 2 +- test/cases/ms-lang.json | 4 ++-- test/css-parse.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cases/ms-lang.css b/test/cases/ms-lang.css index 7507073..44d37de 100644 --- a/test/cases/ms-lang.css +++ b/test/cases/ms-lang.css @@ -1,3 +1,3 @@ -foo:-ms-lang( ar, dv, fa, he, ku-Arab, pa-Arab, prs, ps, sd-Arab, syr, ug, ur, qps-plocm) { +foo:-ms-lang(ar, dv, fa, he, ku-Arab, pa-Arab, prs, ps, sd-Arab, syr, ug, ur, qps-plocm) { bar: 'baz'; } \ No newline at end of file diff --git a/test/cases/ms-lang.json b/test/cases/ms-lang.json index 36a0145..d455cbe 100644 --- a/test/cases/ms-lang.json +++ b/test/cases/ms-lang.json @@ -21,7 +21,7 @@ "line": 2, "column": 13 }, - "source": "rule.css" + "source": "ms-lang.css" } } ], @@ -34,7 +34,7 @@ "line": 3, "column": 2 }, - "source": "rule.css" + "source": "ms-lang.css" } } ] diff --git a/test/css-parse.js b/test/css-parse.js index a1a623c..1562d4a 100644 --- a/test/css-parse.js +++ b/test/css-parse.js @@ -19,7 +19,7 @@ describe('parse(str)', function(){ var json = read(path.join('test', 'cases', file + '.json'), 'utf8'); var ret = parse(css, { source: file + '.css' }); json = JSON.parse(json); - json = JSON.stringify(ret, null, 2); + json = JSON.stringify(json, null, 2); ret = JSON.stringify(ret, null, 2); ret.should.equal(json); }) From 01b3748e8959e8e3786ba69837280d57a05f2efc Mon Sep 17 00:00:00 2001 From: David Evans Date: Thu, 10 Apr 2014 12:50:26 -0700 Subject: [PATCH 4/5] Modify regex of selector() parse to ignore commas inside parenthesis (to handle :-ms-lang(ar, en)) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b950bb8..8491702 100644 --- a/index.js +++ b/index.js @@ -191,7 +191,7 @@ module.exports = function(css, options){ if (!m) return; /* @fix Remove all comments from selectors * http://ostermiller.org/findcomment.html */ - return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').split(/\s*,\s*/); + return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').split(/\s*(?![^(]*\)),\s*/); } /** From 1be9a03b1ab60934c3502b4d7d5625ad608aae1e Mon Sep 17 00:00:00 2001 From: David Evans Date: Fri, 11 Apr 2014 11:49:56 -0700 Subject: [PATCH 5/5] Add a comment --- test/css-parse.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/css-parse.js b/test/css-parse.js index 1562d4a..9b5cba1 100644 --- a/test/css-parse.js +++ b/test/css-parse.js @@ -18,6 +18,7 @@ describe('parse(str)', function(){ var css = read(path.join('test', 'cases', file + '.css'), 'utf8'); var json = read(path.join('test', 'cases', file + '.json'), 'utf8'); var ret = parse(css, { source: file + '.css' }); + // Normalize line endings from input file json = JSON.parse(json); json = JSON.stringify(json, null, 2); ret = JSON.stringify(ret, null, 2);