Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/infer/augments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var shouldSkipInference = require('./should_skip_inference'),
generate = require('babel-generator').default,
findClass = require('./finders').findClass;

/**
Expand All @@ -17,10 +18,16 @@ function inferAugments() {

var path = findClass(comment.context.ast);

/*
* A superclass can be a single name, like React,
* or a MemberExpression like React.Component,
* so we generate code from the AST rather than assuming
* we can access a name like `path.node.superClass.name`
*/
if (path && path.node.superClass) {
comment.augments = [{
title: 'augments',
name: path.node.superClass.name
name: generate(path.node.superClass).code
}];
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"ansi-html": "0.0.5",
"babel-core": "^6.17.0",
"babel-generator": "6.19.0",
"babel-plugin-system-import-transformer": "2.4.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.16.0",
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/es6-class.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This will fail.
*/
class Foo extends React.Component {}
99 changes: 99 additions & 0 deletions test/fixture/es6-class.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[
{
"description": {
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This will fail.",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 16,
"offset": 15
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 16,
"offset": 15
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 16,
"offset": 15
}
}
},
"tags": [],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 3
}
},
"context": {
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 36
}
}
},
"errors": [],
"name": "Foo",
"augments": [
{
"title": "augments",
"name": "React.Component"
}
],
"kind": "class",
"members": {
"instance": [],
"static": []
},
"path": [
{
"name": "Foo",
"kind": "class"
}
],
"namespace": "Foo"
}
]
7 changes: 7 additions & 0 deletions test/fixture/es6-class.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

# Foo

**Extends React.Component**

This will fail.
72 changes: 72 additions & 0 deletions test/fixture/es6-class.output.md.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"type": "root",
"children": [
{
"type": "html",
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->"
},
{
"depth": 1,
"type": "heading",
"children": [
{
"type": "text",
"value": "Foo"
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "strong",
"children": [
{
"type": "text",
"value": "Extends "
},
{
"type": "text",
"value": "React.Component"
}
]
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This will fail.",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 16,
"offset": 15
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 16,
"offset": 15
},
"indent": []
}
}
]
}