compiler.js 5.3 KB

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