Skip to content

Commit a4889c9

Browse files
committed
[wip] Test support for namepaths containing special characters
1 parent c33fe6b commit a4889c9

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

lib/infer/name.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ module.exports = function () {
2727
}
2828

2929
function inferName(path, node) {
30-
if (node && node.name) {
31-
comment.name = node.name;
32-
return true;
30+
if (node) {
31+
if (node.name) {
32+
comment.name = node.name;
33+
return true;
34+
} else if (node.type === 'StringLiteral') {
35+
comment.name = node.value;
36+
return true;
37+
}
3338
}
3439
}
3540

@@ -45,6 +50,7 @@ module.exports = function () {
4550
// infer the named based on the `property` of the MemberExpression (`bar`)
4651
// rather than the `object` (`foo`).
4752
comment.context.ast.traverse({
53+
4854
/**
4955
* Attempt to extract the name from an Identifier node.
5056
* If the name can be resolved, it will stop traversing.
@@ -57,6 +63,7 @@ module.exports = function () {
5763
path.stop();
5864
}
5965
},
66+
6067
/**
6168
* Attempt to extract the name from an Identifier node.
6269
* If the name can be resolved, it will stop traversing.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"concat-stream": "^1.5.0",
2323
"debounce": "^1.0.0",
2424
"disparity": "^2.0.0",
25-
"doctrine": "^1.1.0",
25+
"doctrine": "^1.2.0",
2626
"events": "^1.1.0",
2727
"extend": "^3.0.0",
2828
"get-comments": "^1.0.1",

test/fixture/class.input.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
/**
2-
* This is my class, a demo thing.
3-
* @class MyClass
4-
* @property {number} howMany how many things it contains
5-
*/
6-
function MyClass() {
7-
this.howMany = 2;
8-
}
9-
10-
/**
11-
* Get the number 42
12-
* @param {boolean} getIt whether to get the number
13-
* @returns {number} forty-two
14-
*/
15-
MyClass.prototype.getFoo = function (getIt) {
16-
return getIt ? 42 : 0;
17-
};
1+
// /**
2+
// * This is my class, a demo thing.
3+
// * @class MyClass
4+
// * @property {number} howMany how many things it contains
5+
// */
6+
// function MyClass() {
7+
// this.howMany = 2;
8+
// }
9+
//
10+
// /**
11+
// * Get the number 42
12+
// * @param {boolean} getIt whether to get the number
13+
// * @returns {number} forty-two
14+
// */
15+
// MyClass.prototype.getFoo = function (getIt) {
16+
// return getIt ? 42 : 0;
17+
// };
18+
//
19+
// /**
20+
// * Get undefined
21+
// * @returns {undefined} does not return anything.
22+
// */
23+
// MyClass.prototype.getUndefined = function () { };
24+
//
25+
// /**
26+
// * A colon-separated name
27+
// * @returns {undefined} does not return anything.
28+
// */
29+
// MyClass.prototype['colon:name'] = function () { };
1830

1931
/**
20-
* Get undefined
32+
* A colon-separated name specified manually
33+
*
34+
* @name "colon:foo"
2135
* @returns {undefined} does not return anything.
2236
*/
23-
MyClass.prototype.getUndefined = function () { };
37+
MyClass.prototype['colon:foo'] = function () { };

0 commit comments

Comments
 (0)