From 1b68e752d7c3407860cda9bc529762078e682846 Mon Sep 17 00:00:00 2001 From: Sebastian Werner Date: Wed, 16 Aug 2017 20:19:19 +0200 Subject: [PATCH 1/4] Added failed test for @import-normalize --- test/importTest.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/importTest.js b/test/importTest.js index f52425fa..56b5e1a5 100644 --- a/test/importTest.js +++ b/test/importTest.js @@ -66,4 +66,7 @@ describe("import", function() { test("import disabled", "@import url(test.css);\n.class { a: b c d; }", [ [1, "@import url(test.css);\n.class { a: b c d; }", ""] ], "?-import"); + test("@import-normalize left untouched", "@import-normalize;", [ + [1, "@import-normalize;", ""] + ]); }); From 3b25b935687f61b433e6a903c24f69fabe7f4bfe Mon Sep 17 00:00:00 2001 From: Sebastian Werner Date: Wed, 16 Aug 2017 20:22:18 +0200 Subject: [PATCH 2/4] Fixed import handling not matching import like constructs. --- lib/processCss.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/processCss.js b/lib/processCss.js index 8c688e34..f18320fd 100644 --- a/lib/processCss.js +++ b/lib/processCss.js @@ -42,7 +42,7 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) { } if(options.import) { - css.walkAtRules(/import/i, function(rule) { + css.walkAtRules(/^import$/i, function(rule) { var values = Tokenizer.parseValues(rule.params); var url = values.nodes[0].nodes[0]; if(url.type === "url") { From 308755930ad24de21361151c7718f1e942bae8d4 Mon Sep 17 00:00:00 2001 From: Sebastian Werner Date: Wed, 16 Aug 2017 20:23:16 +0200 Subject: [PATCH 3/4] Made tolerant for null match on urls inside import --- lib/processCss.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/processCss.js b/lib/processCss.js index f18320fd..944bc89f 100644 --- a/lib/processCss.js +++ b/lib/processCss.js @@ -45,9 +45,9 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) { css.walkAtRules(/^import$/i, function(rule) { var values = Tokenizer.parseValues(rule.params); var url = values.nodes[0].nodes[0]; - if(url.type === "url") { + if(url && url.type === "url") { url = url.url; - } else if(url.type === "string") { + } else if(url && url.type === "string") { url = url.value; } else throw rule.error("Unexpected format " + rule.params); if (!url.replace(/\s/g, '').length) { From be3eef5e5a825e349a6323c044d4fbc3542f98ce Mon Sep 17 00:00:00 2001 From: Sebastian Werner Date: Wed, 16 Aug 2017 22:07:13 +0200 Subject: [PATCH 4/4] Added request test case --- test/importTest.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/importTest.js b/test/importTest.js index 56b5e1a5..f3cdba58 100644 --- a/test/importTest.js +++ b/test/importTest.js @@ -1,6 +1,10 @@ /*globals describe */ -var test = require("./helpers").test; +var assert = require('assert'); + +var helpers = require("./helpers"); +var test = helpers.test; +var testError = helpers.testError; describe("import", function() { test("import", "@import url(test.css);\n.class { a: b c d; }", [ @@ -69,4 +73,13 @@ describe("import", function() { test("@import-normalize left untouched", "@import-normalize;", [ [1, "@import-normalize;", ""] ]); -}); + testError("@import without url", "@import;", function(err) { + assert.equal(err.message, [ + 'Unexpected format (1:1)', + '', + '> 1 | @import;', + ' | ^', + '', + ].join('\n')) + }) +})