compiler.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. shouldDecodeNewlinesForHref?: boolean;
  19. // for ssr optimization compiler
  20. scopeId?: string;
  21. // runtime user-configurable
  22. delimiters?: [string, string]; // template delimiters
  23. // allow user kept comments
  24. comments?: boolean
  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. modifiers: ?ASTModifiers;
  53. };
  54. declare type ASTElementHandlers = {
  55. [key: string]: ASTElementHandler | Array<ASTElementHandler>;
  56. };
  57. declare type ASTDirective = {
  58. name: string;
  59. rawName: string;
  60. value: string;
  61. arg: ?string;
  62. modifiers: ?ASTModifiers;
  63. };
  64. declare type ASTNode = ASTElement | ASTText | ASTExpression;
  65. declare type ASTElement = {
  66. type: 1;
  67. tag: string;
  68. attrsList: Array<{ name: string; value: any }>;
  69. attrsMap: { [key: string]: any };
  70. parent: ASTElement | void;
  71. children: Array<ASTNode>;
  72. processed?: true;
  73. static?: boolean;
  74. staticRoot?: boolean;
  75. staticInFor?: boolean;
  76. staticProcessed?: boolean;
  77. hasBindings?: boolean;
  78. text?: string;
  79. attrs?: Array<{ name: string; value: any }>;
  80. props?: Array<{ name: string; value: string }>;
  81. plain?: boolean;
  82. pre?: true;
  83. ns?: string;
  84. component?: string;
  85. inlineTemplate?: true;
  86. transitionMode?: string | null;
  87. slotName?: ?string;
  88. slotTarget?: ?string;
  89. slotScope?: ?string;
  90. scopedSlots?: { [name: string]: ASTElement };
  91. ref?: string;
  92. refInFor?: boolean;
  93. if?: string;
  94. ifProcessed?: boolean;
  95. elseif?: string;
  96. else?: true;
  97. ifConditions?: ASTIfConditions;
  98. for?: string;
  99. forProcessed?: boolean;
  100. key?: string;
  101. alias?: string;
  102. iterator1?: string;
  103. iterator2?: string;
  104. staticClass?: string;
  105. classBinding?: string;
  106. staticStyle?: string;
  107. styleBinding?: string;
  108. events?: ASTElementHandlers;
  109. nativeEvents?: ASTElementHandlers;
  110. transition?: string | true;
  111. transitionOnAppear?: boolean;
  112. model?: {
  113. value: string;
  114. callback: string;
  115. expression: string;
  116. };
  117. directives?: Array<ASTDirective>;
  118. forbidden?: true;
  119. once?: true;
  120. onceProcessed?: boolean;
  121. wrapData?: (code: string) => string;
  122. wrapListeners?: (code: string) => string;
  123. // 2.4 ssr optimization
  124. ssrOptimizability?: number;
  125. // weex specific
  126. appendAsTree?: boolean;
  127. };
  128. declare type ASTExpression = {
  129. type: 2;
  130. expression: string;
  131. text: string;
  132. tokens: Array<string | Object>;
  133. static?: boolean;
  134. // 2.4 ssr optimization
  135. ssrOptimizability?: number;
  136. };
  137. declare type ASTText = {
  138. type: 3;
  139. text: string;
  140. static?: boolean;
  141. isComment?: boolean;
  142. // 2.4 ssr optimization
  143. ssrOptimizability?: number;
  144. };
  145. // SFC-parser related declarations
  146. // an object format describing a single-file component.
  147. declare type SFCDescriptor = {
  148. template: ?SFCBlock;
  149. script: ?SFCBlock;
  150. styles: Array<SFCBlock>;
  151. customBlocks: Array<SFCBlock>;
  152. };
  153. declare type SFCBlock = {
  154. type: string;
  155. content: string;
  156. attrs: {[attribute:string]: string};
  157. start?: number;
  158. end?: number;
  159. lang?: string;
  160. src?: string;
  161. scoped?: boolean;
  162. module?: string | boolean;
  163. };