Skip to content

Commit

Permalink
refactor: use snapshots for some tests (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Nov 26, 2018
1 parent 7a6ff03 commit 8f0232b
Show file tree
Hide file tree
Showing 45 changed files with 5,345 additions and 2,107 deletions.
34 changes: 29 additions & 5 deletions lib/postcss-css-loader-parser.js
Expand Up @@ -6,7 +6,7 @@ const loaderUtils = require('loader-utils');

module.exports = postcss.plugin(
'postcss-css-loader-parser',
(options) => (css) => {
(options) => (css, result) => {
const imports = {};
let exports = {};
const importItems = [];
Expand All @@ -32,18 +32,42 @@ module.exports = postcss.plugin(
}

if (options.import) {
css.walkAtRules(/^import$/i, (rule) => {
const values = Tokenizer.parseValues(rule.params);
css.walkAtRules(/^import$/i, (atrule) => {
// Convert only top-level @import
if (atrule.parent.type !== 'root') {
return;
}

if (atrule.nodes) {
result.warn(
"It looks like you didn't end your @import statement correctly. " +
'Child nodes are attached to it.',
{ node: atrule }
);
return;
}

const values = Tokenizer.parseValues(atrule.params);
let [url] = values.nodes[0].nodes;

if (url && url.type === 'url') {
({ url } = url);
} else if (url && url.type === 'string') {
url = url.value;
} else throw rule.error(`Unexpected format ${rule.params}`);
} else {
result.warn(`Unable to find uri in '${atrule.toString()}'`, {
node: atrule,
});

return;
}

if (!url.replace(/\s/g, '').length) {
return;
}

values.nodes[0].nodes.shift();

const mediaQuery = Tokenizer.stringifyValues(values);

if (loaderUtils.isUrlRequest(url)) {
Expand All @@ -54,7 +78,7 @@ module.exports = postcss.plugin(
url,
mediaQuery,
});
rule.remove();
atrule.remove();
});
}

Expand Down

0 comments on commit 8f0232b

Please sign in to comment.