@@ -3,9 +3,10 @@ const merge = require('lodash.merge')
33const cloneDeep = require ( 'lodash.clonedeep' )
44const parseAndReplace = require ( './expression_parser' )
55
6- let delimiters , unescapeDelimiters , delimiterRegex , unescapeDelimiterRegex , conditionals , loops
6+ let delimiters , unescapeDelimiters , delimiterRegex , unescapeDelimiterRegex , conditionals , loops , options
77
8- module . exports = function PostHTMLExpressions ( options = { } ) {
8+ module . exports = function PostHTMLExpressions ( _options = { } ) {
9+ options = _options
910 // set up delimiter options and detection
1011 delimiters = options . delimiters || [ '{{' , '}}' ]
1112 unescapeDelimiters = options . unescapeDelimiters || [ '{{{' , '}}}' ]
@@ -146,11 +147,11 @@ function walk (opts, nodes) {
146147 // run the loop, different types of loops for arrays and objects
147148 if ( Array . isArray ( target ) ) {
148149 for ( let index = 0 ; index < target . length ; index ++ ) {
149- m . push ( executeLoop ( loopParams . keys , target [ index ] , index , node , opts ) )
150+ m . push ( executeLoop ( loopParams . keys , target [ index ] , index , node ) )
150151 }
151152 } else {
152153 for ( let key in target ) {
153- m . push ( executeLoop ( loopParams . keys , target [ key ] , key , node , opts ) )
154+ m . push ( executeLoop ( loopParams . keys , target [ key ] , key , node ) )
154155 }
155156 }
156157
@@ -240,15 +241,15 @@ function parseLoopStatement (input) {
240241 * Creates a set of local variables within the loop, and evaluates all nodes
241242 * within the loop, returning their contents
242243 */
243- function executeLoop ( loopParams , p1 , p2 , node , opts ) {
244+ function executeLoop ( loopParams , p1 , p2 , node ) {
244245 // two loop locals are allowed
245246 // - for arrays it's the current value and the index
246247 // - for objects, it's the value and the key
247248 const scopedLocals = { }
248249 scopedLocals [ loopParams [ 0 ] ] = p1
249250 if ( loopParams [ 1 ] ) scopedLocals [ loopParams [ 1 ] ] = p2
250251 // merge nondestructively into existing locals
251- const scopedOptions = merge ( opts , { locals : scopedLocals } )
252+ const scopedOptions = merge ( cloneDeep ( options ) , { locals : scopedLocals } )
252253 // walk through the contents and run replacements with modified options
253254 // we need to clone the node because the normal operation modifies
254255 // the node directly
0 commit comments