Skip to content

Commit c38b91b

Browse files
committed
Reparse transformed source
1 parent c50cb7e commit c38b91b

File tree

13 files changed

+280
-32
lines changed

13 files changed

+280
-32
lines changed

index.js

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

33
var sort = require('./lib/sort'),
4-
concat = require('concat-stream'),
54
nestParams = require('./lib/nest_params'),
65
filterAccess = require('./lib/filter_access'),
76
filterJS = require('./lib/filter_js'),
8-
dependency = require('./streams/input/dependency'),
9-
shallow = require('./streams/input/shallow'),
7+
dependency = require('./lib/input/dependency'),
8+
shallow = require('./lib/input/shallow'),
109
parse = require('./lib/parsers/javascript'),
1110
polyglot = require('./lib/parsers/polyglot'),
1211
github = require('./lib/github'),
@@ -47,11 +46,12 @@ module.exports = function (indexes, options, callback) {
4746
indexes = [indexes];
4847
}
4948

50-
var inputStream = options.polyglot ?
51-
shallow(indexes).pipe(polyglot()) :
52-
(options.shallow ? shallow(indexes) : dependency(indexes, options));
49+
var inputFn = (options.polyglot || options.shallow) ? shallow : dependency;
5350

54-
return inputStream.pipe(concat(function (inputs) {
51+
return inputFn(indexes, options, function (error, inputs) {
52+
if (error) {
53+
return callback(error);
54+
}
5555
try {
5656
var flat = inputs
5757
.filter(filterJS)
@@ -77,7 +77,7 @@ module.exports = function (indexes, options, callback) {
7777
} catch (e) {
7878
callback(e);
7979
}
80-
}));
80+
});
8181
};
8282

