From 03b0d8f1b5d66717519fc0a9d5231c1e36ea22d8 Mon Sep 17 00:00:00 2001 From: Inomdzhon Mirdzhamolov Date: Fri, 24 Nov 2023 14:25:25 +0300 Subject: [PATCH] feat: rm polyfill (#6117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Наш `browserlist` покрывает API, который мы полифилили. --- packages/vkui/.eslintrc.js | 6 -- packages/vkui/cssm/cssm.swcrc | 20 +----- packages/vkui/package.json | 3 - packages/vkui/src/index.ts | 2 - packages/vkui/src/lib/polyfills.ts | 107 ----------------------------- 5 files changed, 2 insertions(+), 136 deletions(-) delete mode 100644 packages/vkui/src/lib/polyfills.ts diff --git a/packages/vkui/.eslintrc.js b/packages/vkui/.eslintrc.js index 2a800e7be4..d1156d878d 100644 --- a/packages/vkui/.eslintrc.js +++ b/packages/vkui/.eslintrc.js @@ -146,12 +146,6 @@ module.exports = { ], settings: { lintAllEsApis: true, - polyfills: [ - 'Array.includes', - 'Array.find', - 'String.padStart', - 'Intl', // Отсутствует. Не поддерживается в iOS Safari 9, Calendar должен использоваться только на desktop - ], }, extends: ['plugin:compat/recommended'], rules: { diff --git a/packages/vkui/cssm/cssm.swcrc b/packages/vkui/cssm/cssm.swcrc index a4483ff076..cbd62a7213 100644 --- a/packages/vkui/cssm/cssm.swcrc +++ b/packages/vkui/cssm/cssm.swcrc @@ -1,11 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "exclude": [ - "\\.(test|spec|e2e|e2e-playground|stories)\\.[jt]sx?$", - "testing/", - "storybook/", - "lib/polyfills.ts" - ], + "exclude": ["\\.(test|spec|e2e|e2e-playground|stories)\\.[jt]sx?$", "testing/", "storybook/"], "module": { "type": "es6" @@ -22,17 +17,6 @@ "runtime": "classic" } }, - "target": "esnext", - - "experimental": { - "plugins": [ - [ - "swc-plugin-transform-remove-imports", - { - "test": "^./lib/polyfills$" - } - ] - ] - } + "target": "esnext" } } diff --git a/packages/vkui/package.json b/packages/vkui/package.json index d8aa8d53b5..f92a49a651 100644 --- a/packages/vkui/package.json +++ b/packages/vkui/package.json @@ -17,11 +17,8 @@ "!./src/storybook/" ], "sideEffects": [ - "./dist/lib/polyfills.js", "./dist/index.js", - "./dist/cjs/lib/polyfills.js", "./dist/cjs/index.js", - "./dist/cssm/lib/polyfills.js", "./dist/cssm/index.js", "*.css" ], diff --git a/packages/vkui/src/index.ts b/packages/vkui/src/index.ts index da5f216083..9ce0050106 100644 --- a/packages/vkui/src/index.ts +++ b/packages/vkui/src/index.ts @@ -1,5 +1,3 @@ -import './lib/polyfills'; - import './styles/constants.css'; import './styles/adaptivity.module.css'; import './styles/dynamicTokens.css'; diff --git a/packages/vkui/src/lib/polyfills.ts b/packages/vkui/src/lib/polyfills.ts deleted file mode 100644 index 32f98841b2..0000000000 --- a/packages/vkui/src/lib/polyfills.ts +++ /dev/null @@ -1,107 +0,0 @@ -/* eslint-disable */ -import { canUseDOM } from './dom'; - -export type MatchesMethod = (css: string) => boolean; - -export interface OldElement extends Element { - matchesSelector?: MatchesMethod; - mozMatchesSelector?: MatchesMethod; - msMatchesSelector?: MatchesMethod; -} - -if (canUseDOM) { - const ElementProto = Element.prototype; - - // Element.prototype.matches - if (!ElementProto.matches) { - ElementProto.matches = - (ElementProto as OldElement).matchesSelector || - ElementProto.webkitMatchesSelector || - (ElementProto as OldElement).mozMatchesSelector || - (ElementProto as OldElement).msMatchesSelector; - } - - // Element.prototype.closest - if (!ElementProto.closest) { - ElementProto.closest = function (css: string): Element | null { - let node: Element | null = this; - while (node) { - if (node.matches(css)) { - return node; - } else { - node = node.parentElement; - } - } - return null; - }; - } -} - -// Array.prototype.includes -if (!Array.prototype.includes) { - Object.defineProperty(Array.prototype, 'includes', { - value: function (searchElement: any, fromIndex: number) { - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - const o = Object(this); - const len = o.length >>> 0; - if (len === 0) { - return false; - } - const n = fromIndex | 0; - let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); - function sameValueZero(x: any, y: any) { - return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); - } - while (k < len) { - if (sameValueZero(o[k], searchElement)) { - return true; - } - k++; - } - return false; - }, - }); -} - -// Array.prototype.find -if (!Array.prototype.find) { - Object.defineProperty(Array.prototype, 'find', { - value: function (callback: Parameters['find']>[0]) { - if (this === null) { - throw new TypeError('Array.prototype.find called on null or undefined'); - } else if (typeof callback !== 'function') { - throw new TypeError('callback must be a function'); - } - - let list = Object(this); - let length = list.length >>> 0; - let thisArg = arguments[1]; - - for (let i = 0; i < length; i++) { - let element = list[i]; - if (callback.call(thisArg, element, i, list)) { - return element; - } - } - }, - }); -} - -// String.prototype.padStart -if (!String.prototype.padStart) { - String.prototype.padStart = function padStart(targetLength, padString) { - targetLength = targetLength >> 0; - padString = String(padString || ' '); - if (this.length > targetLength) { - return String(this); - } else { - targetLength = targetLength - this.length; - if (targetLength > padString.length) { - padString += padString.repeat(targetLength / padString.length); - } - return padString.slice(0, targetLength) + String(this); - } - }; -}