Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
@developit
developit / esmodules-polyfill.js
Last active November 15, 2020 21:19
polyfill ES2018 standard library stuff for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)
if (!('trimStart' in String.prototype)) String.prototype.trimStart = String.prototype.trimLeft;
if (!('trimEnd' in String.prototype)) String.prototype.trimEnd = String.prototype.trimRight;
if (!('forEach' in NodeList.prototype)) NodeList.prototype.forEach = [].forEach;
if (!('description' in Symbol.prototype)) {
Object.defineProperty(Symbol.prototype, 'description', {
get() { return /\((.+)\)/.exec(this)[1] }
});
}
@developit
developit / *babel-plugin-dynamic-import-polyfill.md
Created November 12, 2019 19:57
babel-plugin-dynamic-import-polyfill
@connorjclark
connorjclark / gist:cc583554ff07cba7cdc416c06721fd6a
Last active November 1, 2019 19:40
detecting core-js polyfills

Context: https://github.com/GoogleChrome/lighthouse/pull/6730/files#diff-4f9810692cc44a0098f356a1dc35cca3R133

Oh boy :) cracks knuckles tl;dr no, also I overlooked so much, thanks for pointing this out.

The minified JS I linked to is every polyfill that @babel/present-env would provide. The recommended distribution of these polyfills is not the module I linked (@babel/polyfill), but instead via @babel/preset-env. Regardless, they both use the polyfills as defined by core-js. You can see that the polyfills module has a standard bundling and minifying script: https://github.com/babel/babel/blob/fced5cea430cc00e916876b663a8d2a84a5dad1f/packages/babel-polyfill/scripts/build-dist.sh, which is what I linked to before. The question is: does the pattern I'm looking for hold for these core-js polyfills regardless of the minifier used? Additionally: where does this pattern come from? I'll focus on that first.

To further complicate, there's core-js@2 and core-js@3, and both seem to be used (or at leas

const Component = require('preact/compat').Component;
const AUTOBIND_BLACKLIST = {
constructor: 1,
render: 1,
shouldComponentUpdate: 1,
componentWillReceiveProps: 1,
componentWillUpdate: 1,
componentDidUpdate: 1,
componentWillMount: 1,

Modern applications

Most JavaScript developers love making modern applications, with our new language features and latest libraries making our life easier, but has any one ever actually wondered if this ever impacts our users.

We are dealing with abstractions, abstractions are trying to cover a general use case which could not be conforming to yours. Some are over-engineered in ways one can't possibly comprehend, use cases that will never be reached by middle sized applications. Some of these over

@jviide
jviide / README.md
Last active October 4, 2019 21:10

A proof-of-concept Python code rewriter, transforming JavaScript-like tagged template strings (tag"foo{1+2}bar") to plain function calls (tag(["foo", "bar"], [1+2])).

Note that the code requires tagged version 0.0.2 or higher.

You can use ./encoder.py file to transform STDIN input to STDOUT:

$ python3 encoder.py < example_input.py

Combines all bare imports (npm module imports) into a single packd-es import.

Input:

import { h, render } from 'preact@next';
import { useState } from 'preact@next/hooks';
import { html } from 'htm/preact';
render(h(() => html`<a />`), document.body);

lazy-loader

import lazyLoad from 'lazy-loader';

let mapPromise;
function getMap() {
  return mapPromise || (
 mapPromise = lazyLoad('/chunks/map.js', () =&gt; {

inline-loader for webpack

Point this loader at an empty file, and it'll let you supply fake contents for that file.

import one from 'inline-loader?filenam=one.js&code=export default 1!./empty.js';

console.log(one)  // 1
@jviide
jviide / example.py
Last active August 9, 2019 17:38
htm.py ❤️ hyperpython
from htm import htm
from hyperpython import h
from inspect import signature, Parameter
@htm
def html(tag, props, children):
if callable(tag):
return relaxed_call(tag, children=children, **props)
return h(tag, props, children)