版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. import * as lru_cache_min from 'lru-cache/min';
  2. import * as _babel_types from '@babel/types';
  3. import { Statement, Expression, TSType, Program, CallExpression, Node, ObjectPattern, TSModuleDeclaration, TSPropertySignature, TSMethodSignature, TSCallSignatureDeclaration, TSFunctionType } from '@babel/types';
  4. import { CompilerOptions, CodegenResult, ParserOptions, RootNode, CompilerError, SourceLocation, ElementNode, BindingMetadata as BindingMetadata$1 } from '@vue/compiler-core';
  5. export { BindingMetadata, CompilerError, CompilerOptions, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, walkIdentifiers } from '@vue/compiler-core';
  6. import { RawSourceMap } from 'source-map-js';
  7. import { ParserPlugin } from '@babel/parser';
  8. export { parse as babelParse } from '@babel/parser';
  9. import { Result, LazyResult } from 'postcss';
  10. import MagicString from 'magic-string';
  11. export { default as MagicString } from 'magic-string';
  12. import TS from 'typescript';
  13. export { shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST } from '@vue/reactivity-transform';
  14. export interface AssetURLTagConfig {
  15. [name: string]: string[];
  16. }
  17. export interface AssetURLOptions {
  18. /**
  19. * If base is provided, instead of transforming relative asset urls into
  20. * imports, they will be directly rewritten to absolute urls.
  21. */
  22. base?: string | null;
  23. /**
  24. * If true, also processes absolute urls.
  25. */
  26. includeAbsolute?: boolean;
  27. tags?: AssetURLTagConfig;
  28. }
  29. export interface TemplateCompiler {
  30. compile(template: string, options: CompilerOptions): CodegenResult;
  31. parse(template: string, options: ParserOptions): RootNode;
  32. }
  33. export interface SFCTemplateCompileResults {
  34. code: string;
  35. ast?: RootNode;
  36. preamble?: string;
  37. source: string;
  38. tips: string[];
  39. errors: (string | CompilerError)[];
  40. map?: RawSourceMap;
  41. }
  42. export interface SFCTemplateCompileOptions {
  43. source: string;
  44. filename: string;
  45. id: string;
  46. scoped?: boolean;
  47. slotted?: boolean;
  48. isProd?: boolean;
  49. ssr?: boolean;
  50. ssrCssVars?: string[];
  51. inMap?: RawSourceMap;
  52. compiler?: TemplateCompiler;
  53. compilerOptions?: CompilerOptions;
  54. preprocessLang?: string;
  55. preprocessOptions?: any;
  56. /**
  57. * In some cases, compiler-sfc may not be inside the project root (e.g. when
  58. * linked or globally installed). In such cases a custom `require` can be
  59. * passed to correctly resolve the preprocessors.
  60. */
  61. preprocessCustomRequire?: (id: string) => any;
  62. /**
  63. * Configure what tags/attributes to transform into asset url imports,
  64. * or disable the transform altogether with `false`.
  65. */
  66. transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
  67. }
  68. export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
  69. export interface SFCScriptCompileOptions {
  70. /**
  71. * Scope ID for prefixing injected CSS variables.
  72. * This must be consistent with the `id` passed to `compileStyle`.
  73. */
  74. id: string;
  75. /**
  76. * Production mode. Used to determine whether to generate hashed CSS variables
  77. */
  78. isProd?: boolean;
  79. /**
  80. * Enable/disable source map. Defaults to true.
  81. */
  82. sourceMap?: boolean;
  83. /**
  84. * https://babeljs.io/docs/en/babel-parser#plugins
  85. */
  86. babelParserPlugins?: ParserPlugin[];
  87. /**
  88. * A list of files to parse for global types to be made available for type
  89. * resolving in SFC macros. The list must be fully resolved file system paths.
  90. */
  91. globalTypeFiles?: string[];
  92. /**
  93. * Compile the template and inline the resulting render function
  94. * directly inside setup().
  95. * - Only affects `<script setup>`
  96. * - This should only be used in production because it prevents the template
  97. * from being hot-reloaded separately from component state.
  98. */
  99. inlineTemplate?: boolean;
  100. /**
  101. * Generate the final component as a variable instead of default export.
  102. * This is useful in e.g. @vitejs/plugin-vue where the script needs to be
  103. * placed inside the main module.
  104. */
  105. genDefaultAs?: string;
  106. /**
  107. * Options for template compilation when inlining. Note these are options that
  108. * would normally be passed to `compiler-sfc`'s own `compileTemplate()`, not
  109. * options passed to `compiler-dom`.
  110. */
  111. templateOptions?: Partial<SFCTemplateCompileOptions>;
  112. /**
  113. * Hoist <script setup> static constants.
  114. * - Only enables when one `<script setup>` exists.
  115. * @default true
  116. */
  117. hoistStatic?: boolean;
  118. /**
  119. * (**Experimental**) Enable macro `defineModel`
  120. * @default false
  121. */
  122. defineModel?: boolean;
  123. /**
  124. * (**Experimental**) Enable reactive destructure for `defineProps`
  125. * @default false
  126. */
  127. propsDestructure?: boolean;
  128. /**
  129. * File system access methods to be used when resolving types
  130. * imported in SFC macros. Defaults to ts.sys in Node.js, can be overwritten
  131. * to use a virtual file system for use in browsers (e.g. in REPLs)
  132. */
  133. fs?: {
  134. fileExists(file: string): boolean;
  135. readFile(file: string): string | undefined;
  136. };
  137. /**
  138. * (Experimental) Enable syntax transform for using refs without `.value` and
  139. * using destructured props with reactivity
  140. * @deprecated the Reactivity Transform proposal has been dropped. This
  141. * feature will be removed from Vue core in 3.4. If you intend to continue
  142. * using it, disable this and switch to the [Vue Macros implementation](https://vue-macros.sxzz.moe/features/reactivity-transform.html).
  143. */
  144. reactivityTransform?: boolean;
  145. }
  146. interface ImportBinding {
  147. isType: boolean;
  148. imported: string;
  149. local: string;
  150. source: string;
  151. isFromSetup: boolean;
  152. isUsedInTemplate: boolean;
  153. }
  154. /**
  155. * Compile `<script setup>`
  156. * It requires the whole SFC descriptor because we need to handle and merge
  157. * normal `<script>` + `<script setup>` if both are present.
  158. */
  159. export declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock;
  160. export interface SFCParseOptions {
  161. filename?: string;
  162. sourceMap?: boolean;
  163. sourceRoot?: string;
  164. pad?: boolean | 'line' | 'space';
  165. ignoreEmpty?: boolean;
  166. compiler?: TemplateCompiler;
  167. }
  168. export interface SFCBlock {
  169. type: string;
  170. content: string;
  171. attrs: Record<string, string | true>;
  172. loc: SourceLocation;
  173. map?: RawSourceMap;
  174. lang?: string;
  175. src?: string;
  176. }
  177. export interface SFCTemplateBlock extends SFCBlock {
  178. type: 'template';
  179. ast: ElementNode;
  180. }
  181. export interface SFCScriptBlock extends SFCBlock {
  182. type: 'script';
  183. setup?: string | boolean;
  184. bindings?: BindingMetadata$1;
  185. imports?: Record<string, ImportBinding>;
  186. scriptAst?: _babel_types.Statement[];
  187. scriptSetupAst?: _babel_types.Statement[];
  188. warnings?: string[];
  189. /**
  190. * Fully resolved dependency file paths (unix slashes) with imported types
  191. * used in macros, used for HMR cache busting in @vitejs/plugin-vue and
  192. * vue-loader.
  193. */
  194. deps?: string[];
  195. }
  196. export interface SFCStyleBlock extends SFCBlock {
  197. type: 'style';
  198. scoped?: boolean;
  199. module?: string | boolean;
  200. }
  201. export interface SFCDescriptor {
  202. filename: string;
  203. source: string;
  204. template: SFCTemplateBlock | null;
  205. script: SFCScriptBlock | null;
  206. scriptSetup: SFCScriptBlock | null;
  207. styles: SFCStyleBlock[];
  208. customBlocks: SFCBlock[];
  209. cssVars: string[];
  210. /**
  211. * whether the SFC uses :slotted() modifier.
  212. * this is used as a compiler optimization hint.
  213. */
  214. slotted: boolean;
  215. /**
  216. * compare with an existing descriptor to determine whether HMR should perform
  217. * a reload vs. re-render.
  218. *
  219. * Note: this comparison assumes the prev/next script are already identical,
  220. * and only checks the special case where <script setup lang="ts"> unused import
  221. * pruning result changes due to template changes.
  222. */
  223. shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
  224. }
  225. export interface SFCParseResult {
  226. descriptor: SFCDescriptor;
  227. errors: (CompilerError | SyntaxError)[];
  228. }
  229. export declare const parseCache: Map<string, SFCParseResult> | lru_cache_min.LRUCache<string, SFCParseResult, unknown>;
  230. export declare function parse(source: string, { sourceMap, filename, sourceRoot, pad, ignoreEmpty, compiler }?: SFCParseOptions): SFCParseResult;
  231. type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
  232. export interface SFCStyleCompileOptions {
  233. source: string;
  234. filename: string;
  235. id: string;
  236. scoped?: boolean;
  237. trim?: boolean;
  238. isProd?: boolean;
  239. inMap?: RawSourceMap;
  240. preprocessLang?: PreprocessLang;
  241. preprocessOptions?: any;
  242. preprocessCustomRequire?: (id: string) => any;
  243. postcssOptions?: any;
  244. postcssPlugins?: any[];
  245. /**
  246. * @deprecated use `inMap` instead.
  247. */
  248. map?: RawSourceMap;
  249. }
  250. /**
  251. * Aligns with postcss-modules
  252. * https://github.com/css-modules/postcss-modules
  253. */
  254. interface CSSModulesOptions {
  255. scopeBehaviour?: 'global' | 'local';
  256. generateScopedName?: string | ((name: string, filename: string, css: string) => string);
  257. hashPrefix?: string;
  258. localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
  259. exportGlobals?: boolean;
  260. globalModulePaths?: RegExp[];
  261. }
  262. export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
  263. isAsync?: boolean;
  264. modules?: boolean;
  265. modulesOptions?: CSSModulesOptions;
  266. }
  267. export interface SFCStyleCompileResults {
  268. code: string;
  269. map: RawSourceMap | undefined;
  270. rawResult: Result | LazyResult | undefined;
  271. errors: Error[];
  272. modules?: Record<string, string>;
  273. dependencies: Set<string>;
  274. }
  275. export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
  276. export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
  277. export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
  278. /**
  279. * Utility for rewriting `export default` in a script block into a variable
  280. * declaration so that we can inject things into it
  281. */
  282. export declare function rewriteDefaultAST(ast: Statement[], s: MagicString, as: string): void;
  283. type PropsDestructureBindings = Record<string, // public prop key
  284. {
  285. local: string;
  286. default?: Expression;
  287. }>;
  288. interface ModelDecl {
  289. type: TSType | undefined;
  290. options: string | undefined;
  291. identifier: string | undefined;
  292. }
  293. declare const enum BindingTypes {
  294. /**
  295. * returned from data()
  296. */
  297. DATA = "data",
  298. /**
  299. * declared as a prop
  300. */
  301. PROPS = "props",
  302. /**
  303. * a local alias of a `<script setup>` destructured prop.
  304. * the original is stored in __propsAliases of the bindingMetadata object.
  305. */
  306. PROPS_ALIASED = "props-aliased",
  307. /**
  308. * a let binding (may or may not be a ref)
  309. */
  310. SETUP_LET = "setup-let",
  311. /**
  312. * a const binding that can never be a ref.
  313. * these bindings don't need `unref()` calls when processed in inlined
  314. * template expressions.
  315. */
  316. SETUP_CONST = "setup-const",
  317. /**
  318. * a const binding that does not need `unref()`, but may be mutated.
  319. */
  320. SETUP_REACTIVE_CONST = "setup-reactive-const",
  321. /**
  322. * a const binding that may be a ref.
  323. */
  324. SETUP_MAYBE_REF = "setup-maybe-ref",
  325. /**
  326. * bindings that are guaranteed to be refs
  327. */
  328. SETUP_REF = "setup-ref",
  329. /**
  330. * declared by other options, e.g. computed, inject
  331. */
  332. OPTIONS = "options",
  333. /**
  334. * a literal constant, e.g. 'foo', 1, true
  335. */
  336. LITERAL_CONST = "literal-const"
  337. }
  338. type BindingMetadata = {
  339. [key: string]: BindingTypes | undefined;
  340. } & {
  341. __isScriptSetup?: boolean;
  342. __propsAliases?: Record<string, string>;
  343. };
  344. export declare class ScriptCompileContext {
  345. descriptor: SFCDescriptor;
  346. options: Partial<SFCScriptCompileOptions>;
  347. isJS: boolean;
  348. isTS: boolean;
  349. scriptAst: Program | null;
  350. scriptSetupAst: Program | null;
  351. source: string;
  352. filename: string;
  353. s: MagicString;
  354. startOffset: number | undefined;
  355. endOffset: number | undefined;
  356. scope?: TypeScope;
  357. globalScopes?: TypeScope[];
  358. userImports: Record<string, ImportBinding>;
  359. hasDefinePropsCall: boolean;
  360. hasDefineEmitCall: boolean;
  361. hasDefineExposeCall: boolean;
  362. hasDefaultExportName: boolean;
  363. hasDefaultExportRender: boolean;
  364. hasDefineOptionsCall: boolean;
  365. hasDefineSlotsCall: boolean;
  366. hasDefineModelCall: boolean;
  367. propsCall: CallExpression | undefined;
  368. propsDecl: Node | undefined;
  369. propsRuntimeDecl: Node | undefined;
  370. propsTypeDecl: Node | undefined;
  371. propsDestructureDecl: ObjectPattern | undefined;
  372. propsDestructuredBindings: PropsDestructureBindings;
  373. propsDestructureRestId: string | undefined;
  374. propsRuntimeDefaults: Node | undefined;
  375. emitsRuntimeDecl: Node | undefined;
  376. emitsTypeDecl: Node | undefined;
  377. emitDecl: Node | undefined;
  378. modelDecls: Record<string, ModelDecl>;
  379. optionsRuntimeDecl: Node | undefined;
  380. bindingMetadata: BindingMetadata;
  381. helperImports: Set<string>;
  382. helper(key: string): string;
  383. /**
  384. * to be exposed on compiled script block for HMR cache busting
  385. */
  386. deps?: Set<string>;
  387. /**
  388. * cache for resolved fs
  389. */
  390. fs?: NonNullable<SFCScriptCompileOptions['fs']>;
  391. constructor(descriptor: SFCDescriptor, options: Partial<SFCScriptCompileOptions>);
  392. getString(node: Node, scriptSetup?: boolean): string;
  393. error(msg: string, node: Node, scope?: TypeScope): never;
  394. }
  395. /**
  396. * TypeResolveContext is compatible with ScriptCompileContext
  397. * but also allows a simpler version of it with minimal required properties
  398. * when resolveType needs to be used in a non-SFC context, e.g. in a babel
  399. * plugin. The simplest context can be just:
  400. * ```ts
  401. * const ctx: SimpleTypeResolveContext = {
  402. * filename: '...',
  403. * source: '...',
  404. * options: {},
  405. * error() {},
  406. * ast: []
  407. * }
  408. * ```
  409. */
  410. export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'options'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & {
  411. ast: Statement[];
  412. };
  413. export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext;
  414. type Import = Pick<ImportBinding, 'source' | 'imported'>;
  415. interface WithScope {
  416. _ownerScope: TypeScope;
  417. }
  418. type ScopeTypeNode = Node & WithScope & {
  419. _ns?: TSModuleDeclaration & WithScope;
  420. };
  421. declare class TypeScope {
  422. filename: string;
  423. source: string;
  424. offset: number;
  425. imports: Record<string, Import>;
  426. types: Record<string, ScopeTypeNode>;
  427. declares: Record<string, ScopeTypeNode>;
  428. constructor(filename: string, source: string, offset?: number, imports?: Record<string, Import>, types?: Record<string, ScopeTypeNode>, declares?: Record<string, ScopeTypeNode>);
  429. resolvedImportSources: Record<string, string>;
  430. exportedTypes: Record<string, ScopeTypeNode>;
  431. exportedDeclares: Record<string, ScopeTypeNode>;
  432. }
  433. interface MaybeWithScope {
  434. _ownerScope?: TypeScope;
  435. }
  436. interface ResolvedElements {
  437. props: Record<string, (TSPropertySignature | TSMethodSignature) & {
  438. _ownerScope: TypeScope;
  439. }>;
  440. calls?: (TSCallSignatureDeclaration | TSFunctionType)[];
  441. }
  442. /**
  443. * Resolve arbitrary type node to a list of type elements that can be then
  444. * mapped to runtime props or emits.
  445. */
  446. export declare function resolveTypeElements(ctx: TypeResolveContext, node: Node & MaybeWithScope & {
  447. _resolvedElements?: ResolvedElements;
  448. }, scope?: TypeScope): ResolvedElements;
  449. /**
  450. * @private
  451. */
  452. export declare function registerTS(_loadTS: () => typeof TS): void;
  453. /**
  454. * @private
  455. */
  456. export declare function invalidateTypeCache(filename: string): void;
  457. export declare function inferRuntimeType(ctx: TypeResolveContext, node: Node & MaybeWithScope, scope?: TypeScope): string[];
  458. export declare const version: string;
  459. export declare const walk: any;