From cc2639d3d622812647dc5357fff00f545b07c880 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 31 Oct 2020 18:26:44 +0100 Subject: [PATCH] Support for legacy class inheritance (ES5-style) --- wcfsetup/install/files/js/WoltLabSuite/Core/Core.js | 11 ++++++++++- wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js | 1 + wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts | 9 +++++++++ wcfsetup/install/files/ts/WoltLabSuite/Core/Upload.ts | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js index bd232bd328..e0fedbedbc 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js @@ -10,7 +10,7 @@ define(["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.debounce = exports.stringToBool = exports.getStoragePrefix = exports.triggerEvent = exports.serialize = exports.getUuid = exports.getType = exports.isPlainObject = exports.inherit = exports.extend = exports.convertLegacyUrl = exports.clone = void 0; + exports.enableLegacyInheritance = exports.debounce = exports.stringToBool = exports.getStoragePrefix = exports.triggerEvent = exports.serialize = exports.getUuid = exports.getType = exports.isPlainObject = exports.inherit = exports.extend = exports.convertLegacyUrl = exports.clone = void 0; const _clone = function (variable) { if (typeof variable === "object" && (Array.isArray(variable) || isPlainObject(variable))) { return _cloneObject(variable); @@ -230,4 +230,13 @@ define(["require", "exports"], function (require, exports) { }; } exports.debounce = debounce; + function enableLegacyInheritance(legacyClass) { + legacyClass.call = function (thisValue, ...args) { + const constructed = Reflect.construct(legacyClass, args, thisValue.constructor); + Object.entries(constructed).forEach(([key, value]) => { + thisValue[key] = value; + }); + }; + } + exports.enableLegacyInheritance = enableLegacyInheritance; }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js index c83178089c..708cb30a04 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js @@ -329,5 +329,6 @@ define(["require", "exports", "tslib", "./Ajax/Request", "./Core", "./Dom/Change return this._upload(null, file); } } + Core.enableLegacyInheritance(Upload); return Upload; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts index f7d78d149b..60cfa07914 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts @@ -260,3 +260,12 @@ export function debounce( } }; } + +export function enableLegacyInheritance(legacyClass: T): void { + (legacyClass as any).call = function (thisValue, ...args) { + const constructed = Reflect.construct(legacyClass as any, args, thisValue.constructor); + Object.entries(constructed).forEach(([key, value]) => { + thisValue[key] = value; + }); + }; +} diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Upload.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Upload.ts index c61df61b0e..84e39fac4e 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Upload.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Upload.ts @@ -429,4 +429,6 @@ abstract class Upload { } } +Core.enableLegacyInheritance(Upload); + export = Upload; -- 2.20.1