compiler.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. declare type CompilerOptions = {
  2. warn?: Function; // allow customizing warning in different environments; e.g. node
  3. expectHTML?: boolean; // only false for non-web builds
  4. modules?: Array<ModuleOptions>; // platform specific modules; e.g. style; class
  5. staticKeys?: string; // a list of AST properties to be considered static; for optimization
  6. directives?: { [key: string]: Function }; // platform specific directives
  7. isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
  8. canBeLeftOpenTag?: (tag: string) => ?boolean; // check if a tag can be left opened
  9. isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
  10. mustUseProp?: (tag: string, type: ?string, name: string) => boolean; // check if an attribute should be bound as a property
  11. isPreTag?: (attr: string) => ?boolean; // check if a tag needs to preserve whitespace
  12. getTagNamespace?: (tag: string) => ?string; // check the namespace for a tag
  13. transforms?: Array<Function>; // a list of transforms on parsed AST before codegen
  14. preserveWhitespace?: boolean;
  15. isFromDOM?: boolean;
  16. shouldDecodeTags?: boolean;
  17. shouldDecodeNewlines?: boolean;
  18. // for ssr optimization compiler
  19. scopeId?: string;
  20. // runtime user-configurable
  21. delimiters?: [string, string]; // template delimiters
  22. };
  23. declare type CompiledResult = {
  24. ast: ?ASTElement;
  25. render: string;
  26. staticRenderFns: Array<string>;
  27. stringRenderFns?: Array<string>;
  28. errors?: Array<string>;
  29. tips?: Array<string>;
  30. };
  31. declare type ModuleOptions = {
  32. preTransformNode: (el: ASTElement) => void;
  33. transformNode: (el: ASTElement) => void; // transform an element's AST node
  34. postTransformNode: (el: ASTElement) => void;
  35. genData: (el: ASTElement) => string; // generate extra data string for an element
  36. transformCode?: (el: ASTElement, code: string) => string; // further transform generated code for an element
  37. staticKeys?: Array<string>; // AST properties to be considered static
  38. };
  39. declare type ASTModifiers = { [key: string]: boolean };
  40. declare type ASTIfConditions = Array<{ exp: ?string; block: ASTElement }>;
  41. declare type ASTElementHandler = {
  42. value: string;
  43. modifiers: ?ASTModifiers;
  44. };
  45. declare type ASTElementHandlers = {
  46. [key: string]: ASTElementHandler | Array<ASTElementHandler>;
  47. };
  48. declare type ASTDirective = {
  49. name: string;
  50. rawName: string;
  51. value: string;
  52. arg: ?string;
  53. modifiers: ?ASTModifiers;
  54. };
  55. declare type ASTNode = ASTElement | ASTText | ASTExpression;
  56. declare type ASTElement = {
  57. type: 1;
  58. tag: string;
  59. attrsList: Array<{ name: string; value: string }>;
  60. attrsMap: { [key: string]: string | null };
  61. parent: ASTElement | void;
  62. children: Array<ASTNode>;
  63. static?: boolean;
  64. staticRoot?: boolean;
  65. staticInFor?: boolean;
  66. staticProcessed?: boolean;
  67. hasBindings?: boolean;
  68. text?: string;
  69. attrs?: Array<{ name: string; value: string }>;
  70. props?: Array<{ name: string; value: string }>;
  71. plain?: boolean;
  72. pre?: true;
  73. ns?: string;
  74. component?: string;
  75. inlineTemplate?: true;
  76. transitionMode?: string | null;
  77. slotName?: ?string;
  78. slotTarget?: ?string;
  79. slotScope?: ?string;
  80. scopedSlots?: { [name: string]: ASTElement };
  81. ref?: string;
  82. refInFor?: boolean;
  83. if?: string;
  84. ifProcessed?: boolean;
  85. elseif?: string;
  86. else?: true;
  87. ifConditions?: ASTIfConditions;
  88. for?: string;
  89. forProcessed?: boolean;
  90. key?: string;
  91. alias?: string;
  92. iterator1?: string;
  93. iterator2?: string;
  94. staticClass?: string;
  95. classBinding?: string;
  96. staticStyle?: string;
  97. styleBinding?: string;
  98. events?: ASTElementHandlers;
  99. nativeEvents?: ASTElementHandlers;
  100. transition?: string | true;
  101. transitionOnAppear?: boolean;
  102. model?: {
  103. value: string;
  104. callback: string;
  105. expression: string;
  106. };
  107. directives?: Array<ASTDirective>;
  108. forbidden?: true;
  109. once?: true;
  110. onceProcessed?: boolean;
  111. wrapData?: (code: string) => string;
  112. // 2.4 ssr optimization
  113. ssrOptimizability?: number;
  114. // weex specific
  115. appendAsTree?: boolean;
  116. };
  117. declare type ASTExpression = {
  118. type: 2;
  119. expression: string;
  120. text: string;
  121. static?: boolean;
  122. // 2.4 ssr optimization
  123. ssrOptimizability?: number;
  124. };
  125. declare type ASTText = {
  126. type: 3;
  127. text: string;
  128. static?: boolean;
  129. // 2.4 ssr optimization
  130. ssrOptimizability?: number;
  131. };
  132. // SFC-parser related declarations
  133. // an object format describing a single-file component.
  134. declare type SFCDescriptor = {
  135. template: ?SFCBlock;
  136. script: ?SFCBlock;
  137. styles: Array<SFCBlock>;
  138. customBlocks: Array<SFCCustomBlock>;
  139. }
  140. declare type SFCCustomBlock = {
  141. type: string;
  142. content: string;
  143. start?: number;
  144. end?: number;
  145. src?: string;
  146. attrs: {[attribute:string]: string};
  147. };
  148. declare type SFCBlock = {
  149. type: string;
  150. content: string;
  151. start?: number;
  152. end?: number;
  153. lang?: string;
  154. src?: string;
  155. scoped?: boolean;
  156. module?: string | boolean;
  157. };