Skip to content

Commit

Permalink
Fixed adding @css block on property key
Browse files Browse the repository at this point in the history
See #63
  • Loading branch information
Anantachai Saothong (Manta) committed May 5, 2020
1 parent e370d85 commit e0dc5bf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ function format(content, options = {}) {
outputBuffer.append(options.newLineChar)

} else if (inputNode instanceof Stylus.nodes.Literal) {
if (inputNode.parent instanceof Stylus.nodes.Property && inputNode.parent.expr.nodes.length === 1) { // In case of @css property
if (inputNode.parent instanceof Stylus.nodes.Property && inputNode.parent.expr.nodes.length === 1 && inputNode.parent.expr.nodes[0] === inputNode) { // In case of @css property
// Note that it must be wrapped inside a pair of braces
outputBuffer.append('@css {')
if (inputNode.val.trim().length > 0) {
Expand Down
1 change: 1 addition & 0 deletions spec/rule/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
body
.class1
border-color @css { ${$design.primaryLight} }
{type}-{direction} none

@reset-global pc
1 change: 1 addition & 0 deletions spec/rule/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
body {
.class1 {
border-color: @css { ${$design.primaryLight} };
{type}-{direction}: none;
}
}

Expand Down
12 changes: 10 additions & 2 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,25 @@ filesAndDirectories.filter(directoriesOnly).forEach(directory => {
const outputDebuggingFilePath = pt.join(directory, 'output-debugging.json')

const inputContent = fs.readFileSync(inputFilePath, 'utf8')
const outputContent = fs.readFileSync(outputFilePath, 'utf8')

let formattingOptions = undefined
if (fs.existsSync(optionFilePath)) {
formattingOptions = require('../' + optionFilePath)
}

if (fs.existsSync(outputFilePath) === false) {
const actualContent = format(inputContent, formattingOptions)
fs.writeFileSync(outputFilePath, actualContent)
}

const outputContent = fs.readFileSync(outputFilePath, 'utf8')

const testSpecName = pt.basename(directory)
describe(testSpecName, () => {
it('can be formatted', () => {
if (fs.existsSync(inputFormattedFilePath)) fs.unlinkSync(inputFormattedFilePath)
if (fs.existsSync(inputFormattedFilePath)) {
fs.unlinkSync(inputFormattedFilePath)
}

try {
const tree = new Stylus.Parser(inputContent).parse()
Expand Down

0 comments on commit e0dc5bf

Please sign in to comment.