Skip to content

Commit 341adad

Browse files
committed
Merge pull request #358 from SassDoc/name-annotation-v2
Add @​name annotation
2 parents 76dac88 + c25879b commit 341adad

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

src/annotation/annotations/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = [
88
require('./group.js'),
99
require('./ignore.js'),
1010
require('./link.js'),
11+
require('./name.js'),
1112
require('./output.js'),
1213
require('./parameter.js'),
1314
require('./property.js'),

src/annotation/annotations/name.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function access() {
2+
return {
3+
name: 'name',
4+
5+
parse(text) {
6+
return text.trim();
7+
},
8+
9+
// Abuse the autofill feature to rewrite the `item.context`
10+
autofill(item) {
11+
if (item.name) {
12+
item.context.name = item.name;
13+
// Cleanup
14+
delete item.name;
15+
}
16+
},
17+
18+
multiple: false
19+
};
20+
}

test/annotations/name.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
5+
describe('#name', function () {
6+
var name = (new (require('../../dist/annotation'))()).list.name;
7+
8+
it('should return the trimmed string', function () {
9+
assert.equal(name.parse(' '), '');
10+
assert.equal(name.parse(' '), '');
11+
assert.equal(name.parse('\ntest\t'), 'test');
12+
assert.equal(name.parse('\nte\nst\t'), 'te\nst');
13+
});
14+
});

test/data/expected.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,5 +600,29 @@
600600
"path": "test.scss",
601601
"name": "test.scss"
602602
}
603+
},
604+
{
605+
"description": "This is a test placeholder aiming at testing:\n- `@name`\n",
606+
"commentRange": {
607+
"start": 175,
608+
"end": 177
609+
},
610+
"context": {
611+
"type": "placeholder",
612+
"name": "placeholder-[blue,green,red]",
613+
"code": "",
614+
"line": {
615+
"start": 179,
616+
"end": 179
617+
}
618+
},
619+
"group": [
620+
"test"
621+
],
622+
"access": "private",
623+
"file": {
624+
"path": "test.scss",
625+
"name": "test.scss"
626+
}
603627
}
604628
]

test/data/test.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@ $variable-specific-test: ();
171171
/// @alias should-warn
172172

173173
@function alias-test-should-warn() {}
174+
175+
/// This is a test placeholder aiming at testing:
176+
/// - `@name`
177+
/// @name placeholder-[blue,green,red]
178+
179+
%placeholder-#{$color} {}

0 commit comments

Comments
 (0)