Add support for media-url (#1797)

master
Christopher Chedeau 2017-05-29 08:20:03 -07:00 committed by GitHub
parent c9159f7862
commit bf5f9cc05d
4 changed files with 24 additions and 2 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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';
`;

2
tests/css_import/url.css Normal file
View File

@ -0,0 +1,2 @@
@import url('foo');
$dir: 'fonts';