Skip to content

Commit

Permalink
fix: use polyfill (#13)
Browse files Browse the repository at this point in the history
* add babel-plugin-polyfill-es-shims

* use array.prototype.at

* add polyfill libraries
  • Loading branch information
3846masa committed Jun 28, 2022
1 parent 7d518ec commit dc3de29
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .babelrc.js
Expand Up @@ -8,6 +8,12 @@ module.exports = {
},
},
],
[
'polyfill-es-shims',
{
method: 'usage-pure',
},
],
],
presets: [
[
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/properties/background-position/collect_features.ts
Expand Up @@ -48,7 +48,7 @@ export async function collectFeatures({ nodes, parent }: Params): Promise<Featur
} else if (node.type === 'div' && node.value === '/') {
isAfterSlash = true;
} else if (!isAfterSlash) {
const bgPosition = bgPositionList[bgPositionList.length - 1];
const bgPosition = bgPositionList.at(-1);
bgPosition?.push(node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/properties/background-repeat/collect_features.ts
Expand Up @@ -24,7 +24,7 @@ export async function collectFeatures({ nodes, parent }: Params): Promise<Featur
if (node.type === 'div' && node.value === ',') {
bgRepeatList.push([]);
} else {
const bgRepeat = bgRepeatList[bgRepeatList.length - 1];
const bgRepeat = bgRepeatList.at(-1);
bgRepeat?.push(node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/properties/background/collect_features.ts
Expand Up @@ -19,7 +19,7 @@ export async function collectFeatures({ nodes, parent }: Params): Promise<Featur
if (node.type === 'div' && node.value === ',') {
bgLayerList.push([]);
} else {
const bgLayer = bgLayerList[bgLayerList.length - 1];
const bgLayer = bgLayerList.at(-1);
bgLayer?.push(node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/properties/box-shadow/collect_features.ts
Expand Up @@ -21,7 +21,7 @@ export async function collectFeatures({ nodes, parent }: Params): Promise<Featur
if (node.type === 'div' && node.value === ',') {
boxShadowList.push([]);
} else {
const boxShadow = boxShadowList[boxShadowList.length - 1];
const boxShadow = boxShadowList.at(-1);
boxShadow?.push(node);
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@ export async function collectFeatures({ node, parent }: Params): Promise<Feature
if (chlid.type === 'div' && chlid.value === ',') {
colorStopList.push([]);
} else {
const colorStop = colorStopList[colorStopList.length - 1];
const colorStop = colorStopList.at(-1);
colorStop?.push(chlid);
}
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ export async function collectFeatures({ colorStop, node, parent }: Params): Prom

if (colorStop.length >= 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,
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -19,7 +19,7 @@ export async function collectFeatures({ node, parent }: Params): Promise<Feature
if (chlid.type === 'div' && chlid.value === ',') {
colorStopList.push([]);
} else {
const colorStop = colorStopList[colorStopList.length - 1];
const colorStop = colorStopList.at(-1);
colorStop?.push(chlid);
}
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ export async function collectFeatures({ colorStop, node, parent }: Params): Prom

if (colorStop.length >= 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,
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -19,7 +19,7 @@ export async function collectFeatures({ node, parent }: Params): Promise<Feature
if (chlid.type === 'div' && chlid.value === ',') {
colorStopList.push([]);
} else {
const colorStop = colorStopList[colorStopList.length - 1];
const colorStop = colorStopList.at(-1);
colorStop?.push(chlid);
}
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ export async function collectFeatures({ colorStop, node, parent }: Params): Prom

if (colorStop.length >= 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,
Expand Down
27 changes: 26 additions & 1 deletion yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit dc3de29

Please sign in to comment.