Skip to content

Commit

Permalink
Add support for operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsManta committed Mar 31, 2017
1 parent 24d7790 commit e476fdd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const defaultFormattingOptions = {
// TODO: sortImports: 'alphabetical',
sortProperties: 'alphabetical',
alwaysUseImport: false,
alwaysUseNot: false,
}

class StringBuffer {
Expand Down Expand Up @@ -297,9 +298,6 @@ function format(content, options, isDebugging = false) {
outputBuffer.append(options.newLineChar)
}

} else if (inputNode instanceof stylus.nodes.Unit) {
outputBuffer.append(inputNode.val).append(inputNode.type)

} else if (inputNode instanceof stylus.nodes.Call) {
outputBuffer.append(inputNode.name).append('(' + inputNode.args.nodes.map(node => travel(node, levelCount)).join(', ') + ')')

Expand All @@ -312,6 +310,15 @@ function format(content, options, isDebugging = false) {
}
}).join(' '))

} else if (inputNode instanceof stylus.nodes.Unit) {
outputBuffer.append(inputNode.val).append(inputNode.type)

} else if (inputNode instanceof stylus.nodes.UnaryOp) {
outputBuffer.append(inputNode.op === '!' && options.alwaysUseNot ? 'not ' : inputNode.op).append(travel(inputNode.expr, levelCount, true))

} else if (inputNode instanceof stylus.nodes.BinOp) {
outputBuffer.append(travel(inputNode.left, levelCount, true) + ' ' + inputNode.op + ' ' + travel(inputNode.right, levelCount, true))

} else if (inputNode instanceof stylus.nodes.Comment && inputNode.str.startsWith('//')) { // In case of single-line comment
if (insideExpression === false) {
outputBuffer.append(indent)
Expand Down
13 changes: 13 additions & 0 deletions spec/operator/formattingOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"insertColons": true,
"insertSemicolons": true,
"insertBraces": true,
"insertNewLineBetweenGroups": 1,
"insertNewLineBetweenSelectors": false,
"insertSpaceBeforeComments": true,
"insertSpaceAfterComments": true,
"indentChar": "\t",
"newLineChar": "\r\n",
"sortProperties": false,
"alwaysUseImport": false
}
5 changes: 5 additions & 0 deletions spec/operator/input.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body
display !0
visibility not true
left -5px
margin 1+2px
5 changes: 5 additions & 0 deletions spec/operator/output.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
margin: 1 + 2px;
display: !0;
left: -5px;
}

0 comments on commit e476fdd

Please sign in to comment.