compiler.js 4.9 KB

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