bem / bem/bem-xjst

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

Open
#495 5 comments 0 reactions 1 assignee Claimed by @miripiruni View on GitHub
status: review type: bug
Dominant language
JavaScript
Stars
117
Forks
48
PR merge metrics
No merged PRs in 30d

Description

### Input code or something about issue background

```js
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

```html
firstTime:


secondTime:

```

### Actual Behavior

```html
firstTime:


secondTime:

```

### Your Environment

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

// cc @vithar

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.