版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

251 lines
7.8 KiB

  1. import { parse as babelParse } from '@babel/parser';
  2. import { BindingMetadata } from '@vue/compiler-core';
  3. import { CodegenResult } from '@vue/compiler-core';
  4. import { CompilerError } from '@vue/compiler-core';
  5. import { CompilerOptions } from '@vue/compiler-core';
  6. import { ElementNode } from '@vue/compiler-core';
  7. import { generateCodeFrame } from '@vue/compiler-core';
  8. import { Identifier } from '@babel/types';
  9. import { LazyResult } from 'postcss';
  10. import MagicString from 'magic-string';
  11. import { Node as Node_2 } from '@babel/types';
  12. import { ParserOptions } from '@vue/compiler-core';
  13. import { ParserPlugin } from '@babel/parser';
  14. import { RawSourceMap } from 'source-map';
  15. import { Result } from 'postcss';
  16. import { RootNode } from '@vue/compiler-core';
  17. import { SourceLocation } from '@vue/compiler-core';
  18. import { Statement } from '@babel/types';
  19. import { walk } from 'estree-walker';
  20. declare interface AssetURLOptions {
  21. /**
  22. * If base is provided, instead of transforming relative asset urls into
  23. * imports, they will be directly rewritten to absolute urls.
  24. */
  25. base?: string | null;
  26. /**
  27. * If true, also processes absolute urls.
  28. */
  29. includeAbsolute?: boolean;
  30. tags?: AssetURLTagConfig;
  31. }
  32. declare interface AssetURLTagConfig {
  33. [name: string]: string[];
  34. }
  35. export { babelParse }
  36. export { BindingMetadata }
  37. export { CompilerError }
  38. export { CompilerOptions }
  39. /**
  40. * Compile `<script setup>`
  41. * It requires the whole SFC descriptor because we need to handle and merge
  42. * normal `<script>` + `<script setup>` if both are present.
  43. */
  44. export declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock;
  45. export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
  46. export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
  47. export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
  48. /**
  49. * Aligns with postcss-modules
  50. * https://github.com/css-modules/postcss-modules
  51. */
  52. declare interface CSSModulesOptions {
  53. scopeBehaviour?: 'global' | 'local';
  54. generateScopedName?: string | ((name: string, filename: string, css: string) => string);
  55. hashPrefix?: string;
  56. localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
  57. exportGlobals?: boolean;
  58. globalModulePaths?: string[];
  59. }
  60. export { generateCodeFrame }
  61. export { MagicString }
  62. export declare function parse(source: string, { sourceMap, filename, sourceRoot, pad, compiler }?: SFCParseOptions): SFCParseResult;
  63. declare type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
  64. /**
  65. * Utility for rewriting `export default` in a script block into a variable
  66. * declaration so that we can inject things into it
  67. */
  68. export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
  69. export declare interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
  70. isAsync?: boolean;
  71. modules?: boolean;
  72. modulesOptions?: CSSModulesOptions;
  73. }
  74. export declare interface SFCBlock {
  75. type: string;
  76. content: string;
  77. attrs: Record<string, string | true>;
  78. loc: SourceLocation;
  79. map?: RawSourceMap;
  80. lang?: string;
  81. src?: string;
  82. }
  83. export declare interface SFCDescriptor {
  84. filename: string;
  85. source: string;
  86. template: SFCTemplateBlock | null;
  87. script: SFCScriptBlock | null;
  88. scriptSetup: SFCScriptBlock | null;
  89. styles: SFCStyleBlock[];
  90. customBlocks: SFCBlock[];
  91. cssVars: string[];
  92. slotted: boolean;
  93. }
  94. export declare interface SFCParseOptions {
  95. filename?: string;
  96. sourceMap?: boolean;
  97. sourceRoot?: string;
  98. pad?: boolean | 'line' | 'space';
  99. compiler?: TemplateCompiler;
  100. }
  101. declare interface SFCParseResult {
  102. descriptor: SFCDescriptor;
  103. errors: (CompilerError | SyntaxError)[];
  104. }
  105. export declare interface SFCScriptBlock extends SFCBlock {
  106. type: 'script';
  107. setup?: string | boolean;
  108. bindings?: BindingMetadata;
  109. scriptAst?: Statement[];
  110. scriptSetupAst?: Statement[];
  111. }
  112. export declare interface SFCScriptCompileOptions {
  113. /**
  114. * Scope ID for prefixing injected CSS varialbes.
  115. * This must be consistent with the `id` passed to `compileStyle`.
  116. */
  117. id: string;
  118. /**
  119. * Production mode. Used to determine whether to generate hashed CSS variables
  120. */
  121. isProd?: boolean;
  122. /**
  123. * https://babeljs.io/docs/en/babel-parser#plugins
  124. */
  125. babelParserPlugins?: ParserPlugin[];
  126. /**
  127. * Enable ref: label sugar
  128. * https://github.com/vuejs/rfcs/pull/228
  129. * @default true
  130. */
  131. refSugar?: boolean;
  132. /**
  133. * Compile the template and inline the resulting render function
  134. * directly inside setup().
  135. * - Only affects <script setup>
  136. * - This should only be used in production because it prevents the template
  137. * from being hot-reloaded separately from component state.
  138. */
  139. inlineTemplate?: boolean;
  140. templateOptions?: Partial<SFCTemplateCompileOptions>;
  141. }
  142. export declare interface SFCStyleBlock extends SFCBlock {
  143. type: 'style';
  144. scoped?: boolean;
  145. module?: string | boolean;
  146. }
  147. export declare interface SFCStyleCompileOptions {
  148. source: string;
  149. filename: string;
  150. id: string;
  151. scoped?: boolean;
  152. trim?: boolean;
  153. isProd?: boolean;
  154. inMap?: RawSourceMap;
  155. preprocessLang?: PreprocessLang;
  156. preprocessOptions?: any;
  157. preprocessCustomRequire?: (id: string) => any;
  158. postcssOptions?: any;
  159. postcssPlugins?: any[];
  160. /**
  161. * @deprecated
  162. */
  163. map?: RawSourceMap;
  164. }
  165. export declare interface SFCStyleCompileResults {
  166. code: string;
  167. map: RawSourceMap | undefined;
  168. rawResult: Result | LazyResult | undefined;
  169. errors: Error[];
  170. modules?: Record<string, string>;
  171. dependencies: Set<string>;
  172. }
  173. export declare interface SFCTemplateBlock extends SFCBlock {
  174. type: 'template';
  175. ast: ElementNode;
  176. }
  177. export declare interface SFCTemplateCompileOptions {
  178. source: string;
  179. filename: string;
  180. id: string;
  181. scoped?: boolean;
  182. slotted?: boolean;
  183. isProd?: boolean;
  184. ssr?: boolean;
  185. ssrCssVars?: string[];
  186. inMap?: RawSourceMap;
  187. compiler?: TemplateCompiler;
  188. compilerOptions?: CompilerOptions;
  189. preprocessLang?: string;
  190. preprocessOptions?: any;
  191. /**
  192. * In some cases, compiler-sfc may not be inside the project root (e.g. when
  193. * linked or globally installed). In such cases a custom `require` can be
  194. * passed to correctly resolve the preprocessors.
  195. */
  196. preprocessCustomRequire?: (id: string) => any;
  197. /**
  198. * Configure what tags/attributes to transform into asset url imports,
  199. * or disable the transform altogether with `false`.
  200. */
  201. transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
  202. }
  203. export declare interface SFCTemplateCompileResults {
  204. code: string;
  205. ast?: RootNode;
  206. preamble?: string;
  207. source: string;
  208. tips: string[];
  209. errors: (string | CompilerError)[];
  210. map?: RawSourceMap;
  211. }
  212. export declare interface TemplateCompiler {
  213. compile(template: string, options: CompilerOptions): CodegenResult;
  214. parse(template: string, options: ParserOptions): RootNode;
  215. }
  216. export { walk }
  217. /**
  218. * Walk an AST and find identifiers that are variable references.
  219. * This is largely the same logic with `transformExpressions` in compiler-core
  220. * but with some subtle differences as this needs to handle a wider range of
  221. * possible syntax.
  222. */
  223. export declare function walkIdentifiers(root: Node_2, onIdentifier: (node: Identifier, parent: Node_2, parentStack: Node_2[]) => void): void;
  224. export { }