From 93739c18993f98e186a85f9b1b4590ed0cc09eee Mon Sep 17 00:00:00 2001 From: Stephen Collings Date: Mon, 4 Apr 2016 14:05:13 +0100 Subject: [PATCH 1/3] Add failing test for .jsx dependency --- test/bin.js | 7 +++++++ test/fixture/extension.jsx | 1 + test/fixture/extension/extension-required.jsx | 1 + 3 files changed, 9 insertions(+) create mode 100644 test/fixture/extension.jsx create mode 100644 test/fixture/extension/extension-required.jsx diff --git a/test/bin.js b/test/bin.js index 5c5b96e34..ed7c585ab 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/extension.jsx b/test/fixture/extension.jsx new file mode 100644 index 000000000..b2e593ec6 --- /dev/null +++ b/test/fixture/extension.jsx @@ -0,0 +1 @@ +var required = require('./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 = {}; From caa1637880d7418b4a4d164010a6b0e6dfbdd3d9 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 3 Jun 2016 13:31:14 -0400 Subject: [PATCH 2/3] Fix ability to require() JSON and other files without extension. Fixes #402 --- lib/filter_js.js | 10 +- lib/input/dependency.js | 6 ++ test/fixture/es6-ext.es6 | 4 + test/fixture/es6-import.input.js | 1 + test/fixture/es6-import.output.json | 102 ++++++++++++++++-- test/fixture/es6-import.output.md | 4 + test/fixture/es6-import.output.md.json | 45 ++++++++ .../require-json-no-extension.input.js | 1 + .../require-json-no-extension.output.json | 1 + .../require-json-no-extension.output.md | 1 + .../require-json-no-extension.output.md.json | 4 + 11 files changed, 166 insertions(+), 13 deletions(-) create mode 100644 test/fixture/es6-ext.es6 create mode 100644 test/fixture/require-json-no-extension.input.js create mode 100644 test/fixture/require-json-no-extension.output.json create mode 100644 test/fixture/require-json-no-extension.output.md create mode 100644 test/fixture/require-json-no-extension.output.md.json 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/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/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 From 367078e34d25d7db7cb13dded9910d170d1fa360 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 3 Jun 2016 13:56:34 -0400 Subject: [PATCH 3/3] Fix and combine extension testcase --- test/fixture/extension.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixture/extension.jsx b/test/fixture/extension.jsx index b2e593ec6..213dc0d51 100644 --- a/test/fixture/extension.jsx +++ b/test/fixture/extension.jsx @@ -1 +1 @@ -var required = require('./extension-required'); +var required = require('./extension/extension-required');