Fix overeager JS filtering in polyglot mode.

Fixes #363
This commit is contained in:
Tom MacWright 2016-03-19 16:03:37 -04:00
parent c8ad087308
commit 67f8d9ead9
4 changed files with 120 additions and 4 deletions

View File

@ -102,7 +102,7 @@ module.exports = function (indexes, options, callback) {
filterAccess(options.access,
hierarchy(
inputs
.filter(filterJS(options.extension))
.filter(filterJS(options.extension, options.polyglot))
.reduce(function (memo, file) {
return memo.concat(parseFn(file));
}, [])
@ -160,7 +160,7 @@ module.exports.lint = function lint(indexes, options, callback) {
callback(null,
formatLint(hierarchy(
inputs
.filter(filterJS(options.extension))
.filter(filterJS(options.extension, options.polyglot))
.reduce(function (memo, file) {
return memo.concat(parseFn(file));
}, [])

View File

@ -9,12 +9,20 @@ var path = require('path');
* This creates a filter function for use with Array.prototype.filter, which
* expect as argument a file as an objectg with the 'file' property
*
* @public
* @private
* @param {String|Array} extensions 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) {
function filterJS(extensions, allowAll) {
if (allowAll) {
return function () {
return true;
};
}
extensions = extensions || [];
if (typeof extensions === 'string') {

View File

@ -58,6 +58,28 @@ test('defaults to parsing package.json main', function (t) {
});
}, options);
test('polyglot mode', function (t) {
documentation(['build fixture/polyglot/blend.cpp --polyglot'],
function (err, data) {
t.ifError(err);
if (process.env.UPDATE) {
fs.writeFileSync(
path.resolve(__dirname,
'fixture',
'polyglot/blend.json'), JSON.stringify(normalize(data), null, 2), 'utf8');
}
var expected = fs.readFileSync(
path.resolve(__dirname,
'fixture',
'polyglot/blend.json'), 'utf8');
t.deepEqual(
normalize(data),
JSON.parse(expected),
'parsed C++ file');
t.end();
});
}, options);
test('accepts config file', function (t) {
documentation(['build fixture/sorting/input.js -c fixture/config.json'],
function (err, data) {

86
test/fixture/polyglot/blend.json vendored Normal file
View File

@ -0,0 +1,86 @@
[
{
"description": "This method moves a hex to a color",
"tags": [
{
"title": "name",
"description": null,
"lineNumber": 2,
"name": "hexToUInt32Color"
},
{
"title": "param",
"description": null,
"lineNumber": 3,
"type": {
"type": "NameExpression",
"name": "string"
},
"name": "hex"
},
{
"title": "returns",
"description": "color",
"lineNumber": 4,
"type": {
"type": "NameExpression",
"name": "number"
}
}
],
"loc": {
"start": {
"line": 35,
"column": 1
},
"end": {
"line": 40,
"column": 3
}
},
"context": {
"loc": {
"start": {
"line": 35,
"column": 1
},
"end": {
"line": 40,
"column": 3
}
},
"file": "[path]"
},
"name": "hexToUInt32Color",
"params": [
{
"title": "param",
"description": null,
"lineNumber": 3,
"type": {
"type": "NameExpression",
"name": "string"
},
"name": "hex"
}
],
"returns": [
{
"title": "returns",
"description": "color",
"lineNumber": 4,
"type": {
"type": "NameExpression",
"name": "number"
}
}
],
"members": {
"instance": [],
"static": []
},
"path": [
"hexToUInt32Color"
]
}
]