Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
fix: support type expression for @this tag (fixes #181) (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj authored and tmcw committed Aug 18, 2017
1 parent 1c4a4c7 commit 6b210a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/doctrine.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,13 @@
return true;
};

TagParser.prototype.parseThis = function parseAccess() {
// this name may be a name expression (e.g. {foo.bar})
// or a name path (e.g. foo.bar)
TagParser.prototype.parseThis = function parseThis() {
// this name may be a name expression (e.g. {foo.bar}),
// an union (e.g. {foo.bar|foo.baz}) or a name path (e.g. foo.bar)
var value = trim(sliceSource(source, index, this._last));
if (value && value.charAt(0) === '{') {
var gotType = this.parseType();
if (gotType && this._tag.type.type === 'NameExpression') {
if (gotType && this._tag.type.type === 'NameExpression' || this._tag.type.type === 'UnionType') {
this._tag.name = this._tag.type.name;
return true;
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,25 @@ describe('parse', function () {
].join('\n'), { unwrap: true });
res.tags.should.have.length(1);
res.tags[0].should.have.property('title', 'this');
res.tags[0].type.should.have.property('type', 'NameExpression');
res.tags[0].should.have.property('name', 'thingName.name');
});

it('this with UnionType expression', function () {
var res = doctrine.parse(
[
"/**",
" * @this {thingName.name|FooBar}",
"*/"
].join('\n'), { unwrap: true });
res.tags.should.have.length(1);
res.tags[0].should.have.property('title', 'this');
res.tags[0].type.should.have.property('type', 'UnionType');
res.tags[0].type.elements.should.have.length(2);
res.tags[0].type.elements.should.containEql({type: 'NameExpression', name: 'thingName.name'});
res.tags[0].type.elements.should.containEql({type: 'NameExpression', name: 'FooBar'});
});

it('this error with type application', function () {
var res = doctrine.parse(
[
Expand Down

0 comments on commit 6b210a8

Please sign in to comment.