@@ -8,36 +8,34 @@ var resolve = require('resolve');
8
8
module . exports = filter ;
9
9
function filter ( name , str , options , currentDirectory , funcName ) {
10
10
funcName = funcName || 'render' ;
11
- var tr ;
11
+ var trPath ;
12
12
try {
13
13
try {
14
- tr = require ( resolve . sync ( 'jstransformer-' + name , { basedir : currentDirectory || process . cwd ( ) } ) ) ;
14
+ trPath = resolve . sync ( 'jstransformer-' + name , { basedir : currentDirectory || process . cwd ( ) } ) ;
15
15
} catch ( ex ) {
16
- tr = require ( 'jstransformer-' + name ) ;
16
+ trPath = require . resolve ( 'jstransformer-' + name ) ;
17
17
}
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 ) {
39
19
var err = new Error ( 'unknown filter ":' + name + '"' ) ;
40
20
err . code = 'UNKNOWN_FILTER' ;
41
21
throw err ;
42
22
}
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 ;
43
41
}
0 commit comments