compiler.js 5.1 KB

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