Skip to content

Instantly share code, notes, and snippets.

View replace.ts
import ts, { servicesVersion } from "typescript";
type Files = { [key: string]: string };
type SourceFiles = { [key: string]: ts.SourceFile | undefined };
function createHostedProgram(rawFiles: Files, root: string[]) {
}
import fs from "fs/promises";
import path from "path";
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>EdgeJS test</h1>
View deep_proxy.ts
function isObject(value: any): value is object {
return value !== null && typeof value === 'object';
}
export const DELETED = Symbol();
export function deepProxy(
original: any,
handler: (path: string[], value: any | typeof DELETED) => void,
selfPath: string[] = [],
View vitest-with-playwright.ts
import { Browser, chromium, firefox, webkit } from "playwright";
import { afterAll, beforeAll, describe, it } from "vitest";
const browserTypes = process.env.ALL_BROWSERS
? [chromium, firefox, webkit]
: [chromium];
for (const browserType of browserTypes) {
describe(`browser:${browserType.name()}`, () => {
let browser: Browser;
View transformer.ts
import ts, { factory } from "typescript";
export function transformerFactory(context: ts.TransformationContext) {
function visitNode(node: ts.Node): ts.Node {
const newNode = ts.visitEachChild(node, visitNode, context);
if (
ts.isJsxOpeningElement(newNode) ||
ts.isJsxSelfClosingElement(newNode)
) {
return appendSourceMapAttribute(newNode.getSourceFile(), newNode);
View add-index-to-svelte-ast.ts
import { walk } from 'estree-walker';
function updateIndex(fragment: any) {
console.time('updateIndex');
walk(fragment, {
enter(node, parent, key, index) {
node.__id__ = `${parent?.__id__ ?? '$'}${key ? `.${key}` : ''}${
index ? `[${index}]` : ''
}`;
if (node.type === 'VariableDeclaration') {
View tokenize.ts
const DOUBLE_QUOTE = '"';
const SINGLE_QUOTE = "'";
const BACK_QUOTE = "`";
const SLASH = "/";
const STRING_PAIR = [SINGLE_QUOTE, DOUBLE_QUOTE, BACK_QUOTE] as const;
const L_BRACE = "{";
const R_BRACE = "}";
View main.ts
import Worker from "./worker?worker";
import { Api } from "./worker";
import { wrap } from "comlink";
const log = (...args: any[]) => console.log("[main]", ...args);
const api: Api = wrap(new Worker());
const sab = new SharedArrayBuffer(1024);
const ta = new Int32Array(sab);
View inline-test-no-lib.ts
const test =
process.env.NODE_ENV === "test" && require.main === module
? ((q: Function[] = []) => {
setTimeout(() => q.forEach((t) => t()));
return (t: any) => q.push(t);
})()
: null;
test?.(() => {
console.log("xxx");
View inmemory-ts-check.ts
import ts from "typescript";
type Files = { [key: string]: string };
type SourceFiles = { [key: string]: ts.SourceFile | undefined };
function getDiagnostics(rawFiles: Files, root: string[]) {
const compiledFiles: SourceFiles = {};
const options: ts.CompilerOptions = {
target: ts.ScriptTarget.ESNext,
};