diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 0360cd901..5e2795ed2 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -12762,6 +12762,10 @@ Array [ ], "throws": Array [], "todos": Array [], + "type": Object { + "name": "string", + "type": "NameExpression", + }, }, ], "static": Array [], @@ -13012,7 +13016,717 @@ Object { "children": Array [ Object { "type": "text", - "value": "Bar", + "value": "Bar", + }, + ], + "depth": 2, + "type": "heading", + }, + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 38, + "line": 1, + "offset": 37, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "Does nothing. This is from issue #556", + }, + ], + "position": Position { + "end": Object { + "column": 38, + "line": 1, + "offset": 37, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Parameters", + }, + ], + "type": "strong", + }, + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "type": "inlineCode", + "value": "str", + }, + Object { + "type": "text", + "value": " ", + }, + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "type": "text", + "value": "string", + }, + ], + "identifier": "1", + "referenceType": "full", + "type": "linkReference", + }, + ], + "type": "strong", + }, + Object { + "type": "text", + "value": " ", + }, + ], + "type": "paragraph", + }, + ], + "type": "listItem", + }, + ], + "ordered": false, + "type": "list", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "bar", + }, + ], + "depth": 3, + "type": "heading", + }, + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 19, + "line": 1, + "offset": 18, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "A useless property", + }, + ], + "position": Position { + "end": Object { + "column": 19, + "line": 1, + "offset": 18, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Type: ", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "string", + }, + ], + "identifier": "1", + "referenceType": "full", + "type": "linkReference", + }, + ], + "type": "paragraph", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Baz", + }, + ], + "depth": 2, + "type": "heading", + }, + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 54, + "line": 1, + "offset": 53, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This class has fully inferred constructor parameters.", + }, + ], + "position": Position { + "end": Object { + "column": 54, + "line": 1, + "offset": 53, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Parameters", + }, + ], + "type": "strong", + }, + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "type": "inlineCode", + "value": "n", + }, + Object { + "type": "text", + "value": " ", + }, + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "type": "text", + "value": "number", + }, + ], + "identifier": "2", + "referenceType": "full", + "type": "linkReference", + }, + ], + "type": "strong", + }, + Object { + "type": "text", + "value": " ", + }, + ], + "type": "paragraph", + }, + ], + "type": "listItem", + }, + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "type": "inlineCode", + "value": "l", + }, + Object { + "type": "text", + "value": " ", + }, + Object { + "children": Array [ + Object { + "children": Array [ + Object { + "type": "text", + "value": "Array", + }, + ], + "identifier": "3", + "referenceType": "full", + "type": "linkReference", + }, + Object { + "type": "text", + "value": "<", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "string", + }, + ], + "identifier": "1", + "referenceType": "full", + "type": "linkReference", + }, + Object { + "type": "text", + "value": ">", + }, + ], + "type": "strong", + }, + Object { + "type": "text", + "value": " ", + }, + ], + "type": "paragraph", + }, + ], + "type": "listItem", + }, + ], + "ordered": false, + "type": "list", + }, + Object { + "identifier": "1", + "title": undefined, + "type": "definition", + "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String", + }, + Object { + "identifier": "2", + "title": undefined, + "type": "definition", + "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number", + }, + Object { + "identifier": "3", + "title": undefined, + "type": "definition", + "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array", + }, + ], + "type": "root", +} +`; + +exports[`outputs es6-class-property.input.js JSON 1`] = ` +Array [ + Object { + "augments": Array [], + "context": Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 25, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Object { + "end": Object { + "column": 23, + "line": 1, + "offset": 22, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This is for issue 906.", + }, + ], + "position": Object { + "end": Object { + "column": 23, + "line": 1, + "offset": 22, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 23, + "line": 1, + "offset": 22, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [], + "examples": Array [], + "kind": "class", + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [ + Object { + "augments": Array [], + "context": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 11, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Object { + "end": Object { + "column": 31, + "line": 1, + "offset": 30, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This is a read-write property.", + }, + ], + "position": Object { + "end": Object { + "column": 31, + "line": 1, + "offset": 30, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 31, + "line": 1, + "offset": 30, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [], + "examples": Array [], + "kind": "member", + "loc": Object { + "end": Object { + "column": 5, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "memberof": "Issue906", + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "readWriteProp", + "namespace": "Issue906#readWriteProp", + "params": Array [], + "path": Array [ + Object { + "kind": "class", + "name": "Issue906", + }, + Object { + "kind": "member", + "name": "readWriteProp", + "scope": "instance", + }, + ], + "properties": Array [], + "returns": Array [], + "scope": "instance", + "sees": Array [], + "tags": Array [ + Object { + "description": null, + "lineNumber": 2, + "title": "type", + "type": Object { + "name": "boolean", + "type": "NameExpression", + }, + }, + ], + "throws": Array [], + "todos": Array [], + "type": Object { + "name": "boolean", + "type": "NameExpression", + }, + }, + Object { + "augments": Array [], + "context": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 24, + }, + "start": Object { + "column": 2, + "line": 22, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Object { + "end": Object { + "column": 30, + "line": 1, + "offset": 29, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This is a read-only property.", + }, + ], + "position": Object { + "end": Object { + "column": 30, + "line": 1, + "offset": 29, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 30, + "line": 1, + "offset": 29, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [], + "examples": Array [], + "kind": "member", + "loc": Object { + "end": Object { + "column": 5, + "line": 21, + }, + "start": Object { + "column": 2, + "line": 17, + }, + }, + "memberof": "Issue906", + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "readOnlyProp", + "namespace": "Issue906#readOnlyProp", + "params": Array [], + "path": Array [ + Object { + "kind": "class", + "name": "Issue906", + }, + Object { + "kind": "member", + "name": "readOnlyProp", + "scope": "instance", + }, + ], + "properties": Array [], + "readonly": true, + "returns": Array [], + "scope": "instance", + "sees": Array [], + "tags": Array [ + Object { + "description": null, + "lineNumber": 2, + "title": "type", + "type": Object { + "name": "string", + "type": "NameExpression", + }, + }, + Object { + "description": null, + "lineNumber": 3, + "title": "readonly", + }, + ], + "throws": Array [], + "todos": Array [], + "type": Object { + "name": "string", + "type": "NameExpression", + }, + }, + ], + "static": Array [], + }, + "name": "Issue906", + "namespace": "Issue906", + "params": Array [], + "path": Array [ + Object { + "kind": "class", + "name": "Issue906", + }, + ], + "properties": Array [], + "returns": Array [], + "sees": Array [], + "tags": Array [], + "throws": Array [], + "todos": Array [], + }, +] +`; + +exports[`outputs es6-class-property.input.js markdown 1`] = `"[object Object]"`; + +exports[`outputs es6-class-property.input.js markdown AST 1`] = ` +Object { + "children": Array [ + Object { + "type": "html", + "value": "", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Issue906", }, ], "depth": 2, @@ -13023,9 +13737,9 @@ Object { Object { "position": Position { "end": Object { - "column": 38, + "column": 23, "line": 1, - "offset": 37, + "offset": 22, }, "indent": Array [], "start": Object { @@ -13035,14 +13749,14 @@ Object { }, }, "type": "text", - "value": "Does nothing. This is from issue #556", + "value": "This is for issue 906.", }, ], "position": Position { "end": Object { - "column": 38, + "column": 23, "line": 1, - "offset": 37, + "offset": 22, }, "indent": Array [], "start": Object { @@ -13057,60 +13771,7 @@ Object { "children": Array [ Object { "type": "text", - "value": "Parameters", - }, - ], - "type": "strong", - }, - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "type": "inlineCode", - "value": "str", - }, - Object { - "type": "text", - "value": " ", - }, - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "type": "text", - "value": "string", - }, - ], - "identifier": "1", - "referenceType": "full", - "type": "linkReference", - }, - ], - "type": "strong", - }, - Object { - "type": "text", - "value": " ", - }, - ], - "type": "paragraph", - }, - ], - "type": "listItem", - }, - ], - "ordered": false, - "type": "list", - }, - Object { - "children": Array [ - Object { - "type": "text", - "value": "bar", + "value": "readWriteProp", }, ], "depth": 3, @@ -13121,9 +13782,9 @@ Object { Object { "position": Position { "end": Object { - "column": 19, + "column": 31, "line": 1, - "offset": 18, + "offset": 30, }, "indent": Array [], "start": Object { @@ -13133,14 +13794,14 @@ Object { }, }, "type": "text", - "value": "A useless property", + "value": "This is a read-write property.", }, ], "position": Position { "end": Object { - "column": 19, + "column": 31, "line": 1, - "offset": 18, + "offset": 30, }, "indent": Array [], "start": Object { @@ -13155,10 +13816,30 @@ Object { "children": Array [ Object { "type": "text", - "value": "Baz", + "value": "Type: ", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "boolean", + }, + ], + "identifier": "1", + "referenceType": "full", + "type": "linkReference", }, ], - "depth": 2, + "type": "paragraph", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "readOnlyProp", + }, + ], + "depth": 3, "type": "heading", }, Object { @@ -13166,9 +13847,9 @@ Object { Object { "position": Position { "end": Object { - "column": 54, + "column": 30, "line": 1, - "offset": 53, + "offset": 29, }, "indent": Array [], "start": Object { @@ -13178,14 +13859,14 @@ Object { }, }, "type": "text", - "value": "This class has fully inferred constructor parameters.", + "value": "This is a read-only property.", }, ], "position": Position { "end": Object { - "column": 54, + "column": 30, "line": 1, - "offset": 53, + "offset": 29, }, "indent": Array [], "start": Object { @@ -13200,129 +13881,33 @@ Object { "children": Array [ Object { "type": "text", - "value": "Parameters", - }, - ], - "type": "strong", - }, - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "type": "inlineCode", - "value": "n", - }, - Object { - "type": "text", - "value": " ", - }, - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "type": "text", - "value": "number", - }, - ], - "identifier": "2", - "referenceType": "full", - "type": "linkReference", - }, - ], - "type": "strong", - }, - Object { - "type": "text", - "value": " ", - }, - ], - "type": "paragraph", - }, - ], - "type": "listItem", + "value": "Type: ", }, Object { "children": Array [ Object { - "children": Array [ - Object { - "type": "inlineCode", - "value": "l", - }, - Object { - "type": "text", - "value": " ", - }, - Object { - "children": Array [ - Object { - "children": Array [ - Object { - "type": "text", - "value": "Array", - }, - ], - "identifier": "3", - "referenceType": "full", - "type": "linkReference", - }, - Object { - "type": "text", - "value": "<", - }, - Object { - "children": Array [ - Object { - "type": "text", - "value": "string", - }, - ], - "identifier": "1", - "referenceType": "full", - "type": "linkReference", - }, - Object { - "type": "text", - "value": ">", - }, - ], - "type": "strong", - }, - Object { - "type": "text", - "value": " ", - }, - ], - "type": "paragraph", + "type": "text", + "value": "string", }, ], - "type": "listItem", + "identifier": "2", + "referenceType": "full", + "type": "linkReference", }, ], - "ordered": false, - "type": "list", + "type": "paragraph", }, Object { "identifier": "1", "title": undefined, "type": "definition", - "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String", + "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean", }, Object { "identifier": "2", "title": undefined, "type": "definition", - "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number", - }, - Object { - "identifier": "3", - "title": undefined, - "type": "definition", - "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array", + "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String", }, ], "type": "root", @@ -14495,6 +15080,10 @@ Array [ ], "throws": Array [], "todos": Array [], + "type": Object { + "name": "Object", + "type": "NameExpression", + }, }, ] `; @@ -14553,6 +15142,26 @@ Object { }, "type": "paragraph", }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Type: ", + }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "Object", + }, + ], + "identifier": "1", + "referenceType": "full", + "type": "linkReference", + }, + ], + "type": "paragraph", + }, Object { "children": Array [ Object { @@ -14651,7 +15260,7 @@ Object { "value": "Event", }, ], - "identifier": "1", + "identifier": "2", "referenceType": "full", "type": "linkReference", }, @@ -14711,6 +15320,12 @@ Object { "identifier": "1", "title": undefined, "type": "definition", + "url": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object", + }, + Object { + "identifier": "2", + "title": undefined, + "type": "definition", "url": "https://developer.mozilla.org/docs/Web/API/Event", }, ], diff --git a/__tests__/fixture/es6-class-property.input.js b/__tests__/fixture/es6-class-property.input.js new file mode 100644 index 000000000..ee201c725 --- /dev/null +++ b/__tests__/fixture/es6-class-property.input.js @@ -0,0 +1,25 @@ +/** + * This is for issue 906. + */ +export class Issue906 { + /** + * This is a read-write property. + * @type {boolean} + */ + get readWriteProp() { + return this._rw; + } + + set readWriteProp(value) { + this._rw = value; + } + + /** + * This is a read-only property. + * @type {string} + * @readonly + */ + get readOnlyProp() { + return 'foo'; + } +} diff --git a/src/parse.js b/src/parse.js index 5b5512c5a..295b661ed 100644 --- a/src/parse.js +++ b/src/parse.js @@ -386,7 +386,9 @@ const flatteners = { result.todos.push(parseMarkdown(tag.description)); }, tutorial: todo, - type: todo, + type(result, tag) { + result.type = tag.type; + }, typedef: flattenKindShorthand, var: synonym('member'), /**