AST examples of Pattern Matching ESTree Proposal
Note: The ExpressionStatement
and Program
node are omitted in the examples.
match (x) {
when ({ colour: "#000000" }) { "yes" }
else {
"no"
// A very naive implementation of React's use() hook you can copy and paste into your app today | |
// to use with solutions such as remix's experimental `defer()` feature. | |
function use<T>(useable: Promise<T> | T) { | |
if (typeof useable != "object" || !useable || !("then" in useable)) { | |
return useable; | |
} | |
let promise = useable as Promise<T> & { _data?: T; _error?: unknown }; | |
if ("_data" in promise) { |
import fg from 'fast-glob'; | |
/** | |
* From provided ROOT_DIR `scan` pages directory | |
* and return list of user defined pages | |
* (except special ones, like _app, _document, _error) | |
*/ | |
export function getNextPages(cwd: string) { | |
// scan all files in pages folder except pages/api | |
let pageList = fg.sync('pages/**/*.{ts,tsx,js,jsx}', { |
import { readFile } from "fs/promises"; | |
import { createRequire } from "module"; | |
import * as URL from "url"; | |
import { readConfig } from "./config.mjs"; | |
let require = createRequire(import.meta.url); | |
let config = await readConfig(process.cwd(), "development"); | |
let outputFile = URL.pathToFileURL(config.serverBuildPath); |
Note: The ExpressionStatement
and Program
node are omitted in the examples.
match (x) {
when ({ colour: "#000000" }) { "yes" }
else {
"no"
const fs = require("fs"); | |
const path = require("path"); | |
const Template = require("webpack/lib/Template"); | |
const SingleEntryPlugin = require("webpack/lib/SingleEntryPlugin"); | |
const VirtualModulesPlugin = require("webpack-virtual-modules"); | |
const PLUGIN_NAME = "FederatedStartupCodePlugin"; | |
/** |
export const CACHE_STALE_AT_HEADER = 'x-edge-cache-stale-at'; | |
export const CACHE_STATUS_HEADER = 'x-edge-cache-status'; | |
export const CACHE_CONTROL_HEADER = 'Cache-Control'; | |
export const CLIENT_CACHE_CONTROL_HEADER = 'x-client-cache-control'; | |
export const ORIGIN_CACHE_CONTROL_HEADER = 'x-edge-origin-cache-control'; | |
enum CacheStatus { | |
HIT = 'HIT', | |
MISS = 'MISS', | |
REVALIDATING = 'REVALIDATING', |
import React from 'react'; | |
import { FederatedProvider } from './federated-provider'; | |
import { scopes } from './scopes'; | |
// This is an example app on how you would setup your Nextjs app | |
const App = ({ Component }) => { | |
return ( | |
<FederatedProvider scopes={scopes}> | |
<Component /> |
const path = require('path'); | |
const nodeExternals = require('webpack-node-externals'); | |
const cwd = process.cwd(); | |
export const outputPath = path.join(cwd, '.webpack'); | |
export const outputFilename = 'bundle.js'; | |
export default { |
const crypto = require("crypto") | |
// The `generateKeyPairSync` method accepts two arguments: | |
// 1. The type ok keys we want, which in this case is "rsa" | |
// 2. An object with the properties of the key | |
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", { | |
// The standard secure default length for RSA keys is 2048 bits | |
modulusLength: 2048, | |
}) |
const EMPTY_MODULES_CLEANUP_DEP_TYPES = new Set([ | |
'harmony side effect evaluation', | |
'import()', | |
'single entry', | |
]); | |
class SetMap extends Map { | |
add (key, value) { | |
const set = this.get(key); | |
if (set === undefined) { |