From a8c007c5f15a53868cdc2b129cbb1eaa23ea3611 Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Tue, 13 Jul 2021 19:20:59 -0700 Subject: [PATCH] Remove for and since deprecations from deprecate method --- packages/@ember/debug/lib/deprecate.ts | 52 +++------------- packages/@ember/debug/tests/main_test.js | 75 ++++++------------------ 2 files changed, 25 insertions(+), 102 deletions(-) diff --git a/packages/@ember/debug/lib/deprecate.ts b/packages/@ember/debug/lib/deprecate.ts index d9f99a69b52..13b69501da0 100644 --- a/packages/@ember/debug/lib/deprecate.ts +++ b/packages/@ember/debug/lib/deprecate.ts @@ -21,7 +21,7 @@ export interface DeprecationOptions { } export type DeprecateFunc = (message: string, test?: boolean, options?: DeprecationOptions) => void; -export type MissingOptionDeprecateFunc = (id: string) => string; +export type MissingOptionDeprecateFunc = (id: string, missingOption: string) => string; /** @module @ember/debug @@ -68,12 +68,8 @@ export type MissingOptionDeprecateFunc = (id: string) => string; let registerHandler: (handler: HandlerCallback) => void = () => {}; let missingOptionsDeprecation: string; let missingOptionsIdDeprecation: string; -let missingOptionsUntilDeprecation: string; -let missingOptionsForDeprecation: MissingOptionDeprecateFunc = () => ''; -let missingOptionsSinceDeprecation: MissingOptionDeprecateFunc = () => ''; +let missingOptionDeprecation: MissingOptionDeprecateFunc = () => ''; let deprecate: DeprecateFunc = () => {}; -let FOR_MISSING_DEPRECATIONS = new Set(); -let SINCE_MISSING_DEPRECATIONS = new Set(); if (DEBUG) { registerHandler = function registerHandler(handler: HandlerCallback) { @@ -162,13 +158,9 @@ if (DEBUG) { 'must provide an `options` hash as the third parameter. ' + '`options` should include `id` and `until` properties.'; missingOptionsIdDeprecation = 'When calling `deprecate` you must provide `id` in options.'; - missingOptionsUntilDeprecation = 'When calling `deprecate` you must provide `until` in options.'; - missingOptionsForDeprecation = (id: string) => { - return `When calling \`deprecate\` you must provide \`for\` in options. Missing options.for in "${id}" deprecation`; - }; - missingOptionsSinceDeprecation = (id: string) => { - return `When calling \`deprecate\` you must provide \`since\` in options. Missing options.since in "${id}" deprecation`; + missingOptionDeprecation = (id: string, missingOption: string): string => { + return `When calling \`deprecate\` you must provide \`${missingOption}\` in options. Missing options.${missingOption} in "${id}" deprecation`; }; /** @module @ember/debug @@ -203,33 +195,9 @@ if (DEBUG) { deprecate = function deprecate(message, test, options) { assert(missingOptionsDeprecation, Boolean(options && (options.id || options.until))); assert(missingOptionsIdDeprecation, Boolean(options!.id)); - assert(missingOptionsUntilDeprecation, Boolean(options!.until)); - - if (!options!.for && !FOR_MISSING_DEPRECATIONS.has(options!.id)) { - FOR_MISSING_DEPRECATIONS.add(options!.id); - - deprecate(missingOptionsForDeprecation(options!.id), Boolean(options!.for), { - id: 'ember-source.deprecation-without-for', - until: '4.0.0', - for: 'ember-source', - since: { - enabled: '3.24.0', - }, - }); - } - - if (!options!.since && !SINCE_MISSING_DEPRECATIONS.has(options!.id)) { - SINCE_MISSING_DEPRECATIONS.add(options!.id); - - deprecate(missingOptionsSinceDeprecation(options!.id), Boolean(options!.since), { - id: 'ember-source.deprecation-without-since', - until: '4.0.0', - for: 'ember-source', - since: { - enabled: '3.24.0', - }, - }); - } + assert(missingOptionDeprecation(options!.id, 'until'), Boolean(options!.until)); + assert(missingOptionDeprecation(options!.id, 'for'), Boolean(options!.for)); + assert(missingOptionDeprecation(options!.id, 'since'), Boolean(options!.since)); invoke('deprecate', message, test, options); }; @@ -241,9 +209,5 @@ export { registerHandler, missingOptionsDeprecation, missingOptionsIdDeprecation, - missingOptionsUntilDeprecation, - missingOptionsForDeprecation, - missingOptionsSinceDeprecation, - FOR_MISSING_DEPRECATIONS, - SINCE_MISSING_DEPRECATIONS, + missingOptionDeprecation, }; diff --git a/packages/@ember/debug/tests/main_test.js b/packages/@ember/debug/tests/main_test.js index 3089cb8f6a7..8e476f2bab3 100644 --- a/packages/@ember/debug/tests/main_test.js +++ b/packages/@ember/debug/tests/main_test.js @@ -5,11 +5,7 @@ import { registerHandler, missingOptionsDeprecation, missingOptionsIdDeprecation, - missingOptionsUntilDeprecation, - missingOptionsForDeprecation, - missingOptionsSinceDeprecation, - FOR_MISSING_DEPRECATIONS, - SINCE_MISSING_DEPRECATIONS, + missingOptionDeprecation, } from '../lib/deprecate'; import { @@ -45,8 +41,6 @@ moduleFor( teardown() { HANDLERS.deprecate = originalDeprecateHandler; HANDLERS.warn = originalWarnHandler; - FOR_MISSING_DEPRECATIONS.clear(); - SINCE_MISSING_DEPRECATIONS.clear(); ENV.RAISE_ON_DEPRECATION = originalEnvValue; } @@ -256,6 +250,7 @@ moduleFor( assert.expect(4); let id = 'ABC'; let until = 'forever'; + let since = 'forever'; let shouldThrow = false; registerHandler(function (message, options) { @@ -267,14 +262,24 @@ moduleFor( }); try { - deprecate('Deprecation for testing purposes', false, { id, until }); + deprecate('Deprecation for testing purposes', false, { + id, + until, + since, + for: 'namespace', + }); assert.ok(true, 'Deprecation did not throw'); } catch (e) { assert.ok(false, 'Deprecation was thrown despite being added to blacklist'); } try { - deprecate('Deprecation for testing purposes', false, { id, until }); + deprecate('Deprecation for testing purposes', false, { + id, + until, + since, + for: 'namespace', + }); assert.ok(true, 'Deprecation did not throw'); } catch (e) { assert.ok(false, 'Deprecation was thrown despite being added to blacklist'); @@ -322,7 +327,7 @@ moduleFor( assert.throws( () => deprecate('foo', false, { id: 'test' }), - new RegExp(missingOptionsUntilDeprecation), + new RegExp(missingOptionDeprecation('test', 'until')), 'proper assertion is triggered when options.until is missing' ); } @@ -332,35 +337,11 @@ moduleFor( assert.throws( () => deprecate('message1', false, { id: 'test', until: 'forever' }), - new RegExp(missingOptionsForDeprecation('test')), + new RegExp(missingOptionDeprecation('test', 'for')), 'proper assertion is triggered when options.for is missing' ); } - ['@test deprecate without options.for only triggers once per id'](assert) { - ENV.RAISE_ON_DEPRECATION = false; - let messages = []; - registerHandler(function (message, options, next) { - if (options.id === 'ember-source.deprecation-without-for') { - messages.push(message); - } - next(...arguments); - }); - - deprecate('message1', false, { id: 'test', until: 'forever' }); - deprecate('message2', false, { id: 'test', until: 'forever' }); - deprecate('message3', false, { id: 'another', until: 'forever' }); - - assert.equal(messages.length, 2, 'correct number of deprecations'); - assert.equal(messages[0], missingOptionsForDeprecation('test'), 'first message is correct'); - - assert.equal( - messages[1], - missingOptionsForDeprecation('another'), - 'second message is correct' - ); - } - ['@test deprecate without options.since triggers an assertion'](assert) { assert.expect(1); @@ -371,33 +352,11 @@ moduleFor( until: 'forever', for: 'me', }), - new RegExp(missingOptionsSinceDeprecation('test')), + new RegExp(missingOptionDeprecation('test', 'since')), 'proper assertion is triggered when options.since is missing' ); } - ['@test deprecate without options.since only triggers once per id'](assert) { - ENV.RAISE_ON_DEPRECATION = false; - let messages = []; - registerHandler(function (message, options, next) { - if (options.id === 'ember-source.deprecation-without-since') { - messages.push(message); - } - next(...arguments); - }); - deprecate('foo', false, { id: 'test', until: 'forever', for: 'me' }); - deprecate('foobar', false, { id: 'test', until: 'forever', for: 'me' }); - deprecate('baz', false, { id: 'another', until: 'forever', for: 'me' }); - - assert.equal(messages.length, 2, 'deprecation message only sent once'); - assert.equal(messages[0], missingOptionsSinceDeprecation('test'), 'first message is correct'); - assert.equal( - messages[1], - missingOptionsSinceDeprecation('another'), - 'second message is correct' - ); - } - ['@test warn without options triggers an assert'](assert) { assert.expect(1);