-
-
Notifications
You must be signed in to change notification settings - Fork 608
Support for nested items #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,30 +77,55 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) { | |
exports[exportName] = replaceImportsInString(exports[exportName]); | ||
}); | ||
|
||
function processNode(item, isValue) { | ||
switch (item.type) { | ||
case "value": | ||
item.nodes.forEach(function(node){ | ||
processNode(node, true); | ||
}); | ||
break; | ||
case "nested-item": | ||
item.nodes.forEach(function(node){ | ||
processNode(node); | ||
}); | ||
break; | ||
case "item": | ||
var importIndex = imports["$" + item.name]; | ||
if (typeof importIndex === "number") { | ||
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___"; | ||
} | ||
break; | ||
case "url": | ||
if (!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) { | ||
item.stringType = ""; | ||
delete item.innerSpacingBefore; | ||
delete item.innerSpacingAfter; | ||
var url; | ||
|
||
if(isValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
{
type: "nested-item",
name: name,
nodes: [
{ type: "value", nodes: [...] }
]
} So I think you could remove this check here and always use the true case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using the true case makes the background img 2 test and the font face tests fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly, it was because in the case where it's processing a value, the urls in it were not transformed. |
||
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") { | ||
url = loaderUtils.urlToRequest(item.url, options.root); | ||
} else { | ||
url = item.url; | ||
} | ||
} else { | ||
url = item.url; | ||
} | ||
|
||
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___"; | ||
urlItems.push({ | ||
url: url | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
css.walkDecls(function(decl) { | ||
var values = Tokenizer.parseValues(decl.value); | ||
values.nodes.forEach(function(value) { | ||
value.nodes.forEach(function(item) { | ||
switch(item.type) { | ||
case "item": | ||
var importIndex = imports["$" + item.name]; | ||
if(typeof importIndex === "number") { | ||
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___"; | ||
} | ||
break; | ||
case "url": | ||
if(!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) { | ||
item.stringType = ""; | ||
delete item.innerSpacingBefore; | ||
delete item.innerSpacingAfter; | ||
var url = item.url; | ||
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___"; | ||
urlItems.push({ | ||
url: url | ||
}); | ||
} | ||
break; | ||
} | ||
value.nodes.forEach(function(node){ | ||
processNode(node); | ||
}); | ||
}); | ||
decl.value = Tokenizer.stringifyValues(values); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what reason is
isValue
tracked?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it should be named differently, but it's basically to reuse the same
processNode
logic on nested properties... should probably be namedisNested