withfig / fig

Public issue tracker for Fig.
https://fig.io
MIT License
2.05k stars 63 forks source link

Polyfills in userscripts for helpful Web APIs #350

Open lsh opened 3 years ago

lsh commented 3 years ago

Sanity checks

Issue Details

There are some stage 3 Web APIs that are implemented in V8 that have yet to ship in JavaScriptCore. Until these APIs make it into the bundle, it would be nice to have polyfills in place. One worth considering:

Environment

Version 1.0.47 (B253) [Beta] [Dev] [U.S.] 
UserShell: /bin/zsh
Bundle path: /Applications/Fig.app
Autocomplete: true
Settings.json: true
CLI installed: true

More Detail

terminal::native macOS terminal

Anything else?

Array.prototype.at() on MDN.

fedeci commented 3 years ago

Until the feature is implemented you can transpile those files adding polyfills based on the usage of features.

lsh commented 3 years ago

I was thinking about this a little more. There isn't really a process to transpile built into withfig/autocomplete for now, which means if a script uses newer web APIs, would it possibly break on an older installation of MacOS/JavaScriptCore?

fedeci commented 3 years ago

Considering that tsconfig is targeting ESNext it may happen. It is role of the reviewers to warn about those stage 4 proposals. The current solution is not to use APIs requiring polyfills or manually adding core-js imports at the beginning of the file. In the future we may provide an implementation of a custom TS transform and emulate the method used by babel to inject polyfills based on usage.