8383
module.exports.formats = {
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use strict';
22

33
var mdeps = require('module-deps'),
4+
fs = require('fs'),
45
path = require('path'),
6+
babelify = require('babelify'),
7+
concat = require('concat-stream'),
58
moduleFilters = require('../../lib/module_filters');
69

710
/**
@@ -13,22 +16,33 @@ var mdeps = require('module-deps'),
1316
*
1417
* @param {Array<string>} indexes paths to entry files as strings
1518
* @param {Object} options optional options passed
16-
* @param {Array<Object>} [options.transform=[]] optional array of transforms
17-
* @returns {ReadableStream} output
19+
* @param {Function} callback called with (err, inputs)
20+
* @returns {undefined} calls callback
1821
*/
19-
function dependencyStream(indexes, options) {
22+
function dependencyStream(indexes, options, callback) {
2023
var md = mdeps({
2124
filter: function (id) {
2225
return !!options.external || moduleFilters.internalOnly(id);
2326
},
24-
transform: options.transform,
27+
transform: [babelify.configure({
28+
sourceMap: false
29+
})],
2530
postFilter: moduleFilters.externals(indexes, options)
2631
});
2732
indexes.forEach(function (index) {
2833
md.write(path.resolve(index));
2934
});
3035
md.end();
31-
return md;
36+
md.once('error', function (error) {
37+
return callback(error);
38+
});
39+
md.pipe(concat(function (inputs) {
40+
callback(null, inputs.map(function (input) {
41+
// un-transform babelify transformed source
42+
input.source = fs.readFileSync(input.file, 'utf8');
43+
return input
44+
}));
45+
}));
3246
}
3347

3448
module.exports = dependencyStream;

streams/input/shallow.js renamed to lib/input/shallow.js

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

3-
var streamify = require('stream-array');
43
var fs = require('fs');
54

65
/**
@@ -16,10 +15,12 @@ var fs = require('fs');
1615
* or without fs access.
1716
*
1817
* @param {Array<string|Object>} indexes entry points
19-
* @return {ReadableStream} this emits data
18+
* @param {Object} options parsing options
19+
* @param {Function} callback called with (err, inputs)
20+
* @return {undefined} calls callback
2021
*/
21-
module.exports = function (indexes) {
22-
return streamify(indexes.map(function (index) {
22+
module.exports = function (indexes, options, callback) {
23+
return callback(null, indexes.map(function (index) {
2324
if (typeof index === 'string') {
2425
return {
2526
source: fs.readFileSync(index, 'utf8'),

lib/parsers/javascript.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var parseOpts = {
3434
}
3535
};
3636

37-
3837
/**
3938
* Receives a module-dep item,
4039
* reads the file, parses the JavaScript, and parses the JSDoc.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"ast-types": "^0.8.12",
19+
"babelify": "^6.3.0",
1920
"babylon": "^5.8.23",
2021
"brfs": "^1.4.0",
2122
"concat-stream": "^1.5.0",

test/fixture/bad/syntax.output.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"loc": {
44
"line": 1,
55
"column": 0
6-
}
6+
},
7+
"_babel": true,
8+
"codeFrame": "> 1 | *\n | ^\n 2 | "
79
}

test/fixture/jsx.input.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var util = require('util');
2+
3+
/**
4+
* This function returns the number one.
5+
* @returns {Number} numberone
6+
*/
7+
module.exports = (<p>hello</p>);

test/fixture/jsx.output.custom.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# exports
2+
3+
This function returns the number one.
4+
5+
6+
Returns **Number** numberone
7+
8+
9+

test/fixture/jsx.output.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[
2+
{
3+
"description": "This function returns the number one.",
4+
"tags": [
5+
{
6+
"title": "returns",
7+
"description": "numberone",
8+
"lineNumber": 2,
9+
"type": {
10+
"type": "NameExpression",
11+
"name": "Number"
12+
}
13+
}
14+
],
15+
"loc": {
16+
"start": {
17+
"line": 3,
18+
"column": 0
19+
},
20+
"end": {
21+
"line": 6,
22+
"column": 3
23+
}
24+
},
25+
"context": {
26+
"loc": {
27+
"start": {
28+
"line": 7,
29+
"column": 0
30+
},
31+
"end": {
32+
"line": 7,
33+
"column": 32
34+
}
35+
},
36+
"code": "var util = require('util');\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nmodule.exports = (<p>hello</p>);\n"
37+
},
38+
"errors": [
39+
"memberof reference to module not found"
40+
],
41+
"returns": [
42+
{
43+
"title": "returns",
44+
"description": "numberone",
45+
"lineNumber": 2,
46+
"type": {
47+
"type": "NameExpression",
48+
"name": "Number"
49+
}
50+
}
51+
],
52+
"name": "exports",
53+
"memberof": "module",
54+
"scope": "static",
55+
"members": {
56+
"instance": [],
57+
"static": []
58+
},
59+
"events": [],
60+
"path": [
61+
"exports"
62+
]
63+
}
64+
]

test/fixture/jsx.output.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# exports
2+
3+
This function returns the number one.
4+
5+
6+
Returns **Number** numberone
7+
8+
9+

test/fixture/jsx.output.md.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"type": "root",
3+
"children": [
4+
{
5+
"type": "root",
6+
"children": [
7+
{
8+
"depth": 1,
9+
"type": "heading",
10+
"children": [
11+
{
12+
"type": "text",
13+
"value": "exports"
14+
}
15+
]
16+
},
17+
{
18+
"type": "root",
19+
"children": [
20+
{
21+
"type": "paragraph",
22+
"children": [
23+
{
24+
"type": "text",
25+
"value": "This function returns the number one.",
26+
"position": {
27+
"start": {
28+
"line": 1,
29+
"column": 1
30+
},
31+
"end": {
32+
"line": 1,
33+
"column": 38
34+
},
35+
"indent": []
36+
}
37+
}
38+
],
39+
"position": {
40+
"start": {
41+
"line": 1,
42+
"column": 1
43+
},
44+
"end": {
45+
"line": 1,
46+
"column": 38
47+
},
48+
"indent": []
49+
}
50+
}
51+
],
52+
"position": {
53+
"start": {
54+
"line": 1,
55+
"column": 1
56+
},
57+
"end": {
58+
"line": 1,
59+
"column": 38
60+
}
61+
}
62+
},
63+
{
64+
"type": "root",
65+
"children": [
66+
{
67+
"type": "paragraph",
68+
"children": [
69+
{
70+
"type": "text",
71+
"value": "Returns "
72+
},
73+
{
74+
"type": "strong",
75+
"children": [
76+
{
77+
"type": "text",
78+
"value": "Number"
79+
}
80+
]
81+
},
82+
{
83+
"type": "text",
84+
"value": " "
85+
},
86+
{
87+
"type": "root",
88+
"children": [
89+
{
90+
"type": "paragraph",
91+
"children": [
92+
{
93+
"type": "text",
94+
"value": "numberone",
95+
"position": {
96+
"start": {
97+
"line": 1,
98+
"column": 1
99+
},
100+
"end": {
101+
"line": 1,
102+
"column": 10
103+
},
104+
"indent": []
105+
}
106+
}
107+
],
108+
"position": {
109+
"start": {
110+
"line": 1,
111+
"column": 1
112+
},
113+
"end": {
114+
"line": 1,
115+
"column": 10
116+
},
117+
"indent": []
118+
}
119+
}
120+
],
121+
"position": {
122+
"start": {
123+
"line": 1,
124+
"column": 1
125+
},
126+
"end": {
127+
"line": 1,
128+
"column": 10
129+
}
130+
}
131+
}
132+
]
133+
}
134+
]
135+
}
136+
]
137+
}
138+
]
139+
}

0 commit comments

Comments
 (0)