compiler.js 5.1 KB

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