Skip to content

Commit b5a6dfe

Browse files
author
Daniel Clausmeyer
committed
fix: copy options.expressions into new object to not pollute locals
1 parent de0be4a commit b5a6dfe

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ function handleExtendsNodes(tree, options, messages) {
5050
} catch {}
5151
}
5252

53-
options.expressions.locals = merge(options.expressions.locals, locals);
54-
const plugins = [...options.plugins, expressions(options.expressions)];
53+
const plugins = [...options.plugins, expressions({
54+
...options.expressions,
55+
locals: merge(options.expressions.locals, locals)
56+
})];
5557

5658
const layoutPath = path.resolve(options.root, extendsNode.attrs.src);
5759
const layoutHtml = fs.readFileSync(layoutPath, options.encoding);

test/extend.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@ describe('Extend', () => {
428428
});
429429

430430
/*
431-
This plugin merges the locals from options.expressions.locals and the
431+
This plugin used to merge the locals from options.expressions.locals and the
432432
"locals" attribute into the options.expressions.locals property. Arrays in
433-
the attribute locals will be copied into options.expressions.locals and when
434-
the plugin is called again they will be merged again, doubling all array
435-
entries every time the plugin is called.
433+
the attribute locals would be copied into options.expressions.locals and
434+
when the plugin was called again they would be merged again, doubling all
435+
array entries every time the plugin was called.
436436
*/
437437
it('should not pollute options.expression.locals ', async () => {
438438
mfs.writeFileSync('./base.html', `<div class="base">{{ list.join(", ") }}</div>`);
@@ -452,8 +452,8 @@ describe('Extend', () => {
452452
expect(await init(preHtml, options)).toBe(postHtml);
453453
expect(options.expressions.locals).toStrictEqual({});
454454
/*
455-
Since the entries in "list" have been merged with themselves, the content
456-
would be "One, Two, Three, One, Two, Three"
455+
Since the entries in "list" would have been merged with themselves, the
456+
content would have been "One, Two, Three, One, Two, Three"
457457
*/
458458
expect(await init(preHtml, options)).toBe(postHtml);
459459
});

0 commit comments

Comments
 (0)