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

Copy rule for declarations after nested rule #93

Merged

Conversation

demikhovr
Copy link
Contributor

@demikhovr demikhovr commented Jul 4, 2020

No description provided.

@demikhovr
Copy link
Contributor Author

demikhovr commented Jul 4, 2020

There's also another possible solution:

function pickDeclarations (child) {
  var result = []
  var next = child.next()

  while (next && next.type === 'decl') {
    result.push(next)
    next = next.next()
  }

  return result
}

function processRule (rule, bubble, unwrap, preserveEmpty) {
...
if (child.type === 'rule') {
  unwrapped = true
  child.selectors = selectors(rule, child)
  after = pickComment(child.prev(), after)
  var decls = pickDeclarations(child)
  after.after(child)
  after = child

  if (decls.length) {
    var parent = postcss.rule({
      selector: rule.selector,
      nodes: []
    })

    for (var i = 0; i < decls.length; i++) {
      parent.append(decls[i])
    }

    after.after(parent)
    after = parent
  }
}
...

@ai ai merged commit 2a9ac5a into postcss:master Jul 4, 2020
1 check passed
@ai
Copy link
Member

ai commented Jul 4, 2020

Released in 4.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants