Skip to content
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

Use most common scenario to speedup print_selector #78

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export function format(css, { minify = false } = {}) {
*/
function substr(node) {
let loc = node.loc

// If there's no location data, e.g. when using space toggles
if (!loc) return EMPTY_STRING

let start = loc.start
Expand Down Expand Up @@ -132,6 +134,18 @@ export function format(css, { minify = false } = {}) {

children.forEach((child) => {
switch (child.type) {
case TYPE_SELECTORLIST: {
child.children.forEach((grandchild, item) => {
if (grandchild.type === TYPE_SELECTOR) {
buffer += print_simple_selector(grandchild)
}

if (item.next) {
buffer += ',' + SPACE
}
})
break
}
case 'Combinator': {
// putting spaces around `child.name` (+ > ~ or ' '), unless the combinator is ' '
buffer += SPACE
Expand Down Expand Up @@ -164,18 +178,6 @@ export function format(css, { minify = false } = {}) {
}
break
}
case TYPE_SELECTORLIST: {
child.children.forEach((grandchild, item) => {
if (grandchild.type === TYPE_SELECTOR) {
buffer += print_simple_selector(grandchild)
}

if (item.next) {
buffer += ',' + SPACE
}
})
break
}
case 'Nth': {
let nth = child.nth
if (nth) {
Expand Down
Loading