marp | theme |
---|---|
true |
gaia |
https://speakerdeck.com/mizchi/server-side-javascript-notamenobandoruzui-shi-hua のスライドのMarp のソースコード。 PDF だとリンククリックできなくて不便だったので
use std::{rc::Rc, sync::Mutex}; | |
use rand::Rng; | |
use wasm_bindgen::prelude::*; | |
fn draw_triangle(context: &web_sys::CanvasRenderingContext2d, points: [(f64, f64); 3], color: (u8, u8, u8)) { | |
let [top, left, right] = points; | |
let color_str = format!("rgb({},{},{})", color.0, color.1, color.2); | |
context.set_fill_style(&wasm_bindgen::JsValue::from_str(&color_str)); | |
context.move_to(top.0, top.1); |
marp | theme |
---|---|
true |
gaia |
https://speakerdeck.com/mizchi/server-side-javascript-notamenobandoruzui-shi-hua のスライドのMarp のソースコード。 PDF だとリンククリックできなくて不便だったので
import * as ts from "typescript"; | |
export interface Env {} | |
export default { | |
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { | |
const num = ts.SyntaxKind.Identifier; | |
// const num = 80; | |
return new Response(`${num}`); | |
}, | |
}; |
{ | |
"private": true, | |
"type": "module", | |
"scripts": { | |
"start": "tsm --conditions react-server run-rsc.tsx" | |
}, | |
"license": "MIT", | |
"devDependencies": { | |
"@types/react": "^18.0.25", | |
"@types/react-dom": "^18.0.9", |
/* | |
Prompt1: | |
この topoSort関数を以下の Graph 型に対するトポロジカルソートとして実装してください。 | |
```ts | |
type Graph<T> = Map<T, Set<T>>; | |
export function topoSort<T>(graph: Graph<T>): Array<T> { | |
// wip |
/* | |
# Benchmark for typescript compiler API - parse/print/transform | |
CAUTION: JIT is not taken into account | |
I use https://github.com/mizchi/svelte2tsx-component/blob/main/src/core.mts | |
--- | |
code-size 43377chars 5336nodes |
import ts from "typescript/lib/tsserverlibrary.js"; | |
import fs from "node:fs"; | |
import path from "node:path"; | |
import { DocumentRegistry } from "typescript"; | |
const tsconfig = ts.readConfigFile("./tsconfig.json", ts.sys.readFile); | |
const options = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, "./"); | |
const defaultHost = ts.createCompilerHost(options.options); | |
const expandPath = (fname: string) => { |
// lightweight zod | |
type Validator<Expect> = (input: any) => input is Expect; | |
type ValidatorObject<Expect extends {}> = (input: any) => input is { | |
[K in keyof Expect]: Expect[K] extends Validator<infer CT> ? CT : never; | |
}; | |
type ValidatorsToUnion<Vs> = Vs extends Array<Validator<infer T>> ? T | |
: never; | |
type EnumsToUnion<Vs> = Vs extends Array<Validator<infer T>> ? T |
export interface Env {} | |
// very easy pattren only for this case | |
const path$join = (...paths: string[]) => { | |
return paths | |
.map(x => x.replace(/^\.\//, '')) | |
.join("/").replace(/\/+/g, "/"); | |
} | |
const path$dirname = (path: string) => { | |
const parts = path.split("/"); |
/* | |
analyze reserved properties from bundled dts for terser | |
$ pnpm tsm analyze.ts src/*.{ts, tsx} -i src/index.ts | |
{ | |
"reservedProperties": [ | |
"result", | |
"value", | |
"pubTypeKey", | |
"ikey", |