diff --git a/packages/ember-application/lib/system/resolver.js b/packages/ember-application/lib/system/resolver.js index ee8ec96d2aa..f9d57024202 100644 --- a/packages/ember-application/lib/system/resolver.js +++ b/packages/ember-application/lib/system/resolver.js @@ -6,8 +6,8 @@ import { dictionary } from 'ember-utils'; import { get } from 'ember-metal'; import { assert, info } from 'ember-debug'; import { - String as StringUtils, Object as EmberObject, + StringUtils, Namespace } from 'ember-runtime'; import validateType from '../utils/validate-type'; diff --git a/packages/ember-extension-support/lib/container_debug_adapter.js b/packages/ember-extension-support/lib/container_debug_adapter.js index b02e0694c53..752b7be9869 100644 --- a/packages/ember-extension-support/lib/container_debug_adapter.js +++ b/packages/ember-extension-support/lib/container_debug_adapter.js @@ -2,7 +2,7 @@ import Ember from 'ember-metal'; // Ember as namespace import { A as emberA, typeOf, - String as StringUtils, + StringUtils, Namespace, Object as EmberObject } from 'ember-runtime'; diff --git a/packages/ember-extension-support/lib/data_adapter.js b/packages/ember-extension-support/lib/data_adapter.js index c364eb2b759..b25018d9776 100644 --- a/packages/ember-extension-support/lib/data_adapter.js +++ b/packages/ember-extension-support/lib/data_adapter.js @@ -1,7 +1,7 @@ import { getOwner } from 'ember-utils'; import { get, run, objectAt } from 'ember-metal'; import { - String as StringUtils, + StringUtils, Namespace, Object as EmberObject, A as emberA, diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 8e2bebec5fe..23625bd8443 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -32,7 +32,7 @@ import { DEBUG } from 'ember-env-flags'; import { _instrumentStart, get, } from 'ember-metal'; -import { String as StringUtils } from 'ember-runtime'; +import { StringUtils } from 'ember-runtime'; import { assign, getOwner, diff --git a/packages/ember-glimmer/lib/helpers/-class.ts b/packages/ember-glimmer/lib/helpers/-class.ts index 741532c5ee3..e9fecb147ff 100644 --- a/packages/ember-glimmer/lib/helpers/-class.ts +++ b/packages/ember-glimmer/lib/helpers/-class.ts @@ -1,5 +1,5 @@ import { Arguments, VM } from '@glimmer/runtime'; -import { String as StringUtils } from 'ember-runtime'; +import { StringUtils } from 'ember-runtime'; import { InternalHelperReference } from '../utils/references'; function classHelper({ positional }: any) { diff --git a/packages/ember-glimmer/lib/helpers/-normalize-class.ts b/packages/ember-glimmer/lib/helpers/-normalize-class.ts index 3895f772a4e..bf752fe461c 100644 --- a/packages/ember-glimmer/lib/helpers/-normalize-class.ts +++ b/packages/ember-glimmer/lib/helpers/-normalize-class.ts @@ -1,5 +1,5 @@ import { Arguments, VM } from '@glimmer/runtime'; -import { String as StringUtils } from 'ember-runtime'; +import { StringUtils } from 'ember-runtime'; import { InternalHelperReference } from '../utils/references'; function normalizeClass({ positional }: any) { diff --git a/packages/ember-glimmer/lib/helpers/loc.ts b/packages/ember-glimmer/lib/helpers/loc.ts index 07ec7abfd53..d36401a9081 100644 --- a/packages/ember-glimmer/lib/helpers/loc.ts +++ b/packages/ember-glimmer/lib/helpers/loc.ts @@ -3,7 +3,7 @@ @module ember */ -import { String as StringUtils } from 'ember-runtime'; +import { StringUtils } from 'ember-runtime'; import { helper } from '../helper'; /** diff --git a/packages/ember-glimmer/lib/index.ts b/packages/ember-glimmer/lib/index.ts index ee4ebf20bb5..459c553091c 100644 --- a/packages/ember-glimmer/lib/index.ts +++ b/packages/ember-glimmer/lib/index.ts @@ -273,7 +273,9 @@ export { SafeString, escapeExpression, htmlSafe, - isHTMLSafe + deprecatedHTMLSafe, + isHTMLSafe, + deprecatedIsHTMLSafe, } from './utils/string'; export { Renderer, diff --git a/packages/ember-glimmer/lib/utils/bindings.ts b/packages/ember-glimmer/lib/utils/bindings.ts index 15c64b4823d..de84661de79 100644 --- a/packages/ember-glimmer/lib/utils/bindings.ts +++ b/packages/ember-glimmer/lib/utils/bindings.ts @@ -17,7 +17,7 @@ import { import { Core, Ops } from '@glimmer/wire-format'; import { assert } from 'ember-debug'; import { get } from 'ember-metal'; -import { String as StringUtils } from 'ember-runtime'; +import { StringUtils } from 'ember-runtime'; import { ROOT_REF } from '../component'; import { Component } from './curly-component-state-bucket'; import { referenceFromParts } from './references'; diff --git a/packages/ember-glimmer/lib/utils/string.ts b/packages/ember-glimmer/lib/utils/string.ts index 31e28cc0b4d..aa37e12540a 100644 --- a/packages/ember-glimmer/lib/utils/string.ts +++ b/packages/ember-glimmer/lib/utils/string.ts @@ -2,6 +2,8 @@ @module @ember/string */ +import { deprecate } from 'ember-debug'; + export class SafeString { public string: string; @@ -72,6 +74,7 @@ export function escapeExpression(string: any): string { @static @return {Handlebars.SafeString} A string that will not be HTML escaped by Handlebars. @public + @deprecated */ export function htmlSafe(str: string) { if (str === null || str === undefined) { @@ -82,6 +85,19 @@ export function htmlSafe(str: string) { return new SafeString(str); } +export function deprecatedHTMLSafe(str : string) { + deprecate( + 'Ember.String namespace is deprecated. Please, import `htmlSafe` from `ember/template`.', + false, + { + id: 'ember-glimmer.ember-string-html-safe', + until: '3.5.0', + url: '' + } + ); + return htmlSafe(str); +} + /** Detects if a string was decorated using `htmlSafe`. @@ -100,7 +116,21 @@ export function htmlSafe(str: string) { @static @return {Boolean} `true` if the string was decorated with `htmlSafe`, `false` otherwise. @public + @deprecated */ export function isHTMLSafe(str: any | null | undefined): str is SafeString { return str !== null && typeof str === 'object' && typeof str.toHTML === 'function'; } + +export function deprecatedIsHTMLSafe(str: string | SafeString): str is SafeString { + deprecate( + 'Ember.String namespace is deprecated. Please, import `isHTMLSafe` from `ember/template`.', + false, + { + id: 'ember-glimmer.ember-string-is-html-safe', + until: '3.5.0', + url: '' + } + ); + return isHTMLSafe(str); +} diff --git a/packages/ember-glimmer/tests/utils/helpers.js b/packages/ember-glimmer/tests/utils/helpers.js index 5176c6f49d3..34b8d2bc72a 100644 --- a/packages/ember-glimmer/tests/utils/helpers.js +++ b/packages/ember-glimmer/tests/utils/helpers.js @@ -12,7 +12,9 @@ export { InteractiveRender, InertRenderer, htmlSafe, + deprecatedHTMLSafe, SafeString, DOMChanges, - isHTMLSafe + isHTMLSafe, + deprecatedIsHTMLSafe } from 'ember-glimmer'; diff --git a/packages/ember-glimmer/tests/utils/string-test.js b/packages/ember-glimmer/tests/utils/string-test.js index c3fe64b1934..7a7513b327e 100644 --- a/packages/ember-glimmer/tests/utils/string-test.js +++ b/packages/ember-glimmer/tests/utils/string-test.js @@ -1,8 +1,19 @@ -import { SafeString, htmlSafe, isHTMLSafe } from './helpers'; +import { + SafeString, + htmlSafe, + deprecatedHTMLSafe, + isHTMLSafe, + deprecatedIsHTMLSafe +} from './helpers'; import { TestCase } from './abstract-test-case'; import { moduleFor } from './test-case'; moduleFor('SafeString', class extends TestCase { + ['@test deprecated version is deprecated']() { + expectDeprecation(/ember\/template/); + deprecatedHTMLSafe("Hello"); + } + ['@test htmlSafe should return an instance of SafeString']() { let safeString = htmlSafe('you need to be more bold'); @@ -25,6 +36,11 @@ moduleFor('SafeString', class extends TestCase { }); moduleFor('SafeString isHTMLSafe', class extends TestCase { + ['@test deprecated version is deprecated']() { + expectDeprecation(/ember\/template/); + deprecatedIsHTMLSafe("Hello"); + } + ['@test isHTMLSafe should detect SafeString']() { let safeString = htmlSafe('Emphasize the important things.'); diff --git a/packages/ember-routing/lib/system/route.js b/packages/ember-routing/lib/system/route.js index cb1d7224bd1..b981db54e6e 100644 --- a/packages/ember-routing/lib/system/route.js +++ b/packages/ember-routing/lib/system/route.js @@ -13,7 +13,7 @@ import { DEBUG } from 'ember-env-flags'; import { typeOf, copy, - String as StringUtils, + StringUtils, Object as EmberObject, A as emberA, Evented, diff --git a/packages/ember-runtime/lib/ext/string.js b/packages/ember-runtime/lib/ext/string.js index dc05fa46ee7..1530b45ba2f 100644 --- a/packages/ember-runtime/lib/ext/string.js +++ b/packages/ember-runtime/lib/ext/string.js @@ -3,6 +3,7 @@ */ import { ENV } from 'ember-environment'; +import { deprecate } from 'ember-debug'; import { w, loc, @@ -16,7 +17,24 @@ import { const StringPrototype = String.prototype; +function deprecateEmberStringPrototypeExtension(name, fn, opts = {}) { + return function (...args) { + deprecate( + opts.message || `String prototype extensions are deprecated. Please, use ${name} from '@ember/string' instead.`, + false, + opts.options || { + id: 'ember-string.prototype_extensions', + until: '3.5.0', + url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-string-prototype-extensions' + } + ); + + return fn(this, ...args); + }; +} + if (ENV.EXTEND_PROTOTYPES.String) { + /** See [String.w](/api/ember/release/classes/String/methods/w?anchor=w). @@ -29,9 +47,7 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return w(this); - } + value: deprecateEmberStringPrototypeExtension('w', w) }); /** @@ -46,9 +62,9 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function(...args) { - return loc(this, args); - } + value: deprecateEmberStringPrototypeExtension('loc', loc, { + message: '`loc` is deprecated. Please, use an i18n addon instead. See https://emberobserver.com/categories/internationalization for a list of them.', + }) }); /** @@ -63,9 +79,7 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return camelize(this); - } + value: deprecateEmberStringPrototypeExtension('camelize', camelize) }); /** @@ -80,9 +94,7 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return decamelize(this); - } + value: deprecateEmberStringPrototypeExtension('decamelize', decamelize) }); /** @@ -97,9 +109,7 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return dasherize(this); - } + value: deprecateEmberStringPrototypeExtension('dasherize', dasherize) }); /** @@ -114,9 +124,7 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return underscore(this); - } + value: deprecateEmberStringPrototypeExtension('underscore', underscore) }); /** @@ -131,9 +139,7 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return classify(this); - } + value: deprecateEmberStringPrototypeExtension('classify', classify) }); /** @@ -148,8 +154,6 @@ if (ENV.EXTEND_PROTOTYPES.String) { configurable: true, enumerable: false, writeable: true, - value: function() { - return capitalize(this); - } + value: deprecateEmberStringPrototypeExtension('capitalize', capitalize) }); } diff --git a/packages/ember-runtime/lib/index.d.ts b/packages/ember-runtime/lib/index.d.ts index bd8cc8ebd5b..6b1d355b996 100644 --- a/packages/ember-runtime/lib/index.d.ts +++ b/packages/ember-runtime/lib/index.d.ts @@ -18,6 +18,20 @@ export const String: { loc(s: string, ...args: string[]): string; }; +export const StringUtils: { + fmt(s: string, ...args: any[]): string, + loc(s: string, ...args: any[]): string, + w(s: string): string[], + decamelize(s: string): string, + dasherize(s: string): string, + camelize(s: string): string, + classify(s: string): string, + underscore(s: string): string, + capitalize(s: string): string +} + +export function objectAt(arr: any, i: number): any; + export function isEmberArray(arr: any): boolean; export function _contentFor(proxy: any): any; diff --git a/packages/ember-runtime/lib/index.js b/packages/ember-runtime/lib/index.js index ab57fb0d994..6480c2cbd25 100644 --- a/packages/ember-runtime/lib/index.js +++ b/packages/ember-runtime/lib/index.js @@ -1,5 +1,5 @@ export { default as Object, FrameworkObject } from './system/object'; -export { default as String } from './system/string'; +export { default as String, StringUtils } from './system/string'; export { default as RegistryProxyMixin, } from './mixins/registry_proxy'; diff --git a/packages/ember-runtime/lib/system/string.js b/packages/ember-runtime/lib/system/string.js index fc647aa08cd..a7f0d2acaef 100644 --- a/packages/ember-runtime/lib/system/string.js +++ b/packages/ember-runtime/lib/system/string.js @@ -1,6 +1,7 @@ /** @module @ember/string */ +import { deprecate } from 'ember-debug'; import { Cache } from 'ember-metal'; import { inspect } from 'ember-utils'; import { isArray } from '../utils'; @@ -105,6 +106,22 @@ function capitalize(str) { return CAPITALIZE_CACHE.get(str); } +export function deprecateEmberStringUtil(name, fn, opts = {}) { + return function (...args) { + deprecate( + opts.message || `Ember.String namespace is deprecated. Please, use ${name} from '@ember/string' instead.`, + false, + opts.options || { + id: 'ember-string.namespace', + until: '3.5.0', + url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-string-namespace' + } + ); + + return fn(...args); + }; +} + /** Defines string helper methods including string formatting and localization. Unless `EmberENV.EXTEND_PROTOTYPES.String` is `false` these methods will also be @@ -139,8 +156,9 @@ export default { @param {Array} formats Optional array of parameters to interpolate into string. @return {String} formatted string @public + @deprecated Use @ember/string addon instead. */ - loc, + loc: deprecateEmberStringUtil('loc', loc), /** Splits a string into separate units separated by spaces, eliminating any @@ -163,8 +181,9 @@ export default { @param {String} str The string to split @return {Array} array containing the split strings @public + @deprecated Use @ember/string addon instead. */ - w, + w: deprecateEmberStringUtil('w', w), /** Converts a camelized string into all lower case separated by underscores. @@ -180,8 +199,9 @@ export default { @param {String} str The string to decamelize. @return {String} the decamelized string. @public + @deprecated Use @ember/string addon instead. */ - decamelize, + decamelize: deprecateEmberStringUtil('decamelize', decamelize), /** Replaces underscores, spaces, or camelCase with dashes. @@ -198,8 +218,9 @@ export default { @param {String} str The string to dasherize. @return {String} the dasherized string. @public + @deprecated Use @ember/string addon instead. */ - dasherize, + dasherize: deprecateEmberStringUtil('dasherize', dasherize), /** Returns the lowerCamelCase form of a string. @@ -217,8 +238,9 @@ export default { @param {String} str The string to camelize. @return {String} the camelized string. @public + @deprecated Use @ember/string addon instead. */ - camelize, + camelize: deprecateEmberStringUtil('camelize', camelize), /** Returns the UpperCamelCase form of a string. @@ -235,8 +257,9 @@ export default { @param {String} str the string to classify @return {String} the classified string @public + @deprecated Use @ember/string addon instead. */ - classify, + classify: deprecateEmberStringUtil('classify', classify), /** More general than decamelize. Returns the lower\_case\_and\_underscored @@ -254,8 +277,9 @@ export default { @param {String} str The string to underscore. @return {String} the underscored string. @public + @deprecated Use @ember/string addon instead. */ - underscore, + underscore: deprecateEmberStringUtil('underscore', underscore), /** Returns the Capitalized form of a string @@ -272,8 +296,9 @@ export default { @param {String} str The string to capitalize. @return {String} The capitalized string. @public + @deprecated Use @ember/string addon instead. */ - capitalize + capitalize: deprecateEmberStringUtil('capitalize', capitalize) }; export { @@ -286,3 +311,14 @@ export { underscore, capitalize }; + +export const StringUtils = { + loc, + w, + decamelize, + dasherize, + camelize, + classify, + underscore, + capitalize +}; diff --git a/packages/ember-runtime/tests/system/string/camelize_test.js b/packages/ember-runtime/tests/system/string/camelize_test.js index 433b9378aa6..a37992f72c2 100644 --- a/packages/ember-runtime/tests/system/string/camelize_test.js +++ b/packages/ember-runtime/tests/system/string/camelize_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { camelize } from '../../../system/string'; +import { camelize, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.camelize'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.camelize is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.camelize('hello world'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(camelize(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.camelize(), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/capitalize_test.js b/packages/ember-runtime/tests/system/string/capitalize_test.js index 07064a16a17..cc872ede19b 100644 --- a/packages/ember-runtime/tests/system/string/capitalize_test.js +++ b/packages/ember-runtime/tests/system/string/capitalize_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { capitalize } from '../../../system/string'; +import { capitalize, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.capitalize'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.capitalize is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.capitalize('hello world'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(capitalize(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.capitalize(), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/classify_test.js b/packages/ember-runtime/tests/system/string/classify_test.js index 83c4d1b97d8..979873992fb 100644 --- a/packages/ember-runtime/tests/system/string/classify_test.js +++ b/packages/ember-runtime/tests/system/string/classify_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { classify } from '../../../system/string'; +import { classify, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.classify'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.classify is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.classify('hello world'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(classify(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.classify(), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/dasherize_test.js b/packages/ember-runtime/tests/system/string/dasherize_test.js index a2ed66bfe51..c05894df530 100644 --- a/packages/ember-runtime/tests/system/string/dasherize_test.js +++ b/packages/ember-runtime/tests/system/string/dasherize_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { dasherize } from '../../../system/string'; +import { dasherize, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.dasherize'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.dasherize is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.dasherize('HelloWorld'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(dasherize(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.dasherize(), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/decamelize_test.js b/packages/ember-runtime/tests/system/string/decamelize_test.js index f635e18825d..677b79d157e 100644 --- a/packages/ember-runtime/tests/system/string/decamelize_test.js +++ b/packages/ember-runtime/tests/system/string/decamelize_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { decamelize } from '../../../system/string'; +import { decamelize, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.decamelize'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.decamelize is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.decamelize('HelloWorld'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(decamelize(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.decamelize(), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/loc_test.js b/packages/ember-runtime/tests/system/string/loc_test.js index 1d9926a22e2..21739c41397 100644 --- a/packages/ember-runtime/tests/system/string/loc_test.js +++ b/packages/ember-runtime/tests/system/string/loc_test.js @@ -1,8 +1,8 @@ +import Ember from 'ember-metal'; import { ENV } from 'ember-environment'; import { loc } from '../../../system/string'; import { setStrings, getStrings } from '../../../string_registry'; - let oldString; QUnit.module('EmberStringUtils.loc', { @@ -27,10 +27,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.loc is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + Ember.String.loc('_Hello World', []); +}); + function test(given, args, expected, description) { QUnit.test(description, function(assert) { assert.equal(loc(given, args), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/`loc` is deprecated/); assert.equal(given.loc(...args), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/underscore_test.js b/packages/ember-runtime/tests/system/string/underscore_test.js index 52ac5acc806..61e86a099b4 100644 --- a/packages/ember-runtime/tests/system/string/underscore_test.js +++ b/packages/ember-runtime/tests/system/string/underscore_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { underscore } from '../../../system/string'; +import { underscore, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.underscore'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.underscore is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.underscore('hello world'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(underscore(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.underscore(), expected); } }); diff --git a/packages/ember-runtime/tests/system/string/w_test.js b/packages/ember-runtime/tests/system/string/w_test.js index d42194851fb..275a5ecd426 100644 --- a/packages/ember-runtime/tests/system/string/w_test.js +++ b/packages/ember-runtime/tests/system/string/w_test.js @@ -1,5 +1,5 @@ import { ENV } from 'ember-environment'; -import { w } from '../../../system/string'; +import { w, default as EmberString } from '../../../system/string'; QUnit.module('EmberStringUtils.w'); @@ -9,10 +9,16 @@ if (!ENV.EXTEND_PROTOTYPES.String) { }); } +QUnit.test('Ember.String.w is deprecated', function() { + expectDeprecation(/Ember.String namespace is deprecated/); + EmberString.w('Hello World'); +}); + function test(given, expected, description) { QUnit.test(description, function(assert) { assert.deepEqual(w(given), expected); if (ENV.EXTEND_PROTOTYPES.String) { + expectDeprecation(/@ember\/string/); assert.deepEqual(given.w(), expected); } }); diff --git a/packages/ember/lib/index.js b/packages/ember/lib/index.js index 78d87cd073a..20cf774cef0 100644 --- a/packages/ember/lib/index.js +++ b/packages/ember/lib/index.js @@ -424,9 +424,11 @@ import { TextField, TextArea, LinkComponent, + deprecatedHTMLSafe, htmlSafe, template, escapeExpression, + deprecatedIsHTMLSafe, isHTMLSafe, getTemplates, setTemplates @@ -442,6 +444,15 @@ Ember.LinkComponent = LinkComponent; if (ENV.EXTEND_PROTOTYPES.String) { String.prototype.htmlSafe = function() { + deprecate( + `Extending String prototype is deprecated. Please, use htmlSafe from 'ember/template'.`, + false, + { + id: 'ember-runtime.string-prototype-extension', + until: '3.5.0', + url: '' + } + ); return htmlSafe(this); }; } @@ -452,9 +463,9 @@ let EmberHandleBarsUtils = EmberHandlebars.Utils = EmberHandlebars.Utils || {}; EmberHTMLBars.template = EmberHandlebars.template = template; EmberHandleBarsUtils.escapeExpression = escapeExpression; -EmberString.htmlSafe = htmlSafe; +EmberString.htmlSafe = deprecatedHTMLSafe; -EmberString.isHTMLSafe = isHTMLSafe; +EmberString.isHTMLSafe = deprecatedIsHTMLSafe; /** Global hash of shared templates. This will automatically be populated @@ -473,6 +484,19 @@ Object.defineProperty(Ember, 'TEMPLATES', { enumerable: false }); +/** + Global for safe usage of methods coming from module 'ember/template'. + + @property Template + @for Ember + @type Object + @private + */ +Ember._Template = { + htmlSafe, + isHTMLSafe +}; + import VERSION from './version'; export { VERSION }; diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index eadf0fec202..79068e6c560 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -130,7 +130,9 @@ let allExports =[ ['TEMPLATES', 'ember-glimmer', { get: 'getTemplates', set: 'setTemplates' }], ['Handlebars.template', 'ember-glimmer', 'template'], ['Handlebars.Utils.escapeExpression', 'ember-glimmer', 'escapeExpression'], - ['String.htmlSafe', 'ember-glimmer', 'htmlSafe'], + ['String.htmlSafe', 'ember-glimmer', 'deprecatedHTMLSafe'], + ['_Template.htmlSafe', 'ember-glimmer', 'htmlSafe'], + ['_Template.isHTMLSafe', 'ember-glimmer', 'isHTMLSafe'], // ember-runtime ['_RegistryProxyMixin', 'ember-runtime', 'RegistryProxyMixin'], @@ -214,7 +216,7 @@ allExports.forEach(reexport => { }); QUnit.test('Ember.String.isHTMLSafe exports correctly', function(assert) { - confirmExport(Ember, assert, 'String.isHTMLSafe', 'ember-glimmer', 'isHTMLSafe'); + confirmExport(Ember, assert, 'String.isHTMLSafe', 'ember-glimmer', 'deprecatedIsHTMLSafe'); }); if (DEBUG) { diff --git a/packages/ember/tests/routing/query_params_test.js b/packages/ember/tests/routing/query_params_test.js index 50f83fbfcc7..1e391058a2d 100644 --- a/packages/ember/tests/routing/query_params_test.js +++ b/packages/ember/tests/routing/query_params_test.js @@ -3,7 +3,7 @@ import { RSVP, Object as EmberObject, A as emberA, - String as StringUtils + StringUtils } from 'ember-runtime'; import { run, diff --git a/packages/ember/tests/routing/router_service_test/urlFor_test.js b/packages/ember/tests/routing/router_service_test/urlFor_test.js index 61fca5e3766..27d59e0a4f1 100644 --- a/packages/ember/tests/routing/router_service_test/urlFor_test.js +++ b/packages/ember/tests/routing/router_service_test/urlFor_test.js @@ -1,6 +1,6 @@ import { Controller, - String + StringUtils } from 'ember-runtime'; import { Route } from 'ember-routing'; import { @@ -14,7 +14,7 @@ import { import { EMBER_ROUTING_ROUTER_SERVICE } from 'ember/features'; function setupController(app, name) { - let controllerName = `${String.capitalize(name)}Controller`; + let controllerName = `${StringUtils.capitalize(name)}Controller`; Object.defineProperty(app, controllerName, { get() {