diff --git a/src/parser-postcss.js b/src/parser-postcss.js index d4e782b6..7b0ab863 100644 --- a/src/parser-postcss.js +++ b/src/parser-postcss.js @@ -212,7 +212,7 @@ function requireParser(isSCSS) { } function parse(text) { - const isLikelySCSS = !!text.match(/(\w\s*: [^}:]+|#){/); + const isLikelySCSS = !!text.match(/(\w\s*: [^}:]+|#){|\@import url/); try { return parseWithParser(requireParser(isLikelySCSS), text); } catch (e) { diff --git a/src/printer.js b/src/printer.js index 24d27eb7..103310f0 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2604,7 +2604,15 @@ function genericPrintNoParens(path, options, print, args) { } // postcss-media-query-parser case "media-query-list": { - return join(", ", path.map(print, "nodes")); + const parts = []; + path.each(childPath => { + const node = childPath.getValue(); + if (node.type === "media-query" && node.value === "") { + return; + } + parts.push(childPath.call(print)); + }, "nodes"); + return join(", ", parts); } case "media-query": { return join(" ", path.map(print, "nodes")); @@ -2630,6 +2638,9 @@ function genericPrintNoParens(path, options, print, args) { case "media-keyword": { return n.value; } + case "media-url": { + return n.value; + } case "media-unknown": { return n.value; } diff --git a/tests/css_import/__snapshots__/jsfmt.spec.js.snap b/tests/css_import/__snapshots__/jsfmt.spec.js.snap index 9398c12e..b1eece2f 100644 --- a/tests/css_import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/css_import/__snapshots__/jsfmt.spec.js.snap @@ -6,3 +6,12 @@ exports[`directives.css 1`] = ` @import (multiple) "foo.less"; `; + +exports[`url.css 1`] = ` +@import url('foo'); +$dir: 'fonts'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +@import url('foo'); +$dir: 'fonts'; + +`; diff --git a/tests/css_import/url.css b/tests/css_import/url.css new file mode 100644 index 00000000..e91b68d7 --- /dev/null +++ b/tests/css_import/url.css @@ -0,0 +1,2 @@ +@import url('foo'); +$dir: 'fonts';