ember-watson
ember-watson copied to clipboard
Transform Ember.String.fmt with ES6 string interpolation
I'm thinking about using the following transformation:
const str = Ember.String.fmt("a @2 b @1 c @ d", a, b, c);
into
let _watson1;
{
let _opts = [a, b, c];
_watson1 = `a ${_opts[1]} b ${_opts[0]} c ${_opts[0]} d`;
}
const str = _watson1;
This transformation only needs to generate a unique reference: _watson1
.
Any thoughts?
I'd prefer it to transform it in place, so
const str = Ember.String.fmt("a @2 b @1 c @ d", a, b, c);
into
const str = "a ${a} b ${b} c ${c} d";
Yes, that looks much better.
@kamal your code would transform into:
const str = `a ${b} b ${a} c ${a} d`
And what happens if a
, b
or c
are function calls that we do not expect to be called twice?
Just wondering if the ability to transform the .fmt string prototype has been included in watson yet?