Skip to content

Commit

Permalink
Fixed removing colons causing Stylus compilation failures
Browse files Browse the repository at this point in the history
See #79
  • Loading branch information
ThisIsManta committed Jan 31, 2021
1 parent 258de26 commit 0734bec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ function format(content, options = {}) {
}
}

// See https://github.com/ThisIsManta/stylus-supremacy/issues/79
const preserveColons = nodesExcludingCommentsOnTheRight.length === 1 && nodesExcludingCommentsOnTheRight[0] instanceof Stylus.nodes.Expression

// Insert the property value(s) without the last portion of comments
if (nodesExcludingCommentsOnTheRight.every(node => node instanceof Stylus.nodes.Expression)) {
const numberOfLineTaken = _.chain(nodesExcludingCommentsOnTheRight)
Expand All @@ -393,15 +396,15 @@ function format(content, options = {}) {
outputBuffer.append(propertyValues.join((inputNode.expr.isList ? ',' : '') + options.newLineChar + innerIndent))

} else {
if (options.insertColons) {
if (options.insertColons || preserveColons) {
outputBuffer.append(':')
}
outputBuffer.append(' ')
outputBuffer.append(propertyValues.join(inputNode.expr.isList ? comma : ' '))
}

} else {
if (options.insertColons) {
if (options.insertColons || preserveColons) {
outputBuffer.append(':')
}
outputBuffer.append(' ')
Expand Down
6 changes: 5 additions & 1 deletion spec/option-insert-colon-false/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ body
display none

@media (min-width: 100px)
display none
display none

.foo
color: $colors.red $colors.blue 3
display block
5 changes: 5 additions & 0 deletions spec/option-insert-colon-false/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ body {

@media (min-width 100px) {
display none;
}

.foo {
color: $colors.red $colors.blue 3;
display block;
}

1 comment on commit 0734bec

@qnp
Copy link

@qnp qnp commented on 0734bec Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !

Please sign in to comment.