Skip to content

Commit 2c391e3

Browse files
authored
Merge pull request #79 from nokazn/feature/overload-locals
locals at each node overwrite locals difined globally
2 parents eea8959 + 602599d commit 2c391e3

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = (options = {}) => {
3434
const localsJson = JSON.parse(localsRaw);
3535
posthtmlExpressionsOptions = {
3636
...posthtmlExpressionsOptions,
37-
locals: posthtmlExpressionsOptions.locals ? Object.assign(localsJson, posthtmlExpressionsOptions.locals) : localsJson
37+
locals: posthtmlExpressionsOptions.locals ? Object.assign(posthtmlExpressionsOptions.locals, localsJson) : localsJson
3838
};
3939
} catch {}
4040

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>Should override global locals</div>
2+
<div>local</div>
3+
<div>local</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>Should override global locals</div>
2+
<div>local</div>
3+
<div>local</div>

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ test('Should merge global locals', t => {
6060
}})
6161
})
6262

63+
test('Should override global locals', t => {
64+
return process(t, 'override-global-variables', {
65+
posthtmlExpressionsOptions: {
66+
locals: {globalVariable: 'global'}
67+
}})
68+
})
69+
6370
test('Should merge global variables and evaluate each local variable', t => {
6471
return process(t, 'multiple-include', {
6572
posthtmlExpressionsOptions: {

0 commit comments

Comments
 (0)