Skip to content

Commit 7b156d8

Browse files
committed
Babel! 🙌
cc @jfirebaugh for the review This was easier than expected.
1 parent 472e7ff commit 7b156d8

32 files changed

+54
-101
lines changed

lib/is_jsdoc_comment.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
*/
1515
module.exports = function isJSDocComment(comment) {
1616
var asterisks = comment.value.match(/^(\*+)/);
17-
return comment.type === 'Block' && asterisks && asterisks[ 1 ].length === 1;
17+
return (comment.type === 'CommentBlock' || // estree
18+
comment.type === 'Block') // get-comments / traditional
19+
&& asterisks && asterisks[ 1 ].length === 1;
1820
};

lib/parsers/javascript.js

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var espree = require('espree'),
3+
var babel = require('babel'),
44
types = require('ast-types'),
55
extend = require('extend'),
66
isJSDocComment = require('../../lib/is_jsdoc_comment'),
@@ -19,58 +19,6 @@ function commentShebang(code) {
1919
return (code[0] === '#' && code[1] === '!') ? '//' + code : code;
2020
}
2121

22-
var espreeConfig = {
23-
loc: true,
24-
attachComment: true,
25-
// specify parsing features (default only has blockBindings: true)
26-
ecmaFeatures: {
27-
// enable parsing of arrow functions
28-
arrowFunctions: true,
29-
// enable parsing of let/const
30-
blockBindings: true,
31-
// enable parsing of destructured arrays and objects
32-
destructuring: true,
33-
// enable parsing of regular expression y flag
34-
regexYFlag: true,
35-
// enable parsing of regular expression u flag
36-
regexUFlag: true,
37-
// enable parsing of template strings
38-
templateStrings: true,
39-
// enable parsing of binary literals
40-
binaryLiterals: true,
41-
// enable parsing of ES6 octal literals
42-
octalLiterals: true,
43-
// enable parsing unicode code point escape sequences
44-
unicodeCodePointEscapes: true,
45-
// enable parsing of default parameters
46-
defaultParams: true,
47-
// enable parsing of rest parameters
48-
restParams: true,
49-
// enable parsing of for-of statement
50-
forOf: true,
51-
// enable parsing computed object literal properties
52-
objectLiteralComputedProperties: true,
53-
// enable parsing of shorthand object literal methods
54-
objectLiteralShorthandMethods: true,
55-
// enable parsing of shorthand object literal properties
56-
objectLiteralShorthandProperties: true,
57-
// Allow duplicate object literal properties (except '__proto__')
58-
objectLiteralDuplicateProperties: true,
59-
// enable parsing of generators/yield
60-
generators: true,
61-
// enable parsing spread operator
62-
spread: true,
63-
// enable parsing classes
64-
classes: true,
65-
// enable parsing of modules
66-
modules: true,
67-
// enable React JSX parsing
68-
jsx: true,
69-
// enable return in global scope
70-
globalReturn: true
71-
}
72-
};
73-
7422
/**
7523
* Receives a module-dep item,
7624
* reads the file, parses the JavaScript, and parses the JSDoc.
@@ -82,7 +30,7 @@ var espreeConfig = {
8230
module.exports = function (data) {
8331
var results = [];
8432
var code = commentShebang(data.source),
85-
ast = espree.parse(code, espreeConfig);
33+
ast = babel.parse(code);
8634

8735
var visited = {};
8836

@@ -139,6 +87,7 @@ module.exports = function (data) {
13987
}
14088

14189
walkComments(ast, 'leadingComments', true);
90+
walkComments(ast, 'innerComments', false);
14291
walkComments(ast, 'trailingComments', false);
14392

14493
return results;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
},
1717
"dependencies": {
1818
"ast-types": "^0.8.12",
19+
"babel": "^5.8.23",
1920
"brfs": "^1.4.0",
2021
"concat-stream": "^1.5.0",
2122
"doctrine": "^0.6.4",
2223
"documentation-theme-default": "^1.0.0-alpha2",
23-
"espree": "^2.0.3",
2424
"extend": "^3.0.0",
2525
"get-comments": "^1.0.1",
2626
"github-url-from-git": "^1.4.0",

test/fixture/_external-deps-included.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"column": 2
3434
}
3535
},
36-
"code": "module.exports = function () {\n // this returns 1\n return 1;\n};"
36+
"code": "/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n"
3737
},
3838
"errors": [
3939
"memberof reference to module not found"
@@ -96,7 +96,7 @@
9696
"column": 2
9797
}
9898
},
99-
"code": "'use strict';\n\nvar otherDep = require('external2');\n\n/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return otherDep() - 1;\n};"
99+
"code": "'use strict';\n\nvar otherDep = require('external2');\n\n/**\n * This function returns the number one.\n * @return {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return otherDep() - 1;\n};\n"
100100
},
101101
"errors": [
102102
"memberof reference to module not found"
@@ -149,7 +149,7 @@
149149
"column": 1
150150
}
151151
},
152-
"code": "require('external');\nrequire('external2');\nrequire('module-not-found');\n\n/**\n * I am in `external.input.js`.\n */\nfunction foo() {\n 'use strict';\n return 'bar';\n}\n\nmodule.exports = foo;"
152+
"code": "require('external');\nrequire('external2');\nrequire('module-not-found');\n\n/**\n * I am in `external.input.js`.\n */\nfunction foo() {\n 'use strict';\n return 'bar';\n}\n\nmodule.exports = foo;\n"
153153
},
154154
"errors": [],
155155
"name": "foo",

