```js // @noErrors import { VERSION, compile, compileModule, migrate, parse, preprocess, walk } from 'svelte/compiler'; ``` ## 版本 当前版本,如 package.json 中设置。 `const 版本: string;` ## 编译 `编译`将您的`.svelte`源代码转换为导出组件的 JavaScript 模块 ```dts function compile( source: string, options: CompileOptions ): CompileResult; ``` ## 编译模块 `compileModule` 接收包含符文的 JavaScript 源代码,并将其转换为 JavaScript 模块。 ```dts function compileModule( source: string, options: ModuleCompileOptions ): CompileResult; ``` ## 迁移 尽力迁移 Svelte 代码以使用 runes、事件属性和渲染标签。如果代码过于复杂而无法自动迁移,可能会抛出错误。 ```dts function migrate( source: string, { filename, use_ts }?: | { filename?: string; use_ts?: boolean; } | undefined ): { code: string; }; ``` ## 解析 函数解析组件,仅返回其抽象语法树。 现代(`modern`)选项(在 Svelte 5 中默认为 `false`)使解析器返回现代 AST 而不是传统 AST。《`modern` 将在 Svelte 6 中默认为 `true`,并在 Svelte 7 中移除此选项。 ```dts function parse( source: string, options: { filename?: string; modern: true; loose?: boolean; } ): AST.Root; ``` ```dts function parse( source: string, options?: | { filename?: string; modern?: false; loose?: boolean; } | undefined ): Record; ``` ## 预处理 预处理函数提供了方便的钩子,用于任意转换组件源代码。例如,它可以用来将一个`