Clone KV or use orig srcOffsets when replacing a token's attr (kv).

* An alternate patch for https://gerrit.wikimedia.org/r/50345

  During token transformations, a token's attributes are sometimes
  replaced.  But, this would lose src-offsets from the original KV
  object.  This commit fixes that by cloning the original KV in
  most places before replacing the k/v value, and where cloning is
  cumbersome/excessive (ex: new KV([], []), it passes along the
  srcOffsets field from the original KV.

* Sample snippet to test: {{echo|<math>a=3</math>}}

* Eliminates crasher from: roundtrip-test.js 'Homographic function'

* Verified that mw:TemplateParams continue to be recorded and
  output correctly on a few different pages.

* No change in parser tests results.

* Unrelated fixes in ext.core.AttributeExpander.js:
  - Dont clone attributes when cloning the token since they will
    be replaced.
  - Other minor code cleanup.

Change-Id: I97e98e0e9e035b573d48a8dc9214e29add769a39