From 8a439be506d6be983d6199e91e0167654fb806f4 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 18 Jul 2022 13:54:48 +0200 Subject: [PATCH] fix(polyfill): remove usage of backticks / template so it works with ie11 --- patches/event-target-polyfill+0.0.3.patch | 34 +++++++++++-- patches/formdata-polyfill+4.0.10.patch | 61 +++++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 patches/formdata-polyfill+4.0.10.patch diff --git a/patches/event-target-polyfill+0.0.3.patch b/patches/event-target-polyfill+0.0.3.patch index 3acbb5ec4..e06a90acd 100644 --- a/patches/event-target-polyfill+0.0.3.patch +++ b/patches/event-target-polyfill+0.0.3.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/event-target-polyfill/index.js b/node_modules/event-target-polyfill/index.js -index 82f7f42..c7b65b7 100644 +index 82f7f42..d198834 100644 --- a/node_modules/event-target-polyfill/index.js +++ b/node_modules/event-target-polyfill/index.js @@ -12,19 +12,6 @@ function isConstructor(fn) { @@ -27,7 +27,7 @@ index 82f7f42..c7b65b7 100644 if (arguments.length < 2) { throw new TypeError( - `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.` -+ "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, " \ ++ "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, " + + "but only " + arguments.length.toString() + "present." ); } @@ -37,12 +37,12 @@ index 82f7f42..c7b65b7 100644 if (arguments.length < 2) { throw new TypeError( - `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.` -+ "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, " \ ++ "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, " + + "but only " + arguments.length.toString() + "present." ); } const __listeners = this.__listeners; -@@ -78,7 +67,7 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { +@@ -78,14 +67,14 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { EventTarget.prototype.dispatchEvent = function (event) { if (!(event instanceof Event)) { throw new TypeError( @@ -51,3 +51,29 @@ index 82f7f42..c7b65b7 100644 ); } const type = event.type; + const __listeners = this.__listeners; + const listenersForType = __listeners.get(type); + if (listenersForType) { +- for (const [listener, options] of listenersForType.entries()) { ++ listenersForType.forEach(function(options, listener) { + try { + if (typeof listener === "function") { + // Listener functions must be executed with the EventTarget as the `this` context. +@@ -100,7 +89,7 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { + // Unfortunately, this is the best we can do, which isn't great, because the + // native EventTarget will actually do this synchronously before moving to the next + // event in the loop. +- setTimeout(() => { ++ setTimeout(function() { + throw err; + }); + } +@@ -109,7 +98,7 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { + // to remove it now. + listenersForType.delete(listener); + } +- } ++ }) + } + // Since there are no cancellable events on a base EventTarget, + // this should always return true. diff --git a/patches/formdata-polyfill+4.0.10.patch b/patches/formdata-polyfill+4.0.10.patch new file mode 100644 index 000000000..dc9d6de4c --- /dev/null +++ b/patches/formdata-polyfill+4.0.10.patch @@ -0,0 +1,61 @@ +diff --git a/node_modules/formdata-polyfill/FormData.js b/node_modules/formdata-polyfill/FormData.js +index 8e73660..7b64ba4 100644 +--- a/node_modules/formdata-polyfill/FormData.js ++++ b/node_modules/formdata-polyfill/FormData.js +@@ -71,7 +71,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData + + function ensureArgs (args, expected) { + if (args.length < expected) { +- throw new TypeError(`${expected} argument required, but only ${args.length} present.`) ++ throw new TypeError(expected + " argument required, but only " + args.length.toString() + " present.") + } + } + +@@ -342,11 +342,11 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData + ['_blob'] () { + const boundary = '----formdata-polyfill-' + Math.random(), + chunks = [], +- p = `--${boundary}\r\nContent-Disposition: form-data; name="` ++ p = "--" + boundary +" \r\nContent-Disposition: form-data; name=\"" + this.forEach((value, name) => typeof value == 'string' +- ? chunks.push(p + escape(normalizeLinefeeds(name)) + `"\r\n\r\n${normalizeLinefeeds(value)}\r\n`) +- : chunks.push(p + escape(normalizeLinefeeds(name)) + `"; filename="${escape(value.name)}"\r\nContent-Type: ${value.type||"application/octet-stream"}\r\n\r\n`, value, `\r\n`)) +- chunks.push(`--${boundary}--`) ++ ? chunks.push(p + escape(normalizeLinefeeds(name)) + "\"\r\n\r\n" + normalizeLinefeeds(value) + "\r\n") ++ : chunks.push(p + escape(normalizeLinefeeds(name)) + "\"; filename=\"" + escape(value.name) + "\r\nContent-Type: " + (value.type||"application/octet-stream") + "\r\n\r\n", value, "\r\n")) ++ chunks.push("--"+boundary+"--") + return new Blob(chunks, { + type: "multipart/form-data; boundary=" + boundary + }) +diff --git a/node_modules/formdata-polyfill/formdata-to-blob.js b/node_modules/formdata-polyfill/formdata-to-blob.js +index 5a0a517..0b7fbd7 100644 +--- a/node_modules/formdata-polyfill/formdata-to-blob.js ++++ b/node_modules/formdata-polyfill/formdata-to-blob.js +@@ -16,22 +16,22 @@ const escape = (str, filename) => + export function formDataToBlob (formData, BlobClass = Blob) { + const boundary = ('----formdata-polyfill-' + Math.random()) + const chunks = [] +- const prefix = `--${boundary}\r\nContent-Disposition: form-data; name="` ++ const prefix = "--"+$boundary+"\r\nContent-Disposition: form-data; name=\"" + + for (let [name, value] of formData) { + if (typeof value === 'string') { +- chunks.push(prefix + escape(name) + `"\r\n\r\n${value.replace(/\r(?!\n)|(?