Skip to content

Commit 07f4751

Browse files
fredjtmcw
authored andcommitted
fix: support type expression for @this tag (fixes eslint#181) (eslint#182)
1 parent 4f028d8 commit 07f4751

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/doctrine.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,13 @@
607607
return true;
608608
};
609609

610-
TagParser.prototype.parseThis = function parseAccess() {
611-
// this name may be a name expression (e.g. {foo.bar})
612-
// or a name path (e.g. foo.bar)
610+
TagParser.prototype.parseThis = function parseThis() {
611+
// this name may be a name expression (e.g. {foo.bar}),
612+
// an union (e.g. {foo.bar|foo.baz}) or a name path (e.g. foo.bar)
613613
var value = trim(sliceSource(source, index, this._last));
614614
if (value && value.charAt(0) === '{') {
615615
var gotType = this.parseType();
616-
if (gotType && this._tag.type.type === 'NameExpression') {
616+
if (gotType && this._tag.type.type === 'NameExpression' || this._tag.type.type === 'UnionType') {
617617
this._tag.name = this._tag.type.name;
618618
return true;
619619
} else {

test/parse.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,25 @@ describe('parse', function () {
12071207
].join('\n'), { unwrap: true });
12081208
res.tags.should.have.length(1);
12091209
res.tags[0].should.have.property('title', 'this');
1210+
res.tags[0].type.should.have.property('type', 'NameExpression');
12101211
res.tags[0].should.have.property('name', 'thingName.name');
12111212
});
12121213

1214+
it('this with UnionType expression', function () {
1215+
var res = doctrine.parse(
1216+
[
1217+
"/**",
1218+
" * @this {thingName.name|FooBar}",
1219+
"*/"
1220+
].join('\n'), { unwrap: true });
1221+
res.tags.should.have.length(1);
1222+
res.tags[0].should.have.property('title', 'this');
1223+
res.tags[0].type.should.have.property('type', 'UnionType');
1224+
res.tags[0].type.elements.should.have.length(2);
1225+
res.tags[0].type.elements.should.containEql({type: 'NameExpression', name: 'thingName.name'});
1226+
res.tags[0].type.elements.should.containEql({type: 'NameExpression', name: 'FooBar'});
1227+
});
1228+
12131229
it('this error with type application', function () {
12141230
var res = doctrine.parse(
12151231
[

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy