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

Add deprecation warning to Ember.assign #19634

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 3 additions & 4 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Controller from '@ember/controller';
import { assert, deprecate, info } from '@ember/debug';
import { APP_CTRL_ROUTER_PROPS, ROUTER_EVENTS } from '@ember/deprecated-features';
import EmberError from '@ember/error';
import { assign } from '@ember/polyfills';
import { cancel, once, run, scheduleOnce } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
import EmberLocation, { EmberLocation as IEmberLocation } from '../location/api';
Expand Down Expand Up @@ -1018,7 +1017,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {

this._processActiveTransitionQueryParams(targetRouteName, models, queryParams, _queryParams);

assign(queryParams, _queryParams);
Object.assign(queryParams, _queryParams);
this._prepareQueryParams(
targetRouteName,
models,
Expand Down Expand Up @@ -1059,7 +1058,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
// from the active transition.
this._fullyScopeQueryParams(targetRouteName, models, _queryParams);
this._fullyScopeQueryParams(targetRouteName, models, unchangedQPs);
assign(queryParams, unchangedQPs);
Object.assign(queryParams, unchangedQPs);
}

/**
Expand Down Expand Up @@ -1156,7 +1155,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
qps.push(qp);
}

assign(map, qpMeta.map);
Object.assign(map, qpMeta.map);
}

let finalQPMeta = { qps, map };
Expand Down
1 change: 1 addition & 0 deletions packages/@ember/deprecated-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = !!'3.13.0-beta.1';
export const EMBER_COMPONENT_IS_VISIBLE = !!'3.15.0-beta.1';
export const PARTIALS = !!'3.15.0-beta.1';
export const GLOBALS_RESOLVER = !!'3.16.0-beta.1';
export const ASSIGN = !!'4.0.0';
6 changes: 4 additions & 2 deletions packages/@ember/polyfills/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { MERGE } from '@ember/deprecated-features';
import { ASSIGN, MERGE } from '@ember/deprecated-features';
import { assign as assignPolyfill, default as deprecatedAssign } from './lib/assign';
import { default as deprecatedMerge } from './lib/merge';

let merge = MERGE ? deprecatedMerge : undefined;
let assign = ASSIGN ? deprecatedAssign : undefined;

// Export `assignPolyfill` for testing
export { default as assign, assign as assignPolyfill } from './lib/assign';
export { assign, assignPolyfill };
export { merge };

export const hasPropertyAccessors = true;
16 changes: 16 additions & 0 deletions packages/@ember/polyfills/lib/assign.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { deprecate } from '@ember/debug';

/**
@module @ember/polyfills
*/
Expand Down Expand Up @@ -28,6 +30,20 @@ export function assign(target: object, ...sources: any[]): any;
@static
*/
export function assign(target: object) {
deprecate(
'Use of `assign` has been deprecated. Please use `Object.assign` or the spread operator instead.',
false,
{
id: 'ember-polyfills.deprecate-assign',
until: '5.0.0',
url: 'https://deprecations.emberjs.com/v4.x/#toc_ember-polyfills-deprecate-assign',
for: 'ember-source',
since: {
enabled: '4.0.0',
},
}
);

for (let i = 1; i < arguments.length; i++) {
let arg = arguments[i];
if (!arg) {
Expand Down
4 changes: 3 additions & 1 deletion packages/@ember/polyfills/tests/assign_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ moduleFor(
'Ember.assign (polyfill)',
class extends AssignTests {
assign() {
return assignPolyfill(...arguments);
return expectDeprecation(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return expectDeprecation(() => {
expectDeprecation(() => {

If we can safely discard the return value of assignPolyfill's result, then we simply don't need a return value.

assignPolyfill(...arguments);
}, 'Use of `assign` has been deprecated. Please use `Object.assign` or the spread operator instead.');
}
}
);
Expand Down