jridgewell / babel-plugin-transform-incremental-dom

Turn JSX into IncrementalDOM
MIT License
145 stars 12 forks source link

Eagerly evaluate attributes that mutate key #84

Closed jridgewell closed 7 years ago

jridgewell commented 7 years ago

If the key is not the first computed attribute, we will eagerly evaluate any attributes that came before it avoid a bug in the compiling. Ie:

var i = 0;
function render() {
  return <div attr={i++} key={i++} />;
}

Will now evaluate the attr’s value before the key’s value and rewrite the nodes to the eagerly evaluate expression.

var _div$statics = ["key", ""];
var i = 0;
function render() {
  var _attr, _ref;

  _attr = i++;
  return elementVoid("div", _ref = i++, (_div$statics[1] = _ref, _div$statics), "attr", _attr);
}

Fixes #83.