Vmeda.Online/patches/check-es-compat+3.2.1.patch

67 lines
1.8 KiB
Diff

diff --git a/node_modules/check-es-compat/bin/cli.mjs b/node_modules/check-es-compat/bin/cli.mjs
index 928780f..026eb9a 100755
--- a/node_modules/check-es-compat/bin/cli.mjs
+++ b/node_modules/check-es-compat/bin/cli.mjs
@@ -17,7 +17,8 @@ if (args.length === 0) {
}
}
-async function execute(files) {
+async function execute(args) {
+ const { files, polyfills } = parseArguments(args);
const eslint = new ESLint({
// Ignore any config; it's for target's own linter setup rather than this tool.
useEslintrc: false,
@@ -35,7 +36,7 @@ async function execute(files) {
es2023: true,
},
rules: {
- 'ecmascript-compat/compat': 'error',
+ 'ecmascript-compat/compat': ['error', { polyfills }],
},
},
});
@@ -47,3 +48,42 @@ async function execute(files) {
return { hasErrors: results.some((result) => result.errorCount > 0) };
}
+
+function parseArguments(args) {
+ const files = [];
+ const polyfills = [];
+ let nextArgIsPolyfills = false;
+
+ for (const arg of args) {
+ if (nextArgIsPolyfills) {
+ nextArgIsPolyfills = false;
+ polyfills.push(...splitPolyfillsArgument(arg));
+ continue;
+ }
+
+ if (arg.startsWith('--polyfills')) {
+ if (arg.startsWith('--polyfills=')) {
+ polyfills.push(...splitPolyfillsArgument(arg.slice(12)));
+ } else {
+ nextArgIsPolyfills = true;
+ }
+
+ continue;
+ }
+
+ files.push(arg);
+ }
+
+ return { files, polyfills };
+}
+
+function splitPolyfillsArgument(polyfills) {
+ const prototypeAtPolyfill = '{Array,String,TypedArray}.prototype.at';
+ const prototypeAtPlaceholder = '{{PROTOTYPEAT}}';
+
+ return polyfills
+ .replaceAll('\\', '')
+ .replace(prototypeAtPolyfill, prototypeAtPlaceholder)
+ .split(',')
+ .map(polyfill => polyfill === prototypeAtPlaceholder ? prototypeAtPolyfill : polyfill);
+}