File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed
Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module.exports = (options = {}) => {
2020 let content ;
2121 let subtree ;
2222 let source ;
23- const posthtmlExpressionsOptions = options . posthtmlExpressionsOptions || { locals : false } ;
23+ let posthtmlExpressionsOptions = options . posthtmlExpressionsOptions || { locals : false } ;
2424 if ( options . delimiters ) {
2525 posthtmlExpressionsOptions . delimiters = options . delimiters ;
2626 }
@@ -32,7 +32,10 @@ module.exports = (options = {}) => {
3232 try {
3333 const localsRaw = node . attrs . locals || ( node . content ? node . content . join ( ) . replace ( / \n / g, '' ) : false ) ;
3434 const localsJson = JSON . parse ( localsRaw ) ;
35- posthtmlExpressionsOptions . locals = posthtmlExpressionsOptions . locals ? Object . assign ( localsJson , posthtmlExpressionsOptions . locals ) : localsJson ;
35+ posthtmlExpressionsOptions = {
36+ ...posthtmlExpressionsOptions ,
37+ locals : posthtmlExpressionsOptions . locals ? Object . assign ( localsJson , posthtmlExpressionsOptions . locals ) : localsJson
38+ } ;
3639 } catch { }
3740
3841 if ( posthtmlExpressionsOptions . locals ) {
Original file line number Diff line number Diff line change 1+ < div > local1</ div >
2+ < div > global</ div >
3+
4+ < div > local2</ div >
5+ < div > global</ div >
6+
7+ < div > local3</ div >
8+ < div > global</ div >
9+
10+ < div > local4</ div >
11+ < div > global</ div >
12+
13+ < div > local5</ div >
14+ < div > global</ div >
Original file line number Diff line number Diff line change 1+ < include src ="./test/fixtures/includes/6.html "> { "localVariable": "local1" }</ include >
2+ < include src ="./test/fixtures/includes/6.html "> { "localVariable": "local2" }</ include >
3+ < include src ="./test/fixtures/includes/6.html "> { "localVariable": "local3" }</ include >
4+ < include src ="./test/fixtures/includes/6.html "> { "localVariable": "local4" }</ include >
5+ < include src ="./test/fixtures/includes/6.html "> { "localVariable": "local5" }</ include >
Original file line number Diff line number Diff line change 11const test = require ( 'ava' )
2- const plugin = require ( '../lib' )
2+ const plugin = require ( '../lib/index.js ' )
33const posthtml = require ( 'posthtml' )
44
55const path = require ( 'path' )
@@ -60,6 +60,13 @@ test('Should merge global locals', t => {
6060 } } )
6161} )
6262
63+ test ( 'Should merge global variables and evaluate each local variable' , t => {
64+ return process ( t , 'multiple-include' , {
65+ posthtmlExpressionsOptions : {
66+ locals : { globalVariable : 'global' }
67+ } } )
68+ } )
69+
6370test ( 'addDependency message' , t => {
6471 const includePath = require ( 'path' ) . resolve ( './test/fixtures/blocks/button/button.html' )
6572
You can’t perform that action at this time.
0 commit comments