Skip to content

Commit 8f0232b

Browse files
refactor: use snapshots for some tests (webpack-contrib#805)
1 parent 7a6ff03 commit 8f0232b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5345
-2107
lines changed

lib/postcss-css-loader-parser.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const loaderUtils = require('loader-utils');
66

77
module.exports = postcss.plugin(
88
'postcss-css-loader-parser',
9-
(options) => (css) => {
9+
(options) => (css, result) => {
1010
const imports = {};
1111
let exports = {};
1212
const importItems = [];
@@ -32,18 +32,42 @@ module.exports = postcss.plugin(
3232
}
3333

3434
if (options.import) {
35-
css.walkAtRules(/^import$/i, (rule) => {
36-
const values = Tokenizer.parseValues(rule.params);
35+
css.walkAtRules(/^import$/i, (atrule) => {
36+
// Convert only top-level @import
37+
if (atrule.parent.type !== 'root') {
38+
return;
39+
}
40+
41+
if (atrule.nodes) {
42+
result.warn(
43+
"It looks like you didn't end your @import statement correctly. " +
44+
'Child nodes are attached to it.',
45+
{ node: atrule }
46+
);
47+
return;
48+
}
49+
50+
const values = Tokenizer.parseValues(atrule.params);
3751
let [url] = values.nodes[0].nodes;
52+
3853
if (url && url.type === 'url') {
3954
({ url } = url);
4055
} else if (url && url.type === 'string') {
4156
url = url.value;
42-
} else throw rule.error(`Unexpected format ${rule.params}`);
57+
} else {
58+
result.warn(`Unable to find uri in '${atrule.toString()}'`, {
59+
node: atrule,
60+
});
61+
62+
return;
63+
}
64+
4365
if (!url.replace(/\s/g, '').length) {
4466
return;
4567
}
68+
4669
values.nodes[0].nodes.shift();
70+
4771
const mediaQuery = Tokenizer.stringifyValues(values);
4872

4973
if (loaderUtils.isUrlRequest(url)) {
@@ -54,7 +78,7 @@ module.exports = postcss.plugin(
5478
url,
5579
mediaQuery,
5680
});
57-
rule.remove();
81+
atrule.remove();
5882
});
5983
}
6084

0 commit comments

Comments
 (0)