Skip to content

Commit 4b50db0

Browse files
damassiForbesLindesay
authored andcommitted
[pug-filters] do not silence errors when attempting to require filters (#3002)
1 parent 23897f3 commit 4b50db0

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

packages/pug-filters/lib/run-filter.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,34 @@ var resolve = require('resolve');
88
module.exports = filter;
99
function filter(name, str, options, currentDirectory, funcName) {
1010
funcName = funcName || 'render';
11-
var tr;
11+
var trPath;
1212
try {
1313
try {
14-
tr = require(resolve.sync('jstransformer-' + name, {basedir: currentDirectory || process.cwd()}));
14+
trPath = resolve.sync('jstransformer-' + name, {basedir: currentDirectory || process.cwd()});
1515
} catch (ex) {
16-
tr = require('jstransformer-' + name);
16+
trPath = require.resolve('jstransformer-' + name);
1717
}
18-
tr = jstransformer(tr);
19-
} catch (ex) {}
20-
if (tr) {
21-
// TODO: we may want to add a way for people to separately specify "locals"
22-
var result = tr[funcName](str, options, options).body;
23-
if (options && options.minify) {
24-
try {
25-
switch (tr.outputFormat) {
26-
case 'js':
27-
result = uglify.minify(result, {fromString: true}).code;
28-
break;
29-
case 'css':
30-
result = new CleanCSS().minify(result).styles;
31-
break;
32-
}
33-
} catch (ex) {
34-
// better to fail to minify than output nothing
35-
}
36-
}
37-
return result;
38-
} else {
18+
} catch (ex) {
3919
var err = new Error('unknown filter ":' + name + '"');
4020
err.code = 'UNKNOWN_FILTER';
4121
throw err;
4222
}
23+
var tr = jstransformer(require(trPath));
24+
// TODO: we may want to add a way for people to separately specify "locals"
25+
var result = tr[funcName](str, options, options).body;
26+
if (options && options.minify) {
27+
try {
28+
switch (tr.outputFormat) {
29+
case 'js':
30+
result = uglify.minify(result, {fromString: true}).code;
31+
break;
32+
case 'css':
33+
result = new CleanCSS().minify(result).styles;
34+
break;
35+
}
36+
} catch (ex) {
37+
// better to fail to minify than output nothing
38+
}
39+
}
40+
return result;
4341
}

0 commit comments

Comments
 (0)