From 103a212150e694b28ea0478dd81c70bd46d2be8c Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Tue, 13 Jul 2021 15:34:46 -0700 Subject: [PATCH] Remove deprecated loc --- .../-internals/glimmer/lib/helpers/loc.ts | 43 ------ .../-internals/glimmer/lib/setup-registry.ts | 3 - .../tests/integration/helpers/loc-test.js | 127 ------------------ packages/@ember/string/index.ts | 79 ----------- packages/@ember/string/tests/loc_test.js | 80 ----------- packages/ember/tests/reexports_test.js | 1 - tests/docs/expected.js | 1 - 7 files changed, 334 deletions(-) delete mode 100644 packages/@ember/-internals/glimmer/lib/helpers/loc.ts delete mode 100644 packages/@ember/-internals/glimmer/tests/integration/helpers/loc-test.js delete mode 100644 packages/@ember/string/tests/loc_test.js diff --git a/packages/@ember/-internals/glimmer/lib/helpers/loc.ts b/packages/@ember/-internals/glimmer/lib/helpers/loc.ts deleted file mode 100644 index 83a73688d43..00000000000 --- a/packages/@ember/-internals/glimmer/lib/helpers/loc.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** -@module ember -*/ - -import { loc } from '@ember/string'; -import { helper } from '../helper'; - -/** - Calls [String.loc](/ember/release/classes/String/methods/loc?anchor=loc) with the - provided string. This is a convenient way to localize text within a template. - For example: - - ```javascript - Ember.STRINGS = { - '_welcome_': 'Bonjour' - }; - ``` - - ```handlebars -
- {{loc '_welcome_'}} -
- ``` - - ```html -
- Bonjour -
- ``` - - See [String.loc](/ember/release/classes/String/methods/loc?anchor=loc) for how to - set up localized string references. - - @method loc - @for Ember.Templates.helpers - @param {String} str The string to format. - @see {String#loc} - @public - @deprecated -*/ -export default helper(function (params) { - return loc.apply(null, params as any /* let the other side handle errors */); -}); diff --git a/packages/@ember/-internals/glimmer/lib/setup-registry.ts b/packages/@ember/-internals/glimmer/lib/setup-registry.ts index 7eb9588f2d6..4bb5844c9a5 100644 --- a/packages/@ember/-internals/glimmer/lib/setup-registry.ts +++ b/packages/@ember/-internals/glimmer/lib/setup-registry.ts @@ -10,7 +10,6 @@ import LinkTo from './components/link-to'; import TextField from './components/text-field'; import Textarea from './components/textarea'; import { clientBuilder, rehydrationBuilder, serializeBuilder } from './dom'; -import loc from './helpers/loc'; import { Renderer } from './renderer'; import OutletTemplate from './templates/outlet'; import RootTemplate from './templates/root'; @@ -55,8 +54,6 @@ export function setupEngineRegistry(registry: Registry): void { registry.optionsForType('helper', { instantiate: false }); - registry.register('helper:loc', loc); - registry.register('component:-text-field', TextField); registry.register('component:-checkbox', Checkbox); registry.register('component:input', Input); diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/loc-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/loc-test.js deleted file mode 100644 index b5536b06c82..00000000000 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/loc-test.js +++ /dev/null @@ -1,127 +0,0 @@ -import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers'; - -import { set } from '@ember/-internals/metal'; -import { _setStrings } from '@ember/string'; - -moduleFor( - 'Helpers test: {{loc}}', - class extends RenderingTestCase { - constructor() { - super(...arguments); - _setStrings({ - 'Hello Friend': 'Hallo Freund', - Hello: 'Hallo, %@', - }); - } - - teardown() { - super.teardown(); - _setStrings({}); - } - - ['@test it lets the original value through by default']() { - expectDeprecation(() => this.render(`{{loc "Hiya buddy!"}}`), /loc is deprecated/); - this.assertText('Hiya buddy!', 'the unlocalized string is correct'); - runTask(() => this.rerender()); - this.assertText('Hiya buddy!', 'the unlocalized string is correct after rerender'); - } - - ['@test it localizes a simple string']() { - expectDeprecation(() => this.render(`{{loc "Hello Friend"}}`), /loc is deprecated/); - this.assertText('Hallo Freund', 'the localized string is correct'); - runTask(() => this.rerender()); - this.assertText('Hallo Freund', 'the localized string is correct after rerender'); - } - - ['@test it takes passed formats into an account']() { - expectDeprecation(() => { - this.render(`{{loc "%@, %@" "Hello" "Mr. Pitkin"}}`); - }, /loc is deprecated/); - this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct'); - runTask(() => this.rerender()); - this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender'); - } - - ['@test it updates when bound params change']() { - expectDeprecation(() => { - this.render(`{{loc this.simple}} - {{loc this.personal 'Mr. Pitkin'}}`, { - simple: 'Hello Friend', - personal: 'Hello', - }); - this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct'); - }, /loc is deprecated/); - - runTask(() => this.rerender()); - this.assertText( - 'Hallo Freund - Hallo, Mr. Pitkin', - 'the bound value is correct after rerender' - ); - - expectDeprecation(() => { - runTask(() => set(this.context, 'simple', "G'day mate")); - this.assertText( - "G'day mate - Hallo, Mr. Pitkin", - 'the bound value is correct after update' - ); - }, /loc is deprecated/); - - expectDeprecation(() => { - runTask(() => set(this.context, 'simple', 'Hello Friend')); - this.assertText( - 'Hallo Freund - Hallo, Mr. Pitkin', - 'the bound value is correct after reset' - ); - }, /loc is deprecated/); - } - - ['@test it updates when nested bound params change']() { - expectDeprecation(() => { - this.render( - `{{loc this.greetings.simple}} - {{loc this.greetings.personal 'Mr. Pitkin'}}`, - { - greetings: { - simple: 'Hello Friend', - personal: 'Hello', - }, - } - ); - }, /loc is deprecated/); - this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct'); - - runTask(() => this.rerender()); - this.assertText( - 'Hallo Freund - Hallo, Mr. Pitkin', - 'the bound value is correct after rerender' - ); - - expectDeprecation(() => { - runTask(() => set(this.context, 'greetings.simple', "G'day mate")); - this.assertText( - "G'day mate - Hallo, Mr. Pitkin", - 'the bound value is correct after interior mutation' - ); - }, /loc is deprecated/); - - expectDeprecation(() => { - runTask(() => - set(this.context, 'greetings', { - simple: 'Hello Friend', - personal: 'Hello', - }) - ); - this.assertText( - 'Hallo Freund - Hallo, Mr. Pitkin', - 'the bound value is correct after replacement' - ); - }, /loc is deprecated/); - } - - ['@test it can be overriden']() { - this.registerHelper('loc', () => 'Yup'); - this.render(`{{loc this.greeting}}`, { - greeting: 'Hello Friend', - }); - this.assertText('Yup', 'the localized string is correct'); - } - } -); diff --git a/packages/@ember/string/index.ts b/packages/@ember/string/index.ts index ce14383b106..ff1ac0ee5ac 100644 --- a/packages/@ember/string/index.ts +++ b/packages/@ember/string/index.ts @@ -7,7 +7,6 @@ export { getStrings as _getStrings, setStrings as _setStrings } from './lib/stri import { ENV } from '@ember/-internals/environment'; import { Cache } from '@ember/-internals/utils'; import { deprecate } from '@ember/debug'; -import { getString } from './lib/string_registry'; import { htmlSafe as internalHtmlSafe, @@ -81,66 +80,6 @@ const DECAMELIZE_CACHE = new Cache(1000, (str) => @public */ -function _fmt(str: string, formats: any[]) { - // first, replace any ORDERED replacements. - let idx = 0; // the current index for non-numerical replacements - return str.replace(/%@([0-9]+)?/g, (_s: string, argIndex: string) => { - let i = argIndex ? parseInt(argIndex, 10) - 1 : idx++; - let r = i < formats.length ? formats[i] : undefined; - return typeof r === 'string' ? r : r === null ? '(null)' : r === undefined ? '' : String(r); - }); -} - -/** - Formats the passed string, but first looks up the string in the localized - strings hash. This is a convenient way to localize text. - - Note that it is traditional but not required to prefix localized string - keys with an underscore or other character so you can easily identify - localized strings. - - ```javascript - import { loc } from '@ember/string'; - - Ember.STRINGS = { - '_Hello World': 'Bonjour le monde', - '_Hello %@ %@': 'Bonjour %@ %@' - }; - - loc("_Hello World"); // 'Bonjour le monde'; - loc("_Hello %@ %@", ["John", "Smith"]); // "Bonjour John Smith"; - ``` - - @method loc - @param {String} str The string to format - @param {Array} formats Optional array of parameters to interpolate into string. - @return {String} formatted string - @public - @deprecated -*/ -export function loc(str: string, formats: any[]): string { - deprecate( - 'loc is deprecated, please use a dedicated localization solution like ember-intl. More alternatives listed at https://emberobserver.com/categories/internationalization.', - false, - { - id: 'ember-string.loc', - until: '4.0.0', - for: 'ember-source', - url: 'https://deprecations.emberjs.com/v3.x#toc_ember-string-loc', - since: { - enabled: '3.24', - }, - } - ); - - if (!Array.isArray(formats) || arguments.length > 2) { - formats = Array.prototype.slice.call(arguments, 1); - } - - str = getString(str) || str; - return _fmt(str, formats); -} - /** Splits a string into separate units separated by spaces, eliminating any empty strings in the process. This is a convenience method for split that @@ -367,24 +306,6 @@ if (ENV.EXTEND_PROTOTYPES.String) { value: deprecateEmberStringPrototypeExtension('w', w), }, - /** - See [String.loc](/ember/release/classes/String/methods/loc?anchor=loc). - - @method loc - @for @ember/string - @static - @private - @deprecated - */ - loc: { - configurable: true, - enumerable: false, - writeable: true, - value(this: string, ...args: any[]) { - return loc(this, args); - }, - }, - /** See [String.camelize](/ember/release/classes/String/methods/camelize?anchor=camelize). diff --git a/packages/@ember/string/tests/loc_test.js b/packages/@ember/string/tests/loc_test.js deleted file mode 100644 index 33cdc1e6875..00000000000 --- a/packages/@ember/string/tests/loc_test.js +++ /dev/null @@ -1,80 +0,0 @@ -import { ENV } from '@ember/-internals/environment'; -import { loc } from '@ember/string'; -import { setStrings, getStrings } from '@ember/string/lib/string_registry'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; - -let oldString; - -function test(assert, given, args, expected, description) { - expectDeprecation(() => { - assert.equal(loc(given, args), expected, description); - if (ENV.EXTEND_PROTOTYPES.String) { - assert.deepEqual(given.loc(...args), expected, description); - } - }, /loc is deprecated/); -} - -moduleFor( - 'EmberStringUtils.loc', - class extends AbstractTestCase { - beforeEach() { - oldString = getStrings(); - setStrings({ - '_Hello World': 'Bonjour le monde', - '_Hello %@': 'Bonjour %@', - '_Hello %@ %@': 'Bonjour %@ %@', - '_Hello %@# %@#': 'Bonjour %@2 %@1', - }); - } - - afterEach() { - setStrings(oldString); - } - - ['@test String.prototype.loc is not available without EXTEND_PROTOTYPES'](assert) { - if (!ENV.EXTEND_PROTOTYPES.String) { - assert.ok('undefined' === typeof String.prototype.loc, 'String.prototype helper disabled'); - } else { - assert.expect(0); - } - } - - ['@test String loc tests'](assert) { - test( - assert, - '_Hello World', - [], - 'Bonjour le monde', - `loc('_Hello World') => 'Bonjour le monde'` - ); - test( - assert, - '_Hello %@ %@', - ['John', 'Doe'], - 'Bonjour John Doe', - `loc('_Hello %@ %@', ['John', 'Doe']) => 'Bonjour John Doe'` - ); - test( - assert, - '_Hello %@# %@#', - ['John', 'Doe'], - 'Bonjour Doe John', - `loc('_Hello %@# %@#', ['John', 'Doe']) => 'Bonjour Doe John'` - ); - test( - assert, - '_Not In Strings', - [], - '_Not In Strings', - `loc('_Not In Strings') => '_Not In Strings'` - ); - } - - ['@test works with argument form'](assert) { - expectDeprecation(() => { - assert.equal(loc('_Hello %@', 'John'), 'Bonjour John'); - assert.equal(loc('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour John Doe'); - }, /loc is deprecated/); - } - } -); diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index 8960a2a1e1a..49cacd2b3cd 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -435,7 +435,6 @@ let allExports = [ ['String.decamelize', '@ember/string', 'decamelize'], ['String.htmlSafe', '@ember/-internals/glimmer', 'htmlSafe'], ['String.isHTMLSafe', '@ember/-internals/glimmer', 'isHTMLSafe'], - ['String.loc', '@ember/string', 'loc'], ['String.underscore', '@ember/string', 'underscore'], ['String.w', '@ember/string', 'w'], ['STRINGS', '@ember/string', { get: '_getStrings', set: '_setStrings' }], diff --git a/tests/docs/expected.js b/tests/docs/expected.js index 340eefc7de2..3a1c6cbc046 100644 --- a/tests/docs/expected.js +++ b/tests/docs/expected.js @@ -351,7 +351,6 @@ module.exports = { 'loading', 'loadingClass', 'loadingHref', - 'loc', 'localName', 'location', 'log',