2
0

compiler.js 4.7 KB

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