options.d.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { ParserPlugin } from '@babel/parser';
  2. import { GeneratorOptions } from '@babel/generator';
  3. import { CallExpression, Expression, ObjectExpression, ObjectProperty, SpreadElement } from '@babel/types';
  4. import { NodeTransform as VueNodeTransform, DirectiveTransform as VueDirectiveTransform } from '@vue/compiler-core';
  5. import { MiniProgramCompilerOptions } from '@dcloudio/uni-cli-shared';
  6. import { BindingMetadata, CompilerError, RootNode } from '@vue/compiler-core';
  7. import IdentifierGenerator from './identifier';
  8. import { TransformContext } from './transform';
  9. import { VForOptions } from './transforms/vFor';
  10. export interface CodegenRootNode extends RootNode {
  11. renderData: ObjectExpression | CallExpression;
  12. bindingComponents: TransformContext['bindingComponents'];
  13. }
  14. export interface ErrorHandlingOptions {
  15. onWarn?: (warning: CompilerError) => void;
  16. onError?: (error: CompilerError) => void;
  17. }
  18. interface ParserOptions {
  19. /**
  20. * e.g. platform native elements, e.g. `<div>` for browsers
  21. */
  22. isNativeTag?: (tag: string) => boolean;
  23. /**
  24. * e.g. native elements that can self-close, e.g. `<img>`, `<br>`, `<hr>`
  25. */
  26. isVoidTag?: (tag: string) => boolean;
  27. /**
  28. * Separate option for end users to extend the native elements list
  29. */
  30. isCustomElement?: (tag: string) => boolean | void;
  31. }
  32. interface SharedTransformCodegenOptions {
  33. inline?: boolean;
  34. isTS?: boolean;
  35. root?: string;
  36. filename?: string;
  37. bindingMetadata?: BindingMetadata;
  38. prefixIdentifiers?: boolean;
  39. miniProgram?: MiniProgramCompilerOptions;
  40. }
  41. export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHandlingOptions {
  42. hashId?: string | null;
  43. scopeId?: string | null;
  44. filters?: string[];
  45. renderDataSpread?: boolean;
  46. cacheHandlers?: boolean;
  47. nodeTransforms?: VueNodeTransform[];
  48. directiveTransforms?: Record<string, VueDirectiveTransform | undefined>;
  49. isBuiltInComponent?: (tag: string) => symbol | void;
  50. isCustomElement?: (tag: string) => boolean | void;
  51. expressionPlugins?: ParserPlugin[];
  52. skipTransformIdentifier?: boolean;
  53. bindingCssVars?: string[];
  54. }
  55. export interface CodegenRootScope {
  56. id: IdentifierGenerator;
  57. identifiers: string[];
  58. properties: (ObjectProperty | SpreadElement)[];
  59. parent: CodegenScope | null;
  60. }
  61. export interface CodegenVIfScopeInit {
  62. name: 'if' | 'else-if' | 'else' | string;
  63. condition?: Expression;
  64. }
  65. export type CodegenVForScopeInit = VForOptions & {
  66. locals: string[];
  67. };
  68. export interface CodegenVIfScope extends CodegenRootScope, CodegenVIfScopeInit {
  69. parentScope: CodegenRootScope | CodegenVForScope;
  70. }
  71. export interface CodegenVForScope extends CodegenRootScope, CodegenVForScopeInit {
  72. }
  73. export type CodegenScope = CodegenRootScope | CodegenVIfScope | CodegenVForScope;
  74. export interface CodegenOptions extends SharedTransformCodegenOptions {
  75. mode?: 'module' | 'function';
  76. scopeId?: string | null;
  77. sourceMap?: boolean;
  78. runtimeModuleName?: string;
  79. runtimeGlobalName?: string;
  80. generatorOpts?: GeneratorOptions;
  81. }
  82. export interface TemplateCodegenOptions extends Omit<MiniProgramCompilerOptions, 'filter'> {
  83. scopeId?: string | null;
  84. filename: string;
  85. isBuiltInComponent: Required<TransformOptions>['isBuiltInComponent'];
  86. isMiniProgramComponent(name: string): 'plugin' | 'component' | 'dynamicLib' | 'ext' | undefined;
  87. }
  88. export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions;
  89. export {};