-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The check-es-compat patch can be removed if the following PR is resolved: robatwilliams/es-compat#86
- Loading branch information
1 parent
d212af6
commit 7903ef8
Showing
6 changed files
with
164 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
diff --git a/node_modules/check-es-compat/bin/cli.mjs b/node_modules/check-es-compat/bin/cli.mjs | ||
index 25c53f5..26ce475 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 files | ||
useEslintrc: false, | ||
@@ -34,7 +35,7 @@ async function execute(files) { | ||
es2021: true, | ||
}, | ||
rules: { | ||
- 'ecmascript-compat/compat': 'error', | ||
+ 'ecmascript-compat/compat': ['error', { polyfills }], | ||
}, | ||
}, | ||
}); | ||
@@ -46,3 +47,41 @@ 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 | ||
+ .replace(prototypeAtPolyfill, prototypeAtPlaceholder) | ||
+ .split(',') | ||
+ .map(polyfill => polyfill === prototypeAtPlaceholder ? prototypeAtPolyfill : polyfill); | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters