compiler.js 5.8 KB

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