Skip to content

Commit

Permalink
Fixed support for attribute selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Anantachai Saothong (Manta) committed Apr 15, 2017
1 parent 30eea4f commit 8f892df
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions edge/StringBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class StringBuffer {

append(text) {
if (arguments.length > 1) {
throw new Error('Found exceed arguments')
throw new Error('Found too many arguments of', Array.prototype.slice.call(arguments))

} else if (typeof text === 'object' && text !== null) {
throw new Error('Found a non-string argument')
throw new Error('Found a non-string argument of', text)

} else if (text !== '') {
this.buffer.push(text)
Expand Down
28 changes: 16 additions & 12 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ function format(content, options) {

function travel(parentNode, inputNode, indentLevel, insideExpression = false, data = {}) {
// Check argument type
if ([
_.isObject(parentNode) || parentNode === null && inputNode instanceof stylus.nodes.Root,
_.isObject(inputNode),
_.isInteger(indentLevel) && indentLevel >= 0,
_.isBoolean(insideExpression),
_.isPlainObject(data),
].some(constraint => !constraint)) {
throw new Error('Found one or many invalid arguments.')
if (!(_.isObject(parentNode) || parentNode === null && inputNode instanceof stylus.nodes.Root)) {
throw new Error(`Found a parent node of ${JSON.stringify(parentNode)}`)
} else if (!(_.isObject(inputNode))) {
throw new Error(`Found an input node of ${JSON.stringify(inputNode)}` + (parentNode ? `, which had a parent node of ${JSON.stringify(parentNode)}` : ''))
} else if (!(_.isInteger(indentLevel) && indentLevel >= 0)) {
throw new Error(`Found an indent level of ${JSON.stringify(indentLevel)}`)
} else if (!(_.isBoolean(insideExpression))) {
throw new Error(`Found an expression flag of ${JSON.stringify(insideExpression)}`)
} else if (!(_.isPlainObject(data))) {
throw new Error(`Found an additional data object of ${JSON.stringify(data)}`)
}

// Inject a parent node to the current working node
Expand Down Expand Up @@ -305,7 +307,12 @@ function format(content, options) {
if (_.get(lines, (inputNode.lineno - 1) + '.' + (inputNode.column - 1)) === '\\') {
outputBuffer.append('\\')
}
outputBuffer.append(inputNode.val)

if (_.isString(inputNode.val)) {
outputBuffer.append(inputNode.val)
} else {
outputBuffer.append(travel(inputNode, inputNode.val, indentLevel, true))
}
}

} else if (inputNode instanceof stylus.nodes.String) {
Expand Down Expand Up @@ -796,9 +803,6 @@ function format(content, options) {
outputBuffer.append(commentLines.map(line => indent + line).join(options.newLineChar)).append(options.newLineChar)
}

} else if (typeof inputNode === 'string') {
outputBuffer.append(inputNode)

} else {
warnings.push({ message: 'Found unknown object', data: inputNode })
}
Expand Down
3 changes: 3 additions & 0 deletions spec/selector/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ body

.class5::after
display none

&[data-quantity*="-"]
display none

body > a
display none
4 changes: 4 additions & 0 deletions spec/selector/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ body {
.class5::after {
display: none;
}

&[data-quantity*='-'] {
display: none;
}
}

body > a {
Expand Down

0 comments on commit 8f892df

Please sign in to comment.