diff --git a/lib/filter_js.js b/lib/filter_js.js index 589c31f20..73e126687 100644 --- a/lib/filter_js.js +++ b/lib/filter_js.js @@ -10,13 +10,13 @@ var path = require('path'); * expect as argument a file as an objectg with the 'file' property * * @private - * @param {String|Array} extensions to be filtered + * @param {String|Array} extension to be filtered * @param {boolean} allowAll ignore the entire extension check and always * pass through files. This is used by the polglot mode. * @return {Function} a filter function, this function returns true if the input filename extension * is in the extension whitelist */ -function filterJS(extensions, allowAll) { +function filterJS(extension, allowAll) { if (allowAll) { return function () { @@ -24,11 +24,7 @@ function filterJS(extensions, allowAll) { }; } - extensions = extensions || []; - if (typeof extensions === 'string') { - extensions = [extensions]; - } - extensions = extensions.concat(['js', 'es6', 'jsx']); + var extensions = [].concat(extension || []).concat(['js', 'es6', 'jsx']); return function (data) { return extensions.indexOf(path.extname(data.file).substring(1)) !== -1; diff --git a/lib/input/dependency.js b/lib/input/dependency.js index 65a058785..464aba2c2 100644 --- a/lib/input/dependency.js +++ b/lib/input/dependency.js @@ -23,6 +23,7 @@ var mdeps = require('module-deps-sortable'), */ function dependencyStream(indexes, options, callback) { var filterer = filterJS(options.extension, options.polyglot); + var md = mdeps({ /** * Determine whether a module should be included in documentation @@ -32,6 +33,11 @@ function dependencyStream(indexes, options, callback) { filter: function (id) { return !!options.external || moduleFilters.internalOnly(id); }, + extensions: [].concat(options.extension || []) + .concat(['js', 'es6', 'jsx', 'json']) + .map(function (ext) { + return '.' + ext; + }), transform: [babelify.configure({ sourceMap: false, presets: [ diff --git a/test/bin.js b/test/bin.js index 3ba9e650c..6e74bf048 100644 --- a/test/bin.js +++ b/test/bin.js @@ -128,6 +128,13 @@ test('extension option', function (t) { }); }); +test('extension option', function (t) { + documentation(['build fixture/extension.jsx'], function (err, data) { + t.ifError(err); + t.end(); + }); +}); + test('invalid arguments', function (group) { group.test('bad -f option', function (t) { documentation(['build -f DOES-NOT-EXIST fixture/internal.input.js'], function (err) { diff --git a/test/fixture/es6-ext.es6 b/test/fixture/es6-ext.es6 new file mode 100644 index 000000000..7b2aaedff --- /dev/null +++ b/test/fixture/es6-ext.es6 @@ -0,0 +1,4 @@ +/** + * This is the default export frogs! + */ +export default 10; diff --git a/test/fixture/es6-import.input.js b/test/fixture/es6-import.input.js index 772ab77cc..12d244dbc 100644 --- a/test/fixture/es6-import.input.js +++ b/test/fixture/es6-import.input.js @@ -1,3 +1,4 @@ +import hasEx6 from './es6-ext'; import multiply from "./es6.input.js"; import * as foo from "some-other-module"; diff --git a/test/fixture/es6-import.output.json b/test/fixture/es6-import.output.json index 2ee9bd0e2..b4e18d84e 100644 --- a/test/fixture/es6-import.output.json +++ b/test/fixture/es6-import.output.json @@ -65,26 +65,26 @@ ], "loc": { "start": { - "line": 4, + "line": 5, "column": 0 }, "end": { - "line": 7, + "line": 8, "column": 3 } }, "context": { "loc": { "start": { - "line": 8, + "line": 9, "column": 0 }, "end": { - "line": 8, + "line": 9, "column": 43 } }, - "code": "import multiply from \"./es6.input.js\";\nimport * as foo from \"some-other-module\";\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiplyTwice = (a) => a * multiply(a);\n\nexport default multiplyTwice;\n" + "code": "import hasEx6 from './es6-ext';\nimport multiply from \"./es6.input.js\";\nimport * as foo from \"some-other-module\";\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiplyTwice = (a) => a * multiply(a);\n\nexport default multiplyTwice;\n" }, "errors": [], "returns": [ @@ -153,7 +153,7 @@ { "title": "param", "name": "a", - "lineNumber": 8 + "lineNumber": 9 } ], "members": { @@ -168,6 +168,96 @@ ], "namespace": "multiplyTwice" }, + { + "description": { + "type": "root", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This is the default export frogs!", + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 34, + "offset": 33 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 34, + "offset": 33 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 34, + "offset": 33 + } + } + }, + "tags": [], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "code": "/**\n * This is the default export frogs!\n */\nexport default 10;\n" + }, + "errors": [], + "name": "es6-ext", + "members": { + "instance": [], + "static": [] + }, + "path": [ + { + "name": "es6-ext" + } + ], + "namespace": "es6-ext" + }, { "description": { "type": "root", diff --git a/test/fixture/es6-import.output.md b/test/fixture/es6-import.output.md index 83802c08e..6d0be24ba 100644 --- a/test/fixture/es6-import.output.md +++ b/test/fixture/es6-import.output.md @@ -8,6 +8,10 @@ This function returns the number one. Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** numberone +# es6-ext + +This is the default export frogs! + # destructure This function destructures with defaults. diff --git a/test/fixture/es6-import.output.md.json b/test/fixture/es6-import.output.md.json index b5c1a4b93..dfac7e528 100644 --- a/test/fixture/es6-import.output.md.json +++ b/test/fixture/es6-import.output.md.json @@ -147,6 +147,51 @@ } ] }, + { + "depth": 1, + "type": "heading", + "children": [ + { + "type": "text", + "value": "es6-ext" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This is the default export frogs!", + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 34, + "offset": 33 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1, + "offset": 0 + }, + "end": { + "line": 1, + "column": 34, + "offset": 33 + }, + "indent": [] + } + }, { "depth": 1, "type": "heading", diff --git a/test/fixture/extension.jsx b/test/fixture/extension.jsx new file mode 100644 index 000000000..213dc0d51 --- /dev/null +++ b/test/fixture/extension.jsx @@ -0,0 +1 @@ +var required = require('./extension/extension-required'); diff --git a/test/fixture/extension/extension-required.jsx b/test/fixture/extension/extension-required.jsx new file mode 100644 index 000000000..f053ebf79 --- /dev/null +++ b/test/fixture/extension/extension-required.jsx @@ -0,0 +1 @@ +module.exports = {}; diff --git a/test/fixture/require-json-no-extension.input.js b/test/fixture/require-json-no-extension.input.js new file mode 100644 index 000000000..91f5103ca --- /dev/null +++ b/test/fixture/require-json-no-extension.input.js @@ -0,0 +1 @@ +var data = require('./require-json'); diff --git a/test/fixture/require-json-no-extension.output.json b/test/fixture/require-json-no-extension.output.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/test/fixture/require-json-no-extension.output.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/fixture/require-json-no-extension.output.md b/test/fixture/require-json-no-extension.output.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/test/fixture/require-json-no-extension.output.md @@ -0,0 +1 @@ + diff --git a/test/fixture/require-json-no-extension.output.md.json b/test/fixture/require-json-no-extension.output.md.json new file mode 100644 index 000000000..2b1e4c832 --- /dev/null +++ b/test/fixture/require-json-no-extension.output.md.json @@ -0,0 +1,4 @@ +{ + "type": "root", + "children": [] +} \ No newline at end of file