Skip to content

Commit

Permalink
Fixed unexpected newline before a postfix if
Browse files Browse the repository at this point in the history
See #68
  • Loading branch information
ThisIsManta committed May 24, 2020
1 parent d1e7dfa commit d73fb46
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
24 changes: 18 additions & 6 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,13 @@ function format(content, options = {}) {
}

} else if (inputNode instanceof Stylus.nodes.Property) {
if (insideExpression === false) {
outputBuffer.append(indent)
}

// Insert the property name
const propertyName = travelThroughSegments(inputNode, indentLevel).join('')
outputBuffer.append(indent + propertyName)
outputBuffer.append(propertyName)

// Insert the property value(s)
if (inputNode.expr instanceof Stylus.nodes.Expression) {
Expand Down Expand Up @@ -418,10 +422,12 @@ function format(content, options = {}) {
throw error
}

if (options.insertSemicolons) {
outputBuffer.append(';')
if (insideExpression === false) {
if (options.insertSemicolons) {
outputBuffer.append(';')
}
outputBuffer.append(options.newLineChar)
}
outputBuffer.append(options.newLineChar)

} else if (inputNode instanceof Stylus.nodes.Literal) {
if (inputNode.parent instanceof Stylus.nodes.Property && inputNode.parent.expr.nodes.length === 1 && inputNode.parent.expr.nodes[0] === inputNode) { // In case of @css property
Expand Down Expand Up @@ -1358,13 +1364,19 @@ function format(content, options = {}) {
}

function getType(inputNode) {
if (inputNode instanceof Stylus.nodes.Property) {
if (
inputNode instanceof Stylus.nodes.Property ||
inputNode instanceof Stylus.nodes.If && inputNode.postfix && inputNode.block instanceof Stylus.nodes.Property
) {
return 'Property'

} else if (inputNode instanceof Stylus.nodes.Import) {
return 'Import'

} else if (inputNode.block !== undefined || (inputNode instanceof Stylus.nodes.Ident && inputNode.val.block !== undefined)) {
} else if (
inputNode.block !== undefined ||
(inputNode instanceof Stylus.nodes.Ident && inputNode.val.block !== undefined)
) {
return 'Block'

} else {
Expand Down
3 changes: 3 additions & 0 deletions spec/condition/input.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
body
background red unless false
background blue if true

if x == y
margin 1

Expand Down
3 changes: 3 additions & 0 deletions spec/condition/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
body {
background: red unless (false);
background: blue if (true);

if (x == y) {
margin: 1;
}
Expand Down

0 comments on commit d73fb46

Please sign in to comment.