ember-watson icon indicating copy to clipboard operation
ember-watson copied to clipboard

Transform Ember.String.fmt with ES6 string interpolation

Open abuiles opened this issue 9 years ago • 5 comments

abuiles avatar May 12 '15 21:05 abuiles

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?

Serabe avatar Jul 10 '15 23:07 Serabe

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";

kamal avatar Jul 10 '15 23:07 kamal

Yes, that looks much better.

knownasilya avatar Jul 10 '15 23:07 knownasilya

@kamal your code would transform into:

const str = `a ${b} b ${a} c ${a} d`

And what happens if a, b or care function calls that we do not expect to be called twice?

Serabe avatar Jul 10 '15 23:07 Serabe

Just wondering if the ability to transform the .fmt string prototype has been included in watson yet?

dgavey avatar Apr 18 '16 21:04 dgavey