From 81c889ccce7db641942c01eb836d4820502fb278 Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Tue, 6 Jul 2021 11:13:06 -0700 Subject: [PATCH 1/3] Add deprecation warning to Ember.assign --- packages/@ember/deprecated-features/index.ts | 1 + packages/@ember/polyfills/index.ts | 6 ++++-- packages/@ember/polyfills/lib/assign.ts | 16 ++++++++++++++++ packages/@ember/polyfills/tests/assign_test.js | 4 +++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index d750d8b3876..2bccd358190 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -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'; diff --git a/packages/@ember/polyfills/index.ts b/packages/@ember/polyfills/index.ts index 25ed10d0302..23ec49f702f 100644 --- a/packages/@ember/polyfills/index.ts +++ b/packages/@ember/polyfills/index.ts @@ -1,10 +1,12 @@ -import { MERGE } from '@ember/deprecated-features'; +import { MERGE, ASSIGN } from '@ember/deprecated-features'; import { default as deprecatedMerge } from './lib/merge'; +import { default as deprecatedAssign, assign as assignPolyfill } from './lib/assign'; 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; diff --git a/packages/@ember/polyfills/lib/assign.ts b/packages/@ember/polyfills/lib/assign.ts index 52e2ef0a446..340d10defe2 100644 --- a/packages/@ember/polyfills/lib/assign.ts +++ b/packages/@ember/polyfills/lib/assign.ts @@ -1,3 +1,5 @@ +import { deprecate } from '@ember/debug'; + /** @module @ember/polyfills */ @@ -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) { diff --git a/packages/@ember/polyfills/tests/assign_test.js b/packages/@ember/polyfills/tests/assign_test.js index 86ffc241b37..90328e5358b 100644 --- a/packages/@ember/polyfills/tests/assign_test.js +++ b/packages/@ember/polyfills/tests/assign_test.js @@ -49,7 +49,9 @@ moduleFor( 'Ember.assign (polyfill)', class extends AssignTests { assign() { - return assignPolyfill(...arguments); + return expectDeprecation(() => { + assignPolyfill(...arguments); + }, 'Use of `assign` has been deprecated. Please use `Object.assign` or the spread operator instead.'); } } ); From 22297ce3f38716e624dc27c5a04826b8cce178e7 Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Thu, 15 Jul 2021 12:01:34 -0700 Subject: [PATCH 2/3] Remove another internal use of Ember.assign --- packages/@ember/-internals/routing/lib/system/router.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index 539add97aa1..3c018d7f85b 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -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'; @@ -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, @@ -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); } /** @@ -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 }; From 716a04edec37f5b97b53f5581670142872540790 Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Thu, 15 Jul 2021 12:26:25 -0700 Subject: [PATCH 3/3] fix tslint issue --- packages/@ember/polyfills/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@ember/polyfills/index.ts b/packages/@ember/polyfills/index.ts index 23ec49f702f..8e885abd9f7 100644 --- a/packages/@ember/polyfills/index.ts +++ b/packages/@ember/polyfills/index.ts @@ -1,6 +1,6 @@ -import { MERGE, ASSIGN } 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'; -import { default as deprecatedAssign, assign as assignPolyfill } from './lib/assign'; let merge = MERGE ? deprecatedMerge : undefined; let assign = ASSIGN ? deprecatedAssign : undefined;