Skip to content

Commit

Permalink
Merge pull request #19643 from nlfurniss/remove-deprecate-without-for…
Browse files Browse the repository at this point in the history
…-and-since

Remove deprecate without for and since
  • Loading branch information
mixonic committed Jul 20, 2021
2 parents 7222c5e + a8c007c commit 023c3df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 102 deletions.
52 changes: 8 additions & 44 deletions packages/@ember/debug/lib/deprecate.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
};
Expand All @@ -241,9 +209,5 @@ export {
registerHandler,
missingOptionsDeprecation,
missingOptionsIdDeprecation,
missingOptionsUntilDeprecation,
missingOptionsForDeprecation,
missingOptionsSinceDeprecation,
FOR_MISSING_DEPRECATIONS,
SINCE_MISSING_DEPRECATIONS,
missingOptionDeprecation,
};
75 changes: 17 additions & 58 deletions packages/@ember/debug/tests/main_test.js
Expand Up @@ -5,11 +5,7 @@ import {
registerHandler,
missingOptionsDeprecation,
missingOptionsIdDeprecation,
missingOptionsUntilDeprecation,
missingOptionsForDeprecation,
missingOptionsSinceDeprecation,
FOR_MISSING_DEPRECATIONS,
SINCE_MISSING_DEPRECATIONS,
missingOptionDeprecation,
} from '../lib/deprecate';

import {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -256,6 +250,7 @@ moduleFor(
assert.expect(4);
let id = 'ABC';
let until = 'forever';
let since = 'forever';
let shouldThrow = false;

registerHandler(function (message, options) {
Expand All @@ -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');
Expand Down Expand Up @@ -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'
);
}
Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 023c3df

Please sign in to comment.