From dc3de294ff487090bb0053c487e3cc8ee499c340 Mon Sep 17 00:00:00 2001 From: "Masahiro Miyashiro (3846masa)" <3846masahiro+git@gmail.com> Date: Tue, 28 Jun 2022 10:11:50 +0900 Subject: [PATCH] fix: use polyfill (#13) * add babel-plugin-polyfill-es-shims * use array.prototype.at * add polyfill libraries --- .babelrc.js | 6 +++++ package.json | 3 +++ .../background-position/collect_features.ts | 2 +- .../background-repeat/collect_features.ts | 2 +- src/properties/background/collect_features.ts | 2 +- src/properties/box-shadow/collect_features.ts | 2 +- .../__linear-gradient/collect_features.ts | 2 +- .../doubleposition/collect_features.ts | 2 +- .../interpolation_hints/collect_features.ts | 2 +- .../__linear-gradient/to/collect_features.ts | 2 +- .../unitless_0_angle/collect_features.ts | 2 +- .../__radial-gradient/collect_features.ts | 2 +- .../doubleposition/collect_features.ts | 2 +- .../interpolation_hints/collect_features.ts | 2 +- .../conic-gradient/collect_features.ts | 2 +- .../doubleposition/collect_features.ts | 2 +- yarn.lock | 27 ++++++++++++++++++- 17 files changed, 49 insertions(+), 15 deletions(-) diff --git a/.babelrc.js b/.babelrc.js index 37bca161..eeb7909c 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -8,6 +8,12 @@ module.exports = { }, }, ], + [ + 'polyfill-es-shims', + { + method: 'usage-pure', + }, + ], ], presets: [ [ diff --git a/package.json b/package.json index d1c8af3c..cee40083 100644 --- a/package.json +++ b/package.json @@ -33,11 +33,13 @@ }, "dependencies": { "@mdn/browser-compat-data": "5.1.2", + "array.prototype.at": "1.1.0", "dot-prop": "6.0.1", "postcss-media-query-parser": "0.2.3", "postcss-selector-parser": "6.0.10", "postcss-value-parser": "4.2.0", "semver": "7.3.7", + "string.prototype.at": "1.0.3", "ts-results": "3.3.0", "zod": "3.17.3" }, @@ -58,6 +60,7 @@ "@types/semver": "7.3.10", "babel-jest": "28.1.0", "babel-plugin-module-resolver": "4.1.0", + "babel-plugin-polyfill-es-shims": "0.6.1", "browserslist": "4.21.0", "common-tags": "1.8.2", "fs-extra": "10.1.0", diff --git a/src/properties/background-position/collect_features.ts b/src/properties/background-position/collect_features.ts index 9a0292eb..a7e7f1cf 100644 --- a/src/properties/background-position/collect_features.ts +++ b/src/properties/background-position/collect_features.ts @@ -48,7 +48,7 @@ export async function collectFeatures({ nodes, parent }: Params): Promise= 5) { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/src/types/image/gradient/__linear-gradient/interpolation_hints/collect_features.ts b/src/types/image/gradient/__linear-gradient/interpolation_hints/collect_features.ts index 894b591e..726cd18e 100644 --- a/src/types/image/gradient/__linear-gradient/interpolation_hints/collect_features.ts +++ b/src/types/image/gradient/__linear-gradient/interpolation_hints/collect_features.ts @@ -25,7 +25,7 @@ export async function collectFeatures({ colorStop, colorStopIndex, node, parent unit(colorStop[0].value) !== false ) { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/src/types/image/gradient/__linear-gradient/to/collect_features.ts b/src/types/image/gradient/__linear-gradient/to/collect_features.ts index aaceaca3..d811a4d7 100644 --- a/src/types/image/gradient/__linear-gradient/to/collect_features.ts +++ b/src/types/image/gradient/__linear-gradient/to/collect_features.ts @@ -17,7 +17,7 @@ export async function collectFeatures({ colorStop, node, parent }: Params): Prom if (colorStop[0]?.type === 'word' && colorStop[0].value === 'to') { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/src/types/image/gradient/__linear-gradient/unitless_0_angle/collect_features.ts b/src/types/image/gradient/__linear-gradient/unitless_0_angle/collect_features.ts index 48de44a8..34adb362 100644 --- a/src/types/image/gradient/__linear-gradient/unitless_0_angle/collect_features.ts +++ b/src/types/image/gradient/__linear-gradient/unitless_0_angle/collect_features.ts @@ -18,7 +18,7 @@ export async function collectFeatures({ colorStop, colorStopIndex, node, parent if (colorStopIndex === 0 && colorStop.length === 1 && colorStop[0]?.type === 'word' && colorStop[0].value === '0') { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/src/types/image/gradient/__radial-gradient/collect_features.ts b/src/types/image/gradient/__radial-gradient/collect_features.ts index 0bb7d340..44fde1da 100644 --- a/src/types/image/gradient/__radial-gradient/collect_features.ts +++ b/src/types/image/gradient/__radial-gradient/collect_features.ts @@ -19,7 +19,7 @@ export async function collectFeatures({ node, parent }: Params): Promise= 5) { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/src/types/image/gradient/__radial-gradient/interpolation_hints/collect_features.ts b/src/types/image/gradient/__radial-gradient/interpolation_hints/collect_features.ts index 2343faaf..6930f0cd 100644 --- a/src/types/image/gradient/__radial-gradient/interpolation_hints/collect_features.ts +++ b/src/types/image/gradient/__radial-gradient/interpolation_hints/collect_features.ts @@ -25,7 +25,7 @@ export async function collectFeatures({ colorStop, colorStopIndex, node, parent unit(colorStop[0].value) !== false ) { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/src/types/image/gradient/conic-gradient/collect_features.ts b/src/types/image/gradient/conic-gradient/collect_features.ts index 4ac2d07f..f1750834 100644 --- a/src/types/image/gradient/conic-gradient/collect_features.ts +++ b/src/types/image/gradient/conic-gradient/collect_features.ts @@ -19,7 +19,7 @@ export async function collectFeatures({ node, parent }: Params): Promise= 5) { const index = offset + (colorStop[0]?.sourceIndex ?? 0); - const endIndex = offset + (colorStop[colorStop.length - 1]?.sourceEndIndex ?? 0); + const endIndex = offset + (colorStop.at(-1)?.sourceEndIndex ?? 0); features.push({ endIndex, diff --git a/yarn.lock b/yarn.lock index 34d3fb47..521b37f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4,7 +4,6 @@ "@3846masa/configs@github:3846masa/configs#c80e1fee19f90246b2d5e1bc8d5843c9001c5c8c": version "1.0.20" - uid c80e1fee19f90246b2d5e1bc8d5843c9001c5c8c resolved "https://codeload.github.com/3846masa/configs/tar.gz/c80e1fee19f90246b2d5e1bc8d5843c9001c5c8c" dependencies: "@tsconfig/strictest" "1.0.1" @@ -2239,6 +2238,16 @@ array-union@^2.1.0: resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== +array.prototype.at@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/array.prototype.at/-/array.prototype.at-1.1.0.tgz#216bcb1218932543b261f9465fe9b3f4070b8e72" + integrity sha512-NSraJlwBpkNX/w9f+14fatEoHCI0jcZVObhd/vm7LdnvrJ91xUhfsO0BhuXMRH9A3P4Ui3kaA2SWAcbQ4AP9dg== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.3" + es-abstract "^1.19.2" + es-shim-unscopables "^1.0.0" + array.prototype.flat@^1.2.5: version "1.3.0" resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.3.0.tgz#0b0c1567bf57b38b56b4c97b8aa72ab45e4adc7b" @@ -2338,6 +2347,13 @@ babel-plugin-polyfill-corejs3@^0.5.0: "@babel/helper-define-polyfill-provider" "^0.3.1" core-js-compat "^3.21.0" +babel-plugin-polyfill-es-shims@0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-es-shims/-/babel-plugin-polyfill-es-shims-0.6.1.tgz#42c46cf61a63b622a846defaf4dad14378267bfb" + integrity sha512-ytZv444Z0WiLANxmAy8ORwR9X8flXfMFoUSA7jibfJw2DkHMKsdojY4+yB4ICVoOIMdSOkZINLmA+k/2+BWsKA== + dependencies: + "@babel/helper-define-polyfill-provider" "^0.3.1" + babel-plugin-polyfill-regenerator@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.3.1.tgz#2c0678ea47c75c8cc2fbb1852278d8fb68233990" @@ -6692,6 +6708,15 @@ string-length@^4.0.1: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" +string.prototype.at@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/string.prototype.at/-/string.prototype.at-1.0.3.tgz#c2f0cddb402cdbe2c628a3f9cbda3f5b42dc0889" + integrity sha512-P3/I5mrojyow0xOahStcHPr/nNp4CrBAbaP5TlBG/2WB7ioVkzbHpOC7bNRRG8SpojUFDm3KEO2MAY4B89XRww== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.3" + es-abstract "^1.19.1" + string.prototype.padend@^3.0.0: version "3.1.3" resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.1.3.tgz#997a6de12c92c7cb34dc8a201a6c53d9bd88a5f1"