Skip to content

wrap() mutates bemjson which can lead to error for second run for same input data #495

Open
@tadatuta

Description

@tadatuta

Input code or something about issue background

const bemhtml = require('bem-xjst').bemhtml;
const tmpl = bemhtml.compile(function() {
    block('b1').wrap()(node => ({
        block: 'b2',
        content: node.ctx
    }));
});

const bemjson = { block: 'b1' };

const firstTime = tmpl.apply(bemjson);
const secondTime = tmpl.apply(bemjson);

console.log('firstTime:', firstTime);
console.log('secondTime:', secondTime);

Important!

  1. bemjson should be passed by reference
  2. the same instance of compiled template should be used

Expected Behavior

firstTime: <div class="b2"><div class="b1"></div></div>
secondTime: <div class="b2"><div class="b1"></div></div>

Actual Behavior

firstTime: <div class="b2"><div class="b1"></div></div>
secondTime: <div class="b1"></div>

Your Environment

Any version of bem-xjst with wrap() support.

// cc @vithar

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions