EmitPlugin
인터페이스, 출력 분류
A transform that runs inside module emit.
import type { EmitPlugin } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface EmitPlugin { readonly name: string; readonly identity?: string; readonly transformIR?: (lowered: ModuleDecl) => ModuleDecl; readonly transformText?: (code: string) => string;}설명
Plugins are passed to emitModule and
emitGlslModule through EmitOptions as { plugins: [...] }. The core emit knows
nothing about what a plugin does. The plugins shipped with the package (mangle, minify,
prune, obfuscate and others) live on the typeshade/emit-prod subpath, so an
application that emits at runtime and never imports them does not bundle them.
A plugin has two hooks, both optional. transformIR receives the module after every
lowering and optimisation pass has run, and returns a module the backend can spell into
source text. transformText receives the assembled source string and returns the string
to use in its place.
The hooks fire in stages across all plugins: every plugin’s transformIR runs, in plugins
order, before the module is assembled; then every plugin’s transformText runs, in
plugins order, on the assembled string.
예제
예제
const banner: EmitPlugin = { name: 'banner', transformText: (code) => `// generated\n${code}`,}const wgsl = emitModule(MODULE, { plugins: [banner] })인스턴스 속성
name읽기 전용stringThe plugin’s name, used in error messages and diagnostics.
identity선택 사항읽기 전용stringHow this plugin appears in the identity string that
emitIdentitycomputes for an emit configuration. When it is unset,nameis used. Set it when the plugin’s own options change the emitted bytes, so that two configurations of the same plugin produce different identities:minify({a})andminify({b})would otherwise be the same string. None of the plugins shipped with the package set it.transformIR선택 사항읽기 전용(lowered: ModuleDecl) => ModuleDeclRewrites the module after every lowering and optimisation pass. The result must be deterministic for a given module: the GLSL vertex and fragment stages are emitted by separate calls that must agree on every shared name.
transformText선택 사항읽기 전용(code: string) => stringRewrites the assembled source string.
관련 가이드
함께 보기
소스
src/core/emit.ts, 664행, 커밋 c66579bf 기준