postcss-styl
Advanced tools
Comparing version 0.5.3 to 0.5.4
@@ -56,33 +56,42 @@ "use strict" | ||
function getSelectors(sourceCode, selectorLocations) { | ||
if (selectorLocations.length <= 0) { | ||
return [] | ||
} | ||
const selectors = [] | ||
let nextStartIndex = 0 | ||
for (const selectorLocation of selectorLocations) { | ||
if (nextStartIndex > selectorLocation[1]) { | ||
continue | ||
} | ||
const selector = [] | ||
const endIndex = selectorLocation[1] | ||
const cursor = sourceCode.createScopeTokenCursor( | ||
Math.max(selectorLocation[0], nextStartIndex) | ||
) | ||
const startIndex = selectorLocations[0][0] | ||
const endIndex = selectorLocations[selectorLocations.length - 1][1] | ||
let token = cursor.next() | ||
while (token) { | ||
if (endIndex < token.range[0] && cursor.scopeLevel === 0) { | ||
nextStartIndex = token.range[0] | ||
break | ||
} | ||
const cursor = sourceCode.createScopeTokenCursor(startIndex, { | ||
endLocationIndex: endIndex, | ||
}) | ||
let token = cursor.next() | ||
let selector = [] | ||
let linebreak = false | ||
while (token) { | ||
if (token.value === "," && cursor.scopeLevel === 0) { | ||
selector.push(token) | ||
token = cursor.next() | ||
selectors.push(selector) | ||
selector = [] | ||
linebreak = false | ||
} else if (token.type === "linebreak" && cursor.scopeLevel === 0) { | ||
selector.push(token) | ||
linebreak = true | ||
} else if ( | ||
linebreak && | ||
token.type !== "whitespace" && | ||
token.type !== "linebreak" && | ||
token.type !== "comment" && | ||
token.type !== "inline-comment" | ||
) { | ||
selectors.push(selector) | ||
selector = [] | ||
linebreak = false | ||
selector.push(token) | ||
} else { | ||
selector.push(token) | ||
} | ||
const str = selector | ||
.map(t => t.value) | ||
.join("") | ||
.trim() | ||
if (str === "," || str === "") { | ||
selectors[selectors.length - 1].push(...selector) | ||
continue | ||
} | ||
token = cursor.next() | ||
} | ||
if (selector.length > 0) { | ||
selectors.push(selector) | ||
@@ -89,0 +98,0 @@ } |
{ | ||
"name": "postcss-styl", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"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
118830
3616