test/fixture/_multi-file-input.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"column": 2
3434
}
3535
},
36-
"code": "module.exports = function () {\n // this returns 1\n return 1;\n};"
36+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = function () {\n // this returns 1\n return 1;\n};\n"
3737
},
3838
"errors": [
3939
"memberof reference to module not found"
@@ -111,7 +111,7 @@
111111
"column": 1
112112
}
113113
},
114-
"code": "function returnTwo(a) {\n // this returns a + 2\n return a + 2;\n}"
114+
"code": "/**\n * This function returns the number plus two.\n *\n * @param {Number} a the number\n * @returns {Number} numbertwo\n * @example\n * var result = returnTwo(4);\n * // result is 6\n */\nfunction returnTwo(a) {\n // this returns a + 2\n return a + 2;\n}\n"
115115
},
116116
"errors": [
117117
"type Number found, number is standard"

test/fixture/bad/syntax.output.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"index": 0,
3-
"lineNumber": 1,
4-
"column": 1,
5-
"description": "Unexpected token *"
2+
"pos": 0,
3+
"loc": {
4+
"line": 1,
5+
"column": 0
6+
}
67
}

test/fixture/class.output.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"column": 1
4242
}
4343
},
44-
"code": "function MyClass() {\n this.howMany = 2;\n}\n\n/**\n * Get the number 42\n * @param {boolean} getIt whether to get the number\n * @returns {number} forty-two\n */\nMyClass.prototype.getFoo = function (getIt) {\n return getIt ? 42 : 0;\n};\n\n/**\n * Get undefined\n * @returns {undefined} does not return anything.\n */\nMyClass.prototype.getUndefined = function () { };"
44+
"code": "/**\n * This is my class, a demo thing.\n * @class MyClass\n * @property {number} howMany how many things it contains\n */\nfunction MyClass() {\n this.howMany = 2;\n}\n\n/**\n * Get the number 42\n * @param {boolean} getIt whether to get the number\n * @returns {number} forty-two\n */\nMyClass.prototype.getFoo = function (getIt) {\n return getIt ? 42 : 0;\n};\n\n/**\n * Get undefined\n * @returns {undefined} does not return anything.\n */\nMyClass.prototype.getUndefined = function () { };\n"
4545
},
4646
"errors": [],
4747
"class": {
@@ -107,7 +107,7 @@
107107
"column": 2
108108
}
109109
},
110-
"code": "function MyClass() {\n this.howMany = 2;\n}\n\n/**\n * Get the number 42\n * @param {boolean} getIt whether to get the number\n * @returns {number} forty-two\n */\nMyClass.prototype.getFoo = function (getIt) {\n return getIt ? 42 : 0;\n};\n\n/**\n * Get undefined\n * @returns {undefined} does not return anything.\n */\nMyClass.prototype.getUndefined = function () { };"
110+
"code": "/**\n * This is my class, a demo thing.\n * @class MyClass\n * @property {number} howMany how many things it contains\n */\nfunction MyClass() {\n this.howMany = 2;\n}\n\n/**\n * Get the number 42\n * @param {boolean} getIt whether to get the number\n * @returns {number} forty-two\n */\nMyClass.prototype.getFoo = function (getIt) {\n return getIt ? 42 : 0;\n};\n\n/**\n * Get undefined\n * @returns {undefined} does not return anything.\n */\nMyClass.prototype.getUndefined = function () { };\n"
111111
},
112112
"errors": [],
113113
"params": [
@@ -180,7 +180,7 @@
180180
"column": 49
181181
}
182182
},
183-
"code": "function MyClass() {\n this.howMany = 2;\n}\n\n/**\n * Get the number 42\n * @param {boolean} getIt whether to get the number\n * @returns {number} forty-two\n */\nMyClass.prototype.getFoo = function (getIt) {\n return getIt ? 42 : 0;\n};\n\n/**\n * Get undefined\n * @returns {undefined} does not return anything.\n */\nMyClass.prototype.getUndefined = function () { };"
183+
"code": "/**\n * This is my class, a demo thing.\n * @class MyClass\n * @property {number} howMany how many things it contains\n */\nfunction MyClass() {\n this.howMany = 2;\n}\n\n/**\n * Get the number 42\n * @param {boolean} getIt whether to get the number\n * @returns {number} forty-two\n */\nMyClass.prototype.getFoo = function (getIt) {\n return getIt ? 42 : 0;\n};\n\n/**\n * Get undefined\n * @returns {undefined} does not return anything.\n */\nMyClass.prototype.getUndefined = function () { };\n"
184184
},
185185
"errors": [],
186186
"returns": [

test/fixture/es6.output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"column": 31
3434
}
3535
},
36-
"code": "var multiply = (a, b) => a * b;\n\nexport default multiply;"
36+
"code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\nexport default multiply;\n"
3737
},
3838
"errors": [],
3939
"returns": [

test/fixture/event.output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"context": {
5151
"loc": {
5252
"start": {
53-
"line": 9,
53+
"line": 1,
5454
"column": 0
5555
},
5656
"end": {

test/fixture/external.output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"column": 1
2424
}
2525
},
26-
"code": "require('external');\nrequire('external2');\nrequire('module-not-found');\n\n/**\n * I am in `external.input.js`.\n */\nfunction foo() {\n 'use strict';\n return 'bar';\n}\n\nmodule.exports = foo;"
26+
"code": "require('external');\nrequire('external2');\nrequire('module-not-found');\n\n/**\n * I am in `external.input.js`.\n */\nfunction foo() {\n 'use strict';\n return 'bar';\n}\n\nmodule.exports = foo;\n"
2727
},
2828
"errors": [],
2929
"name": "foo",

0 commit comments

Comments
 (0)