amilajack / amilajack/ast-metadata-inferer

Static methods on built-in constructors missing from metadata (e.g. URL.canParse)

Ouverte
#169 0 commentaires 2 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
17
Forks
9
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

`metadata.json` appears to drop entries with the `_static` suffix from `@mdn/browser-compat-data`, so `eslint-plugin-compat` can't detect static-method calls on built-in constructors.

## Repro

In a project with browserslist targeting browsers older than the API's support range:

```ts
const isValidUrl = (url: string): boolean => URL.canParse(url);
```

Expected: `compat/compat` flags this as unsupported on the configured targets.
Actual: no warning. Code ships and throws `TypeError` at runtime on older browsers.

## Trace

In `node_modules/ast-metadata-inferer/`:

- `node_modules/@mdn/browser-compat-data/data.json` contains `api.URL.canParse_static` with the correct support matrix (Chrome 120, Firefox 115, Safari 17, Node 19.9).
- `metadata.json` (the compiled cache `eslint-plugin-compat` reads from) has zero occurrences of `canParse`.

The same blind spot likely affects other static methods on global constructors: `Array.from_static`, `Object.fromEntries_static`, `Object.hasOwn_static`, `Promise.allSettled_static`, `Promise.any_static`, etc.

## Versions

- `ast-metadata-inferer` as bundled with `eslint-plugin-compat@7.0.0`
- `@mdn/browser-compat-data` from `ast-metadata-inferer/node_modules`

## Suggested fix

In the BCD-to-metadata transform, include keys with the `_static` suffix and emit them as `MemberExpression` matchers where `object.name` is the constructor (e.g. `URL`) and `property.name` is the method (e.g. `canParse`).

Happy to send a PR if helpful.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.