Skip to content

Instantly share code, notes, and snippets.

View clone-and-reflect.ts
import { h, render } from "preact";
import { useState } from "preact/hooks";
// Original App
function App() {
const [state, setState] = useState(0);
return h(
"div",
{ class: "root" },
h(
View vite-plugin-raw.js
// vite-plugin-raw
/*
How to use.
// vite.config.js
const raw = require('<this>')
module.exports = {
plugins: [raw()]
View gist:3b8c9545dd974a00d130fac1ba9ecc7d
$ rustc -V
rustc 1.52.0-nightly (e9920ef77 2021-02-11)
$ cargo install pijul --version "~1.0.0-alpha
...
Compiling pijul v1.0.0-alpha.45
error: linking with `cc` failed: exit code: 1
View rewrite-ts.js
/*
Patch typescript to run in snowpack.
I added this workaround for perf_hooks.
Add this task in package.json
"scripts": {
// ...
"postinstall": "node scripts/rewrite-ts.js",
}
*/
View svelte-ssr-css.ts
import { GENERATED_CSS_PREFIX } from "./constants";
import * as uniroll from "uniroll";
import ts from "typescript";
import { svelte } from "./index";
import fetch from "isomorphic-unfetch";
import vm from "vm";
import fs from "fs";
global.fetch = fetch;
View svelte-ssr-test.ts
import * as uniroll from "uniroll";
import ts from "typescript";
import { svelte } from "rollup-plugin-uniroll-svelte";
import fetch from "isomorphic-unfetch";
import vm from "vm";
global.fetch = fetch;
const App = `
<script lang="ts">
export let foo: string;
View printTemplate.ts
import { ExtendedTemplateNode } from "../../types";
import * as compiler from "svelte/compiler";
// import ts from "typescript";
import prettier from "prettier/standalone";
// @ts-ignore
import * as sveltePlugin from "prettier-plugin-svelte";
import * as astring from "astring";
// @ts-ignore
@mizchi
mizchi / printTemplate.ts
Created Feb 9, 2021
Generate code from svelte ast
View printTemplate.ts
import prettier from "prettier/standalone";
import produce from "immer";
import { parse } from "svelte/compiler";
import type { Ast } from "svelte/types/compiler/interfaces";
// @ts-ignore
import * as sveltePlugin from "prettier-plugin-svelte";
function printTemplate(ast: Ast) {
const overridePlugin = produce(sveltePlugin, (d: any) => {
d.parsers.svelte.parse = () => {
View loadExternalLibTypes.ts
// esm.sh の x-typescript-types を返すだけのエンドポイントのラッパー
import { getTypes } from "../pages/api/types";
import type * as Monaco from "monaco-editor";
import path from "path";
import { kvsIndexedDB } from "@kvs/indexeddb";
import ts from "typescript";
type Ctx = {
monaco: typeof Monaco;
extractImportSpecifiers: (code: string) => Promise<string[]>;
View getComponentProps.ts
import ts from "typescript";
import { preprocess } from "svelte/compiler";
import { PreprocessorGroup } from "svelte/types/compiler/preprocess/types";
export async function getComponentProps(code: string) {
let interfaces: Array<{
identifier: string;
type: "number" | "string" | "boolean";
comment?: string;
}> = [];