compiler.js 5.3 KB

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