Skip to content

Reparse transformed source #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2015
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
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict';

var sort = require('./lib/sort'),
concat = require('concat-stream'),
nestParams = require('./lib/nest_params'),
filterAccess = require('./lib/filter_access'),
filterJS = require('./lib/filter_js'),
dependency = require('./streams/input/dependency'),
shallow = require('./streams/input/shallow'),
dependency = require('./lib/input/dependency'),
shallow = require('./lib/input/shallow'),
parse = require('./lib/parsers/javascript'),
polyglot = require('./lib/parsers/polyglot'),
github = require('./lib/github'),
Expand Down Expand Up @@ -47,11 +46,12 @@ module.exports = function (indexes, options, callback) {
indexes = [indexes];
}

var inputStream = options.polyglot ?
shallow(indexes).pipe(polyglot()) :
(options.shallow ? shallow(indexes) : dependency(indexes, options));
var inputFn = (options.polyglot || options.shallow) ? shallow : dependency;

return inputStream.pipe(concat(function (inputs) {
return inputFn(indexes, options, function (error, inputs) {
if (error) {
return callback(error);
}
try {
var flat = inputs
.filter(filterJS)
Expand All @@ -77,7 +77,7 @@ module.exports = function (indexes, options, callback) {
} catch (e) {
callback(e);
}
}));
});
};

module.exports.formats = {
Expand Down
24 changes: 19 additions & 5 deletions streams/input/dependency.js → lib/input/dependency.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

var mdeps = require('module-deps'),
fs = require('fs'),
path = require('path'),
babelify = require('babelify'),
concat = require('concat-stream'),
moduleFilters = require('../../lib/module_filters');

/**
Expand All @@ -13,22 +16,33 @@ var mdeps = require('module-deps'),
*
* @param {Array<string>} indexes paths to entry files as strings
* @param {Object} options optional options passed
* @param {Array<Object>} [options.transform=[]] optional array of transforms
* @returns {ReadableStream} output
* @param {Function} callback called with (err, inputs)
* @returns {undefined} calls callback
*/
function dependencyStream(indexes, options) {
function dependencyStream(indexes, options, callback) {
var md = mdeps({
filter: function (id) {
return !!options.external || moduleFilters.internalOnly(id);
},
transform: options.transform,
transform: [babelify.configure({
sourceMap: false
})],
postFilter: moduleFilters.externals(indexes, options)
});
indexes.forEach(function (index) {
md.write(path.resolve(index));
});
md.end();
return md;
md.once('error', function (error) {
return callback(error);
});
md.pipe(concat(function (inputs) {
callback(null, inputs.map(function (input) {
// un-transform babelify transformed source
input.source = fs.readFileSync(input.file, 'utf8');
return input
}));
}));
}

module.exports = dependencyStream;
9 changes: 5 additions & 4 deletions streams/input/shallow.js → lib/input/shallow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

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

/**
Expand All @@ -16,10 +15,12 @@ var fs = require('fs');
* or without fs access.
*
* @param {Array<string|Object>} indexes entry points
* @return {ReadableStream} this emits data
* @param {Object} options parsing options
* @param {Function} callback called with (err, inputs)
* @return {undefined} calls callback
*/
module.exports = function (indexes) {
return streamify(indexes.map(function (index) {
module.exports = function (indexes, options, callback) {
return callback(null, indexes.map(function (index) {
if (typeof index === 'string') {
return {
source: fs.readFileSync(index, 'utf8'),
Expand Down
1 change: 0 additions & 1 deletion lib/parsers/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var parseOpts = {
}
};


/**
* Receives a module-dep item,
* reads the file, parses the JavaScript, and parses the JSDoc.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"ast-types": "^0.8.12",
"babelify": "^6.3.0",
"babylon": "^5.8.23",
"brfs": "^1.4.0",
"concat-stream": "^1.5.0",
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/bad/syntax.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"loc": {
"line": 1,
"column": 0
}
},
"_babel": true,
"codeFrame": "> 1 | *\n | ^\n 2 | "
}
7 changes: 7 additions & 0 deletions test/fixture/jsx.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var util = require('util');

/**
* This function returns the number one.
* @returns {Number} numberone
*/
module.exports = (<p>hello</p>);
9 changes: 9 additions & 0 deletions test/fixture/jsx.output.custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# exports

This function returns the number one.


Returns **Number** numberone



64 changes: 64 additions & 0 deletions test/fixture/jsx.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[
{
"description": "This function returns the number one.",
"tags": [
{
"title": "returns",
"description": "numberone",
"lineNumber": 2,
"type": {
"type": "NameExpression",
"name": "Number"
}
}
],
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 6,
"column": 3
}
},
"context": {
"loc": {
"start": {
"line": 7,
"column": 0
},
"end": {
"line": 7,
"column": 32
}
},
"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"
},
"errors": [
"memberof reference to module not found"
],
"returns": [
{
"title": "returns",
"description": "numberone",
"lineNumber": 2,
"type": {
"type": "NameExpression",
"name": "Number"
}
}
],
"name": "exports",
"memberof": "module",
"scope": "static",
"members": {
"instance": [],
"static": []
},
"events": [],
"path": [
"exports"
]
}
]
9 changes: 9 additions & 0 deletions test/fixture/jsx.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# exports

This function returns the number one.


Returns **Number** numberone



139 changes: 139 additions & 0 deletions test/fixture/jsx.output.md.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"type": "root",
"children": [
{
"type": "root",
"children": [
{
"depth": 1,
"type": "heading",
"children": [
{
"type": "text",
"value": "exports"
}
]
},
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This function returns the number one.",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 38
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 38
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 38
}
}
},
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Returns "
},
{
"type": "strong",
"children": [
{
"type": "text",
"value": "Number"
}
]
},
{
"type": "text",
"value": " "
},
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "numberone",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
}
}
]
}
]
}
]
}
]
}
Loading