Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Deprecate Ember.String.fmt until 3.0.0 #11969

Merged
merged 1 commit into from
Aug 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});