Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotations on nested blocks #42

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: node_js
node_js:
- '0.10'
- '0.12'
- '4.2'
- 'stable'

sudo: false
Expand Down
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,21 @@ var filterAndGroup = function (lines) {
var group = false

lines.forEach(function (line) {
var isAnnotation = line.indexOf('@') === 0
var trimmedLine = line.trim()
var isAnnotation = trimmedLine.indexOf('@') === 0

if (line.trim().indexOf('---') !== 0) { // Ignore lines that start with "---"
if (trimmedLine.indexOf('---') !== 0) { // Ignore lines that start with "---"
if (group) {
if (isAnnotation) {
nLines.push(line)
nLines.push(trimmedLine)
} else {
nLines[nLines.length - 1] += '\n' + line
}
} else if (isAnnotation) {
group = true
nLines.push(line)
nLines.push(trimmedLine)
} else {
nLines.push(line)
nLines.push(trimmedLine)
}
}
})
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/annotationsNestedBlock.test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.foo {
/// Test description
/// @test TestType
$test-variable: blue;
}
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,28 @@ describe('scss-comment-parser', function () {
})
})

it('should parse annotations on a nested block', function () {
var annotationName = 'test'
var annotations = {
_: {
alias: {
'test': annotationName
}
},
'test': {
name: annotationName,
parse: function (text) {
return text
}
}
}

var result = new ScssCommentParser(annotations).parse(getContent('annotationsNestedBlock.test.scss'))
assert.equal(result.length, 1)
assert.equal(result[0].description, 'Test description\n')
assert.equal(result[0][annotationName], 'TestType')
})

it('should ignore lines that start with "---"', function () {
var result = parser.parse(getContent('ignoreLine.test.scss'))
assert.equal(result.length, 1)
Expand Down