Skip to content

Commit

Permalink
Add missing polyfill options for ES2022 (#75)
Browse files Browse the repository at this point in the history
* add

* test
  • Loading branch information
robatwilliams authored May 12, 2023
1 parent 7c97890 commit 00be982
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ module.exports = [
{
ruleConfig: { definition: esPlugin.rules['no-error-cause'] },
compatFeatures: [compatData.javascript.builtins.Error.Error.options_cause_parameter],
polyfill: 'Error.cause',
},
{
ruleConfig: { definition: esPlugin.rules['no-object-hasown'] },
compatFeatures: [compatData.javascript.builtins.Object.hasOwn],
polyfill: 'Object.hasOwn',
},
{
ruleConfig: { definition: esPlugin.rules['no-private-in'] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ ruleTester.run('compat', require('../rule'), {
code: '"Foo".at(1);',
options: [{ polyfills: ['{Array,String,TypedArray}.prototype.at'] }],
},
{
code: "new Error('message', { cause: originalError })",
options: [{ polyfills: ['Error.cause'] }],
},
{
code: "Object.hasOwn(obj, 'prop');",
options: [{ polyfills: ['Object.hasOwn'] }],
},
],
invalid: [
{
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-plugin-ecmascript-compat/lib/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ module.exports = {
items: {
type: 'string',
enum: [
// This list is hard-coded so it can serve as documentation
'globalThis',
'{Array,String,TypedArray}.prototype.at',
'Array.prototype.flat',
'Array.prototype.flatMap',
'Array.prototype.includes',
'Error.cause',
'Object.entries',
'Object.fromEntries',
'Object.getOwnPropertyDescriptors',
'Object.hasOwn',
'Object.values',
'Promise.prototype.allSettled',
'Promise.prototype.any',
Expand Down
11 changes: 11 additions & 0 deletions packages/eslint-plugin-ecmascript-compat/lib/rule.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const features = require('./features');
const rule = require('./rule');

test('polyfills accepted in the schema exactly match those supported', () => {
const schemaPolyfills = rule.meta.schema[0].properties.polyfills.items.enum;
const supportedPolyfills = features.flatMap((feature) =>
feature.polyfill ? [feature.polyfill] : []
);

expect(schemaPolyfills.sort()).toEqual(supportedPolyfills.sort());
});

0 comments on commit 00be982

Please sign in to comment.