compiler.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. slotTargetDynamic?: boolean;
  106. slotScope?: ?string;
  107. scopedSlots?: { [name: string]: ASTElement };
  108. ref?: string;
  109. refInFor?: boolean;
  110. if?: string;
  111. ifProcessed?: boolean;
  112. elseif?: string;
  113. else?: true;
  114. ifConditions?: ASTIfConditions;
  115. for?: string;
  116. forProcessed?: boolean;
  117. key?: string;
  118. alias?: string;
  119. iterator1?: string;
  120. iterator2?: string;
  121. staticClass?: string;
  122. classBinding?: string;
  123. staticStyle?: string;
  124. styleBinding?: string;
  125. events?: ASTElementHandlers;
  126. nativeEvents?: ASTElementHandlers;
  127. transition?: string | true;
  128. transitionOnAppear?: boolean;
  129. model?: {
  130. value: string;
  131. callback: string;
  132. expression: string;
  133. };
  134. directives?: Array<ASTDirective>;
  135. forbidden?: true;
  136. once?: true;
  137. onceProcessed?: boolean;
  138. wrapData?: (code: string) => string;
  139. wrapListeners?: (code: string) => string;
  140. // 2.4 ssr optimization
  141. ssrOptimizability?: number;
  142. // weex specific
  143. appendAsTree?: boolean;
  144. };
  145. declare type ASTExpression = {
  146. type: 2;
  147. expression: string;
  148. text: string;
  149. tokens: Array<string | Object>;
  150. static?: boolean;
  151. // 2.4 ssr optimization
  152. ssrOptimizability?: number;
  153. start?: number;
  154. end?: number;
  155. };
  156. declare type ASTText = {
  157. type: 3;
  158. text: string;
  159. static?: boolean;
  160. isComment?: boolean;
  161. // 2.4 ssr optimization
  162. ssrOptimizability?: number;
  163. start?: number;
  164. end?: number;
  165. };
  166. // SFC-parser related declarations
  167. // an object format describing a single-file component
  168. declare type SFCDescriptor = {
  169. template: ?SFCBlock;
  170. script: ?SFCBlock;
  171. styles: Array<SFCBlock>;
  172. customBlocks: Array<SFCBlock>;
  173. errors: Array<string | WarningMessage>;
  174. }
  175. declare type SFCBlock = {
  176. type: string;
  177. content: string;
  178. attrs: {[attribute:string]: string};
  179. start?: number;
  180. end?: number;
  181. lang?: string;
  182. src?: string;
  183. scoped?: boolean;
  184. module?: string | boolean;
  185. };