postcss-styl
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -98,15 +98,57 @@ "use strict" | ||
/** | ||
* Remove commnets on selector | ||
* @param {string} selector | ||
* @returns {string} removed comments | ||
*/ | ||
function removeLastCommentsSelector(selector) { | ||
return selector.replace(/\/\/.*$/u, "").replace(/\/\*.*\*\/\s*$/u, "") | ||
} | ||
/** | ||
* Adjust selectors indent | ||
* @param {node} node | ||
* @param {string} selectors | ||
* @param {string} indent | ||
* @returns {string} indented selectors | ||
*/ | ||
function adjustSelectorsIndent(node, selectors, indent) { | ||
const lines = toLines(selectors) | ||
return lines | ||
.map((line, index) => { | ||
const trimed = line.trim() | ||
if (!trimed) { | ||
// ignore blank line | ||
return line | ||
} | ||
if (!node.pythonic) { | ||
// If it is not pythonic, adjust the indentation other than comma delimiter. | ||
if (/^,/u.test(trimed)) { | ||
return line | ||
} | ||
const lastLine = lines[index - 1] | ||
if ( | ||
lastLine && | ||
/,$/u.test(removeLastCommentsSelector(lastLine).trim()) | ||
) { | ||
return line | ||
} | ||
} | ||
return index === 0 | ||
? line.replace(/^\s*/u, "") | ||
: line.replace(/^\s*/u, indent) | ||
}) | ||
.join("") | ||
} | ||
module.exports = class StylusStringifier extends Stringifier { | ||
rawValue(node, prop) { | ||
const value = this.rawValuePlain(node, prop) | ||
if ( | ||
prop === "selector" && | ||
node.parent && | ||
node.parent.pythonic && | ||
/\r\n|\r|\n/gu.test(value) | ||
) { | ||
if (prop === "selector" && /\r\n|\r|\n/gu.test(value)) { | ||
const indent = this.getIndent(node) | ||
return toLines(value) | ||
.map(line => line.replace(/^\s+/u, indent)) | ||
.join("") | ||
return adjustSelectorsIndent(node, value, indent) | ||
} | ||
@@ -113,0 +155,0 @@ return value |
{ | ||
"name": "postcss-styl", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "PostCSS parser plugin for converting Stylus syntax to PostCSS AST.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118526
3606