check for functions in util.shouldIgnore - closes #1865, closes #1859

This commit is contained in:
Sebastian McKenzie
2015-07-07 11:23:31 +01:00
parent 4d25b0d96a
commit 4a36a9fb31
2 changed files with 28 additions and 3 deletions

View File

@@ -56,7 +56,7 @@ export function resolveRelative(loc: string) {
}
}
export function list(val: string): Array<string> {
export function list(val: string): Array {
if (!val) {
return [];
} else if (Array.isArray(val)) {
@@ -114,18 +114,26 @@ export function shouldIgnore(filename, ignore, only) {
if (only) {
for (let pattern of (only: Array)) {
if (pattern.test(filename)) return false;
if (_shouldIgnore(pattern, filename)) return false;
}
return true;
} else if (ignore.length) {
for (let pattern of (ignore: Array)) {
if (pattern.test(filename)) return true;
if (_shouldIgnore(pattern, filename)) return true;
}
}
return false;
}
function _shouldIgnore(pattern, filename) {
if (typeof pattern === "function") {
return pattern(filename);
} else {
return pattern.test(filename);
}
}
var templateVisitor = {
noScope: true,

View File

@@ -72,6 +72,7 @@ suite("util", function () {
assert.deepEqual(util.arrayify("foo,bar"), ["foo", "bar"]);
assert.deepEqual(util.arrayify(["foo", "bar"]), ["foo", "bar"]);
assert.deepEqual(util.arrayify({ foo: "bar" }), [{ foo: "bar" }]);
assert.deepEqual(util.arrayify(function () { return "foo"; })[0](), "foo");
});
test("regexify", function () {
@@ -110,4 +111,20 @@ suite("util", function () {
assert.equal(t.toIdentifier(t.identifier("swag")), "swag");
assert.equal(t.toIdentifier("swag-lord"), "swagLord");
});
test("shouldIgnore", function () {
var reIgnore = /\-reIgnore\.js/;
var fnIgnore = function (src) {
if (src.indexOf("fnIgnore") > 0) {
return true;
}
};
assert.equal(util.shouldIgnore("test.js", []), false);
assert.equal(util.shouldIgnore("test-reIgnore.js", [fnIgnore]), false);
assert.equal(util.shouldIgnore("test-reIgnore.js", [reIgnore]), true);
assert.equal(util.shouldIgnore("test-fnIgnore.js", [fnIgnore]), true);
assert.equal(util.shouldIgnore("test-fnIgnore.js", [reIgnore]), false);
});
});