CompileOptions
Interface in Authoring
How one compile() call is set up.
import type { CompileOptions } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
interface CompileOptions { readonly fileName?: string; readonly consoleSink?: ConsoleSink; readonly deprecations?: boolean; readonly console?: 'cpu' | 'gpu'; readonly readDocument?: (fileName: string) => string | undefined; readonly resolveImport?: (fromFile: string, specifier: string) => string | undefined;}Description
Every field is optional, and the defaults are what
compile(source) did before this interface existed.
Instance properties
fileNameoptionalread onlystringThe name this source is compiled under. It is the
fileof everySourceSpanthe front end stamps on the IR, and thefileNameof every diagnostic, so it is how a consumer that holds a span says which of the author’s files a statement came from.That default is fine for a compile whose output is shader text, since nothing reads the name, but not for one whose output is stepped: a
DebugBreakpointcarries the path the editor knows the file by, and matches it againstspan.file, so a session compiled under the placeholder silently arms no breakpoint at all. An adapter that has a path should pass it.Nothing resolves or reads it: it is a label carried to the spans, not a path the compiler opens. An adapter does not have to care: a
DebugBreakpoint’s path is normalized the same way before it is compared, so either spelling matches.consoleSinkoptionalread onlyConsoleSinkHost sink for
console.*calls made by CPU/debug evaluation.deprecationsoptionalread onlybooleanReport deprecation warnings for spellings whose meaning is scheduled to change. One today: an integer-written literal in a declaration with no annotation or declared integer use still types as
f32and will type asi32(§13).Off by default, and off is the whole of the compiler’s behaviour: the flag adds
category: 'warning'diagnostics and moves no emitted byte, sowgslandglslare byte-identical with it on and with it off. It is how a build finds the lines the flip will move, one release ahead of it.consoleoptionalread only'cpu' | 'gpu'Where a
consolecall is recorded.'cpu', the default, is whatcompile()always did: the CPU run delivers each call toCompileOptions.consoleSink, and the WGSL and GLSL record nothing, so no emitted byte depends on a console call.'gpu'makes the WGSL also record each call a compute or fragment entry reaches, in a_consolestorage buffer the compiler binds at group 0 past the module’s own bindings;CompileResult.consolesays where, anddecodeConsoleturns the buffer the host copies back into the same events. A call the WGSL cannot record is aTS8071warning. GLSL ES 3.00 records nothing either way. Surface §66, Rule 11.9.readDocumentoptionalread only(fileName: string) => string | undefinedReads a file this source imports (Rule 3.9, surface §68): its text, or
undefinedwhen there is none. The source and every shader file it imports, directly or through another, are one program, compiled into one module, and a diagnostic located in an imported file carries that file’s name and offsets. It is asked for a package’spackage.jsontoo, which the defaultresolveImportreads to find a package innode_modules, so areadDocumentthat reads from disk follows a package with no change. Without it nothing is read: a source with no import compiles as it always has, and an import isTS8072. The same hook as the language service’sTypeshadeLanguageServiceHost.readDocument, so both halves read one program.resolveImportoptionalread only(fromFile: string, specifier: string) => string | undefinedThe file a specifier written in
fromFilenames, orundefinedwhen it names none. The default, which the language service applies too, resolves a relative specifier against the importing file (fileNamefor the source), reads.jsand.mjsas.ts, and appends.tsto any other path. Any other specifier names a package: the firstnode_modules/<name>/package.jsonfrom the importing file’s directory up, read throughreadDocument, and the file itsexportspublishes under thetypeshadecondition (surface §68, change 0024). A hook passed here replaces the rule for every specifier.
See also
Source
src/compiler/ts/compile.ts, line 88, at commit 26de7be8