From a4889c97ecbd6a2b11442ef2abd06c7b7459fbd2 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 16 Jun 2016 13:58:11 -0400 Subject: [PATCH] [wip] Test support for namepaths containing special characters --- lib/infer/name.js | 13 +++++++--- package.json | 2 +- test/fixture/class.input.js | 52 +++++++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/lib/infer/name.js b/lib/infer/name.js index 447dea9..c80fd04 100644 --- a/lib/infer/name.js +++ b/lib/infer/name.js @@ -27,9 +27,14 @@ module.exports = function () { } function inferName(path, node) { - if (node && node.name) { - comment.name = node.name; - return true; + if (node) { + if (node.name) { + comment.name = node.name; + return true; + } else if (node.type === 'StringLiteral') { + comment.name = node.value; + return true; + } } } @@ -45,6 +50,7 @@ module.exports = function () { // infer the named based on the `property` of the MemberExpression (`bar`) // rather than the `object` (`foo`). comment.context.ast.traverse({ + /** * Attempt to extract the name from an Identifier node. * If the name can be resolved, it will stop traversing. @@ -57,6 +63,7 @@ module.exports = function () { path.stop(); } }, + /** * Attempt to extract the name from an Identifier node. * If the name can be resolved, it will stop traversing. diff --git a/package.json b/package.json index 1e77ae3..366dc28 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "concat-stream": "^1.5.0", "debounce": "^1.0.0", "disparity": "^2.0.0", - "doctrine": "^1.1.0", + "doctrine": "^1.2.0", "events": "^1.1.0", "extend": "^3.0.0", "get-comments": "^1.0.1", diff --git a/test/fixture/class.input.js b/test/fixture/class.input.js index aa3db42..5dcbcbc 100644 --- a/test/fixture/class.input.js +++ b/test/fixture/class.input.js @@ -1,23 +1,37 @@ -/** - * This is my class, a demo thing. - * @class MyClass - * @property {number} howMany how many things it contains - */ -function MyClass() { - this.howMany = 2; -} +// /** +// * This is my class, a demo thing. +// * @class MyClass +// * @property {number} howMany how many things it contains +// */ +// function MyClass() { +// this.howMany = 2; +// } +// +// /** +// * Get the number 42 +// * @param {boolean} getIt whether to get the number +// * @returns {number} forty-two +// */ +// MyClass.prototype.getFoo = function (getIt) { +// return getIt ? 42 : 0; +// }; +// +// /** +// * Get undefined +// * @returns {undefined} does not return anything. +// */ +// MyClass.prototype.getUndefined = function () { }; +// +// /** +// * A colon-separated name +// * @returns {undefined} does not return anything. +// */ +// MyClass.prototype['colon:name'] = function () { }; /** - * Get the number 42 - * @param {boolean} getIt whether to get the number - * @returns {number} forty-two - */ -MyClass.prototype.getFoo = function (getIt) { - return getIt ? 42 : 0; -}; - -/** - * Get undefined + * A colon-separated name specified manually + * + * @name "colon:foo" * @returns {undefined} does not return anything. */ -MyClass.prototype.getUndefined = function () { }; +MyClass.prototype['colon:foo'] = function () { };