Skip to content

Commit

Permalink
Merge pull request #11969 from cibernox/deprecate_string_fmt
Browse files Browse the repository at this point in the history
[BUGFIX beta] Deprecate Ember.String.fmt until 3.0.0
  • Loading branch information
rwjblue committed Aug 3, 2015
2 parents 1873a12 + fcdfd9a commit a5a0489
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/ember-runtime/lib/ext/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
@method fmt
@for String
@private
@deprecated
*/
StringPrototype.fmt = function (...args) {
return fmt(this, args);
Expand Down
13 changes: 11 additions & 2 deletions packages/ember-runtime/lib/system/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var DECAMELIZE_CACHE = new Cache(1000, function(str) {
return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase();
});

function fmt(str, formats) {
function _fmt(str, formats) {
var cachedFormats = formats;

if (!isArray(cachedFormats) || arguments.length > 2) {
Expand All @@ -80,13 +80,22 @@ function fmt(str, formats) {
});
}

function fmt(str, formats) {
Ember.deprecate(
'Ember.String.fmt is deprecated, use ES6 template strings instead.',
false,
{ id: 'ember-string-utils.fmt', until: '3.0.0', url: 'https://babeljs.io/docs/learn-es6/#template-strings' }
);
return _fmt(...arguments);
}

function loc(str, formats) {
if (!isArray(formats) || arguments.length > 2) {
formats = Array.prototype.slice.call(arguments, 1);
}

str = Ember.STRINGS[str] || str;
return fmt(str, formats);
return _fmt(str, formats);
}

function w(str) {
Expand Down
5 changes: 5 additions & 0 deletions packages/ember-runtime/tests/system/string/fmt_string_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ if (!Ember.EXTEND_PROTOTYPES && !Ember.EXTEND_PROTOTYPES.String) {
}

QUnit.test('\'Hello %@ %@\'.fmt(\'John\', \'Doe\') => \'Hello John Doe\'', function() {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal(fmt('Hello %@ %@', ['John', 'Doe']), 'Hello John Doe');
if (Ember.EXTEND_PROTOTYPES) {
equal('Hello %@ %@'.fmt('John', 'Doe'), 'Hello John Doe');
}
});

QUnit.test('\'Hello %@2 %@1\'.fmt(\'John\', \'Doe\') => \'Hello Doe John\'', function() {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal(fmt('Hello %@2 %@1', ['John', 'Doe']), 'Hello Doe John');
if (Ember.EXTEND_PROTOTYPES) {
equal('Hello %@2 %@1'.fmt('John', 'Doe'), 'Hello Doe John');
}
});

QUnit.test('\'%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01\'.fmt(\'One\', \'Two\', \'Three\', \'Four\', \'Five\', \'Six\', \'Seven\', \'Eight\') => \'Eight Seven Six Five Four Three Two One\'', function() {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal(fmt('%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01', ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']), 'Eight Seven Six Five Four Three Two One');

if (Ember.EXTEND_PROTOTYPES) {
Expand All @@ -32,13 +35,15 @@ QUnit.test('\'%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01\'.fmt(\'One\', \'Two\', \'
});

QUnit.test('\'data: %@\'.fmt({ id: 3 }) => \'data: {id: 3}\'', function() {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal(fmt('data: %@', [{ id: 3 }]), 'data: {id: 3}');
if (Ember.EXTEND_PROTOTYPES) {
equal('data: %@'.fmt({ id: 3 }), 'data: {id: 3}');
}
});

QUnit.test('works with argument form', function() {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal(fmt('%@', 'John'), 'John');
equal(fmt('%@ %@', ['John'], 'Doe'), '[John] Doe');
});

0 comments on commit a5a0489

Please sign in to comment.