@@ -49,6 +49,20 @@ function matchAll(s, r) {
4949 return matches ;
5050}
5151
52+ function getVar ( env , pre , key ) {
53+ var r = typeof env === 'function' ? env ( key ) : env [ key ] ;
54+ if ( typeof r === 'undefined' && key != '' ) {
55+ r = '' ;
56+ } else if ( typeof r === 'undefined' ) {
57+ r = '$' ;
58+ }
59+
60+ if ( typeof r === 'object' ) {
61+ return pre + TOKEN + JSON . stringify ( r ) + TOKEN ;
62+ }
63+ return pre + r ;
64+ }
65+
5266function parseInternal ( string , env , opts ) {
5367 if ( ! opts ) {
5468 opts = { } ;
@@ -72,20 +86,6 @@ function parseInternal(string, env, opts) {
7286
7387 var commented = false ;
7488
75- function getVar ( _ , pre , key ) {
76- var r = typeof env === 'function' ? env ( key ) : env [ key ] ;
77- if ( r === undefined && key != '' ) {
78- r = '' ;
79- } else if ( r === undefined ) {
80- r = '$' ;
81- }
82-
83- if ( typeof r === 'object' ) {
84- return pre + TOKEN + JSON . stringify ( r ) + TOKEN ;
85- }
86- return pre + r ;
87- }
88-
8989 return matches . map ( function ( match ) {
9090 var s = match [ 0 ] ;
9191 if ( ! s || commented ) {
@@ -143,7 +143,7 @@ function parseInternal(string, env, opts) {
143143 i += varend . index - 1 ;
144144 }
145145 }
146- return getVar ( null , '' , varname ) ;
146+ return getVar ( env , '' , varname ) ;
147147 }
148148
149149 for ( i = 0 ; i < s . length ; i ++ ) {
0 commit comments